Docs

Examples

Runnable and copy-paste examples for native ATM checkout, webhooks, status reconciliation and tickets.

Closed beta@atmosphere-money/app-nodeSDK beta: 0.0.0-beta.3ATM API beta: 2026-0671 published lexicons

Compatible with the closed-beta ATM app APIs and versioned ATM event headers. Check atm-api-version on every webhook or XRPC receiver event.

Local examples folder

The examples folder supplied with your integration includes the native Node reference. It exercises the same server-side contracts as the SDK: durable attempts, POST status reconciliation and signed notifications.

sh
cd examples/atm-node-app
npm install --package-lock=false --prefix ../../packages/app-node
npm run build --prefix ../../packages/app-node
npm install
cp adapter.example.ts adapter.local.ts
# Configure the registered test binding and private adapters first.
ATM_FIXTURE_ADAPTER=./adapter.local.ts npm run dev

Run the starter kit

The starter kit is designed to prove the integration shape before you copy helpers into your app. Start with the test environment, send a dashboard test event, then try checkout/status once your app can verify signed events.

  • Register the app in ATM test mode and enable the modules you want to test.
  • Configure adapter.local.ts with app/broker identities, HTTPS checkout/app/dashboard origins, exact catalog refs, private storage, webhook secrets and fresh per-call service-auth.
  • Set ATM_FIXTURE_ADAPTER to that private module. Route the registered HTTPS origin to loopback port 8787 and register its /webhooks/atm URL for signed HTTP.
  • Send a test notification; verify acceptance without logging its body or credentials.
  • Redrive the same delivery with a fresh timestamp and confirm it is acknowledged without a duplicate effect.
  • Open /, use the Buy Digital Fixture button (POST /buy/digital), then view the session-bound /status/<purchaseId> page. The worker polls native status by POST even if the browser never returns.
  • Fixed monthly is not yet available: its exact-invoice recovery API awaits deployment and SDK release, and ATM enables monthly for each app and environment separately.
sh
npm run typecheck
npm run smoke
# After configuring the adapter, open the registered HTTPS app origin.

Minimal checkout server

The smallest native checkout: capture the request, then recover it. The same attempt ID is safe to send again after any failure; it always replays the original body and key.

ts
import type { AtmCreateCheckoutInput } from "@atmosphere-money/app-node";

export async function checkoutUrl(attemptId: string, request: AtmCreateCheckoutInput) {
  await attempts.capture(attemptId, request); // environment "test", exact Product and fixed Price
  const attempt = await attempts.recover(attemptId);
  return attempt.checkout!.url;
}

Hosted checkout recipe

Without the SDK, the wire contract is a JSON POST of the exact bytes you saved, with a fresh service-auth JWT for every call. ATM owns the checkout page, processor session, Wallet and receipts. Prefer the SDK attempt helper, which also handles saving and replay.

ts
import type { AtmCreateCheckoutResult } from "@atmosphere-money/app-node";

const lxm = "money.atmosphere.payment.createCheckout";
const aud = "did:plc:bbbbbbbbbbbbbbbbbbbbbbbb#atmosphere_money_broker";

// storedRequest: the exact JSON you saved before the first attempt. Every retry
// sends these same bytes, including the original idempotencyKey.
export async function postCreateCheckout(storedRequest: string): Promise<AtmCreateCheckoutResult> {
  const response = await fetch(`https://your-assigned-test-checkout.example/xrpc/${lxm}`, {
    method: "POST",
    cache: "no-store",
    redirect: "error",
    headers: {
      authorization: `Bearer ${await mintMyAppServiceAuthJwt({ lxm, aud })}`,
      "content-type": "application/json",
    },
    body: storedRequest,
  });
  // A failure keeps the attempt: retry the same bytes, never a new request.
  if (!response.ok) throw new Error(`createCheckout returned ${response.status}`);
  return (await response.json()) as AtmCreateCheckoutResult; // save it before redirecting
}

Webhook receiver recipe

Verify the raw body, claim the delivery and queue reconciliation. The worker reads canonical status, so dashboard redrives and retries never repeat a purchase effect.

ts
import { createNodeWebhookHandler } from "@atmosphere-money/app-node";

