From 19042e0d37e07e158af5ef2b032cee8f6bb43f96 Mon Sep 17 00:00:00 2001 From: luisramos0 Date: Fri, 7 Feb 2020 11:30:03 +0000 Subject: [PATCH] Make checkout controller able to receive a redirect from stripe with a payment_intent as parameter --- app/controllers/checkout_controller.rb | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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"