Before you start
create a project-scoped client and vault. the examples below use thesekernel and vault variables.
AGENTCARD_MODE is an application-owned assertion, not a
value read from KERNEL. set it from the deployment configuration that owns the
agentcard credential, show the mode in internal checkout controls, and fail
closed when it is missing or does not match the environment you intend to use.
set AGENTCARD_MODE=sandbox instead only when that deployment uses a sandbox
credential.
Lifecycle
- create a
walletitem and open the returnedcard_enrollmentaction for the user. - wait for the wallet to become
connected. - create a reusable
carditem with the merchant, amount, and currency. - attach the vault to a browser and give
state.aliasesto the agent. - when the browser submits a recognized processor request containing the aliases, KERNEL holds the request and starts agentcard authorization.
- show the returned approval action to the user while the checkout remains in progress.
- agentcard executes the approved request, and KERNEL replays the processor response to the browser.
ready after an authorization settles and can be used for another separately approved purchase. only one authorization can be pending on an item at a time.
Enroll a card
before showing an agentcard enrollment option, list the vault’s items. if an agentcard wallet already exists in any state, reuse it and do not let the user add another. show its existing action or status instead. the api makes item keys unique but does not currently enforce one wallet per provider, so the ui must enforce a maximum of one agentcard wallet per vault. the examples usepresentProviderAction, an application-owned function that
publishes the action to an authenticated session for the end user who owns the
vault. bind the action to that user, vault, and item; apply a short application
ttl capped by wallet.expires_at when present; and stop serving it when the
action changes or disappears. derive authenticatedUser from the server-side
session, not a request field. do not log the url or put it in model context. the
browser payment guide
defines the authenticated redirect and expiry contract for this helper.
spec.user_id can reuse a user who was already enrolled through another wallet in your organization. it cannot reference an arbitrary agentcard user.
Create a card item
amount uses minor currency units, so 2306 means 23.06 usd. omitting card_id lets the cardholder select an enrolled card on the approval screen. to pin a card, request the wallet’s advertised payment_methods expansion and set a returned id as spec.card_id.
Reuse a card item for a new purchase
upsert can retrieve an identical item, but it cannot replace the purchase
specification at an existing key. for a later purchase, retrieve the reusable
agentcard item and use update with the complete new specification:
requested or
ready. if it is pending_approval, finish and reconcile that authorization
before preparing another purchase. if it is degraded, retrieve it to allow
recovery and stop if it remains degraded. update replaces the full spec, so
include card_id again when you want to keep the card pinned. never update an item
to retry a failed, timed-out, or indeterminate checkout.
agentcard has no per-item test, merchant_url, or domain allowlist. merchant is the name shown on the approval screen, not an enforced browsing origin. sandbox or live behavior comes from the agentcard credential configured for the integration and must match your application-owned AGENTCARD_MODE assertion before you use the aliases.
Complete the first checkout
use this sequence for an agentcard checkout:- require exactly one agentcard wallet in the vault and wait for it to become
connected. - create a headful browser with the vault attached, surface
browser_live_view_urlthrough your trusted application, and navigate to the checkout. keep this same browser for verification and submission so location-dependent pricing cannot change between the confirmed purchase and the outgoing request. - independently verify the merchant, items, active presentment amount, and active presentment currency from the merchant’s trusted order or cart backend. if one isn’t available, use documented structured checkout data or deterministic extraction for that checkout. for a stripe payment link specifically, prefer
account_settings.display_name,line_item_group.total,line_item_group.currency, andline_item_group.line_itemsfrom the structured payment-link response. use dom text and test ids only as supplemental checks because stripe can duplicate or omit them across layouts. - collect merchant-required fields such as email, billing name, and postal code from the end user. identify checkout-specific agent disclosures and instruct the agent to answer them truthfully in the normal form.
- show the verified purchase to the end user. after confirmation, create or update the card item from that same frozen object and require it to be
ready. the vault attachment covers items created later in the same vault. - start the card and event observer before checkout submission. keep it running concurrently while the browser request is held.
- give the browser agent the aliases, separately collected customer fields, and any required disclosure answer. submit the merchant form once and never retry submission.
- publish the approval action through the authenticated, expiring application flow. never send it to the checkout browser or agent.
- after the authorization settles, reconcile authorization state, item events, the checkout page, and the merchant order record. don’t prepare the next purchase until this attempt is terminal or explicitly classified as indeterminate.
Surface the live view
presentLiveView represents an application-owned route. store the url
server-side with the authenticated end user and browser session binding, and
render or embed it only after checking that session. retain the same binding
through confirmation and approval pauses. remove it when the browser is deleted
or times out, and don’t put it in logs or model context. see
live view for iframe and csp
requirements.
Run checkout and observation concurrently
start the observer before calling the browser agent. the application-owned functions below represent the observer, your existing agent loop, your order backend, and your reconciliation policy:Handle checkout approval
agentcard doesn’t advertise theauthorize operation. authorization begins
only after an attached browser submits a recognized processor request containing
the aliases.
while the request is held, retrieve the card and send action.url through the
same authenticated, expiring user-action flow used for enrollment. stop serving
the url when it disappears, changes, expires, or the authorization settles.
state.authorization describes the pending or most recent authorization,
including its status, browser_id, expected and actual amounts when
available, charge result, and replay result.
CLI
--wait performs one bounded observation. repeat the relevant command to
continue observing an existing checkout; don’t use it as evidence that a
payment succeeded or failed. run --open only in a trusted, human-operated
terminal and never pass its output to an agent.
declines, expirations, and provider failures can return a processor-shaped
failure response to the browser. the exact response depends on the native
adapter. the reusable item can still return to
ready, so item status alone
doesn’t prove that the purchase succeeded or failed.
your reconciliation policy must return succeeded only when the merchant order
record confirms a paid order whose merchant, items, amount, and currency match
the frozen purchase object. treat state.authorization, charged_kind,
replay_delivered, item events, and the checkout page as supporting evidence.
merchant success text is page-specific: Thanks for your payment can appear
for one stripe checkout, but no generic success-text matcher proves that the
merchant created the expected order. return indeterminate when the sources
disagree or the merchant record is unavailable, and don’t retry automatically.
pass the aliases to the browser agent payments guide and observe item events while the checkout runs.