• Checkout/
    Checkout API

    Checkout API

    After a cart is ready to checkout, you can easily convert your cart to an order. The cart remains and can be modified and checked out again if required.

    After a successful Checkout is completed, the response contains the order.

    • The cart currency is set when the first item is added to the cart.
    • The product being added to the cart requires a price in the same currency as the other items in the cart. The API returns a 400 error if a price is not defined in the correct currency.

    By default, carts are automatically deleted 7 days after the last update. You can change this setting by updating cart settings.

    There are a number of actions that happen to your inventory when checking out and paying for an order. For more information please be sure to evaluate our detailed article explaining the processes.

    POST With Customer ID

    https://api.moltin.com/v2/carts/:reference/checkout
    

    You can checkout a Cart with an existing customer ID.

    Parameters

    Headers

    NameRequiredTypeDescription
    x-moltin-customer-tokenOptionalstringA customer token to access specific customer orders.

    Body

    NameRequiredTypeDescription
    customer.idRequiredstringThe ID of the customer.
    billing_address.first_nameRequiredstringFirst name of the billing recipient.
    billing_address.last_nameRequiredstringLast name of the billing recipient.
    billing_address.company_nameOptionalstringCompany name of the billing recipient.
    billing_address.line_1RequiredstringFirst line of the billing address.
    billing_address.line_2OptionalstringSecond line of the billing address.
    billing_address.cityOptionalstringSpecifies the city of the billing address.
    billing_address.countyOptionalstringSpecifies the county of the billing address.
    billing_address.regionRequiredstringSpecifies state, province, or region of the billing address.
    billing_address.postcodeRequiredstringPostcode of the billing address.
    billing_address.countryRequiredstringSpecifies the country of the billing address.
    shipping_address.first_nameRequiredstringFirst name of the shipping recipient.
    shipping_address.last_nameRequiredstringLast name of the shipping recipient.
    shipping_address.phone_numberOptionalstringPhone number of the shipping recipient.
    shipping_address.company_nameOptionalstringCompany of the shipping recipient.
    shipping_address.line_1RequiredstringFirst line of the shipping address.
    shipping_address.line_2OptionalstringSecond line of the shipping address.
    shipping_address.cityOptionalstringCity of the shipping address.
    shipping_address.countyOptionalstringSpecifies the county of the shipping address.
    shipping_address.regionRequiredstringSpecifies the state, province, or region of the shipping address.
    shipping_address.postcodeRequiredstringPost code of the shipping address.
    shipping_address.countryRequiredstringSpecifies the country of the shipping address.
    shipping_address.instructionsOptionalstringShipping instructions.

    Request Examples

    Curl

    curl -X POST https://api.moltin.com/v2/carts/:reference/checkout \
         -H "Authorization: Bearer XXXX" \
         -H "Content-Type: application/json" \
         -d $'{
           "data": {
             "customer": {
               "id": "c8c1c511-beef-4812-9b7a-9f92c587217c"
             },
             "billing_address": {
               "first_name": "John",
               "last_name": "Doe",
               "company_name": "Moltin",
               "line_1": "1234 Disney Drive",
               "line_2": "Disney Resort",
               "city": "Anaheim",
               "county": "Orange",
               "region": "CA",
               "postcode": "92802",
               "country": "US"
             },
             "shipping_address": {
               "first_name": "John",
               "last_name": "Doe",
               "phone_number": "(555) 555-1234",
               "company_name": "Moltin",
               "line_1": "1234 Disney Drive",
               "line_2": "Disney Resort",
               "city": "Anaheim",
               "county": "Orange",
               "region": "CA",
               "postcode": "92802",
               "country": "US",
               "instructions": "Leave in porch"
             }
           }
        }'
    

    JavaScript SDK

    const MoltinGateway = require("@moltin/sdk").gateway;
    const Moltin = MoltinGateway({
        client_id: "X",
    });
    const reference = "XXXX";
    const customerId = "XXXX";
    const billing = {
        first_name: "John",
        last_name: "Doe",
        line_1: "1234 Disney Drive",
        line_2: "Disney Resort",
        city: "Anaheim",
        county: "Orange",
        region: "CA",
        postcode: "92802",
        country: "US",
    };
    Moltin.Cart(reference)
        .Checkout(customerId, billing, shipping)
        .then((order) => {
            // Do something
        });
    

    shipping is optional. billing is shipping if not provided.

    Response Example

    201 Created

    {
        "data": {
            "type": "order",
            "id": "c79a24c1-d639-4ac7-9eb5-3565efd9c84b",
            "status": "incomplete",
            "payment": "unpaid",
            "shipping": "unfulfilled",
            "customer": {
                "name": "Ron Swanson",
                "email": "ronswanson@example.com"
            },
            "shipping_address": {
                "first_name": "Ron",
                "last_name": "Swanson",
                "phone_number": "",
                "company_name": "Moltin",
                "line_1": "1234 Disney Drive",
                "line_2": "Disney Resort",
                "city": "Anaheim",
                "county": "Orange",
                "region": "CA",
                "postcode": "92802",
                "country": "US",
                "instructions": ""
            },
            "billing_address": {
                "first_name": "Ron",
                "last_name": "Swanson",
                "company_name": "Moltin",
                "line_1": "1234 Disney Drive",
                "line_2": "Disney Resort",
                "city": "Anaheim",
                "county": "Orange",
                "region": "CA",
                "postcode": "92802",
                "country": "US"
            },
            "links": {},
            "meta": {
                "display_price": {
                    "with_tax": {
                        "amount": 47500,
                        "currency": "USD",
                        "formatted": "$475.00"
                    },
                    "without_tax": {
                        "amount": 47500,
                        "currency": "USD",
                        "formatted": "$475.00"
                    }
                },
                "timestamps": {
                    "created_at": "2021-06-03T22:47:33Z",
                    "updated_at": "2021-06-03T22:47:33Z"
                }
            },
            "relationships": {
                "items": {
                    "data": [
                        {
                            "type": "item",
                            "id": "5ff8e482-da0b-4c43-b9ae-a13d384f10bd"
                        },
                        {
                            "type": "item",
                            "id": "f8aefa8a-b57a-421e-9b4c-ae8f17e12371"
                        }
                    ]
                }
            }
        },
        "included": {
            "items": [
                {
                    "type": "order_item",
                    "id": "5ff8e482-da0b-4c43-b9ae-a13d384f10bd",
                    "quantity": 1,
                    "product_id": "047e3569-6889-4feb-9a22-1de5722a1a54",
                    "name": "Deck Shoe",
                    "sku": "deck-shoe-001",
                    "unit_price": {
                        "amount": 47500,
                        "currency": "USD",
                        "includes_tax": true
                    },
                    "value": {
                        "amount": 47500,
                        "currency": "USD",
                        "includes_tax": true
                    },
                    "links": {},
                    "meta": {
                        "display_price": {
                            "with_tax": {
                                "unit": {
                                    "amount": 47500,
                                    "currency": "USD",
                                    "formatted": "$475.00"
                                },
                                "value": {
                                    "amount": 47500,
                                    "currency": "USD",
                                    "formatted": "$475.00"
                                }
                            },
                            "without_tax": {
                                "unit": {
                                    "amount": 47500,
                                    "currency": "USD",
                                    "formatted": "$475.00"
                                },
                                "value": {
                                    "amount": 47500,
                                    "currency": "USD",
                                    "formatted": "$475.00"
                                }
                            },
                            "tax": {
                                "unit": {
                                    "amount": 0,
                                    "currency": "USD",
                                    "formatted": "$0.00"
                                },
                                "value": {
                                    "amount": 0,
                                    "currency": "USD",
                                    "formatted": "$0.00"
                                }
                            },
                            "discount": {
                                "unit": {
                                    "amount": -500,
                                    "currency": "USD",
                                    "formatted": "-$5.00"
                                },
                                "value": {
                                    "amount": -500,
                                    "currency": "USD",
                                    "formatted": "-$5.00"
                                }
                            }
                        },
                        "timestamps": {
                            "created_at": "2021-06-03T22:47:33Z",
                            "updated_at": "2021-06-03T22:47:33Z"
                        }
                    },
                    "relationships": {
                        "cart_item": {
                            "data": {
                                "type": "cart_item",
                                "id": "4265f5f8-b616-45d6-90cf-d4d797777d72"
                            }
                        }
                    }
                },
                {
                    "type": "order_item",
                    "id": "f8aefa8a-b57a-421e-9b4c-ae8f17e12371",
                    "quantity": 1,
                    "product_id": "7767cb41-dc76-4214-97e7-0595c4b58e18",
                    "name": "5off",
                    "sku": "5off",
                    "unit_price": {
                        "amount": -500,
                        "currency": "USD",
                        "includes_tax": false
                    },
                    "value": {
                        "amount": -500,
                        "currency": "USD",
                        "includes_tax": false
                    },
                    "links": {},
                    "meta": {
                        "display_price": {
                            "with_tax": {
                                "unit": {
                                    "amount": -500,
                                    "currency": "USD",
                                    "formatted": "-$5.00"
                                },
                                "value": {
                                    "amount": -500,
                                    "currency": "USD",
                                    "formatted": "-$5.00"
                                }
                            },
                            "without_tax": {
                                "unit": {
                                    "amount": -500,
                                    "currency": "USD",
                                    "formatted": "-$5.00"
                                },
                                "value": {
                                    "amount": -500,
                                    "currency": "USD",
                                    "formatted": "-$5.00"
                                }
                            },
                            "tax": {
                                "unit": {
                                    "amount": 0,
                                    "currency": "USD",
                                    "formatted": "$0.00"
                                },
                                "value": {
                                    "amount": 0,
                                    "currency": "USD",
                                    "formatted": "$0.00"
                                }
                            },
                            "discount": {
                                "unit": {
                                    "amount": 0,
                                    "currency": "USD",
                                    "formatted": "$0.00"
                                },
                                "value": {
                                    "amount": 0,
                                    "currency": "USD",
                                    "formatted": "$0.00"
                                }
                            }
                        },
                        "timestamps": {
                            "created_at": "2021-06-03T22:47:33Z",
                            "updated_at": "2021-06-03T22:47:33Z"
                        }
                    },
                    "relationships": {
                        "cart_item": {
                            "data": {
                                "type": "cart_item",
                                "id": "7d7f6c5c-74a8-40c3-8808-d08a825ba986"
                            }
                        }
                    }
                }
            ]
        }
    }
    

    POST With Customer Object

    https://api.moltin.com/v2/carts/:reference/checkout
    

    You can checkout a Cart with an associated customer name and email.

    Parameters

    Path parameters

    NameRequiredTypeDescription
    referenceRequiredstringThe reference for the cart to checkout.

    Headers

    NameRequiredTypeDescription
    X-MOLTIN-CURRENCYOptionalstringSpecifies the currency to be used for the products in the cart. If you do not specify a currency, the site’s default currency is used. This header only affects the first item added to the cart.
    AuthorizationRequiredstringThe Bearer token required to get access to the API.

    Body

    NameRequiredTypeDescription
    customer.emailRequiredstringCustomer email address.
    customer.nameRequiredstringFull name of the customer.
    billing_address.first_nameRequiredstringFirst name of the billing recipient.
    billing_address.last_nameRequiredstringLast name of the billing recipient.
    billing_address.company_nameOptionalstringCompany name of the billing recipient.
    billing_address.line_1RequiredstringFirst line of the billing address.
    billing_address.line_2OptionalstringSecond line of the billing address.
    billing_address.cityOptionalstringcity of the billing address.
    billing_address.countyOptionalstringSpecifies county of the billing address.
    billing_address.regionRequiredstringSpecifies state, province, or region of the billing address.
    billing_address.postcodeRequiredstringPostcode of the billing address.
    billing_address.countryRequiredstringSpecifies Country of the billing address.
    shipping_address.first_nameRequiredstringFirst name of the shipping recipient.
    shipping_address.last_nameRequiredstringLast name of the shipping recipient.
    shipping_address.company_nameOptionalstringCompany name of the shipping recipient.
    shipping_address.phone_numberOptionalstringPhone number of the shipping recipient.
    shipping_address.line_1RequiredstringFirst line of the shipping address.
    shipping_address.line_2OptionalstringSecond line of the shipping address.
    shipping_address.cityOptionalstringCity of the shipping address.
    shipping_address.countyOptionalstringSpecifies the county of the shipping address.
    shipping_address.regionRequiredstringSpecifies the state, province, or region of the shipping address.
    shipping_address.postcodeRequiredstringPostcode of the shipping address.
    shipping_address.countryRequiredstringSpecifies the country of the shipping address.
    shipping_address.instructionsOptionalstringShipping instructions.

    Request Examples

    Curl

    curl -X POST https://api.moltin.com/v2/carts/:reference/checkout \
         -H "Authorization: Bearer XXXX" \
         -H "Content-Type: application/json" \
         -d $'{
           "data": {
             "customer": {
               "email": "john@moltin.com",
               "name": "John Doe"
             },
             "billing_address": {
               "first_name": "John",
               "last_name": "Doe",
               "company_name": "Moltin",
               "line_1": "1234 Disney Drive",
               "line_2": "Disney Resort",
               "city": "Anaheim",
               "county": "Orange",
               "region": "CA",
               "postcode": "92802",
               "country": "US",
             },
             "shipping_address": {
               "first_name": "John",
               "last_name": "Doe",
               "company_name": "Moltin",
               "phone_number": "(555) 555-1234",
               "line_1": "1234 Disney Drive",
               "line_2": "Disney Resort",
               "city": "Anaheim",
               "county": "Orange",
               "region": "CA",
               "postcode": "92802",
               "country": "US",
               "instructions": "Leave in porch"
             }
           }
        }'
    

    JavaScript SDK

    const MoltinGateway = require("@moltin/sdk").gateway;
    const Moltin = MoltinGateway({
        client_id: "X",
    });
    const reference = "XXXX";
    const customer = {
        email: "john@moltin.com",
        name: "John Doe",
    };
    const billing = {
        first_name: "John",
        last_name: "Doe",
        line_1: "1234 Disney Drive",
        line_2: "Disney Resort",
        city: "Anaheim",
        county: "Orange",
        region: "CA",
        postcode: "92802",
        country: "US",
    };
    const shipping = {
        first_name: "John",
        last_name: "Doe",
        line_1: "1234 Disney Drive",
        line_2: "Disney Resort",
        city: "Anaheim",
        county: "Orange",
        region: "CA",
        postcode: "92802",
        country: "US",
    };
    Moltin.Cart(reference)
        .Checkout(customer, billing, shipping)
        .then((order) => {
            // Do something
        });
    

    shipping is optional. billing is shipping if not provided.

    Next Steps

    After a Cart has been converted to an Order using either of the previous methods, you most likely want to capture payment for order.

    Was this helpful?

    Previous
    Checkout workflow