Update a created checkout cart

This tutorial will show you how to update an existing cart and avoid creating a new cart. This way the user can avoid a repeated identification process and avoid re-entering any information in Ecster Pay.

Common use cases when executing the updateCart call:

  • User makes changes to the cart, e.g. add or remove an item
  • Change delivery method
  • You listen to one of Ecster callbacks and want to update an exsiting cart e.g. want to give a specific consumer discount, change delivery methods due users adress

Below you can see a flowchart with the locking mechanism callback function.

Update cart flow

updateCart flowchart

Update checkout cart

To update an existing cart in order to render Ecster Pay with the new information that was sent in you have to use the JavaScript callback function initUpdateCart and the REST call updateCart .

See steps below:

  1. Call initUpdateCart with the current cart key (JavaScript callback in your frontend)
  2. Call updateCart with the current cart key (HTTP REST call in your backend)
  3. Use callback from step 1 "finishUpdateCart" with the new cart key you received in step 2 (JavaScript callback in your frontend)

This will cause Ecster Pay to be refreshed with the new information.

REST call updateCart looks like createCart except for one mandatory parameter; the recent cart key you received. This means that the consumer does not have to re-enter any information. So it's important to use the REST call updateCart when changes are to be made. You can see all mandatory and optional parameters in the API reference section.

When you have called updateCart you will receive the full body that you have sent in and a new unique cart key. The previous key is now expired and cannot be reused.

Note

Remember to always lock your page when a user makes changes (see section Locking mechanism function) to make sure Ecster Pay always knows about the latest changes.

updateCart JSON example

Below you see a updateCart request and the response included the new cart key.

PUT /v1/carts/E0D30C4B583C4D06C5ABAEB787865A71

x-api-key: njdfdsdkjfl5598503mnfkfe
x-merchant-key: 86969769
Content-Type: application/json

{
  "locale": {
    "language": "sv",
    "country": "SE"
  },
  "countryCode": "SE",
  "parameters": {
    "shopTermsUrl": "https://ecster.com/terms/storeTerms.html",
    "returnUrl": "https://ecster.com/return/to/page.html",
    "defaultDeliveryCountry": "SE",
    "purchaseType": {
      "type": "B2C",
      "show": false
    }
  },
  "deliveryMethods": [
    {
      "id": "Delivery1010",
      "name": "Shipping by car",
      "description": "Shipping with a large car",
      "price": 10000,
      "selected": true
    }
  ],
  "cart": {
    "amount": 20000,
    "currency": "SEK",
    "rows": [
      {
        "partNumber": "264275-0044_345",
        "name": "Adidas Stan Smith",
        "description": "White size 9",
        "quantity": 2,
        "unitAmount": 10000,
        "unit": "st",
        "vatRate": 2500,
        "discountAmount": 0,
        "serials": [
          "951358"
        ]
      }
    ]
  },
  "orderReference": "123123",
  "notificationUrl": "https://ecster.se/osn/API",
  "platform": {
    "reference": "2cc5c43d-fb92-472f-828a-1a5ad703d512",
    "info": "info about version"
  },
  "tags": [
    "Shoes:White",
    "Sales:12345"
  ]
}

Here you see the response from the updateCart REST call.

Status: 200 OK

{
    "checkoutCart": {
        "key": "847BD0EB0E08059394204379880E0ADE",
        "locale": {
            "language": "sv",
            "country": "SE"
        },
        "deliveryMethods": [
            {
                "id": "Delivery1010",
                "name": "Shipping by car",
                "description": "Shipping with a large car",
                "price": 10000,
                "selected": true
            }
        ],
        "cart": {
            "amount": 20000,
            "currency": "SEK",
            "rows": [
                {
                    "name": "Adidas Stan Smith",
                    "quantity": 2,
                    "unitAmount": 10000,
                    "vatRate": 2500,
                    "partNumber": "264275-0044_345",
                    "description": "White size 9",
                    "unit": "st",
                    "discountAmount": 0,
                    "serials": [
                        "951358"
                    ]
                }
            ]
        },
        "notificationUrl": "https://ecster.se/osn/API",
        "platform": {
            "reference": "2cc5c43d-fb92-472f-828a-1a5ad703d512",
            "info": "info about version"
        },
        "tags": [
            "APIv1",
            "Shoes:White",
            "Sales:12345"
        ],
        "parameters": {
            "returnUrl": "https://ecster.com/return/to/page.html",
            "shopTermsUrl": "https://ecster.com/terms/storeTerms.html",
            "defaultDeliveryCountry": "SE",
            "purchaseType": {
                "type": "b2c",
                "show": false
            }
        },
        "countryCode": "SE"
    }
}

Next step

When you now have made changes to Ecster Pay the next step is to handle the confirmation step of the purchase. 

Go to next step here

Request test account