Checkout extensibility

Ask about this Page
Copy for AI
View as Markdown

Extend AI Hub Checkout with API Extensions and webhooks to add custom validation, shipping logic, and fraud checks to your agentic commerce flows.

AI Hub Checkout supports extensibility through two mechanisms: API Extensions and the AI Hub webhook. External systems can participate in checkout session processing to provide dynamic validation and enrichment. Examples include tax resolution, fraud detection, and real-time inventory checks.

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 the primary and recommended mechanism for implementing extensibility across commercetools. They are triggered directly within commercetools APIs and work across all sales channels. This makes them the right choice for logic that applies to your entire commerce setup.

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

API Extensions support conditional triggers, which let you control when an extension runs. You can use predicates to filter execution based on the Store associated with a Cart, allowing you to:
  • run an extension only for agentic Stores
  • apply different logic for standard storefronts and AI-driven checkout flows
For example, a predicate like store(key="my-agentic-store") restricts execution to Carts in a specific agentic Store.
For more information about configuring API Extensions and conditional triggers, see API Extensions and the Implement an API Extension tutorial.

AI Hub webhook

AI Hub provides an optional webhook mechanism specifically for checkout extensibility in AI-driven or agentic experiences. Unlike API Extensions, this webhook is scoped to the AI Hub checkout lifecycle and is designed for channel-specific orchestration. You configure the webhook through the API extension settings in the Merchant Center.

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

ScenarioRecommended approach
Channel-agnostic logic (tax, pricing, validation)API Extensions
Core commerce logic reused across all channelsAPI Extensions
Channel-specific variation of shared logicAPI Extensions with conditional triggers
Agentic or AI-specific checkout orchestrationAI Hub webhook
Inventory checks with channel-specific error handlingAI Hub webhook
Stock reservation or delivery promise for a specific channelAI Hub webhook
Shipping options from an external shipping serviceAI Hub webhook
Final checkout validation in AI-driven flowsAI Hub webhook

How they work together

When both mechanisms are active, they execute sequentially:

  1. The agent triggers a checkout session action (Create, Update, Read, or Complete).
  2. commercetools creates or updates the Cart based on the request.
  3. API Extensions are triggered based on configured conditions and they run first to handle core Cart logic, such as taxes or pricing.
  4. If the Cart operation succeeds, AI Hub invokes the webhook, if configured, with the corresponding action (Create, Update, Read, or Complete). The webhook handles external business logic that the Cart resource can't do, such as fraud checks or real-time inventory validation.
  5. The external system evaluates the request.
  6. The webhook returns a response with validation results.
  7. 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.
Multiple API Extensions can be configured at the Project level and chain together during Cart processing. This is standard commercetools behavior. Each agentic channel has a single webhook endpoint. This endpoint handles all checkout lifecycle actions (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

When an API Extension refuses a Cart update during checkout, AI Hub converts the errors returned by the extension into UCP messages for the agent. By default, the message content is the extension error's message and the message code is the extension error's code, without a severity.
To control the message that the agent receives, add the fields of a UCP message to the 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 example eligibility_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 severity requires_buyer_input escalates the checkout to the buyer.
API Extension response with a UCP messagejson
{
  "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"
      }
    }
  ]
}
AI Hub ignores other keys in 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:

FieldDescription
Custom extension URLThe URL of your webhook endpoint.
Custom extension authorization headerOptional. 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 failsWhether 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.
For more details, see the API extension settings on the Manage agentic channels page.

Authentication

AI Hub sends the configured authorization header value directly in the 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 headertext
Authorization: <authorization-header-value>
Provide the complete header value, including the authentication scheme. For example, to make the header read 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.
Your endpoint must validate this value to confirm the request originates from AI Hub. Reject requests with missing or invalid authorization. If your endpoint rejects a request with an HTTP 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

At each checkout lifecycle stage, AI Hub sends a POST request to your endpoint. The request body contains an 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:

Structure of a request bodyjson
{
  "action": "Create",
  "resource": {
    "typeId": "cart",
    "id": "<cart-id>"
  }
}

Action types

ActionDescription
CreateCheckout session initialized
UpdateCart or session updated
ReadCurrent checkout state retrieved
CompleteCheckout 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

HeaderDescription
AuthorizationConfigured authorization header value, sent as-is. Only sent if a value is configured.
Content-Typeapplication/json
Acceptapplication/json

