diff --git a/lib/spree_frontend/controllers/spree/checkout_controller_decorator.rb b/lib/spree_frontend/controllers/spree/checkout_controller_decorator.rb index dacfd8dd..5ef5abc5 100644 --- a/lib/spree_frontend/controllers/spree/checkout_controller_decorator.rb +++ b/lib/spree_frontend/controllers/spree/checkout_controller_decorator.rb @@ -6,10 +6,15 @@ def self.prepended(base) def process_payments_and_set_keys @order.tap do |order| + @client_secret = nil + @pk_key = nil + order.process_payments! - order.reload.payments.valid.where.not(intent_client_key: nil).last.tap do |payment| - @client_secret = payment.intent_client_key - @pk_key = payment.payment_method.preferred_publishable_key + last_valid_payment = order.reload.payments.valid.where.not(intent_client_key: nil).last + + if last_valid_payment + @client_secret = last_valid_payment.intent_client_key + @pk_key = last_valid_payment.payment_method.preferred_publishable_key end end end