Simplify your bKash PGW payment integration with this ready-to-use Node.js backend. Built for developers who want a reliable, easy-to-implement payment solution.
- π³ Easy-to-use bKash PGW integration
- π Secure payment processing
- βοΈ Environment-based configuration
- π Production-ready with Vercel deployment
- π CORS enabled for cross-origin requests
- π οΈ Built with modern JavaScript
- π¦ Node.js
- β‘ Express.js
- π Axios for HTTP requests
- π CORS for cross-origin support
- π dotenv for environment management
- π Node.js (v14 or higher)
- π¦ npm (Node Package Manager)
- π« bKash PGW credentials
- π‘ Basic knowledge of REST APIs
git clone https://github.com/tanvir-robin/bKash-pgw-nodejs.git
cd bkash-pgw-backend
npm install
Create a .env
file in the root directory with the following variables:
APP_KEY=<API_KEY_FROM_PGW>
APP_SECRET=<YOUR_APP_SECRET>
USERNAME=<YOUR_USERNAME>
PASSWORD=<YOUR_PASSWORD>
.env
file to version control!
Run the server with hot-reload using nodemon:
npm start
The server will start on http://localhost:3000
(or your configured port)
{
"dependencies": {
"axios": "^1.7.7",
"cors": "^2.8.5",
"dotenv": "^16.4.5",
"express": "^4.21.1"
},
"devDependencies": {
"nodemon": "^3.1.7"
}
}
POST /initiate
Creates a bKash payment link for transaction initiation.
{
"payerReference": "Customer123",
"callbackURL": "https://example.com/callback",
"amount": "1000",
"merchantInvoiceNumber": "INV-123456"
}
curl --location 'https://your-api-url/initiate' \
--header 'Content-Type: application/json' \
--data '{
"payerReference": "Customer123",
"callbackURL": "https://example.com/callback",
"amount": "1000",
"merchantInvoiceNumber": "INV-123456"
}'
{
"status": "success",
"statusCode": 200,
"paymentID": "TR0011kMH7LtQ1731358567158",
"paymentCreateTime": "2024-03-20T10:30:15:000 GMT+0600",
"transactionStatus": "Initiated",
"amount": "1000",
"currency": "BDT",
"paymentExecuteURL": "https://tokenized.pay.bka.sh/checkout/payment/execute/TR0011..."
}
Access token will be generated in the backend and used automatically. No need to worry about it.
POST /execute
Executes a previously initiated bKash payment.
{
"paymentID": "TR0011kMH7LtQ1731358567158"
}
curl --location 'https://your-api-url/execute' \
--header 'Content-Type: application/json' \
--data '{
"paymentID": "TR0011kMH7LtQ1731358567158"
}'
{
"status": "success",
"statusCode": 200,
"paymentID": "TR0011kMH7LtQ1731358567158",
"trxID": "BK0001XX2ZY",
"transactionStatus": "Completed",
"amount": "1000",
"currency": "BDT",
"intent": "sale",
"merchantInvoiceNumber": "INV-123456"
}
Access token will be generated in the backend and used automatically. No need to worry about it.
This backend can be deployed to any hosting platform of your choice. However, I recommend Vercel for its excellent free tier (Hobby plan) and seamless deployment process. The project includes a vercel.json
configuration file, making it ready for Vercel deployment out of the box.
-
Create a Vercel account at vercel.com
-
Install Vercel CLI:
npm install -g vercel
- Login to Vercel:
vercel login
- Deploy:
vercel
- You will get the deployment URL. Use it to access the endpoints.
Note: The included
vercel.json
handles all the necessary configuration for Vercel deployment. You don't need to modify any additional settings.
You can deploy this backend to any hosting platform that supports Node.js applications, such as:
- Heroku
- Digital Ocean
- AWS
- Google Cloud
- Azure
Just follow your preferred platform's Node.js deployment guidelines.
Ensure you have the following from bKash PGW:
- π API Key
- π΄ App Secret
- π€ Username
- π Password
These credentials should be added to your environment variables as shown in the Environment Setup section.
- π± Fork the repository
- πΏ Create your feature branch (
git checkout -b feature/amazing-feature
) - πΎ Commit your changes (
git commit -m 'Add some amazing feature'
) - π€ Push to the branch (
git push origin feature/amazing-feature
) - π« Open a Pull Request
This project is licensed under the MIT License - see the LICENSE file for details.
For support:
- π§ Email: tanvir.rrrabin@gmail.com
- π Open an issue in the repository
- π Start a discussion
Give a βοΈ if this project helped you!
Made with β€οΈ by Robin | Β© 2024 All rights reserved