3. Checkout

Great! We have a Cart with the reference abc which includes our T-Shirt as a custom_item. We'll now take the Cart and convert it to an Order using the Checkout API.‌

Checkout a Cart

You can Checkout a Cart using an existing Customer ID or an object including the customer name and email. In the example below, we'll provide a name and an email, as we have no customers yet 😢.

You'll need to re-authenticate when the access_token expires.‌

Along with the customers information, we must also provide the billing and shipping information. Using cURL we can send the following request:

Replace XXXX below with your access_token.

‌curl -X POST https://api.moltin.com/v2/carts/abc/checkout \
-H "Authorization: Bearer XXXX" \
-H "Content-Type: application/json" \
-d $'{
"data": {
"customer": {
"email": "jamie.barton@moltin.com",
"name": "Jamie Barton"
},
"billing_address": {
"first_name": "Jamie",
"last_name": "Barton",
"company_name": "Moltin",
"line_1": "British India House",
"postcode": "NE1 6UF",
"county": "Tyne & Wear",
"country": "UK"
},
"shipping_address": {
"first_name": "Jamie",
"last_name": "Barton",
"line_1": "British India House",
"postcode": "NE1 6UF",
"county": "Tyne & Wear",
"country": "UK"
}
}
}'

When the request is complete, you'll receive a 201 CREATED response similar below:

‌{
"data": {
"type": "order",
"id": "a4a83c8b-c71d-4eec-8f0a-30c562bd5f3e",
"status": "incomplete",
"payment": "unpaid",
"shipping": "unfulfilled",
"customer": {
"name": "Jamie Barton",
"email": "jamie.barton@moltin.com"
},
"shipping_address": {
"first_name": "Jamie",
"last_name": "Barton",
"phone_number": "",
"company_name": "",
"line_1": "British India House",
"line_2": "",
"city": "",
"postcode": "NE1 6UF",
"county": "Tyne & Wear",
"country": "UK",
"instructions": ""
},
"billing_address": {
"first_name": "Jamie",
"last_name": "Barton",
"company_name": "Moltin",
"line_1": "British India House",
"line_2": "",
"city": "",
"postcode": "NE1 6UF",
"county": "Tyne & Wear",
"country": "UK"
},
"links": {},
"meta": {
"display_price": {
"with_tax": {
"amount": 1998,
"currency": "USD",
"formatted": "$19.98"
},
"without_tax": {
"amount": 1998,
"currency": "USD",
"formatted": "$19.98"
}
},
"timestamps": {
"created_at": "2018-10-12T15:02:37Z",
"updated_at": "2018-10-12T15:02:37Z"
}
},
"relationships": {
"items": {
"data": [
{
"type": "item",
"id": "e2f7aa51-a96a-4d84-b0cb-f8ec35e94f2f"
}
]
}
}
}
}

👆 Congratulations. This is your first Order.‌

Inspecting the Order

You can see in the Order object above we received a few values that make paying for an Order really easy.

Property

Description

id

This is the ID for the newly created order. You'll need this to get the order again in the future or when paying for an order.

status

This will be either complete or incomplete. Useless when grouping orders in your own UI to your customers when they're logged in.

payment

An order will be immediately unpaid, but once you move onto paying for an order, this can be: authorized, paid or refunded.

shipping

This will be either fulfilled or unfulfilled.

meta

This object contains useful metadata for your order including a formatted order total for your cart, along with when the cart was created.

relationships

This object will contain the IDs for related objects, including the Order Items and the Customer, if you provided one during Checkout.

‌

Clean up your Cart

Once a Cart is converted to an Order, the Cart will exist for another 7 days, unless you touch it again. You can send a request to DELETE the Cart, if you no longer require the items inside.

Replace XXXX below with your access_token.

curl -X DELETE https://api.moltin.com/v2/carts/abc \
-H "Authorization: Bearer XXXX"