Add code to persist payments after failed payments. The state machine

rollbacks the transactions, with this we keep record of what went wrong.
This commit is contained in:
Luis Ramos
2020-07-25 20:55:25 +01:00
parent e80337a458
commit 734fce5ce7

View File

@@ -152,11 +152,23 @@ class CheckoutController < Spree::StoreController
checkout_succeeded
redirect_to(order_path(@order)) && return
else
persist_all_payments if @order.state == "payment"
flash[:error] = order_error
checkout_failed
end
end
# When a payment fails, the order state machine rollbacks all transactions
# Here we ensure we always persist all payments
def persist_all_payments
@order.payments.each do |payment|
original_payment_state = payment.state
if original_payment_state != payment.reload.state
payment.update(state: original_payment_state)
end
end
end
def checkout_workflow(shipping_method_id)
while @order.state != "complete"
if @order.state == "payment"