• Log in
  • Sign up
  • Contact Us

Discuss your project  
Blog • Developer

Moltin Checkout improvements: linking customers to orders

Last updated: 24 Jun 2019

We’ve introduced some improvements to the cart-checkout process that’ll make associating orders with customers simple and efficient.

Linking an order to a customer

Previously, checking out a cart required that you provided a customer object, with a name and email address in the payload. Now, you can check out with an existing Moltin customer.

Check out this basic example using cURL. Here we are checking out a cart and attaching an existing Moltin customer:

curl -X "POST" "https://api.moltin.com/v2/carts/{CART_ID}/checkout" \
-H "Authorization: Bearer XXXX" \
-d $'{
"data": {
"customer": {
"id": {CUSTOMER_ID}
},
"billing_address": {
"first_name": "John",
"last_name": "Doe",
"company_name": "Moltin",
"line_1": "2nd Floor British India House",
"line_2": "15 Carliol Square",
"city": "Newcastle upon Tyne",
"postcode": "NE1 6UF",
"county": "Tyne & Wear",
"country": "UK"
},
"shipping_address": {
"first_name": "John",
"last_name": "Doe",
"company_name": "Moltin",
"line_1": "2nd Floor British India House",
"line_2": "15 Carliol Square",
"city": "Newcastle upon Tyne",
"postcode": "NE1 6UF",
"county": "Tyne & Wear",
"country": "UK"
}
}
}'

This is just as easy to do when using our JavaScript SDK:

Moltin.Cart({CART_ID}).Checkout({CUSTOMER_ID}, {
first_name: "John",
last_name: "Doe",
company_name: "Moltin",
line_1: "2nd Floor British India House",
line_2: "15 Carliol Square",
city: "Newcastle upon Tyne",
postcode: "NE1 6UF",
county: "Tyne & Wear",
country: "UK"
}).then(() => {
// Returns a new order object
});

The returned order object will have a snapshot of the customer’s -mail address and name at the time of the order, but also a relationship to the customer record.

{
"type": "order",
"id": "a2b027ec-f49d-4ce7-94e7-f1848b619c8b",
"status": "incomplete",
"payment": "unpaid",
"shipping": "unfulfilled",
"customer": {
"name": "Jonathan Steele",
"email": "jonathan@moltin.com"
},
"shipping_address": {
"first_name": "Jonathan",
"last_name": "Steele",
"company_name": "Moltin",
"line_1": "British India House",
"line_2": "15 Carliol Square",
"city": "Newcastle upon Tyne",
"postcode": "NE1 6UF",
"county": "Tyne & Wear",
"country": "UK",
"instructions": ""
},
"billing_address": {
"first_name": "Jonathan",
"last_name": "Steele",
"company_name": "Moltin",
"line_1": "British India House",
"line_2": "15 Carliol Square",
"city": "Newcastle upon Tyne",
"postcode": "NE1 6UF",
"county": "Tyne & Wear",
"country": "UK"
},
"relationships": {
"customer": {
"data": {
"type": "customer",
"id": "7b9678e4-a52a-469b-bfdd-6ad9b36d8dc4"
}
}
}
}

Retrieving a customer’s orders

Now that the relationship between your customers and orders exist, it’s easy to collate an order history for a specific customer using tokens.

When making a request for all orders, just add the customer token to the request header (X-Moltin-Customer-Token). This will return all orders associated with that customer.

curl -X "GET" "https://api.moltin.com/v2/orders" \
-H "Authorization: Bearer XXXX" \
-H "X-Moltin-Customer-Token: eyJhbGciOi.AiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJzdWIiOiI3OWN"

Or if you’re using theJavaScript SDK, just pass the customer token to the All method:

Moltin.Orders.All("eyJhbGciOi.AiSFMyNTYiLCAidHlwIjogIkpXVCJ9.eyJzdWIiOiI3OWN")

Service-Driven Commerce: The New Tech Stack

Join our live fireside chat on August 28th at 2:00 pm ET! No one should have to settle for a rigid eCommerce platform like Shopify or Magento and compromise site speed and control. Discover how a service-driven approach can help you move fast and create the customer experience you always imagined.

From Our Blog

21 Aug 2019

Systems quotas to protect your store

Today we are introducing fair usage quotas within our architecture. The use of quotas is common practice for web facing services and their introduction by Moltin is to ensure an optimal and fair...

Read More
author
Jonathan Prest
in Announcements | Developer
20 Jun 2019

Analytics for your Moltin store

Today we’re going to take a look at how to use best-in-class data warehousing and analytics solutions on top of Moltin, specifically in relation to orders and order items.

Read More
author
Matt Foyle
9 min. read in Developer
19 Jun 2019

Further Flows improvements

We've been working hard recently to improve the developer experience when using the Moltin API to build an online store.

Read More
author
James Owers
9 min. read in Announcements | Developer