English | فارسی
A simple, educational sample for integrating with the PayPing payment gateway using Node.js — with zero external dependencies (plain Node.js only).
This project is built on PayPing API v3 (the v3/pay routes).
- The user fills in the form on the home page (email, mobile, name, amount, and description).
POST /payment→ the server creates a payment order by callingPOST api.payping.ir/v3/pay. The response contains apaymentCodeand a ready-to-useurl, so the user is redirected straight to thaturl.- After the bank gateway flow finishes, PayPing sends the result to your
returnUrl(the/verifyroute) as a POST form:status:1means successful,0means not paiderrorCode: the returned error code — empty on successdata: a JSON string containingclientRefId,paymentCode,paymentRefId(tracking code),amount,gatewayAmount,cardNumber, andcardHashPan
- If
statusequals1, the server finalizes the transaction by callingPOST api.payping.ir/v3/pay/verifyand shows the result.
Important: If verify is not called within 10 minutes after the payment, the payment becomes invalid and the paid amount is returned to the payer.
├── server.js # The whole app: form, payment creation, and verification
├── package.json
├── README.md # English documentation
└── README.fa.md # Persian (فارسی) documentation
| Route | Method | PayPing API equivalent (v3) | Description |
|---|---|---|---|
/payment |
POST | POST /v3/pay |
Create payment and redirect to the returned url |
/verify |
POST | POST /v3/pay/verify |
Receive the gateway result and verify the transaction |
- Node.js v18 or later (for the built-in
fetch) - An API token from the PayPing panel (Developers section → Tokens)
# Linux / macOS
PAYPING_TOKEN=your-token node server.js
# Windows (PowerShell)
$env:PAYPING_TOKEN="your-token"; node server.js
# or with npm
npm startThen open http://localhost:3000 in your browser.
| Variable | Default | Description |
|---|---|---|
PAYPING_TOKEN |
— | Your token from payping.ir (required) |
PORT |
3000 |
Server port |
RETURN_URL |
http://localhost:3000/verify |
The URL the user is sent back to after payment; use your own domain in production |
Production example:
PAYPING_TOKEN=xxxx RETURN_URL=https://domain.com/verify PORT=80 node server.js- Besides
paymentCodeandurl, the create-payment response includes amounts:amount(the payment order amount),gatewayAmount(the final amount the payer sees — it may be higher depending on your fee scenario), pluspayerWage/businessWagefees andpaypingVat. - The verify response returns full transaction details: amount, masked card number,
clientRefId, payment date, and fees. - Special verify statuses:
409withmetaData.code = 110→ the transaction has already been verified; no need to verify again.202or502→ verification is still being processed; call verify again.
- Optional create-payment fields you can add if needed:
nationalCode,isReversible(enables refunds for up to 30 minutes after verify), andisBlocked(blockable payment for post-payment splitting via theshare/unblockservices).
- Never commit your token; always use environment variables.
- Always determine and validate the amount on the server side; trusting a client-submitted amount is dangerous. For simplicity, this sample reads the amount from the form, appends it to the
returnUrl, and compares it with theamountsent back by PayPing — in a real project, read it from your invoice/database instead. - Per the official docs: after a successful callback, compare the
amountandclientRefIdsent by PayPing with your own database and abort the process on any mismatch (this comparison is implemented in the sample). - It is recommended to use an invoice number as
clientRefIdand store the verify result along withpaymentRefIdin your database for traceability. - This sample is for educational purposes only; use HTTPS in production and apply the necessary security measures (rate limiting, logging, etc.).
GPL-3.0 — matching the original repository.