From 65d9325287bc73cb4610300ffbdcf6546faf06ff Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Wed, 9 Jun 2021 22:35:02 +0100 Subject: [PATCH] Add #stripe_status helper method to Payment This method could definitely be used elsewhere, but is currently most useful in debugging; at any time in the console you can bring up a payment object and call #stripe_status on it, and it'll make a live call to Stripe and tell you exactly what state the payment is in on the Stripe side. --- app/models/spree/payment.rb | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/app/models/spree/payment.rb b/app/models/spree/payment.rb index 3bb4b60858..1990778eaa 100644 --- a/app/models/spree/payment.rb +++ b/app/models/spree/payment.rb @@ -153,6 +153,17 @@ module Spree I18n.t('payment_method_fee') end + # Returns the current payment status from a live call to the Stripe API. + # Returns nil if the payment is not a Stripe payment or does not have a payment intent. + # If the payment requires authorization the status will be "requires_action". + # If the payment has been captured the status will be "succeeded". + # https://stripe.com/docs/api/payment_intents/object#payment_intent_object-status + def stripe_status + return if response_code.blank? + + Stripe::PaymentIntentValidator.new.call(self).status + end + def clear_authorization_url update_attribute(:cvv_response_message, nil) end