From d191603620485e794728343d5c8630221352979c Mon Sep 17 00:00:00 2001 From: Tanmay Deep Sharma Date: Thu, 11 Jun 2026 18:02:27 +0530 Subject: [PATCH] refactor(billing): rename coerce to to_supported and fix find_plan param name --- enterprise/app/services/enterprise/billing/currencies.rb | 8 ++++---- .../enterprise/billing/handle_stripe_event_service.rb | 4 ++-- .../app/services/enterprise/billing/plan_configuration.rb | 2 +- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/enterprise/app/services/enterprise/billing/currencies.rb b/enterprise/app/services/enterprise/billing/currencies.rb index 783ba7547..c19892cd2 100644 --- a/enterprise/app/services/enterprise/billing/currencies.rb +++ b/enterprise/app/services/enterprise/billing/currencies.rb @@ -29,8 +29,8 @@ module Enterprise::Billing::Currencies SUPPORTED.include?(normalize(code)) end - # Coerce arbitrary input to a usable supported code, else DEFAULT. - def coerce(code) + # Map arbitrary input to a supported code, else DEFAULT. + def to_supported(code) supported?(code) ? normalize(code) : DEFAULT end @@ -39,10 +39,10 @@ module Enterprise::Billing::Currencies end def country_for(code) - COUNTRY_BY_CURRENCY[coerce(code)] + COUNTRY_BY_CURRENCY[to_supported(code)] end def preferred_locale_for(code) - PREFERRED_LOCALE_BY_CURRENCY[coerce(code)] + PREFERRED_LOCALE_BY_CURRENCY[to_supported(code)] end end diff --git a/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb b/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb index 927374c37..8c61e0bbf 100644 --- a/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb +++ b/enterprise/app/services/enterprise/billing/handle_stripe_event_service.rb @@ -151,7 +151,7 @@ class Enterprise::Billing::HandleStripeEventService @account ||= Account.where("custom_attributes->>'stripe_customer_id' = ?", subscription.customer).first end - def find_plan(plan_id) - Enterprise::Billing::PlanConfiguration.find_plan_by_product_id(plan_id) + def find_plan(product_id) + Enterprise::Billing::PlanConfiguration.find_plan_by_product_id(product_id) end end diff --git a/enterprise/app/services/enterprise/billing/plan_configuration.rb b/enterprise/app/services/enterprise/billing/plan_configuration.rb index 389dc4568..347fbc330 100644 --- a/enterprise/app/services/enterprise/billing/plan_configuration.rb +++ b/enterprise/app/services/enterprise/billing/plan_configuration.rb @@ -25,7 +25,7 @@ module Enterprise::Billing::PlanConfiguration # Price id for `plan` in `currency`, falling back to usd then any configured price. def price_id_for(plan, currency) by_currency = price_ids_by_currency(plan) - code = Enterprise::Billing::Currencies.coerce(currency) + code = Enterprise::Billing::Currencies.to_supported(currency) (by_currency[code].presence || by_currency[Enterprise::Billing::Currencies::DEFAULT].presence ||