Payment & commerce integrations
DaloyJS treats payment providers the same way it treats email senders and database clients: wrap the provider SDK in a small plugin function that decorates the root app (handlers read it from ctx.state), and call it from validated route handlers. That keeps your business logic provider-agnostic so you can swap or A/B providers later.
Supported providers
- Stripe: hosted Checkout Sessions built from server-side Price IDs, a plain redirect to
session.url, andconstructEventAsyncwebhook verification that also runs on Workers. - Shopify: the GraphQL Admin API through the community
shopify-api-nodeSDK, Dev Dashboard app credentials, andX-Shopify-Hmac-SHA256webhooks keyed with the app client secret. - Braintree (PayPal): PayPal, cards, Venmo, Apple Pay, and Google Pay through the official
braintreeSDK, with session-scoped client tokens and SDK-verified webhooks. - Authorize.Net: Accept.js nonces charged through the official
authorizenetSDK,duplicateWindowprotection, and HMAC-SHA512 webhook verification. - Adyen: the Sessions flow for Drop-in / Components via
@adyen/api-library,hmacValidatorfor Standard webhooks, and corebasicAuth()on the webhook route. - Mollie:
mollie-api-typescriptwith both classic per-payment webhooks (unsigned, refetch) and next-gen signed webhooks (X-Mollie-Signature). - Tap Payments: GCC and MENA acquiring over the REST Charges API with
resilientFetch,reference.idempotent, andhashstringverification. - PayTabs: MENA acquiring via the official
paytabs_pt2package, wrapped as a Promise-friendly plugin with HMAC-SHA256 IPN verification. - Razorpay: UPI, cards, netbanking, and wallets via the Orders flow, with both the checkout callback signature and
X-Razorpay-Signaturewebhooks verified by core helpers. - Square: the
squareTypeScript SDK,bigintmoney amounts, Web Payments SDK tokens, and the asyncWebhooksHelper.verifySignature. - PayPal Checkout: Orders v2 over REST with cached OAuth tokens,
PayPal-Request-Ididempotency, server-side capture, andverify-webhook-signaturepostback (or certificate self-verification on Node). - Paddle Billing: a merchant of record that handles tax, with server-created transactions opened in Paddle.js and
Paddle-Signatureverified by coreverifyWebhookSignature(). - Checkout.com: Flow payment sessions through
checkout-sdk-node, account-prefixed base URLs,Cko-Idempotency-Keyon payment actions, andCko-Signaturewebhooks.
PayPal wallets are available either directly through PayPal Checkout or through the Braintree gateway. Each provider follows the same plugin shape so you can drop a new one into an existing application without rewriting routes.
What every payment integration needs
- Server-side secrets only. Secret keys, webhook signing secrets, and OAuth access tokens belong in environment variables, never in the browser bundle or in a Next.js client component.
- Server-side amounts. The browser sends an order id (or SKUs and quantities). The server loads the price and currency from its own records. See never trust client amounts.
- Webhook verification. Most providers sign their webhooks; Mollie's classic payment webhooks are unsigned and only carry an id you must refetch. Verify the signature on the raw request body before parsing it. A route without a
request.bodyschema leaves the raw body readable (capped bybodyLimitBytes), soreadBodyLimited()sees the exact bytes the provider signed. - Dedupe and fast acknowledgement. Providers retry, and deliveries arrive out of order. Dedupe atomically on the provider's event id, enqueue the work, and return 2xx quickly. See the webhook pattern.
- Idempotency on outbound calls. Derive provider idempotency keys from your own order id (plus a cart version), never from a fresh random UUID per call. Use
idempotency()for retries of your ownPOST /checkout. - Scoped rate limits and CSRF. Limit and CSRF-protect the browser-facing checkout and refund routes, and exempt the webhook routes. Providers call webhooks from their own infrastructure, without your cookies or CSRF token.
- Error mapping. Surface provider failures through problem+json so clients (and typed clients) see a consistent error shape. Log the provider's detail; do not forward it to the client.
Never trust client amounts
Every provider guide uses the same small, illustrative order module. Back it with your own database; the important parts are the ownership check, the server-side total, and the conditional pending -> paid transition:
Providers disagree on money formats (integer minor units, decimal strings, decimal numbers, bigint), so convert at the plugin edge with one helper:
| Currency examples | Decimals | 10 units in minor units |
|---|---|---|
| JPY, KRW | 0 | 10 |
| USD, EUR, GBP, SAR, AED, QAR, EGP, INR | 2 | 1000 |
| KWD, BHD, OMR, JOD | 3 | 10000 |
Some providers deviate from ISO 4217 for specific currencies, so check each provider's currency table before you add a new market.
The webhook pattern
- 01routeVerifysignature over the raw bytes
- 02jobIdempotencyKeyDedupeatomic on provider event id
- 03routeEnqueueapp.jobs.enqueue({ ... })
- 04workerAck 2xx fastrefetch + fulfil in the worker
A check-then-act dedupe (if (await seen(id)) return; ... markSeen(id)) races: two concurrent retries both pass the check. Instead, let the job queue do the dedupe. JobStore.put is atomic on the idempotency key, so a second enqueue with the same jobIdempotencyKey() returns the existing job with duplicate: true instead of creating another one.
Register the worker once per app with app.useJobs(). If you integrate several providers, put all their handlers in the same map:
Delivery is at-least-once, so the worker must be idempotent too: refetch the authoritative state from the provider, compare amount and currency with the stored order, and use the conditional pending -> paid update. See delivery semantics and the webhook recipe.
Shared app wiring
Every provider guide assumes this wiring. CSRF protection and the rate limit apply to the browser-facing checkout and refund routes; webhook routes are exempt because the provider calls them server to server, authenticated by the signature instead:
See CSRF protection, sessions, and trusted proxies. If your checkout API is called with bearer tokens instead of cookies, swap session() for jwk() and drop csrf().
To make your own POST /checkout safe to retry, mount idempotency() on it. With cookie sessions, scope keys by the session user so one shopper can never replay another's response:
Protected refunds
Refunds move money out of your account, so treat them as an admin operation: authenticate, require a role, check ownership (tenant or merchant), cap the amount at what was captured minus what was already refunded, and write an audit record. Every provider guide links here from its refund section.
Combine the amount check with a row lock or a conditional update in your database so two concurrent refunds cannot both pass it. See resource authorization and administrator access.
Webhook verification matrix
Built from each provider's documentation as of October 2026. Confirm against the provider docs before relying on a cell; providers change these details.
| Provider | Header / field | Algorithm, encoding | Key | Signed input | Timestamp / replay | Dedupe id |
|---|---|---|---|---|---|---|
| Stripe | Stripe-Signature (t=, v1=) | HMAC-SHA256, hex | endpoint whsec_ secret | t, a dot, then the raw body | t, SDK tolerance 300 s | event.id |
| Shopify | X-Shopify-Hmac-SHA256 | HMAC-SHA256, base64 | app client secret | raw body | none signed | X-Shopify-Webhook-Id |
| Braintree | bt_signature form field | verified by webhookNotification.parse() | API key pair | bt_payload | none documented | none: kind + subject id + timestamp |
| Authorize.Net | X-ANET-Signature | HMAC-SHA512, hex (often sha512= prefixed) | Signature Key | raw body | none signed | notificationId |
| Adyen (Standard) | additionalData.hmacSignature per item | HMAC-SHA256, base64 | HMAC key (hex-decoded) | colon-joined fields | none signed; check live | pspReference + eventCode |
| Mollie classic | none (unsigned id=tr_...) | none | none | none | refetch the payment | none: idempotent worker |
| Mollie next-gen | X-Mollie-Signature (sha256=) | HMAC-SHA256, hex | signing secret | raw body | none signed | event id (event_...) |
| Tap | hashstring | HMAC-SHA256, hex | secret API key | x_id...x_created string | none signed | charge id + status |
| PayTabs | Signature | HMAC-SHA256, hex | profile Server Key | raw body | none signed | tran_ref + status |
| Razorpay | X-Razorpay-Signature | HMAC-SHA256, hex | webhook secret | raw body | none signed | x-razorpay-event-id |
| Square | x-square-hmacsha256-signature | HMAC-SHA256, base64 | subscription signature key | notification URL + raw body | none signed | event_id |
| PayPal | PAYPAL-TRANSMISSION-SIG (+ -ID, -TIME, CERT-URL, AUTH-ALGO) | SHA256withRSA, base64; or postback to verify-webhook-signature | PayPal certificate + your webhook id | transmission id, time, webhook id, CRC32 of the raw body | transmission time signed, no documented window | event id |
| Paddle | Paddle-Signature (ts=, h1=) | HMAC-SHA256, hex | notification destination secret | ts, a colon, then the raw body | ts, default tolerance 5 s | event_id (evt_...) |
| Checkout.com | Cko-Signature (optional Authorization key) | HMAC-SHA256, hex | webhook signature key | raw body | none signed | event id (evt_...) |
Where nothing signs a timestamp, a captured delivery can be replayed. The atomic dedupe on the event id, plus refetching state from the provider in the worker, is what makes a replay harmless.
Secure checkout checklist
- PCI DSS scope. Your SAQ depends on who serves the payment fields. A full redirect to a hosted payment page usually lands in SAQ A. When your own page loads the provider's script or fields (Stripe Elements, Accept.js, Hosted Fields), your page can affect the payment page, which is typically SAQ A-EP; confirm with your acquirer, because providers classify their iframe products differently. Receiving raw card numbers on your server means SAQ D. See the PCI DSS controls mapping.
- Hosted fields only. Collect cards with the provider's hosted page, iframe fields, or wallet SDK. A raw PAN must never reach your DaloyJS routes or logs.
- SCA and 3-D Secure. European cards require strong customer authentication. Hosted Checkout, Adyen Drop-in, and similar flows run 3DS for you; a custom server-to-server flow must handle the challenge and redirect states.
- Server-side amounts. Compute totals from your catalogue and verify the paid amount and currency in the webhook worker. See above.
- Minor units and decimals. Convert at the plugin edge with one helper (
src/money.tsabove); 0, 2, and 3 decimal currencies all exist. - Webhooks are the source of truth. The browser redirect back to your site is a UX hint; mark orders paid only from a verified webhook plus a refetch.
- Log redaction. Do not log request bodies on payment routes. Keep provider request ids, error codes, and your order id; drop names, emails, addresses, and anything card-shaped. See redaction.
- Secrets. Separate test and live keys, rotate webhook secrets, and support two secrets during a rotation window where the provider signs with both.
Testing
- Use each provider's sandbox: Stripe test mode and sandboxes, Braintree sandbox, Authorize.Net
apitest, Adyen test accounts, Mollietest_keys, Square sandbox, Razorpay test keys, the Tap and PayTabs test profiles, PayPal sandbox apps, Paddle sandbox accounts, and Checkout.com sandbox keys (sk_sbox_). - Stripe CLI:
stripe listen --forward-to localhost:3000/webhooks/stripeforwards events with a localwhsec_secret, andstripe trigger checkout.session.completedfires a real test event. - Contract tests: sign fake webhooks with the core
signWebhookPayload()and drive them throughapp.request(). Always include the unhappy paths: a wrong secret, a tampered body, and a duplicate delivery.
signWebhookPayload() returns hex. For base64 providers (Shopify, Square, Adyen), convert the hex digest to base64 in the test, or sign with WebCrypto directly. Pass timestamp to reproduce Stripe-style t= signatures.
Runtime compatibility
"Node hosts" means long-lived Node, Vercel Node.js functions, AWS Lambda, and Azure Functions. Cells say "Not verified" where neither the SDK's docs nor its package metadata state support; test before you ship there. The core helpers used for verification (verifyWebhookSignature, readBodyLimited, safeJsonParse, resilientFetch) use only web-standard APIs and run on every DaloyJS adapter.
| SDK | Node hosts | Deno | Cloudflare Workers | Vercel Edge |
|---|---|---|---|---|
stripe 23.x | Yes (Node 20+) | Yes (npm:stripe) | Yes, with createFetchHttpClient() + createSubtleCryptoProvider() | Not verified |
square 46.x | Yes (Node 18+) | Yes (README: Deno 1.25+) | Yes (README) | Not verified |
mollie-api-typescript 1.12.x | Yes | Yes (RUNTIMES.md: Deno 1.39) | Not verified (Fetch-based) | Not verified |
@adyen/api-library 32.x | Yes (Node 18+) | Not verified | Not verified: call the REST API with fetch | Not verified |
braintree 3.x | Yes | Not verified | No (Node http, Buffer): use the GraphQL API | No |
authorizenet 1.x | Yes | Not verified | No (Node-only dependencies): POST the JSON API with fetch | No |
razorpay 2.x | Yes | Not verified | Not verified: call the REST API with fetch | Not verified |
paytabs_pt2 2.x | Yes | Not verified | Not verified: call the PT2 REST API with fetch | Not verified |
shopify-api-node 3.x | Yes | Not verified | No (got, Node HTTP): call GraphQL with fetch | No |
@paddle/paddle-node-sdk 3.x | Yes (Node 20+) | Not verified (ships an edge build for the deno export condition) | Not verified (edge build for worker / workerd) | Not verified |
checkout-sdk-node 5.x | Yes (Node 18+) | Not verified | Not verified (imports axios and Node stream): call the REST API with fetch | Not verified |
@paypal/paypal-server-sdk 2.x | Yes (Node 14.17+) | Not verified | Not verified (axios-based adapter): use the REST guide | Not verified |
Tap (no SDK, fetch) | Yes | Yes | Yes | Yes |
PayPal REST (no SDK, fetch) | Yes | Yes | Yes (postback verification; self-verification needs node:crypto) | Yes (postback verification) |
DaloyJS itself requires Node ^24 || >=26, so the SDKs' own Node floors are already met on Node hosts.
Beyond one-off payments
- Subscriptions and dunning. Let the provider own the billing schedule and retry logic (Stripe Billing, Braintree Recurring Billing, Mollie subscriptions, Adyen tokenization). Drive entitlements from webhooks and handle the failed-payment events, not from your own cron.
- Reconciliation and disputes. Run a nightly job (see
cronEnqueue) that compares provider settlement reports with your ledger, and subscribe to dispute or chargeback events so evidence deadlines are not missed. - Tax and merchant of record. Sales tax, VAT, and GST depend on where the buyer is. Use a tax engine (Stripe Tax and similar), or a merchant-of-record service such as Paddle that takes on the tax liability for you, rather than hard-coding rates.
Common plugin shape
- 01pluginWrap the SDKnew ProviderSDK(secrets)
- 02registerAttach to stateapp.decorate(name, client)
- 03routesCall from handlersstate.<provider>.charge()
- 04callbacksVerify webhooksHMAC over raw body
Each provider guide implements roughly the same interface on ctx.state:
Provider pages keep the shape but specialise the method names where it makes the SDK nicer to read (for example, Shopify gets a graphql() passthrough so you can run typed GraphQL queries without leaving the plugin).