Memoize Checkout#valid_payment_intent_provided?

This commit is contained in:
Matt-Yorkley
2021-11-14 11:39:36 +00:00
parent 0a22a3baa6
commit f83d0a766f

View File

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