Express recipe
Implement ATM checkout and signed webhook verification in an Express app.
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 normal JSON parsing for your checkout route, but preserve the raw request body for ATM webhook verification.
npm install @atmosphere-money/app-node@beta expressCreate checkout route
Create an app order first, check the recipient's payout status, confirm creator app approval, then ask ATM to create the hosted checkout. The route returns only the checkout URL and token to the browser.
import express from "express";
import { createAtmAppClient } from "@atmosphere-money/app-node";
const app = express();
app.use("/checkout", express.json());
const atm = createAtmAppClient({
getServiceAuthToken: ({ lxm, aud }) => mintAppServiceAuthJwt({ lxm, aud })
});
app.post("/checkout", async (req, res) => {
const { recipientDid, amountCents } = req.body;
const payout = await atm.getPayoutStatus(recipientDid);
if (!payout.payable) {
return res.status(409).json({ error: "RecipientNotPayable" });
}
const approval = await atm.requestRecipientApproval({
recipientDid,
environment: "test",
paymentTypes: ["shop"],
feeShareBps: 300,
requestReason: "Enable Express checkout"
});
if (approval.status !== "approved") {
return res.status(409).json({
error: "RecipientAppApprovalRequired",
approvalUrl: approval.dashboardUrl
});
}
const order = await createAppOrder({ recipientDid, amountCents });
const checkout = await atm.initiatePayment({
environment: "test",
recipient: order.recipientDid,
amount: order.amountCents,
currency: "usd",
paymentType: "shop",
returnUrl: `https://app.example/orders/${order.id}/return`,
cancelUrl: `https://app.example/orders/${order.id}`,
metadata: { appOrderId: order.id }
});
res.json({ url: checkout.url, token: checkout.token });
});Verify webhook or XRPC receiver
Fulfillment should come from verified ATM events. Signed HTTP webhooks are the default; XRPC receiver callbacks are optional for apps that already host an AT Protocol service surface.
import { createExpressWebhookHandler } from "@atmosphere-money/app-node";
const atmWebhook = createExpressWebhookHandler({
secret: process.env.ATM_WEBHOOK_SECRET!,
expectedType: "payment.completed",
insertDeliveryIdOnce,
onEvent: async (event) => {
const metadata = event.data.payment.metadata as
| { appOrderId?: string }
| undefined;
const appOrderId = String(metadata?.appOrderId ?? "");
if (!appOrderId) return { status: 422, body: { error: "MissingAppOrderId" } };
await fulfillOrder(appOrderId, event.data.payment.id);
return { body: { ok: true } };
}
});
app.post(
"/webhooks/atm",
express.raw({ type: "application/json" }),
atmWebhook
);Fulfill payment or ticket
The fulfillment step is the same in Express: deduplicate the ATM delivery id, map the ATM payment or ticket event back to your app order, write the app-side fulfillment state once, and store the ATM id for support and reconciliation.
- 01
Deduplicate
Insert the ATM delivery id with a unique constraint before side effects.
- 02
Match order
Read appOrderId, ticket hold id, listing ref, or another private app correlation id from event metadata.
- 03
Fulfill
Grant access, issue app content, reveal tickets, update a subscription, or notify the buyer.
- 04
Reconcile
Store the ATM payment id and event id beside the app order for refunds, disputes, and redrive.
Run local test fixture
Use the runnable starter when one exists, or generate a signed webhook fixture with @atmosphere-money/testing. Your test should prove raw-body verification, duplicate delivery handling, and the app fulfillment mutation.
node --test test/atm-webhook.test.js
# or use @atmosphere-money/testing to create a signed payment.completed fixtureRuntime notes
| Raw body | Mount express.raw() on /webhooks/atm before any JSON parser touches that route. |
|---|---|
| Snippet | docs/developer/examples/express-webhook-route.ts is the copyable route example. |
| Starter status | Express has a recipe and snippet; promote to a runnable starter only if beta testers need it. |