refactor(billing): rename coerce to to_supported and fix find_plan param name
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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 ||
|
||||
|
||||
Reference in New Issue
Block a user