@scanandpay/node
v1.2026.1
Published
Official Scan & Pay Node.js SDK — generate PayTo PayID QR codes and verify our payment confirmation webhook.
Maintainers
Readme
@scanandpay/node
Official Node.js SDK for Scan & Pay — generate PayTo PayID QR codes and payment links from any Node.js backend (Express, NestJS, Next.js, etc.), then react to our signed webhook when a payment is confirmed. Includes React components for the frontend.
Your backend mints a session, we run the payment surface, our webhook confirms back to you.
How the pieces fit
Your backend ── createSession() ─▶ Scan & Pay API (mint QR + pay URL)
Customer phone ── scans QR ─▶ pay.scanandpay.com.au (we collect payment)
Scan & Pay ── signed webhook ─▶ Your backend (payment confirmation)You never handle funds, banking credentials, or PayID resolution — the SDK generates the link, the customer pays on our hosted surface, and you receive a verified webhook telling you the order is paid.
Install
npm install @scanandpay/node
# or
yarn add @scanandpay/nodeQuickstart (Node.js)
import { ScanAndPay } from '@scanandpay/node';
const client = new ScanAndPay({
merchantId: process.env.SCANANDPAY_MERCHANT_ID!,
apiBaseUrl: process.env.SCANANDPAY_API_BASE_URL!,
apiSecret: process.env.SCANANDPAY_API_SECRET!,
webhookSecret: process.env.SCANANDPAY_WEBHOOK_SECRET, // optional
});
// 1. Create a session at checkout. amountCents is an integer number of
// cents. Payments go to your business profile configured in the
// Business Portal.
const session = await client.createSession({
amountCents: 1990, // $19.90
platformOrderId: 'order_456',
});
// 2. Set your webhook address in the Business Portal (Settings → Integrations → Webhook address)
// and verify incoming webhooks with the SDK helper.
import { WebhookSignatureError } from '@scanandpay/node';
app.post('/webhooks/scanandpay', express.raw({ type: 'application/json' }), async (req, res) => {
try {
const signature = (req.headers['x-scanpay-signature'] as string) ?? '';
const event = client.webhooks.verify(signature, req.body.toString('utf8'));
if (event.status === 'confirmed') {
// Mark order paid using event.order_id, event.tx_id, ...
}
res.json({ received: true });
} catch (err) {
if (err instanceof WebhookSignatureError) {
return res.status(401).send('Webhook verification failed');
}
throw err;
}
});Amount format
amountCents is always a positive integer number of cents (e.g. 1990
for $19.90). This matches the Scan & Pay API directly — no float rounding
to worry about.
amountCents: 1990 // ✓ $19.90
amountCents: 50 // ✓ $0.50
amountCents: 100000 // ✓ $1,000.00
amountCents: -1 // ✗ ValidationError — must be greater than 0
amountCents: 0 // ✗ ValidationError — must be greater than 0The SDK validates that amountCents is a positive integer not exceeding
100,000,000 (=$1,000,000) and throws ValidationError before any network
call.
Metadata
Attach a free-form key/value bag to any session. We echo it back unchanged
in the webhook payload + getStatus response, so you can correlate the
payment with your own order/customer/cart records.
await client.createSession({
amountCents: 1990,
platformOrderId: 'order_456',
metadata: {
customer_id: 'cus_42',
cart_id: 'cart_99',
},
});Limits: max 50 keys, max 500 chars per key + value (validated client-side before any network call). Don't put secrets here — metadata isn't encrypted at rest in any special way.
Refunds
Refund a settled payment in full or in part. Refunds are idempotent the
same way sessions are — pass your own idempotencyKey or let the SDK
generate one — and the amount can't exceed the original payment minus
any prior refunds.
const refund = await client.createRefund({
paymentSessionId: session.sessionId,
amountCents: 1990,
reason: 'customer_request',
});API versioning
The SDK pins itself to a date-stamped API contract via the Scanpay-Version
header (e.g. 2026-05-11). When we evolve the wire format, your
already-installed SDK keeps running against the contract it was built for.
Upgrade at your own pace.
import { API_VERSION, SDK_VERSION } from '@scanandpay/node';
console.log(API_VERSION); // 2026-05-11
console.log(SDK_VERSION); // 1.2026.1Idempotency
Every createSession call sends an Idempotency-Key header. The SDK
generates a UUIDv7 by default; pass your own to make retries safe across
process restarts.
await client.createSession({
amountCents: 1990,
platformOrderId: 'order_456',
idempotencyKey: 'order_456:attempt_1', // optional
});Retries
Transient failures (5xx, 408, 429, network errors) are retried 3× with exponential backoff (250ms / 500ms / 1000ms). Tune per request:
await client.createSession({
amountCents: 1990,
platformOrderId: 'order_456',
retry: { retries: 5, baseMs: 100 },
});Quickstart (React)
import { CheckoutWidget } from '@scanandpay/node/react';
function CheckoutPage({ session }) {
return (
<CheckoutWidget
session={session}
pollUrl="/api/scanandpay/status"
onSuccess={(sessionId) => { window.location.href = '/thank-you'; }}
theme="light"
/>
);
}Errors
All thrown errors extend ScanAndPayError:
| Class | When |
|---|---|
| ValidationError | Bad input rejected before any HTTP call |
| AuthenticationError | API rejected X-Scanpay-Key (rotate the secret) |
| ApiError | Non-2xx response — has statusCode + responseBody |
| NetworkError | Transport failure after exhausting retries |
| IdempotencyError | Reserved — the API does not return this today. |
| WebhookSignatureError | Webhook signature, timestamp, or replay check failed |
Credentials
Sign in to the merchant dashboard at business.scanandpay.com.au, open Settings → Integrations, and copy:
Merchant IDAPI Base URLAPI SecretWebhook Secret
Store them in environment variables — never commit them to source control.
Webhook address & receiving payment results
To receive payment confirmations:
- Open Settings → Integrations → Webhook address in the Business Portal.
- Enter your store's public
httpsaddress (confirmed with your passkey) and save it. - When a payment completes, Scan & Pay delivers a signed notification to that address. Verify each incoming webhook with
client.webhooks.verify(signature, rawBody)before fulfilling the order.
Production integration checklist
Use the SDK from your backend only. Your frontend can display the returned payment URL or QR widget, but it must never receive the API Secret or Webhook Secret.
- Create your local order first. Store the cart, customer, amount,
currency, and a durable
platformOrderIdin your own database with a pending payment status. - Create one Scan & Pay session for that order. Call
client.createSession()from your backend using the sameplatformOrderId. Pass an idempotency key based on your order id if the request may be retried by a job queue, serverless function, or browser refresh. - Render the payment step as pending. Show the returned payment session
to the customer with
CheckoutWidget, your own QR renderer, or a redirect to the returned pay URL. Do not send the customer to a success page yet. - Expose a small status endpoint. If you use
CheckoutWidget, pointpollUrlat your own backend endpoint. That endpoint should callclient.getStatus(sessionId)and return only the public status fields your UI needs. - Set your webhook address and verify on raw bytes. Configure your
public
httpswebhook address in the Business Portal under Settings → Integrations → Webhook address (confirmed with your passkey). Useclient.webhooks.verify(signature, rawBody)before trusting any webhook payload. A parsed or re-serialized body will fail signature verification. - React to our payment confirmation webhook. Treat
event.status === 'confirmed'as the signal to mark your order paid in your own database. The Place Order click and QR render only mean payment has started — money has not moved until the webhook arrives. - Keep test and live credentials separate. Use environment variables or your secret manager, and never commit merchant credentials into source control, frontend bundles, mobile apps, logs, screenshots, or support tickets.
Safe to share publicly: package install commands, SDK method names, request/response fields, webhook verification rules, idempotency guidance, test-mode behaviour, and error handling. Keep your database schema, internal routes, cloud project names, merchant secrets, and admin tooling private.
Integration pitfalls
Things that bite first-time integrators (we've hit each one ourselves):
- Create the order BEFORE minting the session. The session binds
to your
platformOrderIdand the webhook references the same id when the payment is confirmed. Persist the order in your DB (statuspending) first, then callclient.createSession({...}). - Don't finalise the order on Place Order. A common pattern in
checkout code is a hardcoded list — "if this gateway type is one
of these redirect gateways, defer; otherwise finalise immediately".
If that list is missing
scanandpay, the checkout flashes a success screen and the<CheckoutWidget>never renders. Always treat Scan & Pay as a deferred / async-confirmation gateway, like any hosted or redirect checkout — the customer needs to see the QR and complete the scan-and-pay in their banking app before the order can be considered paid. - Webhook is the source of truth. Mark the order paid only when
the verified webhook arrives with
event.status === 'confirmed'. The Place Order click on your site does NOT mean money has moved.
Documentation
- API reference: https://docs.scanandpay.com.au/api/payments
- Webhook payload + signing: https://docs.scanandpay.com.au/api/webhooks
- OpenAPI spec: https://docs.scanandpay.com.au/api-spec.yaml
Licence
Apache-2.0.
