Merge pull request #10914 from abdellani/fix-stripe-sca-failure

redirect user to payment when the card doesn't have enough credit
This commit is contained in:
Filipe
2023-06-28 19:58:18 +01:00
committed by GitHub
3 changed files with 38 additions and 21 deletions

View File

@@ -41,8 +41,8 @@ module OrderCompletion
main_app.order_path(@order, order_token: @order.token)
end
def order_failed_route
main_app.checkout_path
def order_failed_route(step: 'details')
main_app.checkout_step_path(step:)
end
def order_invalid_for_checkout?
@@ -60,8 +60,8 @@ module OrderCompletion
def process_payment_completion!
unless @order.process_payments!
processing_failed
return redirect_to order_failed_route
payment_failed
return redirect_to order_failed_route(step: 'payment')
end
if OrderWorkflow.new(@order).next && @order.complete?
@@ -82,12 +82,20 @@ module OrderCompletion
order_completion_reset(@order)
end
def processing_failed(error = RuntimeError.new(order_processing_error))
def payment_failed
notify_failure
end
def processing_failed
notify_failure
Checkout::PostCheckoutActions.new(@order).failure
end
def notify_failure(error = RuntimeError.new(order_processing_error))
Bugsnag.notify(error) do |payload|
payload.add_metadata :order, @order
end
flash[:error] = order_processing_error if flash.blank?
Checkout::PostCheckoutActions.new(@order).failure
end
def order_processing_error

View File

@@ -53,7 +53,7 @@ module PaymentGateways
it "redirects to checkout state path" do
expect(post(:confirm, params: { payment_method_id: payment_method.id })).
to redirect_to checkout_path
to redirect_to checkout_step_path(step: :payment)
expect(flash[:error]).to eq(
'Payment could not be processed, please check the details you entered'

View File

@@ -44,6 +44,7 @@ module PaymentGateways
order.update_attribute :state, "payment"
order.payments << payment
order.update_attribute :state, "confirmation"
end
it "creates a customer record" do
@@ -72,20 +73,28 @@ Please try again!"
end
end
context "using split checkout" do
before do
order.update_attribute :state, "confirmation"
end
it "completes the order and redirects to the order confirmation page" do
expect(controller).to receive(:processing_succeeded).and_call_original
expect(controller).to receive(:order_completion_reset).and_call_original
it "completes the order and redirects to the order confirmation page" do
expect(controller).to receive(:processing_succeeded).and_call_original
expect(controller).to receive(:order_completion_reset).and_call_original
get :confirm, params: { payment_intent: "pi_123" }
get :confirm, params: { payment_intent: "pi_123" }
expect(order.completed?).to be true
expect(response).to redirect_to order_path(order, order_token: order.token)
expect(flash[:notice]).to eq 'Your order has been processed successfully'
end
expect(order.completed?).to be true
expect(response).to redirect_to order_path(order, order_token: order.token)
expect(flash[:notice]).to eq 'Your order has been processed successfully'
context 'when order completion fails' do
it "redirects to checkout state path" do
expect(controller).to receive(:process_payment_completion!).and_call_original
allow(order).to receive(:process_payments!).and_return(false)
expect(
get(:confirm, params: { payment_intent: "pi_123" })
).to redirect_to checkout_step_path(step: :payment)
expect(flash[:error]).to eq(
'Payment could not be processed, please check the details you entered'
)
end
end
end
@@ -99,7 +108,7 @@ Please try again!"
get :confirm, params: { payment_intent: "pi_123" }
expect(order.completed?).to be false
expect(response).to redirect_to checkout_path
expect(response).to redirect_to checkout_step_path(step: :details)
expect(flash[:error]).to eq "Payment could not be processed, \
please check the details you entered"
end
@@ -112,7 +121,7 @@ please check the details you entered"
get :confirm, params: { payment_intent: "pi_666" }
expect(order.completed?).to be false
expect(response).to redirect_to checkout_path
expect(response).to redirect_to checkout_step_path(step: :details)
expect(flash[:error]).to eq "Payment could not be processed, \
please check the details you entered"
end
@@ -130,7 +139,7 @@ please check the details you entered"
get :confirm, params: { payment_intent: "pi_123" }
expect(order.completed?).to be false
expect(response).to redirect_to checkout_path
expect(response).to redirect_to checkout_step_path(step: :details)
expect(flash[:error]).to eq "Payment could not be processed, \
please check the details you entered"
end