Hono recipe
Native ATM test checkout and notification verification with Hono route handlers.
Compatible with the closed-beta ATM app APIs and versioned ATM event headers. Check atm-api-version on every webhook or XRPC receiver event.
Install SDK
Use Hono when your AT Protocol app is a small service with Web Request routes. The same routes run in Node-compatible Hono deployments and on Workers.
Install the pinned native build supplied for your integration and keep its integrity hash in your lockfile. Older npm betas may not include the native checkout helpers.
# For example, a supplied package tarball, plus Hono:
npm install ./atmosphere-money-app-node-<version>.tgz honoConfigure attempts
Every recipe shares one durable attempt store. An attempt keeps the exact native request and idempotency key, ATM's response and the latest canonical status, so a retry never builds a second request.
import {
createAtmCheckoutAttempts,
type AtmCheckoutAttempt,
type AtmDurableStore,
} from "@atmosphere-money/app-node";
// Implement AtmDurableStore with compare-and-swap in your database. Serverless
// and edge filesystems are not durable; createAtmFileStore suits one server only.
declare const attemptStore: AtmDurableStore<AtmCheckoutAttempt>;
export const attempts = createAtmCheckoutAttempts({
// Your assigned test configuration: app DID, test broker DID and checkout origin.
appDid: "did:plc:aaaaaaaaaaaaaaaaaaaaaaaa",
brokerDid: "did:plc:bbbbbbbbbbbbbbbbbbbbbbbb",
brokerUrl: "https://your-assigned-test-checkout.example",
store: attemptStore,
// A NEW token per call, signed by your PDS via com.atproto.server.getServiceAuth.
getServiceAuthToken: ({ lxm, aud }) => mintMyAppServiceAuthJwt({ lxm, aud }),
});Create checkout route
Create the order and its attempt once, with a unique attempt ID that also serves as the idempotency key. The checkout route runs only after an authorized Buy click: it captures that stored request, sends it, and returns only the checkout URL. A repeat click or a retry recovers the same operation. The status token stays on your server.
import { Hono, type Context } from "hono";
import type { AtmCreateCheckoutInput } from "@atmosphere-money/app-node";
const app = new Hono();
app.post("/orders/:id/checkout", async (context: Context) => {
// Your session and CSRF middleware run first; load the order by its owner.
const order = await loadOwnedOrder(context, context.req.param("id"));
if (!order) return context.json({ error: "OrderNotFound" }, 404);
await attempts.capture(order.attemptId, order.request);
const attempt = await attempts.recover(order.attemptId);
context.header("cache-control", "private, no-store");
return context.json({ url: attempt.checkout!.url }); // never the statusToken
});
export default app;
// Your app: the buyer's own order, with its attempt ID and request stored once.
declare function loadOwnedOrder(
context: Context,
orderId: string,
): Promise<{ attemptId: string; request: AtmCreateCheckoutInput } | null>;Add event receiver
AT Protocol apps use the canonical #AtmEventReceiver / money.atmosphere.event.receiveEvent wake-up transport by default. A conventional web app can explicitly select the signed HTTP webhook shown in this recipe. Verify each delivery, claim it, and queue reconciliation before acknowledging.
import { Hono, type Context } from "hono";
import { createHonoWebhookHandler } from "@atmosphere-money/app-node";
const app = new Hono();
app.post("/webhooks/atm", async (context: Context) => {
// Secrets arrive through context bindings on Workers, not process.env.
const atmWebhook = createHonoWebhookHandler({
secret: [context.env.ATM_WEBHOOK_SECRET, context.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); // the worker reads canonical status
return { body: { ok: true } };
},
});
return atmWebhook(context);
});Reconcile and fulfil
Fulfilment is the same in Hono. A background worker reconciles each attempt on a schedule and whenever a notification is queued, even if the buyer never returns. Only completed status with fulfillment “fulfil” grants a direct digital purchase.
// Background worker: on a schedule, and for every queued notification.
export async function reconcileOrder(
attemptId: string,
app: {
grantPurchaseOnce(effectKey: string): Promise<void>;
markUnpaid(): Promise<void>;
pollAgainLater(): Promise<void>;
holdForReview(): Promise<void>;
},
) {
const result = await attempts.reconcile(attemptId); // POSTs getCheckoutStatus
switch (result.action) {
case "fulfil":
// Insert result.effectKey under a unique constraint and grant the
// purchase in the SAME database transaction.
return app.grantPurchaseOnce(result.effectKey!);
case "closed": // failed, canceled or expired
return app.markUnpaid();
case "wait": // pending; deadlines passing are not outcomes
return app.pollAgainLater();
case "order": // an order owner must confirm; not used by fixed digital checkout
return app.holdForReview();
}
}Run local test fixture
The examples/atm-node-app Node reference is the runnable native starter. Your tests should prove capture before any request, recovery after a restart or lost reply, status polling by POST, and a single grant for a repeated completed status. With push enabled, use signed fixtures from @atmosphere-money/testing to prove raw-body verification and duplicate delivery handling.
npm run typecheck
# Then send a signed fixture from @atmosphere-money/testing through app.request().Runtime notes
| Web Request | The helper reads context.req.raw, so signature verification sees the original request body. |
|---|---|
| Workers | On Cloudflare Workers, see the Workers recipe for Node.js compatibility and storage guidance. |
| Starter | examples/atm-hono-worker-starter uses this webhook handler with native test checkout, a D1 attempt store and a Cron Trigger status sweep. |