=============== LIBRARY RULES =============== From library maintainers: - This is an unofficial SDK, not affiliated with SimplePay Zrt. - Read the IPN body as raw text (request.text(), readRawBody, express.text()) and send handleIpnRequest's responseBody back unchanged with the signature in the Signature header. - getSimplePayConfig is not exported; read keys from process.env.SIMPLEPAY_MERCHANT_KEY_. - getPaymentResponse event values are uppercase: SUCCESS, FAIL, TIMEOUT, CANCEL. - Fulfil orders from the IPN (status FINISHED), not from the back URL. ### Install simplepay-js-sdk with yarn Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/getting-started.md Installs the simplepay-js-sdk package using yarn. Requires Node.js 20 or newer and an ESM project. ```bash yarn add simplepay-js-sdk ``` -------------------------------- ### Install simplepay-js-sdk with pnpm Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/getting-started.md Installs the simplepay-js-sdk package using pnpm. Requires Node.js 20 or newer and an ESM project. ```bash pnpm add simplepay-js-sdk ``` -------------------------------- ### Start a sandbox payment with startPayment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/getting-started.md Starts a payment by calling startPayment with order details and logs the returned paymentUrl. Open paymentUrl and pay with a sandbox test card, e.g. 4908 3660 9990 0425, expiry 12/28, CVC 123. ```typescript import { startPayment } from 'simplepay-js-sdk' const response = await startPayment({ orderRef: `order-${Date.now()}`, // unique order reference total: 1212, customerEmail: 'customer@example.com', invoice: { name: 'Test Customer', country: 'HU', state: 'Budapest', city: 'Budapest', zip: '1111', address: 'Fő utca 1.', }, }) console.log(response.paymentUrl) ``` -------------------------------- ### Start payment, get response, handle IPN Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/README-ENG.md Use startPayment to initiate a payment, getPaymentResponse to parse the back URL response, and handleIpnRequest to process IPN. The IPN handler expects the raw request body and the Signature header, and returns a response with the same signature. ```ts import { startPayment, getPaymentResponse, handleIpnRequest } from 'simplepay-js-sdk' // 1. start a payment const { paymentUrl } = await startPayment({ orderRef: 'order-12', total: 1212, customerEmail: 'customer@example.com', }) // redirect the customer to paymentUrl // 2. back URL: ?r=...&s=... const result = getPaymentResponse(r, s) // result.event: SUCCESS | FAIL | TIMEOUT | CANCEL // 3. IPN: read the raw body, send the response back unchanged const ipnBody = await request.text() const { responseBody, signature } = handleIpnRequest( ipnBody, request.headers.get('Signature') ?? '', process.env.SIMPLEPAY_MERCHANT_KEY_HUF!, ) return new Response(responseBody, { status: 200, headers: { 'Content-Type': 'application/json', 'Signature': signature }, }) ``` -------------------------------- ### Start payment endpoint (server/api/simplepay/start.post.ts) Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/recipes/nuxt.md Nitro server route that starts a payment using startPayment. Reads orderId from the request body, fetches the order from your database, and returns the payment URL. Throws a 502 error if starting fails. ```ts import { startPayment } from 'simplepay-js-sdk' export default defineEventHandler(async (event) => { const { orderId } = await readBody<{ orderId: string }>(event) const order = await getOrder(orderId) // from your database try { const response = await startPayment({ orderRef: order.ref, total: order.total, customerEmail: order.email, invoice: order.invoice, }) return { paymentUrl: response.paymentUrl } } catch (error) { console.error('SimplePay start', error) throw createError({ statusCode: 502, statusMessage: 'Could not start the payment' }) } }) ``` -------------------------------- ### Install SimplePay JS SDK with npm Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/README-ENG.md Install the package from npm. ```bash npm install simplepay-js-sdk ``` -------------------------------- ### Start Payment with startPayment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Initiates a one-time payment and returns a paymentUrl to redirect the customer to SimplePay. Required parameters: orderRef, total, customerEmail. Optional: currency (default 'HUF'), language (default 'HU'), method (default 'CARD'), invoice, and redirectUrl to override SIMPLEPAY_REDIRECT_URL. ```typescript import { startPayment } from 'simplepay-js-sdk' const initiatePayment = async () => { try { const response = await startPayment({ orderRef: 'order-12', total: 1212, currency: 'HUF', customerEmail: 'customer@example.com', language: 'HU', method: 'CARD', invoice: { name: 'Customer Name', country: 'HU', state: 'Budapest', city: 'Budapest', zip: '1234', address: 'Street 1', }, }, { redirectUrl: 'https://yoursite.com/payment/callback', }) // Redirect the user to response.paymentUrl return response } catch (error) { console.error('Payment initiation failed:', error) throw error } } ``` -------------------------------- ### startApplePay Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Starts an Apple Pay session by calling /payment/v2/startapplepay. Returns an applePaySession for completeMerchantValidation. Throws when domain is not an FQDN, when errorCodes is present, or when applePaySession.merchantSessionIdentifier is missing. ```APIDOC ## startApplePay ### Description Starts an Apple Pay session by calling /payment/v2/startapplepay. Returns an applePaySession for completeMerchantValidation. Throws when domain is not an FQDN, when errorCodes is present, or when applePaySession.merchantSessionIdentifier is missing. ### Method POST (via SDK) ### Endpoint /payment/v2/startapplepay ### Parameters - **orderRef** (string) - Required - Order reference - **total** (string) - Required - Total amount - **currency** (string) - Required - Currency code (e.g., 'HUF') - **customerEmail** (string) - Required - Customer email - **language** (string) - Required - Language code (e.g., 'HU') - **domain** (string) - Required - Registered FQDN ### Response #### Success Response - **applePaySession** (object) - Contains merchantSessionIdentifier and other session data - **transactionId** (string) - Transaction identifier ### Request Example ```typescript import { startApplePay } from 'simplepay-js-sdk' const session = await startApplePay({ orderRef: order.orderRef, total: order.total, currency: 'HUF', customerEmail: order.email, language: 'HU', domain: 'shop.example.com', }) ``` ``` -------------------------------- ### Development commands Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/README-ENG.md Run tests, build the package, or start the docs dev server. ```bash yarn test # tests yarn build # build the package yarn docs:dev # docs locally ``` -------------------------------- ### Next.js App Router integration with startPayment and handleIpnRequest Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Shows how to integrate the SimplePay SDK in a Next.js App Router project. The start route reads the JSON body and returns the payment URL; the IPN route reads the raw text body and responds with the Signature header. Requires the SIMPLEPAY_MERCHANT_KEY_HUF environment variable. ```typescript import { startPayment, handleIpnRequest } from 'simplepay-js-sdk' import { NextRequest, NextResponse } from 'next/server' // app/api/payment/start/route.ts export const POST = async (request: NextRequest) => { const body = await request.json() try { const response = await startPayment({ orderRef: body.orderRef, total: body.total, customerEmail: body.email, invoice: body.invoice, }) return NextResponse.json({ paymentUrl: response.paymentUrl }) } catch (error) { return NextResponse.json({ error: 'Payment failed' }, { status: 500 }) } } // app/api/payment/ipn/route.ts export const POST = async (request: NextRequest) => { const ipnBody = await request.text() const signature = request.headers.get('Signature') ?? '' const { responseBody, signature: respSignature } = handleIpnRequest(ipnBody, signature, process.env.SIMPLEPAY_MERCHANT_KEY_HUF!) return new Response(responseBody, { status: 200, headers: { 'Content-Type': 'application/json', 'Signature': respSignature }, }) } ``` -------------------------------- ### Full Express example: start payment, back URL, and IPN route Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/recipes/express.md Complete Express server using the simplepay-js-sdk. Requires "type": "module" in package.json. The start route uses express.json(), the back URL reads query params r and s, and the IPN route uses express.text({ type: 'application/json' }) to receive the raw body. The IPN handler verifies the signature, processes FINISHED status, and responds with the result body and signature. ```TypeScript import express from 'express' import { startPayment, getPaymentResponse, handleIpnRequest } from 'simplepay-js-sdk' const app = express() // Start a payment – the JSON parser is fine here app.post('/api/simplepay/start', express.json(), async (req, res) => { const order = await getOrder(req.body.orderId) try { const { paymentUrl } = await startPayment({ orderRef: order.ref, total: order.total, customerEmail: order.email, }) res.json({ paymentUrl }) } catch (error) { console.error('SimplePay start', error) res.status(502).json({ error: 'Could not start the payment' }) } }) // Back URL (SIMPLEPAY_REDIRECT_URL = https://example.com/payment/back) app.get('/payment/back', (req, res) => { try { const result = getPaymentResponse(String(req.query.r ?? ''), String(req.query.s ?? '')) res.render('payment-result', result) // event: SUCCESS | FAIL | TIMEOUT | CANCEL } catch { res.status(400).send('Invalid redirect') } }) // IPN – needs RAW text, NOT express.json() app.post('/api/simplepay/ipn', express.text({ type: 'application/json' }), async (req, res) => { const ipnBody = typeof req.body === 'string' ? req.body : '' const incomingSignature = req.get('Signature') ?? '' let result try { result = handleIpnRequest(ipnBody, incomingSignature, process.env.SIMPLEPAY_MERCHANT_KEY_HUF!) } catch (error) { console.error('SimplePay IPN', error) res.status(400).send('Invalid signature') return } const ipn = JSON.parse(ipnBody) as { orderRef: string, transactionId: number, status: string } if (ipn.status === 'FINISHED') { await markOrderPaid(ipn.orderRef, ipn.transactionId) // make it idempotent } res .status(200) .set('Signature', result.signature) .type('application/json') .send(result.responseBody) // as a string, unchanged }) app.listen(3000) ``` -------------------------------- ### Set up merchant keys in .env Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/getting-started.md Defines the merchant ID, secret key, and redirect URL as environment variables named after the currency. Until SIMPLEPAY_PRODUCTION is true, every call goes to the sandbox (https://sandbox.simplepay.hu/payment/v2). Keep the secret key out of the browser, git, and logs. ```bash SIMPLEPAY_MERCHANT_ID_HUF=P123456 SIMPLEPAY_MERCHANT_KEY_HUF=your-secret-key SIMPLEPAY_REDIRECT_URL=https://example.com/payment/back # SIMPLEPAY_PRODUCTION=true # live only! ``` -------------------------------- ### startGooglePay Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Starts the Google Pay payment on the server side by calling the SimplePay API. It returns a response that may include a redirect URL for 3DS authentication. ```APIDOC ## startGooglePay ### Description Starts the Google Pay payment on the server side by calling the SimplePay API. It returns a response that may include a redirect URL for 3DS authentication. ### Method Server function ### Parameters #### Request Body - **orderRef** (string) - Required - Order reference - **total** (string) - Required - Total amount - **currency** (string) - Required - Currency code (e.g., 'HUF') - **customerEmail** (string) - Required - Customer email - **language** (string) - Required - Language code (e.g., 'HU') - **googlePayToken** (string) - Required - Google Pay token #### Options - **redirectUrl** (string) - Required - Absolute HTTPS URL for redirect after 3DS ### Response #### Success Response - **errorCodes** (array) - Contains error codes; `3004` indicates 3DS challenge - **redirectUrl** (string) - Present when 3DS challenge is required ### Request Example ```typescript import { startGooglePay } from 'simplepay-js-sdk' const order = await loadOrder(orderRef) const response = await startGooglePay({ orderRef: order.orderRef, total: order.total, currency: 'HUF', customerEmail: order.email, language: 'HU', googlePayToken, }, { redirectUrl: 'https://yoursite.com/payment/callback', }) return response ``` ### Notes Return this JSON to the browser. When `errorCodes` contains `3004` and `redirectUrl` is present, the helper redirects the customer to the 3DS challenge. Any other `errorCodes` value throws. In production, `redirectUrl` must be absolute `https`. `HUF_SZEP` is rejected. ``` -------------------------------- ### Example .env for sandbox Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/configuration.md Sample environment file with sandbox merchant IDs and secret keys for HUF and HUF_SZEP, plus redirect URL and logging. Only set the currencies you use; missing keys cause an error. ```bash # sandbox SIMPLEPAY_MERCHANT_ID_HUF=P123456 SIMPLEPAY_MERCHANT_KEY_HUF=sandbox-secret-key SIMPLEPAY_MERCHANT_ID_HUF_SZEP=P123457 SIMPLEPAY_MERCHANT_KEY_HUF_SZEP=sandbox-szep-key SIMPLEPAY_REDIRECT_URL=https://example.com/payment/back SIMPLEPAY_LOGGER=true ``` -------------------------------- ### Client-side payment initiation (Vue component) Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/recipes/nuxt.md Client-side script that calls the start endpoint and redirects to the returned payment URL. Uses $fetch and navigateTo with external: true. ```vue ``` -------------------------------- ### Start Google Pay server call with startGooglePay Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Call on the server to start the Google Pay payment. Returns JSON to the browser. When errorCodes contains 3004 and redirectUrl is present, the helper redirects the customer to the 3DS challenge; any other errorCodes value throws. In production, redirectUrl must be absolute https. HUF_SZEP is rejected. After 3DS, SimplePay redirects to the url sent in this request; verify r and s with getPaymentResponse and confirm payment with the existing IPN handler. ```typescript import { startGooglePay } from 'simplepay-js-sdk' const order = await loadOrder(orderRef) const response = await startGooglePay({ orderRef: order.orderRef, total: order.total, currency: 'HUF', customerEmail: order.email, language: 'HU', googlePayToken, }, { redirectUrl: 'https://yoursite.com/payment/callback', }) return response ``` -------------------------------- ### startApplePay Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/apple-pay.md Starts an Apple Pay session on the server for merchant validation. It validates the domain, loads the order, and returns a session containing transactionId and applePaySession. ```APIDOC ## startApplePay ### Description Starts an Apple Pay session on the server for merchant validation. It validates the domain, loads the order, and returns a session containing transactionId and applePaySession. ### Method startApplePay ### Parameters #### Options - **orderRef** (string) - Required - Order reference - **total** (string) - Required - Total amount - **currency** (string) - Required - 3-letter currency code - **customerEmail** (string) - Required - Customer email - **language** (string) - Required - Language code - **domain** (string) - Required - Registered FQDN ### Response Returns a session object containing `transactionId` and `applePaySession`. ### Request Example ```ts import { startApplePay } from 'simplepay-js-sdk' // POST /api/apple-pay/validate body: { orderRef, domain } const REGISTERED_DOMAIN = 'shop.example.com' if (domain !== REGISTERED_DOMAIN) { throw new Error('Unregistered Apple Pay domain') } const order = await loadOrder(orderRef) const session = await startApplePay({ orderRef: order.orderRef, total: order.total, currency: 'HUF', customerEmail: order.email, language: 'EN', domain: REGISTERED_DOMAIN, // your own registered FQDN – not the value from the browser }) await saveApplePayTransaction(order.orderRef, session.transactionId) return session // contains transactionId, applePaySession ``` ``` -------------------------------- ### Express.js integration with startPayment, getPaymentResponse, and handleIpnRequest Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Shows how to integrate the SimplePay SDK in an Express.js app. Use express.text({ type: '*/*' }) for the IPN route to get the raw body string, and always set the Signature header in the IPN response. The callback route uses getPaymentResponse with the r and s query parameters. ```typescript import express from 'express' import { startPayment, getPaymentResponse, handleIpnRequest } from 'simplepay-js-sdk' const app = express() app.post('/api/payment/start', async (req, res) => { try { const response = await startPayment({ orderRef: req.body.orderRef, total: req.body.total, customerEmail: req.body.email, invoice: req.body.invoice, }) res.json({ paymentUrl: response.paymentUrl }) } catch (error) { res.status(500).json({ error: 'Payment failed' }) } }) app.get('/api/payment/callback', (req, res) => { const { r, s } = req.query const result = getPaymentResponse(r as string, s as string) // Handle result based on result.event res.redirect(`/payment/${result.event.toLowerCase()}`) }) app.post('/api/payment/ipn', express.text({ type: '*/*' }), (req, res) => { const signature = req.get('Signature') ?? '' const { responseBody, signature: respSignature } = handleIpnRequest(req.body, signature, process.env.SIMPLEPAY_MERCHANT_KEY_HUF!) res.set('Signature', respSignature).type('json').send(responseBody) }) ``` -------------------------------- ### Start Apple Pay validation with startApplePay Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/apple-pay.md Server-side validation endpoint that calls startApplePay from 'simplepay-js-sdk'. It verifies the domain matches the registered FQDN, loads the order, and starts the Apple Pay session. Throws when domain is not a valid FQDN ('Apple Pay domain must be the registered FQDN'), when SimplePay returns error codes, or when the response has no applePaySession ('Missing Apple Pay session'). ```TypeScript import { startApplePay } from 'simplepay-js-sdk' // POST /api/apple-pay/validate body: { orderRef, domain } const REGISTERED_DOMAIN = 'shop.example.com' if (domain !== REGISTERED_DOMAIN) { throw new Error('Unregistered Apple Pay domain') } const order = await loadOrder(orderRef) const session = await startApplePay({ orderRef: order.orderRef, total: order.total, currency: 'HUF', customerEmail: order.email, language: 'EN', domain: REGISTERED_DOMAIN, // your own registered FQDN – not the value from the browser }) await saveApplePayTransaction(order.orderRef, session.transactionId) return session // contains transactionId, applePaySession ``` -------------------------------- ### startPayment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/reference/api.md Starts a one-time payment and returns a SimplePayResponse containing the payment URL to redirect the customer to. Accepts payment data and optional configuration. ```APIDOC ## startPayment ### Description Starts a one-time payment (`POST /start`). Redirect the customer to the returned `paymentUrl`. ### Method POST ### Endpoint /start ### Parameters #### Request Body - `paymentData` (PaymentData) - Required - Payment data object - `config.redirectUrl` (string) - Optional - Return URL for this payment (default: `SIMPLEPAY_REDIRECT_URL`) ### Response #### Success Response (200) - `paymentUrl` (string) - URL to redirect the customer to ### Notes - Defaults: `currency: 'HUF'`, `language: 'HU'`, `method: 'CARD'`, 30-minute timeout ``` -------------------------------- ### Import available types from simplepay-js-sdk Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Imports all TypeScript types provided by the SDK, including Currency, Language, PaymentMethod, and various response types. Use this to get type definitions for payments, recurring payments, tokens, and IPN responses. ```typescript import type { Currency, // 'HUF' | 'HUF_SZEP' | 'EUR' | 'USD' Language, // 'HU' | 'EN' | 'DE' | ... (16 languages) PaymentMethod, // 'CARD' | 'WIRE' GooglePayPaymentData, SimplePayGooglePayResponse, SimplePayResponse, SimplePayRecurringResponse, SimplePayTokenResponse, SimplePayCancelCardResponse, SimplePayResult, SimplePayIPNResponse, } from 'simplepay-js-sdk' ``` -------------------------------- ### Install the simplepay-js-sdk Agent Skill with npx skills add Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/ai/agent-skill.md Run this command in your project root to install the Agent Skill for AI coding agents like Claude Code, Cursor, and Codex. The agent then loads the skill automatically when working on a SimplePay integration. ```bash npx skills add rrd108/simplepay-js-sdk ``` -------------------------------- ### startRecurringPayment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/reference/api.md Starts a recurring payment with card registration. The response's tokens array is needed for later charges. ```APIDOC ## startRecurringPayment ### Description Starts a recurring payment with card registration. The response's tokens array is needed for later charges. ### Method POST ### Endpoint /start ### Parameters #### Request Body - paymentData (RecurringPaymentData) - Required - Payment data for recurring payment. ### Response #### Success Response - tokens (array) - Tokens needed for later charges. ### Notes - No config argument: the return URL is always SIMPLEPAY_REDIRECT_URL. - Always CARD, threeDSReqAuthMethod: '02'. - recurring defaults for falsy fields: times: 3, until: about 180 days, maxAmount: 12000. ``` -------------------------------- ### Example IPN response body Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/ipn.md Example JSON result after handleIpnRequest adds receiveDate as text before the last '}'. Shows field order and types preserved byte-identically. ```JSON {"salt":"223G0O8HqBUlXjZ0Ix9u4V4hnkJwPgDx","orderRef":"order-12","method":"CARD","merchant":"P123456","finishDate":"2026-12-02T10:12:43+01:00","paymentDate":"2026-12-02T10:12:16+01:00","transactionId":504233881,"status":"FINISHED","receiveDate":"2026-12-02T09:12:44+00:00"} ``` -------------------------------- ### Start a payment in a Next.js route handler (app/api/simplepay/start/route.ts) Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/recipes/nextjs.md POST route handler that starts a payment using startPayment. Must run on the Node.js runtime (default; not Edge). Returns the paymentUrl as JSON, or a 502 error if starting fails. ```ts import { startPayment } from 'simplepay-js-sdk' export const runtime = 'nodejs' export async function POST(request: Request) { const { orderId } = await request.json() const order = await getOrder(orderId) try { const { paymentUrl } = await startPayment({ orderRef: order.ref, total: order.total, customerEmail: order.email, }) return Response.json({ paymentUrl }) } catch (error) { console.error('SimplePay start', error) return Response.json({ error: 'Could not start the payment' }, { status: 502 }) } } ``` -------------------------------- ### Start a payment with startPayment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/index.md Call startPayment to initiate a one-time payment. Provide orderRef, total, and customerEmail; the returned paymentUrl is used to redirect the customer. ```typescript import { startPayment } from 'simplepay-js-sdk' const { paymentUrl } = await startPayment({ orderRef: 'order-12', total: 1212, customerEmail: 'customer@example.com', }) // redirect the customer to paymentUrl ``` -------------------------------- ### Start SZÉP card payment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/one-time-payment.md Starts a payment with currency HUF_SZEP. Requires SIMPLEPAY_MERCHANT_ID_HUF_SZEP and SIMPLEPAY_MERCHANT_KEY_HUF_SZEP. The request currency is HUF. ```ts await startPayment({ orderRef: 'order-13', total: 5000, currency: 'HUF_SZEP', customerEmail: 'customer@example.com', }) ``` -------------------------------- ### Example result object from getPaymentResponse Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/back-url.md Example return value of getPaymentResponse. The event field is uppercase and can be SUCCESS, FAIL, TIMEOUT, or CANCEL. The tokens field holds card registration tokens for recurring payments when SimplePay sends them. ```ts { responseCode: 0, transactionId: '504233881', event: 'SUCCESS', merchantId: 'P123456', orderRef: 'order-12', tokens: undefined, // card registration tokens for recurring payments } ``` -------------------------------- ### Complete IPN endpoint (framework-agnostic) Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/ipn.md Web-standard Request/Response example for handling IPN. Reads raw text (not JSON), verifies signature via handleIpnRequest, closes order only after valid signature, and returns response unchanged with new signature. Requires SIMPLEPAY_MERCHANT_KEY_HUF env var. ```TypeScript import { handleIpnRequest } from 'simplepay-js-sdk' export async function POST(request: Request) { // 1. RAW text – not request.json()! const ipnBody = await request.text() // 2. the signature comes in a header const incomingSignature = request.headers.get('Signature') ?? '' let result try { // 3. verify + receiveDate + new signature result = handleIpnRequest(ipnBody, incomingSignature, process.env.SIMPLEPAY_MERCHANT_KEY_HUF!) } catch (error) { // bad signature or not a JSON object: don't touch the order console.error('Invalid SimplePay IPN', error) return new Response('Invalid signature', { status: 400 }) } // 4. close the order – only after a valid signature const ipn = JSON.parse(ipnBody) as { orderRef: string, transactionId: number, status: string } if (ipn.status === 'FINISHED') { await markOrderPaid(ipn.orderRef, ipn.transactionId) // your function, make it idempotent } // 5. send the response back UNCHANGED return new Response(result.responseBody, { status: 200, headers: { 'Content-Type': 'application/json', 'Signature': result.signature, }, }) } ``` -------------------------------- ### Start a payment with startPayment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/one-time-payment.md Calls startPayment with required orderRef, total, and customerEmail, plus optional currency, language, method, and invoice data. The second argument can override redirectUrl. Redirect the customer to response.paymentUrl. ```ts import { startPayment } from 'simplepay-js-sdk' const response = await startPayment({ orderRef: 'order-12', // required, unique total: 1212, // required, number or string customerEmail: 'customer@example.com', // required currency: 'HUF', // optional: HUF | HUF_SZEP | EUR | USD, default HUF language: 'EN', // optional, default HU method: 'CARD', // optional: CARD | WIRE, default CARD invoice: { // optional name: 'Test Customer', country: 'HU', state: 'Budapest', city: 'Budapest', zip: '1111', address: 'Fő utca 1.', address2: '2nd floor', // optional phone: '+36301234567', // optional }, }, { redirectUrl: 'https://example.com/payment/back', // optional, overrides SIMPLEPAY_REDIRECT_URL }) // redirect return Response.redirect(response.paymentUrl, 303) ``` -------------------------------- ### Make Token Payments using startTokenPayment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Processes merchant-initiated payments using a saved card token, e.g., via cron job. Requires the token from the card registration and a valid Currency type. ```typescript import { startTokenPayment } from 'simplepay-js-sdk' import type { Currency } from 'simplepay-js-sdk' const processTokenPayment = async () => { try { const response = await startTokenPayment({ orderRef: Date.now().toString(), token: '1234567890123456', // from your database total: 1212, currency: 'HUF' as Currency, customer: 'Customer Name', customerEmail: 'customer@example.com', language: 'HU', method: 'CARD', invoice: { name: 'Customer Name', country: 'HU', state: 'Budapest', city: 'Budapest', zip: '1234', address: 'Street 1', }, }) return response } catch (error) { console.error('Token payment failed:', error) throw error } } ``` -------------------------------- ### startApplePay method signature Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/reference/api.md Starts an Apple Pay session for merchant validation via POST /startapplepay. The domain must be the registered FQDN. Returns a promise resolving to SimplePayApplePayStartResponse containing transactionId and applePaySession. ```typescript startApplePay(paymentData: ApplePayStartData): Promise ``` -------------------------------- ### startTokenPayment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Makes a merchant-initiated payment using a previously saved card token. This is typically used for recurring charges via cron jobs. ```APIDOC ## startTokenPayment ### Description Makes a merchant-initiated payment using a previously saved card token. This is typically used for recurring charges via cron jobs. ### Method startTokenPayment ### Parameters #### Request Body - `orderRef` (string) - Required - Order reference - `token` (string) - Required - Card token from database - `total` (number) - Required - Total amount in minor units - `currency` (string) - Required - Currency code (e.g., 'HUF') - `customer` (string) - Required - Customer name - `customerEmail` (string) - Required - Customer email - `language` (string) - Required - Language code (e.g., 'HU') - `method` (string) - Required - Payment method (e.g., 'CARD') - `invoice.name` (string) - Required - Invoice name - `invoice.country` (string) - Required - Country code - `invoice.state` (string) - Required - State/region - `invoice.city` (string) - Required - City - `invoice.zip` (string) - Required - ZIP code - `invoice.address` (string) - Required - Street address ### Response #### Success Response - (object) - Payment response ### Request Example ```typescript import { startTokenPayment } from 'simplepay-js-sdk' import type { Currency } from 'simplepay-js-sdk' const processTokenPayment = async () => { try { const response = await startTokenPayment({ orderRef: Date.now().toString(), token: '1234567890123456', // from your database total: 1212, currency: 'HUF' as Currency, customer: 'Customer Name', customerEmail: 'customer@example.com', language: 'HU', method: 'CARD', invoice: { name: 'Customer Name', country: 'HU', state: 'Budapest', city: 'Budapest', zip: '1234', address: 'Street 1', }, }) return response } catch (error) { console.error('Token payment failed:', error) throw error } } ``` ``` -------------------------------- ### handleIpnRequest Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Handles the full IPN flow. Processes the incoming IPN request and returns the appropriate response. ```APIDOC ## handleIpnRequest ### Description Handles the full IPN flow. Processes the incoming IPN request and returns the appropriate response. ### Method Function ### Signature `handleIpnRequest(...)` ### Parameters - (parameters not specified in source) ### Returns - **SimplePayIPNResponse** - The IPN response object. ### Example (No example provided in source) ``` -------------------------------- ### Import utility functions from simplepay-js-sdk Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Imports utility functions for signature verification and generation, decoding payment redirect responses, handling IPN requests, and converting dates to SimplePay-compatible ISO 8601 strings. ```typescript import { checkSignature, // Verify HMAC-SHA384 signature generateSignature, // Generate HMAC-SHA384 signature getPaymentResponse, // Decode payment redirect response handleIpnRequest, // Handle full IPN flow toISO8601DateString, // Convert Date to SimplePay-compatible ISO 8601 string } from 'simplepay-js-sdk' ``` -------------------------------- ### startApplePay Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/reference/api.md Starts an Apple Pay session for merchant validation. It calls the POST /startapplepay endpoint and returns a response containing transactionId and applePaySession. ```APIDOC ## startApplePay ### Description Starts an Apple Pay session for merchant validation. It calls the POST /startapplepay endpoint and returns a response containing transactionId and applePaySession. ### Method POST ### Endpoint /startapplepay ### Parameters #### Request Body - **paymentData** (ApplePayStartData) - Required - The payment data for starting the Apple Pay session. ### Response #### Success Response (200) - **transactionId** (string) - The transaction identifier. - **applePaySession** (object) - The Apple Pay session object. ### Request Example ```ts startApplePay(paymentData: ApplePayStartData): Promise ``` ``` -------------------------------- ### ApplePayStartData Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/reference/types.md Input data for starting an Apple Pay payment. ```APIDOC ```ts interface ApplePayStartData { orderRef: string total: number | string customerEmail: string domain: string // the registered FQDN currency?: Currency // not HUF_SZEP language?: Language invoice?: PaymentData['invoice'] } ``` ``` -------------------------------- ### startPayment Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/one-time-payment.md Starts a one-time card or wire payment with SimplePay. It sends a signed request to SimplePay's /start endpoint and returns a SimplePayResponse containing the paymentUrl to redirect the customer to. ```APIDOC ## startPayment ### Description Starts a one-time card or wire payment with SimplePay. It sends a signed request to SimplePay's /start endpoint and returns a SimplePayResponse containing the paymentUrl to redirect the customer to. ### Method POST ### Endpoint /start ### Parameters #### Request Body - **orderRef** (string) - Required - Your order reference. Must be unique within the merchant account. - **total** (number | string) - Required - Amount to charge. The SDK converts it to a string. - **customerEmail** (string) - Required - Customer's email address. - **currency** (Currency) - Optional - `HUF`, `HUF_SZEP`, `EUR` or `USD`. Default `HUF`. - **language** (Language) - Optional - Payment page language. Default `HU`. - **method** ('CARD' | 'WIRE') - Optional - Card or wire transfer. Default `CARD`. - **invoice** (object) - Optional - Billing data, see [Types](../reference/types#paymentdata). #### PaymentConfig (second argument, optional) - **redirectUrl** (string) - Return URL for this payment. Must be absolute `https` in production. ### Response #### Success Response (200) - **salt** (string) - Salt value. - **merchant** (string) - Merchant identifier. - **orderRef** (string) - Order reference. - **currency** (string) - Currency. - **transactionId** (string) - Transaction identifier. - **timeout** (string) - Timeout timestamp. - **total** (string) - Total amount. - **paymentUrl** (string) - URL to redirect the customer to. ### Request Example ```ts import { startPayment } from 'simplepay-js-sdk' const response = await startPayment({ orderRef: 'order-12', // required, unique total: 1212, // required, number or string customerEmail: 'customer@example.com', // required currency: 'HUF', // optional: HUF | HUF_SZEP | EUR | USD, default HUF language: 'EN', // optional, default HU method: 'CARD', // optional: CARD | WIRE, default CARD invoice: { // optional name: 'Test Customer', country: 'HU', state: 'Budapest', city: 'Budapest', zip: '1111', address: 'Fő utca 1.', address2: '2nd floor', // optional phone: '+36301234567', // optional }, }, { redirectUrl: 'https://example.com/payment/back', // optional, overrides SIMPLEPAY_REDIRECT_URL }) // redirect return Response.redirect(response.paymentUrl, 303) ``` ### Response Example ```ts { salt: '...', merchant: 'P123456', orderRef: 'order-12', currency: 'HUF', transactionId: '504233881', timeout: '2026-12-02T10:30:00+00:00', total: '1212', paymentUrl: 'https://sandbox.simplepay.hu/pay/pay/pspHU/...', } ``` ### Error Handling `startPayment` throws when: - the currency has no keys: `Missing SimplePay configuration for HUF` - the currency is unknown: `Unsupported currency: XYZ` - in production the return URL is missing or not `https` - SimplePay answers with a non-2xx status: `SimplePay API error: 500` - the response signature is missing or wrong: `Missing response signature`, `Invalid response signature` - SimplePay returns error codes: `SimplePay API error: 5321` (several codes are comma-separated) - no answer within 30 seconds (`TimeoutError`) ```ts try { const { paymentUrl } = await startPayment(data) return redirect(paymentUrl) } catch (error) { console.error('SimplePay payment start failed', error) // show an error page; the order stays unpaid } ``` ``` -------------------------------- ### getPaymentResponse Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Decodes the payment redirect response. Returns the payment response object. ```APIDOC ## getPaymentResponse ### Description Decodes the payment redirect response. Returns the payment response object. ### Method Function ### Signature `getPaymentResponse(...)` ### Parameters - (parameters not specified in source) ### Returns - **SimplePayResponse** - The decoded payment response. ### Example (No example provided in source) ``` -------------------------------- ### SimplePayResponse example Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/one-time-payment.md Shows the shape of the resolved SimplePayResponse. Store transactionId with the order because SimplePay's admin and the IPN identify the payment by it. ```ts { salt: '...', merchant: 'P123456', orderRef: 'order-12', currency: 'HUF', transactionId: '504233881', timeout: '2026-12-02T10:30:00+00:00', total: '1212', paymentUrl: 'https://sandbox.simplepay.hu/pay/pay/pspHU/...', } ``` -------------------------------- ### Call startApplePay and doApplePay from server Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Server-side calls for merchant-hosted Apple Pay. startApplePay throws when domain is not an FQDN, when errorCodes is present, or when applePaySession.merchantSessionIdentifier is missing. doApplePay accepts only a base64 applePayToken and a positive integer transactionId, and throws unless applePayStatus is STATUS_SUCCESS; HUF_SZEP is rejected. Confirm payment with the existing IPN handler. ```typescript import { doApplePay, startApplePay } from 'simplepay-js-sdk' const order = await loadOrder(orderRef) const session = await startApplePay({ orderRef: order.orderRef, total: order.total, currency: 'HUF', customerEmail: order.email, language: 'HU', domain: 'shop.example.com', }) return session const payment = await doApplePay({ transactionId, applePayToken, currency: 'HUF', }) return payment ``` -------------------------------- ### handleIpnRequest Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Processes an Instant Payment Notification (IPN) from SimplePay. Validates the signature and returns the response body and signature to send back to SimplePay. ```APIDOC ## handleIpnRequest ### Description Handles the IPN (Instant Payment Notification) from SimplePay. Validates the signature and returns the response body and signature to send back to SimplePay. ### Method Function call ### Parameters - `ipnBody` (string) - Required - The raw request body as text - `incomingSignature` (string) - Required - The Signature header from the request - `merchantKey` (string) - Required - The merchant key from environment variable SIMPLEPAY_MERCHANT_KEY_ ### Response - `responseBody` (string) - The exact response body to send back - `signature` (string) - The signature to include in the response header ### Request Example ```typescript import { handleIpnRequest } from 'simplepay-js-sdk' const handleIpn = async (request: Request) => { const ipnBody = await request.text() // IMPORTANT: use .text(), NOT .json() const incomingSignature = request.headers.get('Signature') ?? '' // getSimplePayConfig is internal and NOT exported - read the key from the environment const merchantKey = process.env.SIMPLEPAY_MERCHANT_KEY_HUF! // throws on an invalid signature: answer 400 and do not touch the order const { responseBody, signature } = handleIpnRequest( ipnBody, incomingSignature, merchantKey ) // CRITICAL: Send responseBody exactly as returned - do NOT modify it return new Response(responseBody, { status: 200, headers: { 'Content-Type': 'application/json', 'Signature': signature, }, }) } ``` ``` -------------------------------- ### Back URL redirect example with r and s parameters Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/docs/en/guide/back-url.md Shows the redirect URL SimplePay sends the customer to after payment, cancellation, or timeout. The r parameter is Base64-encoded JSON with the result, and s is the signature of that JSON. ```text https://example.com/payment/back?r=eyJyIjowLCJ0Ijo1MDQy...&s=El%2Bq... ``` -------------------------------- ### Environment variables for SimplePay configuration Source: https://github.com/rrd108/simplepay-js-sdk/blob/main/skills/simplepay-js-sdk/SKILL.md Set these environment variables in your .env file. Never hardcode secrets in source code. Required variables include merchant key, merchant ID, and redirect URL. Optional variables for additional currencies, SZEP card payments, and environment settings (production and logging). ```env # Required SIMPLEPAY_MERCHANT_KEY_HUF=your-secret-merchant-key SIMPLEPAY_MERCHANT_ID_HUF=your-merchant-id SIMPLEPAY_REDIRECT_URL=https://yoursite.com/payment/callback # Optional - additional currencies SIMPLEPAY_MERCHANT_KEY_EUR=your-eur-key SIMPLEPAY_MERCHANT_ID_EUR=your-eur-id SIMPLEPAY_MERCHANT_KEY_USD=your-usd-key SIMPLEPAY_MERCHANT_ID_USD=your-usd-id # Optional - SZEP card payments SIMPLEPAY_MERCHANT_KEY_HUF_SZEP=your-szep-key SIMPLEPAY_MERCHANT_ID_HUF_SZEP=your-szep-id # Optional - environment SIMPLEPAY_PRODUCTION=true # omit or set to false for sandbox SIMPLEPAY_LOGGER=true # enable debug logging (development only) ```