Delivery address changed callback
Optional callback that allows partner to calculate and re-calculate shipping price or to update any other data that are tied to delivery address, zip, country, etc. based on the user inputs in the Checkout3 “Invoice address” or “Delivery address” forms and update the purchase accordingly.
Callback is triggered in multiple cases:
- Checkout3 form is refreshed either by calling
refreshForm()
on the Checkout3 instance or by reloading the page in browser. - “Invoice Address” is added or edited if the user has not provided “Delivery Address”
- “Delivery Address” is added, edited or removed by the user.
Checkout3 makes sure the data payload for the callback is correct and relevant for the calculation of the shipping by the partner. Partner needs to process the callback.
Delivery address is different, shipping price needs to be updated
Callback is called with a new payload (or different data from previously stored information), partner is able to use Update Items feature to update the total cost of the purchase and call refreshForm()
on the Checkout3 instance to make sure the correct information is displayed in the Checkout3 form.
Delivery address is the same, shipping price doesn’t need to be updated
Callback is called with the same payload as previously, the shipping costs doesn’t have to be updated, partner calls deliveryAddressChangedContinue()
to continue with no need to update items and refreshing the form.
Registering a callback
To use this optional callback, partner has to pass an additional flag deliveryAddressChangedCallback
to avardaCheckoutInit
. Please refer to Showing the checkout form for additional info about Checkout 3 Form initialisation.
Callback Payload
Callback payload is an object
with zip
, country
and source
string properties as the first parameter and checkoutInstance
as the second parameter.
Property | Data type | Description |
---|---|---|
zip | string | ZIP of the changed address |
country | string | ISO country code alpha2 format – SE , FI , etc. |
source | string “invoice”|”delivery” | Indicates which address has triggered the deliveryAddressChanged callback. |
Contents of the first payload object
Below you can see a code example.