Handling Orders
This section explains how to create and manage orders for headless storefronts.
Creating an order from a cart
To successfully complete this section, you must first create a cart with a redirect URL. For instructions on how to create a cart, see the Carts article in this guide.
Adding a billing address
You can change a cart to a checkout by adding a billing address. To add a checkout billing address, send a request to the Add Checkout Billing Address endpoint. Your checkoutId will correspond with the cart ID returned by the Create a Cart endpoint. For an example request, see the End-to-End Guide: Headless Checkout Flow with REST Management APIs.
Adding a consignment
Now that you have transformed your headless cart into a checkout, you need to add a consignment with a shipping address, line items, and a shipping option. You can do so by adding and then updating a consignment. For an example request, see the End-to-End Guide: Headless Checkout Flow with REST Management APIs.
Creating an order
Now that you have added a billing address and a consignment to your checkout, you can create an order by sending a request to the Create an Order endpoint. When a new order is created by API, the order status is set to incomplete.
Request
Response
Processing payments
Depending on the shopper’s card-on-file authorization, you can use one of the following methods to process the payment.
- Stored Card – A shopper has authorized a merchant to store their payment details.
- Credit Card – A shopper has not authorized a merchant to store their payment details.
Using the Stored Card method
- Start by retrieving the available payment methods. Send a
GETrequest to theGet Accepted Payment Methodsendpoint.
- To process a payment for an order, you must make a call to the Payments API, which requires a Payment Access Token. To generate a payment access token, or PAT, send a request to the Create Payment Access Token endpoint.
Make a note of the access token id. This token is required in the subsequent order payment call to the Process Payment endpoint.
- Send a request to the Process Payment endpoint. The headers to process a payment are different from the headers you normally send with a BigCommerce API. The
Authorizationbearer token is the PAT ID returned by the Create Payment Access Token endpoint (step two). To learn more, see Payments API: Stored Cards.
Request
Response
Using the Credit Card method
If a shopper does not have a payment method saved on file, you can process a payment using a credit card. There are two steps to this method:
-
Send a request to the Create Payment Access Token endpoint to get the payment access token that must be passed using the
Authorizationheader to process the payment. -
Send a request to the Process Payment endpoint. The headers to process a payment are different from the headers you normally send with a BigCommerce API. The
Authorizationbearer token is the PAT ID returned by the Create Payment Access Token endpoint (step one). To learn more, see Payments API: Credit Cards.
A successful transaction will return a success status. The order status is then automatically changed to Awaiting Fulfillment. If you get a different response, see Error Codes for troubleshooting.