Created with Sketch.
Created with Sketch.
Checkout 3.0

Update delivery address for an ongoing session

On this page you will find all necessary information about how to update delivery address for an ongoing checkout session.


The following steps are required:

  1. Send updated delivery address via a backend API call
  2. Refresh checkout to display the updated delivery address

1. Update delivery address

In order to update the delivery address in the checkout, send a server t to server PUT request with “Partner access token” as authorization with JSON data to the /api/partner/payments/{purchaseid}/address endpoint. (Replace {purchaseid} in the URL with the actual purchaseId of your session.)

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

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

# Send updated delivery address to Checkout
PUT {api_url}/api/partner/payments/{purchaseid}/address
Authorization: Bearer {partner_access_token}
Content-type: application/json

{
  "differentDeliveryAddress": "Hidden",
  "deliveryAddress": {
    "address1": "string",
    "address2": "string",
    "zip": "string",
    "city": "string",
    "country": "AF",
    "invoicingAddressViewType": "InvalidEditable",
    "firstName": "string",
    "lastName": "string",
    "type": "Default"
  }
}
PropertyData typeDescription
differentDeliveryAddressCheck-box state TypeDecides if the user is able to see the delivery address or it’s hidden
deliveryAddressDeliveryAddress objectDelivery address data

Example

<?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 delivery address
$update_items_url = "$api_url/api/partner/payments/$purchase_id/address";
$update_data = array(
    "differentDeliveryAddress" => "Checked"
    "deliveryAddress" => array(
        "country" => "SE",
        "type" => "Default",
        "firstName" => "Peter",
        "lastName" => "Parker",
        "zip" => "30593",
        "city" => "Halmstad"
    ),
);

$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";
};

Response

If the request is successful, an empty response with status code 204 (No Content) will be returned.


2. Refresh checkout to show the updated address

Call the below Javascript function to reload the checkout with the updated information.

window.avardaCheckout.refreshForm();