From f83d0a766f86896d211cc0ffebf361f9b0193abc Mon Sep 17 00:00:00 2001 From: Matt-Yorkley <9029026+Matt-Yorkley@users.noreply.github.com> Date: Sun, 14 Nov 2021 11:39:36 +0000 Subject: [PATCH] Memoize Checkout#valid_payment_intent_provided? --- app/controllers/checkout_controller.rb | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 6b0f08ba99..8567f30502 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -148,12 +148,14 @@ class CheckoutController < ::BaseController end def valid_payment_intent_provided? - return false unless params["payment_intent"]&.starts_with?("pi_") + @valid_payment_intent_provided ||= begin + return false unless params["payment_intent"]&.starts_with?("pi_") - last_payment = OrderPaymentFinder.new(@order).last_payment - @order.state == "payment" && - last_payment&.state == "requires_authorization" && - last_payment&.response_code == params["payment_intent"] + last_payment = OrderPaymentFinder.new(@order).last_payment + @order.state == "payment" && + last_payment&.state == "requires_authorization" && + last_payment&.response_code == params["payment_intent"] + end end def handle_redirect_from_stripe