Use OrderPaymentFinder methods instead of payments.last and payments.pending.last

This commit is contained in:
Luis Ramos
2020-04-18 11:56:52 +01:00
committed by Maikel Linke
parent 52becf6abc
commit d482cccefe
5 changed files with 27 additions and 15 deletions

View File

@@ -153,10 +153,12 @@ class CheckoutController < Spree::StoreController
end
def valid_payment_intent_provided?
params["payment_intent"]&.starts_with?("pi_") &&
@order.state == "payment" &&
@order.payments.last.state == "pending" &&
@order.payments.last.response_code == params["payment_intent"]
return false unless params["payment_intent"]&.starts_with?("pi_")
last_payment = OrderPaymentFinder.new(@order).last_payment
@order.state == "payment" &&
last_payment&.state == "pending" &&
last_payment&.response_code == params["payment_intent"]
end
def handle_redirect_from_stripe