Make a purchase

Making a purchase requires several steps, described in detail below. First, you create a cart. Second, you add shipping details, and finally, you create the order.

Create a Cart

To create a Cart, you need to add a Product to it and assign it to a Store with a HTTP POST towards /orderv1/carts

curl --request POST \
  --url https://api.${env}.brinkcommerce.com/orderv1/carts \
  --header 'x-api-key: ${api-key}' \
  --data '{
      "store": {
      "countryCode": "SE",
      "languageCode": "SV"
    },
    "products": [{
      "id": "product-variant-id",
      "quantity": 1
    }]
  }'

Add shipping to cart

You add shipping to the Cart in the same way as adding any other Product, but this time you need to add a Product with the type "shipping". This is done with a HTTP PUT towards /orderv1/carts.

Authorization

When you create a cart you get a jwtToken in the response. The token is required to authorize your access to the cart, by sending it as a value for the HTTP header "Authorization".

curl --request POST \
  --url https://api.${env}.brinkcommerce.com/orderv1/carts \
  --header 'x-api-key: ${api-key}' \
  --data '{
    "products": [{
      "id": "shipment-id",
      "quantity": 1
    }]
  }'

Create order

The last part is to turn the Cart into an Order and pay for it. We'll be using Klarna Checkout in this example.

We create an order from the cart with a HTTP POST towards /orderv1/carts/klarna/orders

Note

All merchant urls are required. For test purposes the url to terms are not important, but the urls to the checkout and confirmation page are.

curl --request POST \
  --url https://api.${env}.brinkcommerce.com/orderv1/carts/klarna/orders \
  --header 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uSWQiOiI3M2U3NTY3MS0' \
  --header 'content-type: application/json' \
  --data '{
    "merchant_urls": {
      "terms": "https://example.com/terms-and-conditions",
      "checkout": "https://example.com/checkout/?klarnaOrderId={checkout.order.id}",
      "confirmation": "https://example.com/success-klarna/?klarnaOrderId={checkout.order.id}"
      }
    }'

Response

{
  "order_id": "5a807f17-33e7-4a33-84cf-515c473a42d7", # Klarna order id
  "status": "CHECKOUT_INCOMPLETE",
  "merchant_reference1": "10001", # Brink order.reference
  "merchant_reference2": "6b0d5ebc-78c1-4fa0-9008-af24cec7de39", # Brink order.id
  "html_snippet": "<div ..." # Klarna checkout/confirmation snippet
}

Render checkout snippet

From the create order call response, get the html_snippet property and embed it into your page where you would like the Klarna Checkout to be rendered at.

Klarna Checkout

Klarna Checkout

When the payments is completed in Klarna Checkout, the customer will be directed to the confirmation url specified in the create order call.


Render confirmation snippet

On the confirmation page you first need to get the Klarna order, this is done with a HTTP GET towards /orderv1/payments/klarna/order

curl --request GET \
  --url https://api.${env}.brinkcommerce.com/orderv1/payments/klarna/order \
  --header 'authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzZXNzaW9uSWQ

Response

{
  "order_id": "5a807f17-33e7-4a33-84cf-515c473a42d7", # Klarna order id
  "status": "CHECKOUT_INCOMPLETE",
  "merchant_reference1": "10001", # Brink order.reference
  "merchant_reference2": "6b0d5ebc-78c1-4fa0-9008-af24cec7de39", # Brink order.id
  "html_snippet": "<div ..." # Klarna checkout/confirmation snippet
}

Get the value of the html_snippet property from the read order call response and embed it into your page where you would like the confirmation iframe to be shown.

Klarna Checkout - Confirmation page

Klarna Checkout - Confirmation page

What now?

Amazing work! You have now created a product and purchased it through Brink Commercial API.

If you want to be a bit more adventurous, you could try to create and use a discount code in your next purchase, or even check out our Post Purchase API.