Checkout Flow

Build a cart with one-time items and recurring subscriptions, then run checkout against a broker that speaks network.attested.*. The PoS owns the cart records; the broker owns the payment record and issues the checkout URL.

1. Create a cart

Start with a cart. Provide the recipient's DID as subject (required) and a currency. By default the cart is marked private, so the issued record on the payer's PDS omits subject and the line item refs — pass private: false to publish them.

typescript
const { data: created } = await paymentAgent.com.atiproto.payment.cart.create({
subject: "did:plc:creator123",
currency: "USD",
});
const cartUri = created.cart.uri;

2. Add line items

Each line item is a one-time item or a recurring subscription. Pass the cart's URI as cartUri so the PoS adds the line to the existing cart. Each line item carries its own subject — either a com.atproto.repo.strongRef to a specific record (a post, a feed) or a #userRef wrapping a user's DID.

One-time item targeting a user

typescript
await paymentAgent.com.atiproto.payment.item.create({
cartUri,
subject: {
$type: "com.atiproto.item#userRef",
did: "did:plc:creator123",
},
amount: 500,
quantity: 1,
message: "Great post!",
});

One-time item targeting a specific record

typescript
await paymentAgent.com.atiproto.payment.item.create({
cartUri,
subject: {
$type: "com.atproto.repo.strongRef",
uri: "at://did:plc:creator456/app.bsky.feed.post/abc123",
cid: "bafyrei...",
},
amount: 1000,
});

Recurring subscription

interval mirrors the broker shape: pass a #namedInterval for the common cases or a #customInterval for an arbitrary day count.

typescript
await paymentAgent.com.atiproto.payment.subscription.create({
cartUri,
subject: {
$type: "com.atiproto.subscription#userRef",
did: "did:plc:creator123",
},
amount: 999,
interval: {
$type: "network.attested.payment.initiate#namedInterval",
value: "monthly",
},
});

3. Check out

Once the cart is populated, call payment.cart.checkout with the cart URI and an optional broker (did:web:...). When a broker is pre-seeded the PoS workflows through network.attested.payment.initiate and resolves with a checkoutUrl and a strongRef payment.

Broker pre-seeded

typescript
const { data: checkout } = await paymentAgent.com.atiproto.payment.cart.checkout({
cart: cartUri,
broker: "did:web:broker.example",
redirectUrl: "https://yourapp.com/checkout/complete",
});
// payment is a com.atproto.repo.strongRef to the new network.attested.payment record
window.location.href = checkout.checkoutUrl;

No broker pre-seeded

Skip the broker parameter and the PoS returns an #initiateRequest payload in payment (discriminated by $type) so the caller can route to a broker themselves, then attach the resulting payment via payment.cart.put.

typescript
const { data: prep } = await paymentAgent.com.atiproto.payment.cart.checkout({
cart: cartUri,
});
if (prep.payment.$type === "com.atiproto.payment.cart.checkout#initiateRequest") {
// Pick a broker from the recipient's profile and call initiate yourself.
const broker = await pickBroker(prep.payment.subject);
const initiate = await callBrokerInitiate(broker, prep.payment);
// Tell the PoS which payment record settles the cart.
await paymentAgent.com.atiproto.payment.cart.put({
uri: cartUri,
record: {
...prep.cart,
payment: { uri: initiate.payment.uri, cid: initiate.payment.cid },
},
});
window.location.href = initiate.checkoutUrl;
}

4. Verify and read status

The cart record carries a unified status field that the recipient AppView snapshots from the broker payment (pending / completed / failed / refunded / cancelled). Fetch the cart to see the latest snapshot. To independently verify the broker payment or any signed record, call network.attested.verify.

typescript
// Hydrate the cart and its line items
const { data: hydrated } = await paymentAgent.com.atiproto.payment.cart.get({
uri: cartUri,
});
// Independently verify the broker payment
const { data: verified } = await xrpc.call(
"network.attested.verify",
{ uri: hydrated.cart.payment?.uri },
);

Cart management

  • List carts — payment.cart.list. Filters: recipient subject, a record at-uri (accepts a specific record or a repo-level at://did:plc:...), unified status (cart-lifecycle or broker-payment-snapshot values).
  • Get cart details — payment.cart.get returns the cart view plus a single items array (union of item and subscription views).
  • Attach a payment — payment.cart.put takes the full cart record (including the payment strongRef) when the caller ran the broker call themselves.