diff --git a/app/controllers/checkout_controller.rb b/app/controllers/checkout_controller.rb index 90bc4357d2..f593e8896d 100644 --- a/app/controllers/checkout_controller.rb +++ b/app/controllers/checkout_controller.rb @@ -35,6 +35,16 @@ class CheckoutController < Spree::StoreController rescue_from Spree::Core::GatewayError, with: :rescue_from_spree_gateway_error def edit + if valid_payment_intent_provided? + if advance_order_state(@order) && order_complete? + checkout_succeeded + redirect_to(order_path(@order)) && return + else + flash[:error] = order_workflow_error + current_order.updater.shipping_address_from_distributor + end + end + # This is only required because of spree_paypal_express. If we implement # a version of paypal that uses this controller, and more specifically # the #update_failed method, then we can remove this call @@ -151,6 +161,13 @@ class CheckoutController < Spree::StoreController end 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"] + end + def checkout_workflow(shipping_method_id) while @order.state != "complete" if @order.state == "payment"