paystation-sdk
v1.0.2
Published
PayStation Bangladesh Backend SDK for Node.js
Downloads
44
Maintainers
Readme
PayStation SDK
A production-ready Node.js backend SDK for integrating the PayStation Bangladesh payment gateway.
Supports Express, Next.js, Nuxt, Hono, Fastify, Serverless environments.
✨ Features
- 💳 Initiate payment (Hosted Checkout)
- 🔍 Check transaction status
- 🔁 Transaction status via trxId
- 🔔 Callback handling support
- 🌐 Sandbox & Live environment
- ⚙️ Works with all Node.js frameworks
- 🔐 Backend-only (secure)
📦 Installation
npm install paystation-sdk⚙️ Configuration
import { PayStation } from "paystation-sdk";
const paystation = new PayStation({
environment: "sandbox" // "sandbox" | "live"
});🔐 Default Credentials (Sandbox)
merchantId: "104-1653730183"
password: "gamecoderstorepass"⚠️ For production, always use your own credentials.
🌍 Environments
| Mode | Base URL | | ------- | --------------------------------- | | Sandbox | https://sandbox.paystation.com.bd | | Live | https://api.paystation.com.bd |
💳 Initiate Payment
Example
const response = await paystation.initiatePayment({
invoice_number: "INV_" + Date.now(),
currency: "BDT",
payment_amount: 10,
reference: "Test Payment",
cust_name: "Shohel",
cust_phone: "01700000000",
cust_email: "[email protected]",
callback_url: "https://yourdomain.com/callback",
checkout_items: "Test Product"
});✅ Success Response
{
"status_code": "200",
"status": "success",
"message": "Payment Link Created Successfully.",
"payment_amount": "10",
"invoice_number": "INV_123456",
"payment_url": "https://api.paystation.com.bd/checkout/XXXX"
}❌ Failed Response
{
"status_code": "1008",
"status": "failed",
"message": "Duplicate invoice number."
}📌 As documented by PayStation
🔍 Transaction Status
Example
const status = await paystation.transactionStatus("INV_123456");✅ Success Response
{
"status_code": "200",
"status": "success",
"message": "Transaction found.",
"data": {
"invoice_number": "INV_123456",
"trx_status": "Success",
"trx_id": "10XB9900",
"payment_amount": "120",
"order_date_time": "2022-12-25 10:25:30",
"payer_mobile_no": "01700000001",
"payment_method": "bkash",
"reference": "Test Payment",
"checkout_items": "Test Product"
}
}❌ Failed Transaction
{
"status_code": "200",
"status": "success",
"data": {
"trx_status": "Failed"
}
}🔎 Transaction Status (by trxId)
const status = await paystation.transactionStatusByTrxId("TRX_ID");Response Example
{
"status_code": "200",
"status": "success",
"data": {
"invoice_number": "59734251219",
"trx_status": "success",
"trx_id": "CG20D8AYB4121",
"trx_amount": 2,
"trx_date": "2025-07-02",
"payment_amount": "2.00",
"payment_method": "bKash"
}
}🔔 Callback Handling
After payment, PayStation redirects:
https://yourdomain.com/callback?status=Successful&invoice_number=123&trx_id=ABC123Example (Express)
app.get("/callback", (req, res) => {
const { status, invoice_number, trx_id } = req.query;
if (status === "Successful") {
return res.redirect(`/success?invoice=${invoice_number}&trx=${trx_id}`);
}
return res.redirect(`/failed?invoice=${invoice_number}`);
});✅ Success Route
app.get("/success", (req, res) => {
res.send("Payment Successful");
});❌ Failed Route
app.get("/failed", (req, res) => {
res.send("Payment Failed");
});🧪 Full Express Example
import express from "express";
import { PayStation } from "paystation-sdk";
const app = express();
app.use(express.json());
const ps = new PayStation({ environment: "sandbox" });
app.post("/pay", async (req, res) => {
const data = await ps.initiatePayment({
invoice_number: "INV_" + Date.now(),
currency: "BDT",
payment_amount: 10,
cust_name: "Shohel",
cust_phone: "01700000000",
cust_email: "[email protected]",
callback_url: "http://localhost:3000/callback"
});
res.json(data);
});
app.listen(3000);🔐 Security Best Practices
- Never expose credentials in frontend
- Always verify payment using
transactionStatus - Do not trust callback alone
- Use
.envfor production credentials
📁 Project Structure
src/
core/
PayStation.ts
types/
index.ts📦 Publish
npm publish --access public🔁 Version Update
npm version patch
npm publish📄 License
MIT License © Shohel Hossain
👨💻 Author
Shohel Hossain https://github.com/developershohel
⭐ Support
If this SDK helps you, please ⭐ the repo!
