Orders flow through a state machine, beginning at a cart state and ending up at a complete state. The intermediary states can be configured using the Checkout Flow API.
The default states are as follows:
cart
address
delivery
payment
confirm
complete
The payment state will only be triggered if payment_required? returns true.
The confirm state will only be triggered if confirmation_required? returns true.
The complete state can only be reached in one of two ways:
No payment is required on the order.
Payment is required on the order, and at least the order total has been received as payment.
Assuming that an order meets the criteria for the next state, you will be able to transition it to the next state by calling next on that object. If this returns false, then the order does not meet the criteria. To work out why it cannot transition, check the result of an errors method call.
Changing state from payment to complete require at least one payment that completed.!
so
payment = @order.payments.create({
amount: @order.total,
payment_method: payment_method,
source: credit_card, })
payment.complete!
@order.next!