Checkout 3.0
Update Items

Update Items

On this page you will find all necessary information about How to Update items. Make sure you check Embed Checkout article, before continuing reading this article.


When updating items in the cart, the merchant should:

  1. Send updated cart to Checkout
  2. Refresh app to show the updated price

1. Send updated cart to Checkout

In order to send updated cart to Checkout application, merchant has to send a PUT request with “Partner access token” as authorization with JSON data to /api/partner/payments/{purchaseid}/items. “Purchase ID” has to be included in the URL.

More information about generating a “Partner access token” here: Obtain partner access token for the purchase

More information about getting a “Purchase ID” for a current session here: Initialize payment

# Send updated cart to Checkout
PUT {api_url}/api/partner/payments/{purchaseid}/items
Authorization: Bearer {partner_access_token}
Content-type: application/json
 
{
  "items": [
    {
      "description": "Test Item 1",
      "notes": "Test Notes 1",
      "amount": 100,
      "taxCode": "20",
      "taxAmount": 20,
      "quantity": 2
    }
  ]
}
PropertyData typeDescription
items[]List Item

Item:

PropertyData typeDescription
DescriptionstringName of item
NotesstringOptional notes
AmountdecimalItem cost
TaxCodestringTax code
TaxAmountdecimalTax amount
QuantitydecimalQuantity

Example

<?php
$api_url = "https://stage.checkout-api.avarda.com";
// "Partner access token" generated by calling `$api_url/api/partner/tokens` see more info: <https://docs.avarda.com/checkout-3/getting-started/#obtain-partner-access-token>
$partner_access_token = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6InBpVmxsb1FEU01LeGgxbTJ5Z3FHU1ZkZ0ZwQSIsImtpZCI6...";
// "PurchaseId" of the current session
$purchase_id = "GVPF5b";
 
 
// Send PUT request to update items
$update_items_url = "$api_url/api/partner/payments/$purchase_id/items";
$update_data = array(
    "items" => array(array(
        "description" => "Test Item 1",
        "notes" => "Test Notes 1",
        "amount" => 200,
        "taxCode" => "20%",
        "taxAmount" => 40,
        "quantity" => 2
    )),
);
 
$options = array(
    'http' => array(
        'header'  => "Content-type: application/json\r\nAuthorization: Bearer $partner_access_token\r\n",
        'method'  => 'PUT',
        'content' => json_encode($update_data)
    )
);
$context  = stream_context_create($options);
$update_result = file_get_contents($update_items_url, false, $context);
if ($update_result === false) { /* Handle error */
} else {
    $update_response = json_decode($update_result);
    echo "Updated Successfully";
};

2. Refresh app to show the updated price

This ensures that the form will be reloaded with the actual price.

window.avardaCheckout.refreshForm();

PHP integration example

Check the PHP demo example of Checkout 3.0 integration in our public repository on Github: https://github.com/avarda-ab/checkout3-phpdemo (opens in a new tab)