Create a cart and go to checkout#
This guide walks through a checkout you build yourself: creating a cart, adding products, setting a shipping address and method, then confirming the cart to receive an order with a checkout URL.
Using the hosted checkout? Then only steps 1 and 2 are yours:
create the cart, add the items and send the customer to cart.checkout.url. The hosted checkout
asks for the addresses, shipping and payment, and calls confirmCart itself. Don't call
confirmCart from your storefront in that case.
Overview#
- Create an empty cart with
createCart - Add products by SKU with
addItemsToCart - Set a shipping address with
addShippingAddressToCart - Choose a shipping method with
addShippingMethodToCart - Verify the cart is valid, then confirm it with
confirmCart - Redirect the customer to the checkout URL
Step 1 — Create a cart#
Input: CartInput!. Every field is optional. With a storefront token the cart belongs to the token's channel; with an API key pass channel_id.
Returns: Cart
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID of the cart |
number | String! | Required | Cart number |
total | Money! | Required | Total value |
subtotal | Money! | Required | Total before discounts |
Save the returned cart.id — you'll pass it as cart_id in every subsequent mutation.
Pass country_code to pre-set the delivery country and ensure correct tax calculation from the
start. See createCart for all fields.
Step 2 — Add items#
Input: AddItemsToCartInput!
| Name | Type | Required | Description |
|---|---|---|---|
cart_id | String! | Required | ID of the cart returned in step 1. |
items | [ItemInput!]!▾ | Required | Items to add. |
Returns: Cart
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID of the cart |
number | String! | Required | Cart number |
total | Money! | Required | Total value |
subtotal | Money! | Required | Total before discounts |
Step 3 — Set a shipping address#
Input: AddShippingAddressToCartInput!
| Name | Type | Required | Description |
|---|---|---|---|
cart_id | String! | Required | ID of the cart. |
address | AddressInput!▾ | Required | Delivery address. |
Returns: Cart
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID of the cart |
number | String! | Required | Cart number |
total | Money! | Required | Total value |
subtotal | Money! | Required | Total before discounts |
Step 4 — Choose a shipping method#
First, query the available shipping methods for your channel:
Then apply one to the cart:
Input: AddShippingMethodToCartInput!
| Name | Type | Required | Description |
|---|---|---|---|
cart_id | String! | Required | ID of the cart. |
method_id | String! | Required | ID of the shipping method to apply. |
Returns: Cart
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID of the cart |
number | String! | Required | Cart number |
total | Money! | Required | Total value |
subtotal | Money! | Required | Total before discounts |
Step 5 — Verify and confirm#
Before confirming, check that the cart has no validation errors:
Once valid, confirm the cart to convert it into an order:
Input: ConfirmCartInput!
| Name | Type | Required | Description |
|---|---|---|---|
cart_id | String! | Required | ID of the cart to confirm. |
Returns: Order
| Name | Type | Required | Description |
|---|---|---|---|
id | ID! | Required | The ID |
number | String! | Required | Order number |
total | Money! | Required | Total value |
currency | Currency! | Required | Currency code |
Redirect the customer to order.checkout.url to complete payment.
Notes#
confirmCartfails ifcart.validation_errorsis non-empty — ensure items, shipping address, and shipping method are all set.Moneyvalues (total,subtotal) are integers in cents — e.g.2499means € 24,99.- To add a billing address before confirming, use
addBillingAddressToCartwith the sameAddressInputshape. - To add a payment method before confirming, use
addPaymentMethodToCartwithmethod_idand the requiredissuer_id. - See Authentication for how to pass your API key.