export const POST = createNodeWebhookHandler({
  secret: [process.env.ATM_WEBHOOK_SECRET, process.env.ATM_WEBHOOK_PREVIOUS_SECRET]
    .filter((value): value is string => Boolean(value)),
  deliveryStore: {
    claim: claimWebhookDelivery,
    complete: completeWebhookDelivery,
    release: releaseWebhookDelivery,
  },
  onEvent: async (event) => {
    if (event.environment !== "test" || event.apiVersion !== "2026-07")
      return { status: 422, body: { error: "UnexpectedEventBinding" } };
    await enqueueReconciliation(event);
    return { body: { ok: true } };
  },
});

XRPC receiver recipe

AT Protocol-native apps can receive the same signed event envelope through an app-hosted XRPC method. This is ATM's default event delivery path for AT Protocol apps; advertise the canonical receiver in the app DID document and pair it with authenticated status reconciliation. Pull-only exposes successfully delivered test receiver history for diagnostics only; every live environment requires the XRPC receiver or signed webhook.

http
POST /xrpc/money.atmosphere.event.receiveEvent
Authorization: Bearer <ATM service-auth jwt>
Content-Type: application/json

{
  "id": "whd_...",
  "type": "payment.completed",
  "createdAt": "2026-06-05T00:00:00.000Z",
  "apiVersion": "2026-07",
  "environment": "test",
  "data": {
    "$type": "money.atmosphere.event.defs#paymentCompleted",
    "paymentId": "pay_...",
    "appOrderId": "ord_123"
  }
}

Ticket purchase recipe

Paid tickets use their own admitted Tickets contract, not native checkout. Create a hold with ATM Tickets first: it reserves scarce capacity and returns the ATM checkout URL for the buyer.

ts
import { createTicketHoldBody } from "@atmosphere-money/app-node";

export async function startTicketCheckout(input: {
  eventUri: string;
  ticketTypeId: string;
  buyerDid: string;
  buyerAssertionJwt: string;
}) {
  const availability = await atm.getTicketAvailability({
    environment: "test",
    eventUri: input.eventUri,
  });
  if (availability.available === false) return { soldOut: true };

  const hold = await atm.createTicketHold(createTicketHoldBody({
    environment: "test",
    eventUri: input.eventUri,
    buyerDid: input.buyerDid,
    buyerAssertionJwt: input.buyerAssertionJwt,
    items: [{ ticketTypeId: input.ticketTypeId, quantity: 2 }],
    returnUrl: "https://events.example/orders/123",
    cancelUrl: "https://events.example/e/abc",
    idempotencyKey: `hold:${input.eventUri}:${input.buyerDid}:${input.ticketTypeId}:2`,
  }));
  // Persist hold.statusToken on your server before redirecting to hold.url.
  return { url: hold.url };
}

Free ticket recipe

Limited free tickets should still use ATM Tickets because capacity is scarce. Use app service-auth plus a buyer assertion and issue the ticket immediately without checkout. Supply a delivery email on every new claim because Stripe never collects one on this path.

ts
import { createFreeTicketClaimBody } from "@atmosphere-money/app-node";

export async function claimFreeTicket(input: {
  eventUri: string;
  ticketTypeId: string;
  buyerDid: string;
  buyerAssertionJwt: string;
  customerEmail: string;
}) {
  return atm.claimFreeTicket(createFreeTicketClaimBody({
    environment: "test",
    eventUri: input.eventUri,
    buyerDid: input.buyerDid,
    buyerAssertionJwt: input.buyerAssertionJwt,
    customerEmail: input.customerEmail,
    items: [{ ticketTypeId: input.ticketTypeId, quantity: 1 }],
    idempotencyKey: `claim:${input.eventUri}:${input.buyerDid}:${input.ticketTypeId}`,
  }));
}

Optional webhook receiver

The example webhook verifies the raw body, claims the delivery, and wakes canonical reconciliation. It completes the claim only after that wake-up is durable; fulfilment waits for authenticated status to return completed.

Status polling

A durable backend worker calls attempts.reconcile, which POSTs the saved status token to getCheckoutStatus, whether or not the browser returns. That canonical state drives fulfilment and the processing UI.

Ticket hold

Ticketing examples use the same ATM App Node SDK because Tickets is an ATM module. The atmosphere.tickets site carries the ticket-specific concepts, diagrams, generated reference, and scanner flows.