Merge pull request #7769 from Matt-Yorkley/payment-status-checking

Stripe: payment status debugging
This commit is contained in:
Andy Brett
2021-09-08 15:21:38 -07:00
committed by GitHub
8 changed files with 129 additions and 34 deletions

View File

@@ -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?