Skip to content

Ready to use bKash PGW Payment getaway backend built with Node.js and Express.js for developer who want to integrate bKash on their application.

Notifications You must be signed in to change notification settings

tanvir-robin/bKash-pgw-nodejs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

7 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ bKash PGW Payment Gateway Backend

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.

✨ Features

  • πŸ’³ 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

πŸ”§ Tech Stack

  • πŸ“¦ Node.js
  • ⚑ Express.js
  • πŸ”„ Axios for HTTP requests
  • 🌍 CORS for cross-origin support
  • πŸ”‘ dotenv for environment management

πŸ“‹ Prerequisites

  • πŸ“Œ Node.js (v14 or higher)
  • πŸ“¦ npm (Node Package Manager)
  • 🎫 bKash PGW credentials
  • πŸ’‘ Basic knowledge of REST APIs

πŸš€ Getting Started

πŸ“₯ Clone the Repository

git clone https://github.com/tanvir-robin/bKash-pgw-nodejs.git
cd bkash-pgw-backend

πŸ“¦ Install Dependencies

npm install

βš™οΈ Environment Setup

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>

⚠️ Important: Never commit your .env file to version control!

πŸ’» Development

Run the server with hot-reload using nodemon:

npm start

The server will start on http://localhost:3000 (or your configured port)

πŸ“¦ Dependencies

{
  "dependencies": {
    "axios": "^1.7.7",
    "cors": "^2.8.5",
    "dotenv": "^16.4.5",
    "express": "^4.21.1"
  },
  "devDependencies": {
    "nodemon": "^3.1.7"
  }
}

πŸ›£οΈ API Endpoints

1. πŸ”— Create Payment Link

POST /initiate

Creates a bKash payment link for transaction initiation.

Request Body

{
    "payerReference": "Customer123",
    "callbackURL": "https://example.com/callback",
    "amount": "1000",
    "merchantInvoiceNumber": "INV-123456"
}

Sample cURL Request

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"
}'

Success Response

{
    "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.

2. βœ… Execute Payment

POST /execute

Executes a previously initiated bKash payment.

Request Body

{
    "paymentID": "TR0011kMH7LtQ1731358567158"
}

Sample cURL Request

curl --location 'https://your-api-url/execute' \
--header 'Content-Type: application/json' \
--data '{
    "paymentID": "TR0011kMH7LtQ1731358567158"
}'

Success Response

{
    "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.

🌐 Deployment

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.

πŸš€ Deploying to Vercel

  1. Create a Vercel account at vercel.com

  2. Install Vercel CLI:

npm install -g vercel
  1. Login to Vercel:
vercel login
  1. Deploy:
vercel
  1. 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.

🌍 Other Hosting Platforms

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.

πŸ”‘ API Configuration

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.

🀝 Contributing

  1. πŸ”± Fork the repository
  2. 🌿 Create your feature branch (git checkout -b feature/amazing-feature)
  3. πŸ’Ύ Commit your changes (git commit -m 'Add some amazing feature')
  4. πŸ“€ Push to the branch (git push origin feature/amazing-feature)
  5. πŸ“« Open a Pull Request

πŸ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ’¬ Support

For support:

🌟 Show your support

Give a ⭐️ if this project helped you!


Made with ❀️ by Robin | © 2024 All rights reserved

About

Ready to use bKash PGW Payment getaway backend built with Node.js and Express.js for developer who want to integrate bKash on their application.

Topics

Resources

Stars

Watchers

Forks