From a5629da994554c07d9fd00e6628ec19fccc18aa1 Mon Sep 17 00:00:00 2001 From: Ikraam Ghoor Date: Thu, 27 Jan 2022 11:26:41 +0200 Subject: [PATCH] Fix adding a new customer card in admin Adding a new card in the admin was updating the wrong fields. This adds support for creating a new card using v3_intents. It also support reusing an existing card. --- app/models/spree/payment_method/stripe_credit_card.rb | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/models/spree/payment_method/stripe_credit_card.rb b/app/models/spree/payment_method/stripe_credit_card.rb index fb707580..ba34efd6 100644 --- a/app/models/spree/payment_method/stripe_credit_card.rb +++ b/app/models/spree/payment_method/stripe_credit_card.rb @@ -112,7 +112,7 @@ def create_profile(payment) }.merge! address_for(payment) source = update_source!(payment.source) - if source.number.blank? && source.gateway_payment_profile_id.present? + if reuse_existing_source?(source) if v3_intents? creditcard = ActiveMerchant::Billing::StripeGateway::StripePaymentToken.new('id' => source.gateway_payment_profile_id) else @@ -124,7 +124,7 @@ def create_profile(payment) response = gateway.store(creditcard, options) if response.success? - if v3_intents? + if v3_intents? && reuse_existing_source?(source) payment.source.update!( cc_type: payment.source.cc_type, gateway_customer_profile_id: response.params['customer'], @@ -212,6 +212,10 @@ def perform_refund(payment) refund end + + def reuse_existing_source?(source) + source.number.blank? && source.gateway_payment_profile_id.present? + end end end end