mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-02-09 23:06:06 +00:00
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:
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user