From 938b5045efd170c28873beb34b2e52c6ad8a1fc7 Mon Sep 17 00:00:00 2001 From: Alexey Boldak Date: Sun, 29 May 2022 14:17:25 +0300 Subject: [PATCH] Do not set @client_secret and @pk_key if order has no valid payments --- .../spree/checkout_controller_decorator.rb | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) 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