Who this is for. Developers who build the steps after payment, or connect orders to another system. After this page you know what exists once a checkout is paid, which record to change afterwards, and how to set the format of order numbers.
When a checkout becomes an order
A checkout becomes an order once its invoice is fully paid. Where that happens depends on the payment: in the purchase call itself when the provider settles the whole amount there, and for a free checkout; or later, from the provider's webhook, when the payment completes away from the page (The payment-processing page and webhooks). A checkout whose payment is waiting for authentication or a redirect, or covers only part of the total, is split from its cart and kept until the payment resolves (From cart to order).
What the conversion does, in order
The conversion runs in one database transaction, so it completes as a whole or not at all:
- A new order is created with a uuid of its own, not the checkout's.
- Every field the two records share is copied to the order: the person, both addresses, the currency, the totals and the rest.
- The checkout's lines become the order's lines: each line now belongs to the order and no longer to the cart. The metadata field values, the record of applied discounts and the fulfilments move to the order with them.
- The purchased lines leave the cart. A cart with nothing left in it is deleted; a cart that still holds lines the shopper did not check out keeps them for later.
- An order number is generated (Order numbers).
- The checkout record is removed and the order is saved.
- The order's date (
ordered) is set, and each invoice of the checkout is re-pointed to the order. - The order's financial status is worked out from its invoices, and the transaction commits.
Most of what the order gathers was made earlier. The fulfilments were created when shipping was chosen, the invoice by the purchase call, and the payment's transactions sit on the invoice. The conversion adds the order itself and its number, and moves the rest across.
The shopper's browser is sent to the order-complete page, /checkout/complete/<order uuid>, with the order's uuid, which the purchase response also carries (The payment-processing page and webhooks).
The record to change after payment
Once the conversion has run, the checkout has done its job and is gone. Everything that happens to the purchase from then on happens to the order and the records around it:
| To change | Change this |
|---|---|
| What the customer paid, or money returned | The invoice and its transactions, or a refund (Invoices, transactions and refunds) |
| Where the goods are | A fulfilment's status (Stock, fulfilment and the member's order screens) |
| The order's financial status | Its invoices and refunds: the status is worked out from them every time the order is saved |
| The order's fulfilment status | Its fulfilments: the status is worked out from them every time the order is saved |
Code that keeps a checkout's id or uuid, to find the purchase later, switches to the order's uuid at this point. The money records keep their history: a transaction is final once saved, an invoice moves forward through its statuses and stays once issued, and a refund is final once it has succeeded, failed or been cancelled.
The financial status
getFinancialStatus() returns the value and getFinancialStatusDisplay() the admin's label:
| Value | Label |
|---|---|
unpaid | Unpaid |
authorized | Payment Authorized |
partially_paid | Partially Paid |
paid | Paid |
partially_refunded | Partially Refunded |
refunded | Fully Refunded |
voided | Payment Voided |
The fulfilment status, and what a customer sees at each stage, are on Stock, fulfilment and the member's order screens.
The order's currency and the language of its lines
The order is in the checkout's currency, copied across with the totals, and so are its invoices and every payment and refund on them (The currency a payment is taken in). Read the code with getCurrencyCode(), and print amounts with the money getters, which format in the order's own currency. Never put a currency symbol in front of an amount by hand: on a multi-currency store the same template shows orders in several currencies.
The order's lines are the checkout's lines, so each name is the one stored when the item was added to the cart: the product's name in the client's default language (Its currency, and the language of its lines). On a multilingual site, print a line in the shopper's language from its product's description, as the member's order screen on Stock, fulfilment and the member's order screens does.
Wherever a template has the order, such as the member's order screen or a job's email template, the summary reads: