Extend AI Hub Checkout with API Extensions and webhooks to add custom validation, shipping logic, and fraud checks to your agentic commerce flows.
This extensibility model applies only to the Google AI Hub checkout module. It doesn't apply to the Stripe ACS module, which uses its own order import flow, or to the OpenAI module.
Extensibility model
commercetools provides two extensibility mechanisms that you can use independently or together.
API Extensions
API Extensions are:
- triggered within commercetools APIs on Carts and Orders
- channel-agnostic, working across all sales channels (storefronts, APIs, integrations)
- suitable for synchronous validation and enrichment
Typical use cases include:
- tax calculation
- external pricing
- validation logic
- Custom Field enrichment
- compliance rules
Conditional triggers
- run an extension only for agentic Stores
- apply different logic for standard storefronts and AI-driven checkout flows
store(key="my-agentic-store") restricts execution to Carts in a specific agentic Store.AI Hub webhook
The AI Hub webhook is:
- invoked during checkout lifecycle actions (create, update, read, complete)
- designed for agentic or channel-specific orchestration
- focused on real-time checkout decision-making
Typical use cases include:
- inventory checks that return errors specific to each agentic channel (for example, Google)
- delivery or shipping promise creation and stock reservation in a backend system for a specific channel
- shipping options and delivery estimates from an external shipping service
- fraud checks specific to an agentic channel
When to use which
| Scenario | Recommended approach |
|---|---|
| Channel-agnostic logic (tax, pricing, validation) | API Extensions |
| Core commerce logic reused across all channels | API Extensions |
| Channel-specific variation of shared logic | API Extensions with conditional triggers |
| Agentic or AI-specific checkout orchestration | AI Hub webhook |
| Inventory checks with channel-specific error handling | AI Hub webhook |
| Stock reservation or delivery promise for a specific channel | AI Hub webhook |
| Shipping options from an external shipping service | AI Hub webhook |
| Final checkout validation in AI-driven flows | AI Hub webhook |
How they work together
When both mechanisms are active, they execute sequentially:
- The agent triggers a checkout session action (
Create,Update,Read, orComplete). - commercetools creates or updates the Cart based on the request.
- API Extensions are triggered based on configured conditions and they run first to handle core Cart logic, such as taxes or pricing.
- If the Cart operation succeeds, AI Hub invokes the webhook, if configured, with the corresponding action (
Create,Update,Read, orComplete). The webhook handles external business logic that the Cart resource can't do, such as fraud checks or real-time inventory validation. - The external system evaluates the request.
- The webhook returns a response with validation results.
- AI Hub proceeds or blocks checkout based on the response.
Because execution is sequential, the two mechanisms cannot return conflicting results:
- If an API Extension blocks the Cart update, the process stops immediately and the webhook is never invoked. The agent receives an error and can retry. For details about how API Extension errors reach the agent, see Return messages from API Extensions.
- If the API Extension succeeds but the webhook returns an error message, the Cart update is preserved, but the checkout session is flagged as incomplete. The agent is blocked from completing checkout until the issue is resolved (for example, by adjusting quantities or changing the shipping address).
- If the webhook call itself fails, for example due to a server error or timeout, the system proceeds with checkout rather than blocking the shopper due to a technical issue. To block checkout in this case instead, enable Stop checkout if the custom extension fails.
Create, Update, Read, Complete). If your implementation needs to address multiple concerns (fraud, inventory), route internally within your endpoint. Different agentic channels can each have their own webhook configuration.Return messages from API Extensions
content is the extension error's message and the message code is the extension error's code, without a severity.extensionExtraInfo object of the error that your API Extension returns. All of these fields are optional:code: the UCP code that the agent acts on, for exampleeligibility_invalid.content: the text that the agent or buyer receives.path: a JSONPath expression that points to the field of the UCP request that the message is about, for example$.line_items[0].quantity.severity: who must resolve the issue. For the available values, see Messages. The severityrequires_buyer_inputescalates the checkout to the buyer.
{
"errors": [
{
"code": "InvalidInput",
"message": "This buyer is over their monthly order limit.",
"extensionExtraInfo": {
"code": "eligibility_invalid",
"content": "This buyer is over their monthly order limit.",
"path": "$.line_items[0].quantity",
"severity": "requires_buyer_review"
}
}
]
}
extensionExtraInfo, and drops any UCP field with an invalid value without affecting the rest of the message.AI Hub webhook reference
To use the AI Hub webhook, you build and host an HTTP endpoint that receives requests from AI Hub and returns structured responses. AI Hub acts as the caller: it sends an HTTP POST request to your endpoint at each checkout lifecycle stage. Your endpoint processes the request and returns a JSON response that tells AI Hub whether to proceed or block the checkout.
The following sections describe the contract between AI Hub and your endpoint, including configuration, request format, and expected response structure.
Configuration
Configure the webhook in the Merchant Center under the Checkout tab of the agentic channel. The following fields are available:
| Field | Description |
|---|---|
| Custom extension URL | The URL of your webhook endpoint. |
| Custom extension authorization header | Optional. The complete value of the Authorization header sent with webhook requests, including the authentication scheme, such as Bearer my-token or Basic <credentials>. The value is sent as-is, without adding or removing a scheme prefix. Requires a Custom extension URL. |
| Stop checkout if the custom extension fails | Whether checkout is blocked when the webhook call fails. By default, checkout continues without the webhook result. |
| Timeout (ms) | Maximum total time in milliseconds to wait for the endpoint to respond, including any automatic retry. Must be no more than 10000 (10 seconds). If set to 0, the default of 1000 ms applies. Required when Custom extension URL is set. |
Authentication
Authorization header of every webhook request. The system does not add a scheme prefix or perform any transformation, so the value you configure is sent exactly as written.Authorization: <authorization-header-value>
Bearer my-token, configure the authorization header value as Bearer my-token. If you don't configure a value, webhook requests are sent without an Authorization header.401 or 403 status code, AI Hub treats the webhook call as failed.Use HTTPS for production endpoints. IP allowlisting and request signing are not supported.
Actions
action field that identifies the stage, and a resource field with the Cart ID. AI Hub constructs this payload automatically based on the checkout event.The following example shows the structure of a request body:
{
"action": "Create",
"resource": {
"typeId": "cart",
"id": "<cart-id>"
}
}
Action types
| Action | Description |
|---|---|
Create | Checkout session initialized |
Update | Cart or session updated |
Read | Current checkout state retrieved |
Complete | Checkout completion requested |
Create
Invoked when a checkout session is initialized. Use this action to set up context for the checkout flow.
Typical integrations:
- checkout context setup
- external system initialization
Update
Invoked when the Cart or session is updated. Use this action to revalidate Cart changes or sync with external systems.
Typical integrations:
- inventory validation (soft check)
- external system synchronization
Read
Invoked when an agent retrieves the current state of the checkout. Use this action to return the latest validation state without modifying the Cart.
Typical integrations:
- checkout state synchronization
Complete
Invoked as the final validation step before Order creation. Use this action for hard checks that determine whether checkout can proceed.
Typical integrations:
- fraud detection
- inventory validation (hard check)
- business rule enforcement
Request format
This section describes the exact format of the HTTP request that AI Hub sends to your endpoint. Use this as a reference when building your service.
Headers
| Header | Description |
|---|---|
Authorization | Configured authorization header value, sent as-is. Only sent if a value is configured. |
Content-Type | application/json |
Accept | application/json |
Body
action identifier and a Cart reference. No additional Cart data, customer information, or channel details are included in the payload.id.Treat the Cart as read-only in your endpoint. AI Hub continues to update the Cart after the webhook call using the Cart version it read before the call, so a Cart update made by your endpoint causes the checkout session update to fail.
Response format
200 response with a JSON body that tells AI Hub the outcome of the validation. The fields are set at the top level of the response body.Structure
{
"type": "Success",
"messages": []
}
Response fields
| Field | Type | Required | Description |
|---|---|---|---|
type | String | Yes | Success or Failure. Indicates the outcome of the validation. |
messages | Array | No | Messages for the agent. Messages of type error block checkout. |
errors | Array | No | Legacy list of errors. Each error is passed to the agent as an error message without a severity. Use messages instead. |
shippingMethods | Array | No | Shipping methods offered by your endpoint. If present, these replace the Shipping Methods of your Project for this checkout. |
orderUrl | String | No | URL of the customer-facing order status page. If present, it is used instead of the order URL configured for the Store. |
futureOrderNumber | String | No | For the Complete action: the order number to assign to the Order. It is also used as the payment reference when the payment is authorized. |
metadata | Object | No | For the Complete action: an object containing a payment.authorization object of string key-value pairs. The pairs are added to the metadata of the payment authorization request that is sent to Stripe, Adyen, or Cybersource. |
Success response
Success response without error messages indicates that checkout can proceed:{
"type": "Success"
}
Failure response
Failure response with at least one error message blocks checkout:{
"type": "Failure",
"messages": [
{
"type": "error",
"code": "out_of_stock",
"content": "Item is out of stock.",
"path": "$.line_items[0]",
"severity": "recoverable"
}
]
}
When checkout is blocked by an error message, the Cart is preserved. The shopper (or agent) receives the messages from the response and can adjust the Cart, for example, by changing quantities or updating the shipping address. Each adjustment triggers a new webhook request, allowing re-validation until checkout succeeds.
Messages
messages array is a UCP message that is passed to the agent as written.| Field | Type | Required | Description |
|---|---|---|---|
type | String | Yes | error if the request was not carried out, warning if it was carried out but something was adjusted, or info for anything else. Only error messages block checkout. |
code | String | Conditional | Machine-readable code that the agent acts on, such as out_of_stock or address_undeliverable. Required for error and warning messages. |
content | String | Yes | Text that the agent or buyer receives. |
content_type | String | No | plain or markdown. |
path | String | No | JSONPath expression that points to the field of the UCP request that the message is about, for example $.line_items[0].item.id. |
severity | String | No | Who must resolve the issue: recoverable (the agent can change the request and retry), unrecoverable (retrying doesn't help), requires_buyer_input (the buyer must provide information that the API can't collect), or requires_buyer_review (the buyer must authorize before the Order is placed). |
error message with the severity requires_buyer_input escalates the checkout: the checkout session status changes to requires_escalation, and the buyer is handed over to the checkout URL configured for the Store. Any other error message leaves the checkout session incomplete so that the agent can adjust the request and retry.Order view URL
Complete action, the webhook response can include an optional orderUrl field. When present, the Google Checkout module uses this URL as the order view link that Google shows to the shopper after checkout. The URL can include an external order number and any required query parameters, such as a customer token.{
"result": {
"type": "Success"
},
"orderUrl": "https://example.com/orders/123456789?token=customer_abcde"
}
orderUrl, the module composes the URL from the order URL template instead. For details on how the module selects and composes the order view URL, see Order view URL.Errors
errors array is supported for webhooks written against an earlier version of this contract. Each error contains a code and a message, and is passed to the agent as an error message without a path or severity.{
"type": "Failure",
"errors": [
{
"code": "address_unverifiable",
"message": "The delivery address could not be verified."
}
]
}
| Field | Type | Description |
|---|---|---|
code | String | Error code identifying the type of error. |
message | String | Human-readable description of the error. |
messages and errors, AI Hub reads both.Shipping methods
shippingMethods field if an external service provides the shipping options for your agentic checkout:- If the field is omitted, AI Hub offers the Shipping Methods of your Project.
- If the field is present, AI Hub offers only the Shipping Methods in the field. An empty array means that no shipping options are available, for example, for an address that no carrier serves.
Each Shipping Method contains the following fields:
| Field | Type | Description |
|---|---|---|
id | String | Identifier of the Shipping Method. |
localizedName | Object | Name of the shipping method as a LocalizedString. |
localizedDescription | Object | Description of the Shipping Method as a LocalizedString. |
shippingRate | Object | Object containing a price field with a CentPrecisionMoney value. |
taxCategory | Object | Key reference to the TaxCategory used for the shipping costs, in the format { "typeId": "tax-category", "key": "<tax-category-key>" }. |
carrierInfo | String | Name of the carrier. |
earliestDeliveryTime | String | Earliest estimated delivery date and time, in ISO 8601 format. |
latestDeliveryTime | String | Latest estimated delivery date and time, in ISO 8601 format. |
HTTP status codes
| Status | Description |
|---|---|
200 | Request processed. The business logic outcome is in the response body. |
4xx | Client error. The webhook call is treated as failed and is not retried. |
5xx | Server error. The webhook call is retried once if the timeout budget allows, and is otherwise treated as failed. |
200 response, not through HTTP status codes. If your endpoint returns an error message with any other status code, the message doesn't reach the agent.Timeouts
Create, Update, Read, and Complete actions. The budget covers the initial request, any retry delay, and the retry attempt combined.Allowed values are no more than 10,000 ms (10 seconds). The default is 1,000 ms. If the initial request already consumes the full budget, no retry is attempted.
2xx, or returns a response body that doesn't match the response format. By default, AI Hub then ignores the webhook result and proceeds with checkout. This is a fail-open behavior that prioritizes checkout completion over blocking the shopper due to a technical issue with the webhook endpoint. To block checkout when the webhook call fails, enable Stop checkout if the custom extension fails.In these technical failure cases, no webhook-provided changes are applied to the Cart/session. The Cart/session remains in the state it was in before the webhook call, and checkout continues without any validation results or other enrichments that would have come from that webhook response.
Idempotency and retries
200 response. A failed webhook call does not roll back the shopper's checkout session; instead, the webhook result is discarded and the Cart/session remains unchanged by that webhook attempt.5xx status code, and the remaining time in the Timeout (ms) budget allows. The retry shares the same total budget as the initial attempt, so retries are only performed when the initial request finishes with time left over. Responses with an HTTP 4xx status code are not retried. AI Hub does not send idempotency headers, so your endpoint can receive the same request twice.Because failed webhook attempts do not apply partial webhook-driven changes, if all attempts within the budget fail, the Cart/session is unchanged by that call and a subsequent checkout action is effectively a fresh attempt against the current Cart/session state.
200 response with an error message is a deliberate business decision and still blocks checkout, as described in Failure response.