mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-03-13 04:00:21 +00:00
Merge pull request #7769 from Matt-Yorkley/payment-status-checking
Stripe: payment status debugging
This commit is contained in:
@@ -3,9 +3,15 @@
|
||||
# This class validates if a given payment intent ID is valid in Stripe
|
||||
module Stripe
|
||||
class PaymentIntentValidator
|
||||
def call(payment_intent_id, stripe_account_id)
|
||||
payment_intent_response = Stripe::PaymentIntent.retrieve(payment_intent_id,
|
||||
stripe_account: stripe_account_id)
|
||||
def initialize(payment)
|
||||
@payment = payment
|
||||
end
|
||||
|
||||
def call
|
||||
payment_intent_response = Stripe::PaymentIntent.retrieve(
|
||||
payment_intent_id,
|
||||
stripe_account: stripe_account_id
|
||||
)
|
||||
|
||||
raise_if_last_payment_error_present(payment_intent_response)
|
||||
|
||||
@@ -14,6 +20,18 @@ module Stripe
|
||||
|
||||
private
|
||||
|
||||
attr_accessor :payment
|
||||
|
||||
def payment_intent_id
|
||||
payment.response_code
|
||||
end
|
||||
|
||||
def stripe_account_id
|
||||
enterprise_id = payment.payment_method&.preferred_enterprise_id
|
||||
|
||||
StripeAccount.find_by(enterprise_id: enterprise_id)&.stripe_user_id
|
||||
end
|
||||
|
||||
def raise_if_last_payment_error_present(payment_intent_response)
|
||||
return unless payment_intent_response.respond_to?(:last_payment_error) &&
|
||||
payment_intent_response.last_payment_error.present?
|
||||
|
||||
Reference in New Issue
Block a user