mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Record invalid payment states for debugging
We observed invalid payment states in Bugsnag but we don't actually know in which state the payment intent was in. From the context we can guess that it was "succeeded" but it would be good to validate this. And in the future it would be good to know if there are other invalid states we can end up in. The notification to Bugsnag happens in another part of the code.
This commit is contained in:
@@ -294,7 +294,7 @@ en:
|
||||
error: Error
|
||||
processing_payment: "Processing payment..."
|
||||
no_pending_payments: "No pending payments"
|
||||
invalid_payment_state: "Invalid payment state"
|
||||
invalid_payment_state: "Invalid payment state: %{state}"
|
||||
filter_results: Filter Results
|
||||
quantity: Quantity
|
||||
pick_up: Pick up
|
||||
|
||||
@@ -23,9 +23,10 @@ module Stripe
|
||||
end
|
||||
|
||||
def raise_if_not_in_capture_state(payment_intent_response)
|
||||
return unless payment_intent_response.status != 'requires_capture'
|
||||
state = payment_intent_response.status
|
||||
return unless state != 'requires_capture'
|
||||
|
||||
raise Stripe::StripeError, I18n.t(:invalid_payment_state)
|
||||
raise Stripe::StripeError, I18n.t(:invalid_payment_state, state: state)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
@@ -40,7 +40,7 @@ module Stripe
|
||||
it "raises Stripe error with an invalid_payment_state message" do
|
||||
expect {
|
||||
validator.call(payment_intent_id, stripe_account_id)
|
||||
}.to raise_error Stripe::StripeError, "Invalid payment state"
|
||||
}.to raise_error Stripe::StripeError, "Invalid payment state: failed"
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
@@ -39,6 +39,16 @@ describe Spree::Gateway::StripeSCA, type: :model do
|
||||
|
||||
expect(response.success?).to eq true
|
||||
end
|
||||
|
||||
it "provides an error message to help developer debug" do
|
||||
stub_request(:get, "https://api.stripe.com/v1/payment_intents/12345").
|
||||
to_return(status: 200, body: capture_successful)
|
||||
|
||||
response = subject.purchase(order.total, credit_card, gateway_options)
|
||||
|
||||
expect(response.success?).to eq false
|
||||
expect(response.message).to eq "Invalid payment state: succeeded"
|
||||
end
|
||||
end
|
||||
|
||||
def payment_intent(amount, status)
|
||||
|
||||
Reference in New Issue
Block a user