# Handle callbacks

Choose Kustom Checkout callbacks for address, shipping and validation. Handle the ten-second validation deadline and configure fail-closed behavior.

> Live page: opens the session console, which lists every call in this session — both the calls the docs made and the ones Kustom made back (`GET /demo-api/session/calls`).

Kustom can call your server when the customer changes their address, selects shipping or
submits a purchase. Register the callbacks your integration needs.

## Do you need any callbacks?

| Callback | You need it only if |
| --- | --- |
| `address_update` | Totals depend on the destination — shipping cost or tax that varies by address |
| `shipping_option_update` | The customer picks a shipping option inside the checkout iframe, rather than on a page of yours |
| `validation` | Stock, an expiring price or a fraud check can invalidate the order between creation and purchase |

If none of these conditions apply, you need none of these callbacks.

See [Server-side callbacks](/checkout/callbacks/) for the `address_update` and
`shipping_option_update` request and response formats.

## Fail open, or fail closed?

Validation must answer within ten seconds. By default, Kustom treats a timeout as approval
and redirects the customer to confirmation. This is fail-open behavior.

Set `options.require_validate_callback_success: true` to block the purchase on a timeout or
any response other than a `2xx` or a redirect. Use this fail-closed behavior when validation
must succeed, such as a stock check, an expiring price or a required legal check.

## Answer the validation callback

Register `merchant_urls.validation`. Kustom `POST`s the full order, including line items,
addresses and amounts, while its status is still `checkout_incomplete`.

```json
{
  "merchant_urls": {
    "validation": "https://shop.example/api/kustom/validate"
  }
}
```

Reply within the ten-second window:

| Your response | What happens |
| --- | --- |
| `200` | The purchase proceeds |
| `303` with a `Location` header | Kustom sends the customer to that URL instead of confirmation — this is the rejection message the customer actually sees, so make the page explain why: out of stock, price changed, no longer available |
| Anything else, or no reply in time | Fail open (the default): treated the same as `200`. Fail closed (`require_validate_callback_success: true`): the customer gets a generic error and the purchase stops |

## When it breaks

| Failure | What happens |
| --- | --- |
| The handler takes longer than ten seconds | Fail open lets the purchase through. Fail closed shows the customer a generic error |
| The handler reads or updates the order through the API instead of reading the `POST` body | Your own call can race the response you're about to send — treat the callback body as the order, don't refetch it |
| A response that is neither a `2xx` nor a `3xx` with `Location` | Under fail open — the default — it is treated as an approval and the purchase completes, whatever the status was. It stops the purchase only with `require_validate_callback_success: true`. The exception either way is a `400` carrying `error_type: address_error` or `approval_failed`, which denies and shows the customer your `error_text` |
| The customer authenticates with 3D Secure before your answer lands | Your `200` doesn't by itself mean the purchase completed. Deny after that authentication and Kustom cancels the payment — refunding it if it had already been captured — so the reservation is released and you see no order |

## Prove it

The docs' validation endpoint always returns `200`. To test failure handling in your
integration, use an endpoint that returns `500` or doesn't answer. Complete a Playground
purchase and check that it proceeds or stops according to
`options.require_validate_callback_success`.

Inspect requests and responses in the console above for the docs' endpoint, or in Developer
Logs for your own endpoint.

Next: [Confirm the order](/checkout/integrate/confirmation-and-push/).

## Related

- [Server-side callbacks](/checkout/callbacks/) — every callback's payload, response shape and
  the push retry schedule.
- [Checkout URLs and callbacks](/checkout/integrate/merchant-urls/) — where `validation` and the
  other callback URLs are registered.
- [Confirm the order](/checkout/integrate/confirmation-and-push/) — what happens once the
  purchase Kustom allowed actually completes.