Body

The request body contains only the action identifier and a Cart reference. No additional Cart data, customer information, or channel details are included in the payload.
To access Cart contents for validation, your endpoint must retrieve the Cart from the commercetools API using the provided 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

Your endpoint must return an HTTP 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

Structure of a response bodyjson
{
  "type": "Success",
  "messages": []
}

Response fields

FieldTypeRequiredDescription
typeStringYesSuccess or Failure. Indicates the outcome of the validation.
messagesArrayNoMessages for the agent. Messages of type error block checkout.
errorsArrayNoLegacy list of errors. Each error is passed to the agent as an error message without a severity. Use messages instead.
shippingMethodsArrayNoShipping methods offered by your endpoint. If present, these replace the Shipping Methods of your Project for this checkout.
orderUrlStringNoURL of the customer-facing order status page. If present, it is used instead of the order URL configured for the Store.
futureOrderNumberStringNoFor the Complete action: the order number to assign to the Order. It is also used as the payment reference when the payment is authorized.
metadataObjectNoFor 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.
AI Hub validates the response body. A response that doesn't match this structure is treated as a failed webhook call. For more information, see Timeouts.

Success response

A Success response without error messages indicates that checkout can proceed:
Response structure for a successful requestjson
{
  "type": "Success"
}

Failure response

A Failure response with at least one error message blocks checkout:
Response structure for a failed requestjson
{
  "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

Each entry in the messages array is a UCP message that is passed to the agent as written.
FieldTypeRequiredDescription
typeStringYeserror 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.
codeStringConditionalMachine-readable code that the agent acts on, such as out_of_stock or address_undeliverable. Required for error and warning messages.
contentStringYesText that the agent or buyer receives.
content_typeStringNoplain or markdown.
pathStringNoJSONPath expression that points to the field of the UCP request that the message is about, for example $.line_items[0].item.id.
severityStringNoWho 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).
An 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.
Message codes can be custom strings defined by the implementer. Because error behavior depends on the underlying agent protocol, aligning with platform-specific codes improves interoperability. For Google Universal Commerce Protocol (UCP) channels, see the Google UCP error code reference. Messages should be consistent and deterministic to ensure predictable checkout behavior.

Order view URL

On the 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.
Response that returns an order view URLjson
{
  "result": {
    "type": "Success"
  },
  "orderUrl": "https://example.com/orders/123456789?token=customer_abcde"
}
If the response doesn't include an 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

The 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.
Example of a response that contains an errorjson
{
  "type": "Failure",
  "errors": [
    {
      "code": "address_unverifiable",
      "message": "The delivery address could not be verified."
    }
  ]
}
FieldTypeDescription
codeStringError code identifying the type of error.
messageStringHuman-readable description of the error.
If you send both messages and errors, AI Hub reads both.

Shipping methods

Use the 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:

FieldTypeDescription
idStringIdentifier of the Shipping Method.
localizedNameObjectName of the shipping method as a LocalizedString.
localizedDescriptionObjectDescription of the Shipping Method as a LocalizedString.
shippingRateObjectObject containing a price field with a CentPrecisionMoney value.
taxCategoryObjectKey reference to the TaxCategory used for the shipping costs, in the format { "typeId": "tax-category", "key": "<tax-category-key>" }.
carrierInfoStringName of the carrier.
earliestDeliveryTimeStringEarliest estimated delivery date and time, in ISO 8601 format.
latestDeliveryTimeStringLatest estimated delivery date and time, in ISO 8601 format.

HTTP status codes

StatusDescription
200Request processed. The business logic outcome is in the response body.
4xxClient error. The webhook call is treated as failed and is not retried.
5xxServer error. The webhook call is retried once if the timeout budget allows, and is otherwise treated as failed.
Return business logic errors (validation failures, fraud checks) in the response body of an HTTP 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

The Timeout (ms) value is a single, retry-inclusive budget for the entire webhook call. It applies uniformly to the 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.

The webhook call fails if the request exceeds the configured timeout, cannot be completed because of a network error, returns a status code other than 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

AI Hub only applies webhook business logic from a successful HTTP 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.
Within a single webhook call, AI Hub retries once after a 300 ms delay if the initial attempt fails because of a network error, a timeout, or an HTTP 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.

This fail-open behavior applies only to technical failures. A successful 200 response with an error message is a deliberate business decision and still blocks checkout, as described in Failure response.