Mollie is a major European payment platform, strong on iDEAL, Bancontact, SEPA, Klarna, and a deep catalogue of local methods alongside cards and wallets. This guide uses Mollie's TypeScript SDK mollie-api-typescript (1.12.x as of October 2026) from a DaloyJS server and covers both of Mollie's webhook styles.
What you should know up front
Right package. mollie-api-typescript is the SDK Mollie develops new features for (Fetch-based, ESM + CJS, ships SignatureValidator). The older @mollie/api-client (4.x) says it enters maintenance mode after 17 November 2026; migrate new code now.
It's a redirect flow. You create a payment, Mollie returns _links.checkout.href, you redirect the customer there. They come back to your redirectUrl. The redirect is a UX signal only; the webhook plus a refetch is the source of truth.
Two webhook styles. Classic webhooks are configured per payment (webhookUrl) and post an unsigned, form-encoded id=tr_.... Next-gen webhooks are configured in the Dashboard or API, signed with X-Mollie-Signature, and post JSON events. Both are covered below.
Amounts are decimal strings. Mollie wants { currency: "EUR", value: "10.00" }, with the number of decimals the currency uses. Build it from the stored order with formatMinor() from the overview, never from the request body.
Test vs live is the API key. Keys are prefixed test_ or live_. With OAuth / organization access tokens you set testmode (and profileId) on the client instead; see the SDK README.
Generate a test API key (Dashboard -> Developers -> API keys). It starts with test_.
Enable the payment methods you want on the website profile. iDEAL and Bancontact need explicit activation.
Optional, for next-gen webhooks: create a webhook in Developers -> Webhooks pointing at your DaloyJS endpoint and store its signing secret.
2. Install
bash
pnpm add mollie-api-typescript
bash
npm install mollie-api-typescript
bash
yarn add mollie-api-typescript
bash
bun add mollie-api-typescript
3. Environment variables
.envbash
MOLLIE_API_KEY=test_replace_me # or live_...MOLLIE_WEBHOOK_SECRET=replace_me # next-gen webhooks onlyMOLLIE_WEBHOOK_SECRET_PREVIOUS= # the old secret; set it before rotating, Mollie has no overlap windowAPP_URL=https://your-app.example.com
4. Plugin
src/plugins/mollie.tsts
import { Client, SignatureValidator, InvalidSignatureException } from "mollie-api-typescript";import type { App } from "@daloyjs/core";const mollie = new Client({ security: { apiKey: process.env.MOLLIE_API_KEY! },});// Accept the current and the previous signing secret, so a rotation needs no synchronized deploy.const validator = new SignatureValidator( [process.env.MOLLIE_WEBHOOK_SECRET, process.env.MOLLIE_WEBHOOK_SECRET_PREVIOUS].filter( (s): s is string => !!s, ),);export interface MollieClient { raw: Client; createPayment(input: { amount: { currency: string; value: string }; description: string; redirectUrl: string; orderId: string; idempotencyKey: string; }): Promise<{ id: string; checkoutUrl: string; status: string }>; getPayment(id: string): Promise<{ id: string; status: string; amount: { currency: string; value: string }; orderId?: string; }>; /** Next-gen webhooks only. Throws nothing; false for missing or invalid signatures. */ verifySignedWebhook(rawBody: string, signatureHeader: string | null): Promise<boolean>;}// Exported so job handlers (which run outside a request) can use it too.export const mollieClient: MollieClient = { raw: mollie, async createPayment({ amount, description, redirectUrl, orderId, idempotencyKey }) { const res = await mollie.payments.create({ idempotencyKey, paymentRequest: { amount, description, redirectUrl, // Classic per-payment webhook. Omit it if you rely only on next-gen webhooks. webhookUrl: `${process.env.APP_URL}/webhooks/mollie/payments`, metadata: { orderId }, }, }); return { id: res.id!, status: res.status!, checkoutUrl: res.links?.checkout?.href ?? "" }; }, async getPayment(id) { const res = await mollie.payments.get({ paymentId: id }); const metadata = res.metadata as { orderId?: string } | null | undefined; return { id: res.id!, status: res.status!, amount: res.amount!, orderId: metadata?.orderId }; }, async verifySignedWebhook(rawBody, signatureHeader) { if (!signatureHeader) return false; // Headers joins repeated X-Mollie-Signature headers with ", "; validate each value. const signatures = signatureHeader.split(",").map((s) => s.trim()); try { return await validator.validatePayload(rawBody, signatures); } catch (error) { if (error instanceof InvalidSignatureException) return false; throw error; } },};// Call with the root app, not through app.register(): a decoration made// inside a registered plugin is visible only to that plugin's own routes.export function molliePlugin(app: App) { app.decorate("mollie", mollieClient);}declare module "@daloyjs/core" { interface AppState { mollie: MollieClient; }}
SignatureValidator.validatePayload() returns false when no signature is present and throws InvalidSignatureException when none of the signatures match. The wrapper folds both into false, so a signed route can simply require true. The HMAC is computed over the raw body; re-serialising parsed JSON breaks it.
5. Create a payment
Redirect payment flow
ShopperDaloyJS routeMollie
01requestShopperDaloyJS routePOST /checkout/mollie{ orderId } only
02requestDaloyJS routeMolliepayments.createamount from the stored order, order-derived idempotencyKey
04asyncShopperMolliePays on the hosted checkout, returns via redirectUrlredirect is a UX hint, not proof
The server loads the amount from the order and derives the idempotency key from the order id and version, so a retried request cannot create a second payment. The redirect back is a UX signal only.
The route relies on the shared app wiring (session, scoped csrf() and rateLimit()) and the overview's orders and money modules.
src/routes/checkout-mollie.tsts
import { z } from "zod";import { HttpError } from "@daloyjs/core";import * as errors from "mollie-api-typescript/models/errors";import { molliePlugin } from "../plugins/mollie.ts";import { orders } from "../orders.ts";import { formatMinor } from "../money.ts";molliePlugin(app);app.post( "/checkout/mollie", { operationId: "createMolliePayment", request: { body: z.object({ orderId: z.string().min(1).max(80) }).strict(), }, responses: { 201: { description: "payment created", body: z.object({ paymentId: z.string(), checkoutUrl: z.url() }), }, }, }, async ({ body, state }) => { const order = await orders.forCheckout(body.orderId, state.session.get<string>("userId")); try { const payment = await state.mollie.createPayment({ amount: { currency: order.currency, value: formatMinor(order.amountMinor, order.currency) }, description: `Order ${order.id}`, redirectUrl: `${process.env.APP_URL}/checkout/return?order=${encodeURIComponent(order.id)}`, orderId: order.id, // Same order + same cart version = same key, so a retry cannot double-create. idempotencyKey: `payment:${order.id}:v${order.version}`, }); return { status: 201, body: { paymentId: payment.id, checkoutUrl: payment.checkoutUrl } }; } catch (e) { if (e instanceof errors.ErrorResponse) { // Keep Mollie's status/title/detail in your logs, not in the client response. app.log.warn({ event: "mollie.create_failed", status: e.status, title: e.title }, "Mollie rejected the payment"); throw new HttpError(502, { type: "https://your-app.example.com/problems/payment-provider", title: "Payment provider error", detail: "The payment could not be started. Please try again.", }); } throw e; } },);
02asyncDaloyJS routeJob workerenqueue { paymentId }, then 200no status in the body
03requestJob workerMolliepayments.get(id)the API response is authoritative
A classic webhook carries only the payment id and no signature. That is safe because nothing in the body is trusted: the worker fetches the payment from the Mollie API with your secret key and acts on that.
Mollie calls the payment's webhookUrl with a single form field, id, whenever the status changes. There is no signature and no status in the body: you fetch the payment from the API and act on what it says. A forged request can only make you refetch a payment, because the API answer (authenticated with your secret key) decides everything.
src/webhooks/mollie-classic.tsts
import { z } from "zod";import { readBodyLimited } from "@daloyjs/core";app.post( "/webhooks/mollie/payments", { operationId: "mollieClassicWebhook", // No request.body schema: read and validate the tiny form body ourselves. responses: { 200: { description: "ok", body: z.object({ ok: z.literal(true) }) }, }, }, async ({ request }) => { const raw = new TextDecoder().decode(await readBodyLimited(request, 4_096)); const paymentId = new URLSearchParams(raw).get("id") ?? ""; if (/^tr_[A-Za-z0-9]{1,64}$/.test(paymentId)) { // No idempotency key: Mollie reuses the same id for every status change, // so deduping on it would drop later updates. The worker is idempotent. await app.jobs!.enqueue({ name: "mollie.payment", payload: { paymentId } }); } // Ack unknown ids too, so probes learn nothing about which ids exist. return { status: 200, body: { ok: true as const } }; },);
Mollie retries a delivery that does not get a 2xx (its docs describe 10 attempts with increasing intervals over roughly 26 hours), so ack fast and let the worker do the API call.
7. Next-gen signed webhooks
Next-gen webhook verification
MollieDaloyJS routeJob worker
01requestMollieDaloyJS routePOST /webhooks/mollieX-Mollie-Signature: sha256=... over the JSON body
03asyncDaloyJS routeJob workerenqueue keyed by event id, then 200worker refetches the payment
Next-gen webhooks are signed, so require a valid signature, dedupe atomically on the event id, and still refetch the payment in the worker because deliveries can arrive late or out of order.
Next-gen webhooks post a JSON event (resource: "event", an id like event_..., a type such as payment.paid, the entityId, and optionally an embedded entity snapshot) and sign the raw body with HMAC-SHA256 in X-Mollie-Signature (sha256=<hex>). The signature covers no timestamp, so the event id is your replay and dedupe key. Rotating the signing secret takes effect immediately: Mollie revokes the old secret and signs with the new one in the same step, with no overlap window. Deploy the new secret alongside the old one before you rotate, which is why the plugin accepts two secrets. Mollie's own docs still mark parts of this API as beta, so check which event types your account can subscribe to.
// Refund (amount from your ledger, never from the request).await state.mollie.raw.refunds.create({ paymentId: order.providerRef!, idempotencyKey: `refund:${order.id}:${order.refundedMinor}:${amountMinor}`, refundRequest: { amount: { currency: order.currency, value: formatMinor(amountMinor, order.currency) }, description: "Customer request", },});// Capture a previously authorized card payment (manual capture mode).await state.mollie.raw.captures.create({ paymentId: order.providerRef!, captureRequest: { amount: { currency: order.currency, value: formatMinor(order.amountMinor, order.currency) } },});// Cancel an open payment.await state.mollie.raw.payments.cancel({ paymentId: order.providerRef! });
Pagination
List endpoints return async iterables; let for await walk the pages for you:
ts
const pages = await state.mollie.raw.payments.list({ limit: 50 });for await (const page of pages) { for (const payment of page.result.embedded?.payments ?? []) { // ... }}
Runtimes
The SDK is built on the Fetch API and ships ESM + CJS. Its RUNTIMES.md lists Node.js LTS releases, Bun 1+, and Deno 1.39 as supported; Cloudflare Workers and Vercel Edge are not listed, so test there before relying on it. SignatureValidator uses WebCrypto and works anywhere crypto.subtle exists. See the runtime table.
Modernisation notes
Use mollie-api-typescript over @mollie/api-client. It is where new features land, with first-class types, standalone functions, and async-iterable pagination.
Prefer signed next-gen webhooks where your event types are supported, and keep refetching in the worker either way.
Idempotency keys from the order. A random UUID per call gives no protection; payment:${order.id}:v${order.version} does.
Don't trust the redirect. The redirectUrl only tells you the user came back; they can close the tab mid-iDEAL. The webhook plus payments.get is what flips an order to paid.