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:
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
}
]
}
Property | Data type | Description |
items | [] | List Item |
Property | Data type | Description |
Description | string | Name of item |
Notes | string | Optional notes |
Amount | decimal | Item cost |
TaxCode | string | Tax code |
TaxAmount | decimal | Tax amount |
Quantity | decimal | Quantity |
<?php
$api_url = "https://avdonl-s-checkout.avarda.org";
// "Partner access token" generated by calling `$api_url/api/partner/tokens` see more info: <https://docs.avarda.com/?post_type=checkout30&p=1552#accessToken-obtaining>
$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";
};
This ensures that the form will be reloaded with the actual price.
window.avardaCheckout.refreshForm();
Check the PHP demo example of Checkout 3.0 integration in our public repository on Github: https://github.com/avarda-ab/checkout3-phpdemo