Confirm the cart
The model setsconfirm to true only when the shopper said yes to the cart in the model’s last result, asks to check out or pay, says they added the card for a cart that waits, says they approved, or asks for the approval link again. The tool then confirms the cart Agentcard last showed, so you handle no cart hash and no conversation id.
Show the shopper the cart before the model confirms it. “Showing the cart” renders it.
When the confirm needs the shopper to approve, the answer carries these fields:
The approval link works for about 15 minutes. The model asks the shopper for one thing, the approval, in one short line, such as “approve the payment to place your order (up to $19.02)”. The dollar amount in the parentheses is the cart’s
max_charge, the most the shopper’s card can be held for. A store that prices its final total at checkout asks for more than the cart’s total, and a flight asks for exactly its total.
chat.ts
approvedCeilingCents beside its total whenever the cart carries one. A shopper who sees only the total approves less than the card can be held for.
Place the order
The shopper taps the link, sees the store and the amount, and approves with their passkey. Agentcard places the order against that approval. Your server hears about it as apurchase.message, and the SDK hands you text ready to post:
An order takes a few seconds to go through after the approval. A call that lands while Agentcard is still placing the order pauses once for 12 seconds and reads the conversation. The model then reads
order_placed with the order number, or placing. A placing status means the order is going through, so the model never asks for another approval. A call that finds the order already placed reads it at once.
When shopper_need_not_reply is true, a purchase.message will tell the shopper how the order went, and the model tells them they need not reply. Post that message into the chat when it arrives. The order events your company receives are documented in Order events.
Handle a refusal where it happens
The shopper declines or lets the approval expire
After a decline, the cart stays on the table. The shopper can say yes for a new approval link, or tell the agent what to change.
approval_declined has advances set to true. Open buy.nextStep(message) as “Taking the next step once the shopper finishes outside the chat” shows, and the agent offers the next step without waiting for the shopper.
Drop a message after its facts.validUntil: the link or window it names has closed. isStale(message) checks it, and listen and the webhook handler skip stale messages for you.
The cart changed
A cart changes when its price or contents drift after the shopper saw it. Agentcard refuses the confirm, and the tool answersneeds_input with error_code: cart_changed and the cart as it stands now. The model shows the shopper the new total and asks again. Nothing is charged.
The other refusals that still answer the shopper come back as needs_input with the reason in reply and the code in error_code:
A confirm that takes too long
A request that takes Agentcard more than 110 seconds comes back before its cart is ready. A confirm that takes that long returns the order it placed, sends the approval link it paused on, or readsplacing while the order is still going through. A call that times out throws an AgentcardApiError with code: timeout. Whether the turn ran is then unknown, so read the conversation before you call again:
recover.ts
Check it with live credentials
The sandbox stops before payment. A confirm there endsdeclined: a paid purchase answers decline_code: sandbox_mode, and a table booking answers decline_code: sandbox_unavailable. Both mean the sandbox worked, and everything before the confirm ran for real. The approval link, the passkey tap, and the placed order exist only with live credentials.
To check them end to end, switch to live credentials as the Quickstart describes, and buy one inexpensive item with your own card.
- Ask for the item, pick a product, and say yes to the cart.
- Check that the approval link arrives alone, with one short line that names the amount, and that the model’s reply holds no link.
- Approve with your passkey. Check that “order placed” arrives in the chat with nothing typed after the tap.
- Ask for the item again, say yes, and decline the approval. Check that no charge appears and the cart is still there.