A complete solution for integrating bKash payment gateway with Next.js applications. This project provides a seamless way to accept payments through bKash in your web applications.
- β Complete bKash payment flow integration
- β Sandbox testing environment
- β Dark/Light theme support
- β Responsive design
- β Toast notifications
- β Success and failure handling
- β Comprehensive documentation
- β Developer tools and GitHub integration
- Next.js 14 - React framework with App Router
- TypeScript - Type safety
- Tailwind CSS - Styling
- next-themes - Theme management
- Sonner - Toast notifications
- Zod - Schema validation
- Lucide React - Icons
- Clone the repository:
git clone https://github.com/anbuinfosec/bkash-pgw.git
cd bkash-pgw- Install dependencies:
npm install
# or
yarn install
# or
pnpm install
# or
bun install- Set up environment variables:
Create a .env.local file in the root directory with the following variables or add the data on config/index.tx:
# bKash API Credentials
BKASH_USERNAME=sandboxTokenizedUser02
BKASH_PASSWORD=sandboxTokenizedUser02@12345
BKASH_API_KEY=4f6o0cjiki2rfm34kfdadl1eqq
BKASH_SECRET_KEY=2is7hdktrekvrbljjh44ll3d9l1dtjo4pasmjvs5vl5qr3fug4b
# bKash API URLs
BKASH_GRANT_TOKEN_URL=https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/token/grant
BKASH_CREATE_PAYMENT_URL=https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/create
BKASH_EXECUTE_PAYMENT_URL=https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/execute
BKASH_REFUND_TRANSACTION_URL=https://tokenized.sandbox.bka.sh/v1.2.0-beta/tokenized/checkout/payment/refund
# Application URL
NEXT_PUBLIC_URL=http://localhost:3000- Run the development server:
npm run dev
# or
yarn dev
# or
pnpm dev
# or
bun dev- Open http://localhost:3000 in your browser to see the application.
| Variable | Description |
|---|---|
BKASH_USERNAME |
bKash API username |
BKASH_PASSWORD |
bKash API password |
BKASH_API_KEY |
bKash API key |
BKASH_SECRET_KEY |
bKash API secret key |
BKASH_GRANT_TOKEN_URL |
URL for granting tokens |
BKASH_CREATE_PAYMENT_URL |
URL for creating payments |
BKASH_EXECUTE_PAYMENT_URL |
URL for executing payments |
BKASH_REFUND_TRANSACTION_URL |
URL for refunding transactions |
NEXT_PUBLIC_URL |
Your application's public URL |
- User enters amount and name on the home page
- User clicks "Pay with bKash"
- User is redirected to bKash payment page
- User completes payment
- User is redirected back to the application
- Payment is verified and success/failure page is shown
Use the following credentials for testing:
| Type | Number | PIN | OTP |
|---|---|---|---|
| Regular Customer | 01929918378 | 12121 | 123456 |
| Insufficient Balance | 01823074817 | 12121 | 123456 |
| Debit Block | 01823074818 | 12121 | 123456 |
| Merchant | 01619777282 | 12121 | 123456 |
POST /api/create
Request Body:
{
"amount": "100",
"name": "John Doe"
}Response:
{
"bkashURL": "https://sandbox.bka.sh/checkout/payment/...",
"paymentID": "TR0001",
"statusMessage": "Successful"
}POST /api/callback
Request Body:
{
"paymentID": "TR0001",
"id_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9..."
}Response:
{
"success": true,
"transactionStatus": "Completed",
"trxID": "ABC123XYZ",
"statusMessage": "Successful"
}POST /api/refund
Request Body:
{
"paymentID": "TR0001",
"amount": "100",
"trxID": "ABC123XYZ",
"reason": "Customer requested refund"
}Response:
{
"success": true,
"refundTrxID": "REF123XYZ",
"statusMessage": "Refund Successful"
}The easiest way to deploy this application is to use the Vercel Platform.
- Push your code to a GitHub repository
- Import the project to Vercel
- Set the environment variables in the Vercel dashboard
- Deploy
To build the application for production:
npm run build
# or
yarn build
# or
pnpm build
# or
bun buildFor more detailed information about the bKash Payment Gateway API, visit the official documentation.
To test the payment flow:
- Go to the home page
- Enter an amount (e.g., 100)
- Enter a name
- Click "Pay with bKash"
- Use the sandbox credentials provided above
- Complete the payment flow
- Verify the success/failure page
Contributions are welcome! Please feel free to submit a Pull Request.
- 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.
Mohammad Alamin - @anbuinfosec
