Accept payments with Tap Payments in DaloyJS
Tap Payments is a leading acquirer for the GCC and wider MENA region. It is how you accept KNET (Kuwait), Mada (Saudi), Benefit / BenefitPay (Bahrain), STC Pay, plus cards, Apple Pay, Google Pay, and BNPL methods. There is no first-party Node SDK; you integrate against the REST API with fetch, which also means the integration runs on every DaloyJS runtime.
What you should know up front
- Bearer auth, secret key in the backend only.
Authorization: Bearer sk_test_...orsk_live_.... Public keys (pk_*) are for the frontend SDKs. - It's a redirect flow. You create a charge, Tap returns
transaction.url, you redirect the customer. They come back via yourredirect.urlwith?tap_id=chg_xxx. That is a UX hint, not proof of payment. - The server picks the amount, currency, and payment source. The browser sends only an order id. See never trust client amounts.
- Idempotency is a body field. Tap deduplicates on
reference.idempotentfor charges, authorizations, and refunds, for 24 hours. Derive it from your order id. - Webhooks carry a
hashstringheader: an HMAC-SHA256 (hex) over a specific concatenation of charge fields, keyed with your secret key. Verify it on every request, then refetch the charge. - Amounts are decimals with the currency's precision. Tap takes
amountas a number, and the hashstring rounds it to the currency's decimals: 2 for most currencies, 3 for KWD, BHD, OMR, and JOD.
| Currency | Decimals | Example x_amount |
|---|---|---|
| SAR, AED, QAR, EGP, USD, EUR, GBP | 2 | 10.00 |
| KWD, BHD, OMR, JOD | 3 | 10.000 |
1. Provision
- Create an account at tap.company and sign in to the dashboard.
- Grab your Merchant ID, plus Test/Live Secret Keys (
sk_*) and Public Keys (pk_*). - Enable the payment methods you need (KNET, Mada, Benefit, and so on); some require contacting Tap support.
- Your charges pass a
post.url, so Tap posts webhooks for each charge to your DaloyJS server.
2. Environment variables
3. Plugin (no SDK: fetch-based)
The field order and the amount rounding inside buildHashString are the parts Tap is strict about. Keep them pinned to their webhook docs: x_gateway_reference is reference.gateway, x_payment_reference is reference.payment, and x_created is transaction.created, each empty when missing. verifyWebhookSignature() compares the hex digest in constant time.
4. Create a hosted charge
- 01requestCustomerDaloyJS routePOST /checkout/tap{ orderId } only
- 02requestDaloyJS routeTapPOST /v2/chargesamount from the order, reference.idempotent, src_all
- 03responseDaloyJS routeCustomerReturn transaction.url201 { redirectUrl }
- 04asyncCustomerTapPays on the hosted page, returns with ?tap_id=chg_xxxredirect is a UX hint, not proof
The route relies on the shared app wiring (session, scoped csrf() and rateLimit()) and the overview's orders and money modules.
5. Webhook
- 01requestTapDaloyJS routePOST /webhooks/taphashstring header over ordered fields
- 02noteDaloyJS routeDaloyJS routeRebuild the hash string, verifyWebhookSignatureHMAC-SHA256 hex, constant-time compare
- 03responseDaloyJS routeTap401 when the hash does not match{ error: 'bad hashstring' }
- 04asyncDaloyJS routeJob workerenqueue keyed by charge id + status, then 200worker refetches and compares with the order
6. Refunds
Expose refunds only through a protected refund route. The plugin call, with an idempotent reference per logical refund:
Authorize + capture
For an auth-then-capture flow (hotels, marketplaces, anything where the final amount is decided later), Tap has a separate Authorize API with void and capture operations. Not every payment method supports it; confirm with Tap per scheme before relying on it.
Runtimes
Everything here is fetch (through resilientFetch) plus the core WebCrypto helpers, so the plugin runs unchanged on Node hosts, Deno, Bun, Cloudflare Workers, and Vercel Edge. See the runtime table.
Errors
Tap returns JSON like { "errors": [{ "code": "1101", "description": "..." }] } with an HTTP error status. The plugin keeps the code for your logs; map the failure to a generic problem+json (for example a 502 "Payment provider error") instead of forwarding Tap's description. Common causes are 400 (bad body), 401 (wrong key or test/live mismatch), and 404 (a charge from a different account).
Modernisation notes
- Use
src_allfor the hosted page. It saves you from maintaining a method picker and lets Tap roll out new options without a redeploy. If you do offer a method picker, map the user's choice to a server-side allowlist of source ids. - Always refetch in the worker. The hash proves the fields came from Tap, but deliveries are retried and can arrive out of order.
- Never fulfil from the redirect. The
?tap_id=on the return URL is for showing the customer "thanks", never for marking the order paid. - Keep
buildHashStringin one place. If Tap changes the hash inputs you want to update one function, not eight call sites.
See also the payments overview, Adyen guide, Mollie guide, and problem+json errors.