Agent orders: promotion, variant and webhook tests
Test agent orders for correct variants, applicable discounts and reliable webhook processing. Use current Shopify contracts and practical merchant checks.
Tru Commerce Team · November 26, 2026 · Checkout & Protocols
Agent orders need the same commercial precision as storefront orders: the intended variant, an applicable promotion and a verifiable merchant state. These are separate integration contracts. A successful tool response does not prove that the right item received a discount or that the resulting order was processed once.
Reviewed 26 November 2026. This guide uses current Shopify API and webhook documentation to build a proposed merchant acceptance pack. It does not report an observed customer failure rate. Tru Commerce builds commerce integrations.
Preserve the selected variant through every operation
A shopper's product request and the merchandise identifier sent to a cart are not the same record. Resolve the request to an actual variant and preserve the selected options, quantity and any selling plan. If the request is ambiguous, ask a clarifying question or present distinct choices.
An illustrative case is a blue medium shirt and a blue large shirt. Both match a generic product description. Only one matches the buyer's selection. Changing the quantity should not silently reset the size; changing the size should trigger a fresh check of the resulting merchandise and offer.
Shopify's cartLinesUpdate reference supports updating quantity, merchandise, custom attributes and selling plan. It distinguishes omitted or null attributes, which preserve existing attributes, from an empty array, which clears them. Its response includes the cart, user errors and warnings. Test those semantics rather than treating every HTTP success as a successful requested change.
Keep the mapping explicit in your product-data API contract. The out-of-stock guide covers freshness; this guide focuses on preserving the approved selection while the basket changes.
A submitted discount code is not an applied discount
Shopify's cartDiscountCodesUpdate replaces the current code list with the supplied list. An empty array removes the codes. Codes are case-insensitive, and the documentation instructs integrations to inspect each returned code's applicability to the current cart.
That distinction belongs in the buyer experience. An agent should not announce a saving merely because it sent a code. It should inspect the authoritative cart and explain whether the promotion applied. If the basket changes, recheck the outcome rather than retaining the earlier savings sentence.
For example, a promotion might be applicable before a product is removed and inapplicable afterward. The test should verify the current cart outcome and revised total. This is an illustrative test condition; the actual eligibility rules belong to the merchant's configured promotion engine.
Avoid blanket claims that agents cannot submit promotion codes or that every protocol supports the same discount fields. The integration route, platform version and enabled extension determine the contract. When implementing ACP or UCP, verify the negotiated feature rather than copying a storefront assumption.
Test the basket as a sequence, not an isolated mutation
Most useful failures appear after a change. Run a small sequence that adds an item, updates a variant, applies a code and then changes the basket again. Record the authoritative state after each step and compare it with the agent's message.
| Test fixture | Operation | Evidence to inspect |
|---|---|---|
| Valid product with two sizes | Change the selected size | Returned merchandise and displayed size agree |
| Existing line attributes | Update quantity without attributes | Existing attributes remain when the contract says they should |
| Existing line attributes | Submit an empty attribute array | Clearing is deliberate and visible to the integration |
| Existing promotion codes | Submit a different list | Full intended list is represented after replacement |
| Code that does not qualify | Apply code to the current cart | Applicability and total are reflected accurately |
| Previously qualifying basket | Remove a qualifying item | Agent refreshes the promotion result and total |
| Cart mutation returns warnings | Inspect response | Warning meaning is handled rather than ignored |
These are acceptance tests, not results from a vendor comparison. Use test products and known promotion rules so expected outcomes can be established before the agent runs.
The shipping and tax guide adds destination and delivery choices to this sequence. The final approved amount should be based on the current offer, not a remembered product price plus an old discount.
Verify webhook authenticity before updating business state
Order and fulfillment events can inform merchant systems after the conversational interaction ends. The receiver must establish that a delivery is authentic before it changes internal state.
Shopify's delivery verification documentation specifies HMAC verification using the raw request body. It also distinguishes the delivery identifier, X-Shopify-Webhook-Id, from X-Shopify-Event-Id, which correlates deliveries from the same merchant action across subscriptions. Use the identifier appropriate to the task rather than treating every ID as an order ID.
This distinction is operationally useful. Delivery deduplication prevents a repeated delivery from reapplying a side effect. Event correlation helps explain why more than one subscription reported the same underlying action. Neither alone tells finance whether two order records represent the same commercial purchase.
Define the scope of each idempotency record. Include the merchant or account boundary where relevant so unrelated stores cannot collide. Retain the provider event and resource identifiers needed for investigation without storing unnecessary customer details in general logs.
Separate receiving, processing and reconciling
The same Shopify guidance recommends idempotent processing, quick acknowledgment and queueing for bursts. It notes that reconciliation jobs can retrieve information missed by webhook processing. Build the receiver around recoverable state rather than a single request handler that performs every downstream action inline.
A practical design records authenticated receipt durably, then tracks processing status and any failed downstream step. Do not mark the business side effect complete merely because the incoming delivery was acknowledged. An acknowledgment means the receiver accepted the delivery, not that fulfillment or reporting finished.
The exact implementation depends on the integration, but the acceptance criteria can remain clear:
| Receiver condition | Desired behavior to verify | Evidence |
|---|---|---|
| Invalid signature | Reject before business processing | Rejection record without a commercial side effect |
| Repeated delivery | Do not repeat a completed side effect | Delivery ID and processing result |
| Two subscriptions report one event | Correlate without confusing deliveries with orders | Event ID, subscription context and resource ID |
| Worker fails after receipt | Preserve work for controlled recovery | Durable receipt and failed processing status |
| Downstream system is unavailable | Investigate or retry under an explicit policy | Attempt history and responsible owner |
| An event was missed | Reconcile against authoritative resources | Difference report and corrective action |
These checks do not require every provider to use identical headers or delivery semantics. If you also process payment-provider webhooks, implement their documented verification and event model separately.
Join the evidence without overstating the outcome
Maintain a trace from the selected variant to the cart, checkout and merchant order where those records exist. Payment and fulfillment records may arrive through separate systems. Join them deliberately rather than inferring an order from the final assistant message.
A useful operations view distinguishes cart changes, accepted checkout, payment state, order state and receiver failures. That lets the team answer whether the customer saw the correct promotion and whether the merchant recorded the resulting purchase.
Use the commerce-agent recovery guide for uncertainty around completion. Webhook replay is not permission to create a new checkout or charge. It is a way to recover processing of evidence under the applicable integration contract.
Before expanding the pilot, run the sequence and receiver tests with engineering, merchandising and operations. Save sanitized inputs, expected outcomes and merchant records. If you need to connect these boundaries, review agentic checkout and book a workflow review with your variant model, promotion setup and event consumers.
FAQ
It depends on the supported integration. Shopify documents a cart mutation for discount codes, but sending a code does not prove it applies. Inspect the returned cart and applicability.
Do not assume it does. Recheck the authoritative basket after changes because eligibility and totals can change with the selected merchandise or quantity.
No. Delivery, event and commercial resource identifiers serve different purposes. Use provider-documented identifiers for delivery deduplication and retain the order identifier for commercial reconciliation.
No. Receipt and downstream processing are separate states. Track failed processing and reconcile against authoritative merchant records where needed.
Sources
- 1.Shopify's cartLinesUpdate reference - shopify.dev
- 2.Shopify's cartDiscountCodesUpdate - shopify.dev
- 3.Shopify's delivery verification documentation - shopify.dev
Put this into practice
Walk through your shopper journey, integration requirements and the results you want to measure with Tru Commerce.
Choose a time after the form · 30 minutes · no card
Continue reading
November 26, 2026
Agent identity: what merchants should verify and buy
Compare agent verification approaches and merchant evidence requirements. Separate request identity, customer authorization and payment controls before buying.
November 26, 2026
Shipping and tax in agent checkout: an offer checklist
Design agent checkout around buyer context, delivery choices and accurate offer estimates. Test shipping, tax calculation and changes before purchase approval.
November 26, 2026
ACP implementation: merchant checkout readiness
Implement ACP around authoritative checkout, payment compatibility and order recovery. Review channel access, capability negotiation and merchant pilot tests.