diff --git a/config/locales/en.yml b/config/locales/en.yml index 87ffc7298..5ac671fac 100644 --- a/config/locales/en.yml +++ b/config/locales/en.yml @@ -169,7 +169,7 @@ en: invalid_option: Invalid topup option plan_not_eligible: Top-ups are only available for paid plans. Please upgrade your plan first. stripe_customer_not_configured: Stripe customer not configured - no_payment_method: No payment methods found. Please add a payment method before making a purchase. + no_payment_method: No payment method available for your billing currency. Please add a card before making a purchase. billing: currency_required: Currency is required currency_switch_unavailable: Currency switching is not available for this account diff --git a/enterprise/app/services/enterprise/billing/default_payment_method_reconciler.rb b/enterprise/app/services/enterprise/billing/default_payment_method_reconciler.rb index cbadc2f4e..e2bf4d487 100644 --- a/enterprise/app/services/enterprise/billing/default_payment_method_reconciler.rb +++ b/enterprise/app/services/enterprise/billing/default_payment_method_reconciler.rb @@ -1,16 +1,13 @@ # Ensures the customer's default Stripe payment method can actually bill the given currency. PIX/boleto # are BRL-only, so when an account moves to a currency they can't pay we drop them as the default and # pick a compatible method (a card) if one is attached. Incompatible methods stay attached for later. +# Keyed off invoice_settings.default_payment_method, since that's what Stripe Billing charges. class Enterprise::Billing::DefaultPaymentMethodReconciler pattr_initialize [:account!, :currency!] # Returns the id of a currency-compatible default payment method, or nil if none is available. def reconcile - customer = Stripe::Customer.retrieve(stripe_customer_id) - # Legacy card sources are currency-agnostic. - return customer.default_source if customer.default_source.present? - - current_default = customer.invoice_settings.default_payment_method + current_default = current_default_payment_method return current_default if compatible?(payment_methods.find { |method| method.id == current_default }) compatible = payment_methods.find { |method| compatible?(method) } @@ -22,6 +19,10 @@ class Enterprise::Billing::DefaultPaymentMethodReconciler private + def current_default_payment_method + Stripe::Customer.retrieve(stripe_customer_id).invoice_settings.default_payment_method + end + def payment_methods @payment_methods ||= Stripe::PaymentMethod.list(customer: stripe_customer_id, limit: 100).data end