From 0768ce70ab6a44306ff15c97b69be542588f7679 Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma Date: Tue, 2 Jun 2026 16:17:02 +0530 Subject: [PATCH] refactor(billing): require CHATWOOT_CLOUD_TOPUP_OPTIONS, drop hardcoded fallback --- .../enterprise/billing/topup_checkout_service.rb | 15 +-------------- .../billing/topup_checkout_service_spec.rb | 9 +++++++++ 2 files changed, 10 insertions(+), 14 deletions(-) diff --git a/enterprise/app/services/enterprise/billing/topup_checkout_service.rb b/enterprise/app/services/enterprise/billing/topup_checkout_service.rb index e9fd000b8..e896a4d48 100644 --- a/enterprise/app/services/enterprise/billing/topup_checkout_service.rb +++ b/enterprise/app/services/enterprise/billing/topup_checkout_service.rb @@ -5,17 +5,6 @@ class Enterprise::Billing::TopupCheckoutService TOPUP_OPTIONS_CONFIG = 'CHATWOOT_CLOUD_TOPUP_OPTIONS'.freeze - # Used only when CHATWOOT_CLOUD_TOPUP_OPTIONS is not configured, so the - # billing page never breaks during rollout. Real rates live in the config. - FALLBACK_OPTIONS = { - 'usd' => [ - { 'credits' => 1000, 'amount' => 20.0 }, - { 'credits' => 2500, 'amount' => 50.0 }, - { 'credits' => 6000, 'amount' => 100.0 }, - { 'credits' => 12_000, 'amount' => 200.0 } - ] - }.freeze - pattr_initialize [:account!] # Topup packages for the account's billing currency, used by the controller @@ -124,8 +113,6 @@ class Enterprise::Billing::TopupCheckoutService def configured_options config = InstallationConfig.find_by(name: TOPUP_OPTIONS_CONFIG)&.value config = JSON.parse(config) if config.is_a?(String) - config.presence || FALLBACK_OPTIONS - rescue JSON::ParserError - FALLBACK_OPTIONS + config || {} end end diff --git a/spec/enterprise/services/enterprise/billing/topup_checkout_service_spec.rb b/spec/enterprise/services/enterprise/billing/topup_checkout_service_spec.rb index fa4c052a1..2629bdbd9 100644 --- a/spec/enterprise/services/enterprise/billing/topup_checkout_service_spec.rb +++ b/spec/enterprise/services/enterprise/billing/topup_checkout_service_spec.rb @@ -15,6 +15,15 @@ describe Enterprise::Billing::TopupCheckoutService do { 'name' => 'Business', 'product_id' => ['prod_business'], 'price_ids' => ['price_business'] } ]) + create(:installation_config, name: 'CHATWOOT_CLOUD_TOPUP_OPTIONS', value: { + 'usd' => [ + { 'credits' => 1000, 'amount' => 20.0 }, + { 'credits' => 2500, 'amount' => 50.0 }, + { 'credits' => 6000, 'amount' => 100.0 }, + { 'credits' => 12_000, 'amount' => 200.0 } + ] + }) + account.update!( custom_attributes: { plan_name: 'Business', stripe_customer_id: stripe_customer_id }, limits: { 'captain_responses' => 500 }