Order States

A new order starts in the Checkout state, where it is editable. When a payment is initiated, the order transitions to Processing. If the payment is accepted, the order advances to the Accepted state; if it is declined, the order returns to Checkout. After all conditions are met, the order finally reaches the Completed state. However, if there's a failure after acceptance, it will transition to Declined.

Order states

  • Checkout : The order starts here, where it can be edited.
  • Processing : The order is considered validated and ready to be accepted, if any changes are required, it will first need to change back to the Checkout state.
  • Accepted : The customer has completed their checkout. The order is more or less locked, but additional information received from external systems can be added.
  • Completed : All payments are accepted, shippings ready and the order is completed. It can move on to after payment actions.
  • Declined : One of the payments were declined after the customer left the checkout process, the order is cancelled.

Example of State Transitions

The state of an order can change in various ways depending on the customer's actions and the payment process. Here's a simple example of how the states can evolve:

  1. The payment process begins, and the state changes to Processing . No changes can be made to the order at this point.
  2. If the customer cancels payment to modify the order, such as increasing the quantity of an item, the state reverts to Checkout .
  3. The payment process is restarted, and the state returns to Processing .
  4. Once the payment is successfully completed, the state changes to Accepted .
  5. After confirmation by the payment provider, the state updates to Completed .

Order states example

Payments typically initiate state changes since they are closely tied to the events that trigger these transitions, such as a customer clicking the buy button, completing the payment process, or the payment provider accepting the payment. When multiple payments are involved, the process becomes more complex, but essentially, both payment adapters participate in driving the state changes. In most cases, the adapters will agree on the state, but occasionally, one payment may be completed before the other.

Below is a sequence diagram illustrating how this process might unfold.

Order state sequence

Copyright © Norce 2024. All right reserved.