Update cart
The Update Cart PUT request will replace the current cart of the session. To update the Cart while the Checkout is rendered on the screen, a call to the Checkout Client API's suspend() function shall be performed before calling the Checkout Backend API.
Suspend and resume flow​
/*
javascript client side flow to update Cart
*/
// Suspend the Checkout, showing a spinner...
window.collector.checkout.api.suspend();
// ... then call the backend API to set the new Cart
yourSetCartRequestFunction();
// ... and finally resume the Checkout after the backend call is completed to update the Checkout
window.collector.checkout.api.resume();
Once in suspend mode, the Checkout cart can be updated by sending in a new cart to the Checkout API from your backend as the following code shows:
Update cart request​
- Request
- Response
- Error
/*
PUT /merchants/123/checkouts/1eec44b5-66d3-4058-a31f-3444229fb727/cart HTTP/1.1
Host: api.checkout.uat.walleydev.com
Content-Type: application/json
Authorization: SharedKey bXlVc2VybmFtZTpmN2E1ODA4MGQzZTk0M2VmNWYyMTZlMDE...
*/
{
"items": [
{
"id": "2",
"description": "Another product",
"unitPrice": 123.45,
"unitWeight": 1.2,
"quantity": 1,
"vat": 20,
"requiresElectronicId": true,
"sku": "a unique alphanumeric code for article identification"
}
],
"shippingProperties": {
"height": 10,
"width": 20,
"isBulky": true
}
}
{
"id": "f5f4e86d-95b1-4c1a-8ad0-1d5907236bd7",
"data": null,
"error": null
}
/*
Example error. More errors available below.
*/
{
"id": "862336bb-86a5-418b-b6ff-5547398d5c6b",
"data": null,
"error": {
"code": 423,
"message": "The resource requested is currently locked for modification. Try again.",
"errors": [
{
"reason": "Resource_Locked",
"message": "The resource requested is currently locked for modification. Try again."
}
]
}
}
Once the backend request has completed, a call to the Checkout Client API's resume()
function shall be made to update the state of the Checkout session.
// resume on the client after the backend has updated the cart
window.collector.checkout.api.resume();
Please note
This operation cannot be performed if the Checkout session has expired.
Request Properties​
Request headers
Header | Required | Explanation |
---|---|---|
Authorization | Yes | The authorization header is generated with the access credentials (username and shared access key) received from Walley Merchant Services. Instructions on how to generate the authorization header value can be found under the authorization section. |
Request item properties
Property | Required | Explanation |
---|---|---|
id | Yes | The article id or equivalent. Max 50 characters. The combination of id and description (property below) must be unique within the Checkout session including the fees in the cart. Values are trimmed from leading and trailing white-spaces. Shown on the invoice or receipt. |
description | Yes | Descriptions longer than 50 characters will be truncated. Description and id (property above) must be unique within the Checkout session including the fees in the cart. Values are trimmed from leading and trailing white-spaces. Shown on the invoice or receipt. |
unitPrice | Yes | The unit price of the article including VAT. Both positive and negative values allowed. Max 2 decimals, i.e. 100.00 |
unitWeight | No | The weight of the article. Only positive values are allowed (including zero) |
quantity | Yes | Allowed values are 1 to 99999999 . |
vat | Yes | The VAT of the article in percent. Allowed values are 0 to 100 . Max 2 decimals, i.e. 25.00 |
requiresElectronicId | No | When set to true it indicates that a product needs strong identification and the customer will need to strongly identify themselves at the point of purchase using electronic id such as Mobilt BankID. An example would be selling tickets that are delivered electronically. This feature is supported for B2C and B2B on the Swedish, Norwegian and Finnish markets. |
sku | No | A stock Keeping Unit is a unique alphanumeric code that is used to identify product types and variations. Maximum allowed characters are 1024. |
Please note
Each item in the cart is identified by a unique identifier. The identifier used depends on which PaymentService version is used to active the purchase.
For PaymentService v10 or later: All properties except quantity are used as the unique identifier. Multiple articles with the same unique combination of properties will be merged (quantities are summed). Uniqueness does not span to fees.
For PaymentService v9 or earlier: The combination of id and description is the unique identifier of an article. Multiple articles with the same unique combination will be merged (quantities are summed) as long as all other properties (except quantity) are equal. Uniqueness also spans to fees.
The shippingProperties
is optional and only relevant if a Delivery Module is used.
It gives flexibility to customize what delivery methods should be available based on the items in the cart.
Read more about how these properties are included when Fetching Delivery Methods.
Important error responses​
Error code | Error Reason | Cause |
---|---|---|
400 | Duplicate_Articles | Can't add article/fees since multiple articles/fees with same id and description already exist. |
400 | Validation_Error | The request contains properties with invalid values. Details are provided in the response body. |
423 | Resource_Locked | Another modifying request is currently being executed for the Checkout session. Retry by sending the request again. |
900 | Purchase_Commitment_Found | The customer has clicked the Complete Purchase button and the Checkout is therefore locked for modifications. |
900 | Purchase_Completed | Purchase is already complete. |