Merchant commerce kit
Serve UCP and ACP checkout with the Verification Gateway SDK — how agents pay (agent tokens, saved cards, your hosted checkout), holds, pending settlements, durable stores, AP2 mandates and the confirm → pending_merchant → reportSettlement flow. SDK 5.25.0.
The checkout kits in @astrasyncai/verification-gateway do the protocol work for a merchant that
sells to AI agents. You write your catalog, your charge and your fulfilment; the kit handles
negotiation, idempotency, signatures, AP2 mandates, owner approvals and reporting the settlement
back to AstraSync. AstraSync never moves the money: you charge with your own processor.
Use @astrasyncai/verification-gateway@5.25.0 or later for everything on this page; version
markers note features added after the kits first shipped, including How agents
pay. The kits themselves shipped in 5.15.0.
The two kits
| Kit | Protocol | Routes it serves |
|---|---|---|
createUcpCheckoutKit() | UCP 2026-08-25 | POST /checkout-sessions, GET/PUT /checkout-sessions/{id}, POST …/{id}/complete, POST …/{id}/cancel, GET /orders/{id} |
createAcpCheckoutKit() | ACP | The ACP checkout-session routes under your basePath |
Both return an object with a fetch-style handle(request), resolvePending() and (SDK 5.25.0)
resolvePayment(). The UCP kit also
returns profile and profileHandler() for GET /.well-known/ucp.
import { createUcpCheckoutKit, expressHandler } from '@astrasyncai/verification-gateway';
import { createClient } from '@astrasyncai/verification-gateway/sdk';
const astrasync = createClient({
apiBaseUrl: 'https://astrasync.ai/api', // always includes /api
apiKey: process.env.ASTRASYNC_API_KEY!,
});
const kit = createUcpCheckoutKit({
profile: {
endpoint: 'https://shop.example.com/ucp/v1',
keys: [publicJwk],
paymentHandlers: ['ai.astrasync.card_token'],
ap2Mandates: true,
},
signingKey: { privateKey, kid: publicJwk.kid },
currency: 'AUD',
catalog: async (id) => products.find(id), // { id, title, price (minor units), image_url?, description? } or null
// SDK 5.25.0: ctx.confirm carries every confirm field (agent, cart, value, attribution,
// counterpartyUrl, acceptedHandlers, merchantCollects…). Spread it so new fields reach AstraSync.
verifyPurchase: (ctx) => astrasync.confirmCheckout(ctx.confirm),
// Optional (SDK 5.25.0). Charges a payment method saved in AstraSync; see "How agents pay".
settle: async ({ result }) => chargeWithYourProcessor(result),
reportSettlement: (r) => astrasync.reportSettlement(r),
fulfil: async ({ session }) => orders.create(session), // → { id, permalink_url? }
store: checkoutStore, // durable, see below
idempotencyStore, // durable, see below
links: [
{ type: 'terms_of_service', url: 'https://shop.example.com/terms' },
{ type: 'privacy_policy', url: 'https://shop.example.com/privacy' },
],
});Product images (SDK 5.20.0). Your catalog() item can carry image_url and description.
image_url must be an absolute http(s) URL (use HTTPS); the kit drops a relative or invalid value
when it prices the line. The UCP kit returns both on line_items[].item; the ACP kit returns them
on each line item's item and on the order's line items. Use PNG, JPEG or WebP (no SVG), square,
1000×1000 recommended, at most 2 MB: the same image rules as the
bridge catalog.
Mount it on Express
expressHandler(kit) runs a kit on Express. The kit checks signatures and idempotency
fingerprints over the exact request bytes, so give it the raw body:
app.get('/.well-known/ucp', (_req, res) => res.json(kit.profile));
app.use('/ucp/v1', express.raw({ type: '*/*' }), expressHandler(kit));When the AstraSync Express middleware runs first, the handler scopes sessions and idempotency keys
to the caller's verified ASTRA-id. Without it the kit scopes to the Authorization header, then
X-Astra-Id. There is never a shared anonymous scope.
Durable stores
The kit keeps checkout sessions in a CheckoutStore and replayed responses in an
IdempotencyStore. The defaults are in memory: sessions are lost on restart and are not shared
across instances. The kit warns once at startup when a kit runs on the in-memory defaults
outside tests. Pass your own stores in production.
interface CheckoutStore {
get(id: string): Promise<CheckoutSession | null>;
put(session: CheckoutSession): Promise<void>;
// Optional: atomic compare-and-set of the session status.
claim?(
id: string,
from: CheckoutSession['status'],
to: CheckoutSession['status']
): Promise<boolean>;
}claim(id, from, to) sets the status to to only when it is currently from, and returns
whether this call won. The kit claims complete_in_progress before it verifies the purchase, so
two concurrent completes of one checkout can never both charge. A busy UCP checkout comes back
unchanged with a recoverable checkout_in_progress message; ACP answers 409. Implement it
atomically, for example UPDATE checkout SET status = $to WHERE id = $id AND status = $from.
Without claim the kit warns once and the lock is best-effort.
How agents pay (SDK 5.25.0)
Your payment processor decides whether an agent's wallet works, not AstraSync and not the agent. An agent paying with its own wallet (for example Stripe Link) can pay at a store whose processor takes that wallet, and fails at one whose gateway challenges every card with 3-D Secure or only offers a card saved in AstraSync. So you choose how agents pay, without changing processor and with no processor-specific code in the kit. Turn on any of three options:
| Option | Kit config | Who charges | What AstraSync does |
|---|---|---|---|
| The agent's own token | agentTokens: { handlers, charge } | Your processor charges the token the agent sends | Records the order. It receives only the credential's presence and type, never the token, and mints nothing |
| A payment method saved in AstraSync | paymentHandlers: ['ai.astrasync.card_token'] + settle | You charge the agent-blind card token AstraSync hands you | Hands you the token. Saved cards work only for stores on AstraSync's own Stripe account |
| Your hosted checkout | hostedCheckout: { create, buyer: 'agent' | 'human' } | Your processor's hosted page (Stripe Checkout, Adyen, Fat Zebra…) | Records the order as merchant-collected (pending_merchant); you report it from your payment webhook |
import {
createUcpCheckoutKit,
stripeSharedPaymentTokenHandler,
} from '@astrasyncai/verification-gateway';
const kit = createUcpCheckoutKit({
// …profile, catalog, verifyPurchase, reportSettlement, fulfil, stores as above
agentTokens: {
handlers: [stripeSharedPaymentTokenHandler()], // a preset for com.stripe.payments
charge: async ({ instrument, handler, session, result }) => chargeAgentToken(instrument),
},
hostedCheckout: {
buyer: 'agent', // 'human': the shopper must pay on the page themselves
// Put session.id in the payment's metadata so your webhook can find the checkout.
create: async ({ session, approvalId, result }) => createHostedPage(session), // → { url, reference }
},
});The agent's own token
agentTokens.handlers are standard handler declarations your processor accepts (name, id, spec,
config). stripeSharedPaymentTokenHandler() is a preset for Stripe shared payment tokens
(com.stripe.payments), nothing more: the kit does nothing Stripe-specific. The kit advertises
these handlers in your UCP profile and in ACP capabilities.payment.handlers, beside AstraSync's.
When an agent completes with one of them and a credential, the kit confirms with
merchantCollects: true and commerceArtifacts: { paymentCredential: { type, handler } } (the
credential's presence and type only), then calls your charge({ instrument, handler, session, result }) with exactly what the agent sent. The token is never stored and never sent to
AstraSync. If the purchase is held for the owner's approval, the session goes back to payable
after approval (resume outcome awaiting_agent) and the agent completes again with its token.
Stripe's shared payment tokens need an agreement between you and the agent's platform and aren't available to every seller or region. Check with Stripe before you turn them on.
A payment method saved in AstraSync
List ai.astrasync.card_token in your payment handlers and pass settle. On a granted purchase
AstraSync hands you an agent-blind card token to charge on your own processor integration (see
the purchase flow). Saved cards work only for stores on AstraSync's own
Stripe account. settle is optional: without it the kit never asks for an AstraSync payment method.
Your hosted checkout
hostedCheckout.create({ session, approvalId, result }) creates a payment page on your processor
and returns its https url and your reference. Put the kit session id (session.id) in the
payment's metadata.
- UCP answers
requires_escalationwithcontinue_urlset to your page. - ACP keeps the session
complete_in_progresswithcontinue_urlset to your page. - The message is
payment_required(the agent may pay there) or, withbuyer: 'human',buyer_payment_required: the shopper must pay there themselves. - With hosted checkout on, a Complete with no instrument (UCP) or no
payment_data(ACP) is accepted. A repeated Complete while the page is open returns the same link.
Choosing buyer. Use 'agent' when your hosted page takes agent wallets (Stripe Checkout
offers Link). Use 'human', a forced human checkout, when your processor can't take an agent's
payment, for example a gateway that challenges every card with 3-D Secure. The agent is told the
shopper must complete payment and hands them the link.
Finish the payment from your processor's webhook:
await kit.resolvePayment(referenceOrSessionId, { status: 'settled', processorRef: payment.id });
// or { status: 'failed' } for a declined, abandoned or expired pageSettled reports the settlement to AstraSync, runs fulfil and completes the session (and sends the
UCP order webhook). Failed reports it and returns the session to payable. Calling it again is
safe. To look a checkout up by your reference, the kit uses your store's
findByPaymentReference(reference) when you implement it; otherwise it keeps a process-local
index, which is lost on restart and not shared across instances. In production implement
findByPaymentReference on a persistent store, or pass the kit session id from your payment's
metadata.
settle and charge can also return { status: 'requires_payment', url, reference?, buyer? }
for a single purchase (say, a 3-D Secure challenge). The kit sends the buyer to that page the same
way and resolvePayment finishes it.
The fallback chain
At Complete, and when an approved hold resumes, the kit tries in order:
- The agent sent a token for one of your agent-token handlers → your
charge. - Else the buyer has a payment method saved in AstraSync that you accept → your
settle. - Else (nothing on file, or AstraSync couldn't prepare the payment) your hosted checkout is on → the kit re-confirms as merchant-collected and returns your page.
- Else → the recoverable
instrument_requiredmessage, naming what you accept.
Only your processor declines. A missing payment method (no_instrument on the confirm) is
instrument_required. An AstraSync platform failure (settlementOutcome.status: 'failed' on the
confirm) is the recoverable settlement_unavailable. A missing or malformed UCP instrument is
instrument_required. None of them calls settle, says "declined" or consumes the buyer's
approval. An approval that comes back approved with nothing to settle from moves on through the
chain instead of waiting as held.
What the kit sends on the confirm
verifyPurchase receives each confirm field on its context and all of them together as
ctx.confirm, ready for client.confirmCheckout(ctx.confirm):
counterpartyUrl: your public origin. The kits always send it.acceptedHandlers: the AstraSync handlers you accept, so AstraSync only hands you an instrument you take and never redeems an approval it can't settle (a card store is never handed a stablecoin voucher). The kits always send it.merchantCollects: true: you collect the payment yourself (agent token or hosted checkout). Nothing is minted from the buyer's AstraSync payment methods.commerceArtifacts: for an agent token,paymentCredential: { type, handler }.
Spread ctx.confirm rather than picking fields, so new fields reach AstraSync without code changes.
Merchant-collected checkout without a kit (SDK 5.24.0)
If you take orders on your own checkout rather than through a kit, call
confirmCheckout({ …, merchantCollects: true }). Nothing is minted from the buyer's AstraSync
payment methods; the result is settlementOutcome: { status: 'pending_merchant', orderId } with
no settlementToken. Send the buyer to your checkout, then call reportSettlement() from your
payment webhook. The owner's approval applies first, as for any purchase. Merchants on the
AstraSync bridge handoff return the page as paymentUrl (see
Merchants).
The purchase flow
On complete, the kit calls your verifyPurchase (normally client.confirmCheckout(ctx.confirm)).
Only the confirm leg can settle; quotes never move money.
confirmCheckoutverifies the agent and applies the owner's policy.- Granted: AstraSync records the order and returns
settlementOutcome: { status: 'pending_merchant', orderId }plus what you settle with:- Card saved in AstraSync (handler
ai.astrasync.card_token, stores on AstraSync's own Stripe account): an agent-blindsettlementToken. Charge it on your own processor integration as merchant of record, with idempotency keyvoucher:<token.jti>andmetadata: { jti, sessionId }. - Stablecoin, any merchant (handler
ai.astrasync.voucher): thesettlementvoucher. Redeem it and move the funds. - Merchant-collected (agent token or hosted checkout): no token. You charge through your own processor.
- Card saved in AstraSync (handler
- Your
settleorchargereturns{ status: 'settled', processorRef },{ status: 'pending' },{ status: 'failed', failureCode }or (SDK 5.25.0){ status: 'requires_payment', url, reference?, buyer? }. - The kit reports the outcome with
reportSettlement({ orderId, status, processorRef, amountMinor, currency }), then calls yourfulfiland returns the order.
Amounts must match the order exactly, and replays are safe. Never pass the settlement token, voucher or mandates to the agent, and never log them.
Holds: the owner must approve
When the purchase needs the owner's approval, the kit never calls settle or fulfil. The kit
treats any step-up signal as a hold (requiresStepUp, requiresApproval,
recommendation: 'step_up_required', settlementOutcome.status: 'requires_approval', or a
stepUpApproval that is not yet consumed). From SDK 5.25.0, an approval that comes back
approved with nothing to settle from (settlementOutcome no_instrument or failed) is not a
hold: the fallback chain takes over.
- UCP: the checkout returns
status: 'requires_escalation'withcontinue_urlset to the owner'sapprovalUrl. - ACP: the checkout returns
status: 'pending_approval'withcontinue_urlset to theapprovalUrl.
After the owner approves, the platform completes the checkout again and the approval is redeemed.
Every purchase needs a proven agent
AstraSync only lets a purchase settle when the caller is proven to be allowed to act as the agent. It accepts exactly three proofs:
- Connector owner: the agent belongs to the person signed in on the AstraSync connector. AstraSync's bridge supplies this proof on its own.
- Owner approval: the agent's owner approves the purchase with a passkey.
- Runtime challenge: the agent passes a runtime challenge, which works for agents running through a Workforce Guard checkpoint or a self-hosted challenge handler.
When a purchase reaches your kit with none of these, it is held for the owner's approval, the same way a purchase above the agent's limit is held. One approval covers both. Expect holds on direct agent purchases that don't come through the AstraSync bridge. Make sure your Events URL is set (below), so an approved hold completes on its own.
Approval events: finish a held checkout without the agent (SDK 5.19.0)
When the owner decides, AstraSync sends a signed event to your endpoint's Events URL:
X-AstraSync-Signature: t=<unix>,v1=<hex>[,v1old=<hex>]
{ "eventId", "type": "step_up.approved" | "step_up.denied" | "step_up.expired" | "step_up.lapsed",
"approvalId", "checkoutSessionId", "kitSessionId"?, "protocol"?: "ucp" | "acp",
"counterpartyId", "agentAstraId", "transactionValue", "currency", "decidedAt", "redeemBy"? }Mount the handler next to your kits:
app.post(
'/astrasync/events',
express.raw({ type: '*/*' }),
approvalEventsHandler({ secret: process.env.ASTRASYNC_WEBHOOK_SECRET!, kits: [ucp, acp] })
);- Approved: the kit runs
validateCart, confirms at the held amount (your catalogue is not re-priced), then settles, reports and fulfils. No agent call is needed. - Resume outcomes (SDK 5.25.0): besides completed and declined, a resume can end
instrument_required(nothing to pay with),settlement_unavailable(a platform failure),awaiting_payment(your hosted checkout page is open) orawaiting_agent(an agent-token purchase is payable again for the agent to complete). All are terminal for that event. - Denied, expired or lapsed: the session goes back to payable with an
approval_denied,approval_expiredorapproval_lapsedmessage. From SDK 5.20.0 the message isrecoverable. Platforms shouldn't retry on their own afterapproval_denied. Afterexpiredorlapsed, completing again asks for a new approval. - Retries: answer 2xx once the session is finished, and 5xx for a temporary failure, so
AstraSync retries. An approved event is retried for about 10½ minutes inside its 15-minute
redeemBy. If it can't be delivered by then, it is followed bystep_up.lapsed. - Secret rotation: for 24 hours after a rotation, the previous secret signs a second value,
v1old. Pass[current, previous]as the secret. - No Events URL: a held kit purchase on an endpoint with no Events URL raises a warning on the endpoint and in Activity, because the hold can't finish without one.
Set the Events URL in the dashboard, and test it from code (SDK 5.21.0)
After registration, endpoint settings change in the dashboard only, behind your login and MFA. Set the Events URL (and the catalogue, checkout, skill and health check URLs) on the endpoint page. Every change to one of these URLs alerts the endpoint's owner.
Why: your API key lives in your host's environment. If the host is ever compromised, a leaked key
must not be able to point agents at someone else's checkout or catalogue under your verified
identity. SDK 5.21.0 removed updateEndpoint, and PATCH /api/endpoints/:id refuses API keys.
From code you can still send a test event:
import { createClient } from '@astrasyncai/verification-gateway/sdk';
const client = createClient({ apiBaseUrl, apiKey, counterpartyId: 'ASTRAE-…' });
const r = await client.sendTestEvent(undefined, { type: 'step_up.lapsed' });
// r = { delivered, status: 'delivered' | 'failed' | 'not_configured', responseCode, error, eventId }sendTestEvent(POST /api/endpoints/:id/events/test) delivers one signed, synthetic event now (approvalId: "test_…"). Your kit acknowledges and ignores it. It isn't retried.- Use it to test
step_up.lapsed, which otherwise only happens when delivery fails for the whole retry window. - A real approval's payload (for a held kit approval at this endpoint, so your resume path runs)
is sent from the endpoint page in the dashboard only.
approvedre-confirms and is held again, with nothing charged; the other types release the session.
Pending settlements
When your processor confirms asynchronously, return { status: 'pending' } from settle. The kit
keeps the session in complete_in_progress with no order. When your processor's webhook arrives,
finish it:
await kit.resolvePending(sessionId, { status: 'settled', processorRef: charge.id });
// or: { status: 'failed', failureCode: 'card_declined' }resolvePending reports the settlement and runs fulfil (or the failed path). The stored
session never holds the settlement token, voucher or mandates.
UCP specifics
- Payment handlers. List the handlers you accept in the profile.
astrasyncPaymentHandlers()builds the entries (ai.astrasync.card_tokendeclares card instruments,ai.astrasync.voucherstablecoin); youragentTokens.handlersare added beside them. Complete takes exactly one payment instrument with ahandler_idfrom your profile, or none when hosted checkout is on. From SDK 5.25.0 anything else is the recoverableinstrument_required(it used to bepayment_failed, which agents relayed as "card declined"). links. Terms, privacy, refund, shipping and FAQ links are returned on every checkout and covered by the AP2merchant_authorizationsignature.- Agent binding. After
verifyPurchase, the kit runscheckUcpAgentBindingautomatically: theUCP-Agentprofile must match the UCP profile the agent registered with AstraSync (fromresult.agent.protocolIdentities). A mismatch never settles. By default an agent with no registered UCP profile passes (for example, calls relayed by the AstraSync bridge); setucpAgentBinding: 'strict'to refuse those too, or'off'to skip the check. PassresolveIdentities(req, result)to supply the identities yourself. - Orders.
GET /orders/{id}returns the order entity (buildUcpOrder). Setwebhookto send signed order webhooks when an order is created, including fromresolvePending.
What the verification result gives you
result.mandates: AP2 v0.2 Checkout + Payment mandates, when your endpoint listsap2and the request was granted. Closed mandates needcheckoutJwtandtransactionValueonconfirmCheckout(the UCP kit passes its signed checkout ascheckoutJwt). See AP2.result.agent.protocolIdentities: the protocol identities the agent registered (agent key, UCP profile, key directory, wallet). Bind an incoming protocol request to the verified agent with them.result.settlementOutcome: read itsstatus, neversuccessalone. Treat a status newer than your SDK as pending, never failed.
MPP: confirm before the 402
If you also accept MPP, run confirmCheckout before you
issue the 402 challenge. A hold then surfaces before the agent spends any single-use payment
credential. To take Stripe shared payment tokens in a UCP or ACP checkout, use agentTokens with
the stripeSharedPaymentTokenHandler() preset (see How agents pay).
Routes that hold their own approval
If one of your routes asks the owner for approval itself (it creates its own hold and answers
202 while it waits), set approvalHeldByRoute on the Express middleware so the owner isn't asked
twice:
createMiddleware({
// …
approvalHeldByRoute: (req) => req.method === 'POST' && req.path === '/signin',
});A result that only needs the owner's approval then reaches your handler
(req.agentVerification.requiresStepUp is true), and verify-access creates no approval. Any deny
is still refused.
Route patterns in dashboard rules
Endpoint route rules in the dashboard use the same patterns everywhere (the Express and Next.js middleware, edge config and the AstraSync bridge):
| Pattern | Matches | Example |
|---|---|---|
* | Any characters, including / | /ucp/v1/checkout-sessions/* |
:name | Exactly one path segment | /ucp/v1/checkout-sessions/:id/complete |
Everything else is literal. Patterns are anchored at both ends.
Unmatched routes on Express
A request that matches no route rule passes through by default. Set
defaultRoutePolicy: 'observe' on the Express middleware to evaluate unmatched routes for the
audit trail instead. With evaluateAlwaysIfCredentialed: true, an unmatched request that carries
an X-Astra-Id is also evaluated in observe mode. Observe mode populates req.agentVerification
and never vetoes the request.
createMiddleware({
// …
defaultRoutePolicy: 'observe', // default 'pass'
evaluateAlwaysIfCredentialed: true,
});Not available yet
createMastercardRegistry()is an inert stub until Mastercard publishes its agent registry: it resolves no keys. See Payment networks.- Cards saved in AstraSync (
ai.astrasync.card_token) settle only for stores on AstraSync's own Stripe account. Any merchant can take agent payments through its own processor with agent tokens or a hosted checkout, or collect payment on its own checkout (merchantCollects).

