Tenzro
Tutorial — Payments

Build an agentic commerce workflow

A real agentic checkout cycles through session opening, mandate validation, and authorized execution. The same DelegationScope + SpendingPolicy gate both the AP2 session flow and the one-shot MPP/x402 paths — so the agent can fall back to a stateless 402 challenge whenever a session is overkill.
Level
Advanced
Time
~30 min
Prerequisites
Delegated machine DID, controller human DID
Stack
TypeScript
01

Open an AP2 session against the merchant

A session pins the agent DID, the provider DID, and the service URL with a max-amount ceiling.

import { TenzroClient } from "tenzro-sdk";
const client = new TenzroClient({ endpoint: "https://rpc.tenzro.network" });

const session = await client.ap2().createSession(
  "did:tenzro:machine:agent-1",
  "did:tenzro:machine:merchant-1",
  "https://api.merchant.example/checkout",
  "1.00",
  "TNZO",
);
02

Validate the intent/cart mandate pair

Sign Intent and Cart VDCs off-chain and validate the pair against all three ceilings — AP2 cap, DelegationScope, runtime SpendingPolicy.

const result = await client.ap2().validateMandatePair(intentVdc, cartVdc, true);
if (!result.valid) throw new Error(result.error);
03

Authorize and execute

Authorize within the session ceiling, then settle.

const auth = await client.ap2().authorizePayment(session.session_id, "0.80");
const receipt = await client.ap2().executePayment(session.session_id, auth.authorization_id);
console.log("settled:", receipt);
04

Fall back to a one-shot MPP or x402 challenge

For one-off resources the agent can call the MPP or x402 paths directly by URL — both are gated by the same DelegationScope and SpendingPolicy.

const r1 = await client.payment.payMpp("https://api.merchant.example/inference", "did:tenzro:machine:agent-1");
const r2 = await client.payment.payX402("https://api.merchant.example/data", "did:tenzro:machine:agent-1");
Related
← All tutorials