Refactor payment intent status checking and return "ok" if the payment has already been processed successfully in a previous request

If the page is reloaded after the payment has already gone through, we can skip the processing and give a non-error response; the payment is already completed and Stripe's response confirms it was successful.
This commit is contained in:
Matt-Yorkley
2021-05-16 12:28:55 +01:00
parent 2b9f9fce86
commit fd021d4778

View File

@@ -31,6 +31,7 @@ class ProcessPaymentIntent
def call!
return Result.new(ok: false) unless valid?
return Result.new(ok: true) if already_processed?
OrderWorkflow.new(order).next
@@ -56,10 +57,17 @@ class ProcessPaymentIntent
end
def ready_for_capture?
payment_intent_response = Stripe::PaymentIntentValidator.new.
call(payment_intent, stripe_account_id)
payment_intent_status == 'requires_capture'
end
payment_intent_response.status == 'requires_capture'
def already_processed?
payment_intent_status == 'succeeded'
end
def payment_intent_status
@payment_intent_status ||= Stripe::PaymentIntentValidator.new.
call(payment_intent, stripe_account_id).
status
end
def matches_last_payment?