fix(billing): clear pending switch marker on stripe preflight failures
This commit is contained in:
@@ -42,6 +42,12 @@ class Enterprise::Billing::SwitchCurrencyService
|
||||
# The Stripe swap self-reverted, so drop the pending marker and surface a single error type.
|
||||
clear_pending
|
||||
raise Error, e.message
|
||||
rescue Stripe::StripeError
|
||||
# A raw Stripe failure in the preflight (payment-method/location sync) happens before any
|
||||
# subscription change, so drop the marker too — otherwise a transient blip locks out switching
|
||||
# until the stale timeout. A post-success persist failure isn't a Stripe error and is left for the webhook.
|
||||
clear_pending
|
||||
raise
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -127,6 +127,13 @@ describe Enterprise::Billing::SwitchCurrencyService do
|
||||
expect(account.reload.custom_attributes['billing_currency_switch_pending']).to be_present
|
||||
end
|
||||
|
||||
it 'clears the pending marker when a stripe preflight call fails' do
|
||||
allow(Stripe::Customer).to receive(:retrieve).and_raise(Stripe::StripeError.new('customer temporarily unavailable'))
|
||||
|
||||
expect { service.perform }.to raise_error(Stripe::StripeError)
|
||||
expect(account.reload.custom_attributes).not_to have_key('billing_currency_switch_pending')
|
||||
end
|
||||
|
||||
it 'proceeds when the in-progress marker is stale' do
|
||||
account.update!(custom_attributes: account.custom_attributes.merge(
|
||||
'billing_currency_switch_pending' => { 'currency' => 'brl', 'started_at' => 1.hour.ago.to_i }
|
||||
|
||||
Reference in New Issue
Block a user