Bkash Payment Gateway

Guides

Deployment Guide

Step-by-step guide to deploy your bKash payment integration to production.

Prerequisites

Before deploying, ensure you have:

  • ✅ Active bKash merchant account
  • ✅ Live App Key, App Secret, Username and Password from bKash Developer Portal
  • ✅ PHP 7.4+ with required extensions
  • ✅ Laravel 8, 9, 10, 11, or 12
  • ✅ Valid SSL certificate for your domain

TLS Requirement

bKash requires TLS 1.2 or higher. Test your server by running:
curl "https://tokenized.sandbox.bka.sh/v1.2.0-beta" -v

Switch to Production Credentials

Update your .env file with live credentials:

.env
env
# Production Mode
BKASH_SANDBOX=false

# Live Credentials (Get from bKash Developer Portal)
BKASH_APP_KEY=your_live_app_key
BKASH_APP_SECRET=your_live_app_secret
BKASH_USERNAME=your_live_username
BKASH_PASSWORD=your_live_password
BKASH_BASE_URL=https://tokenized.pay.bka.sh/v1.2.0-beta
BKASH_CURRENCY=BDT
BKASH_VERIFY_SSL=true

Get Live Credentials

Apply for production access at the bKash Developer Portal.
bKash Developer Portal

Environment Variables

All bKash configuration is controlled via environment variables. Here's a complete list:

VariableDescriptionProduction Value
BKASH_SANDBOXEnable/disable sandbox modefalse
BKASH_APP_KEYYour bKash App KeyLive App Key
BKASH_APP_SECRETYour bKash App SecretLive App Secret
BKASH_USERNAMEYour bKash UsernameLive Username
BKASH_PASSWORDYour bKash PasswordLive Password
BKASH_BASE_URLAPI Base URLhttps://tokenized.pay.bka.sh/v1.2.0-beta
BKASH_CURRENCYCurrency for transactionsBDT
BKASH_VERIFY_SSLEnable SSL verificationtrue
BKASH_CALLBACK_URLPayment callback URLhttps://yourdomain.com/payment/callback

URL Configuration

Make sure your application URL is correctly configured in .env:

.env
env
APP_URL=https://yourdomain.com

# bKash callback URLs
BKASH_CALLBACK_URL=https://yourdomain.com/payment/callback

# Routes (define in routes/web.php)
# /payment - Payment form
# /payment/initiate - Initiate payment
# /payment/callback - Payment callback
# /payment/success - Success page
# /payment/cancel - Cancel page

Public URLs Required

bKash must be able to reach your callback URLs. Make sure your application is publicly accessible.
Note: localhost will not work in production.

Deployment Steps

1. Deploy Your Code

Deploy your Laravel application to your production server:

terminal
bash
# Push to your repository
git push origin main

# Or deploy manually
rsync -avz /path/to/project/ user@server:/var/www/your-app/

2. Install Dependencies

terminal
bash
cd /var/www/your-app
composer install --no-dev --optimize-autoloader

3. Clear and Cache Config

terminal
bash
php artisan config:clear
php artisan cache:clear
php artisan route:clear
php artisan view:clear

# Cache for production
php artisan config:cache
php artisan route:cache
php artisan view:cache

4. Run Migrations

terminal
bash
php artisan migrate --force

Testing in Production

Before going live, test your integration with real (but small) transactions:

terminal
bash
# Test with small amount (10 BDT)
php artisan tinker
>>> Bkash::createPayment(10, 'TEST-' . date('YmdHis'), 'TEST-' . date('YmdHis'));

bKash Panel Configuration

Configure the following settings in your bKash merchant panel:

  • App Key: Your production App Key
  • App Secret: Your production App Secret
  • Username: Your production Username
  • Password: Your production Password
  • Callback URL: https://yourdomain.com/payment/callback

Register Your Server IP

For refunds and transaction queries, you may need to register your server's IP address with bKash in the developer portal.

Monitoring & Logging

Enable logging to monitor payment activity:

.env
env
# Enable bKash logging
BKASH_LOG_ERRORS=true
BKASH_LOG_CHANNEL=daily

Check logs at: storage/logs/laravel.log

Troubleshooting

Issue: "Invalid App Key" (2001)

  • Check your .env file for correct App Key
  • Make sure you're using live credentials in production
  • Verify BKASH_SANDBOX=false

Issue: "Invalid App Secret" (2002)

  • Check your .env file for correct App Secret
  • Ensure you're not using sandbox credentials

Issue: "Invalid Username/Password" (2003)

  • Verify your production username and password
  • Check for any special characters that might need escaping

Issue: "Token Expired" (2004)

  • Tokens auto-refresh automatically
  • Clear cache if needed: php artisan cache:clear

Issue: "Callback URL not accessible"

  • Make sure your application is publicly accessible
  • Check if your firewall is blocking bKash IPs
  • Verify the route exists and is correct
  • Ensure HTTPS is enabled

Issue: SSL Certificate Error

  • Set BKASH_VERIFY_SSL=true for production
  • Ensure your SSL certificate is valid

Performance Optimization

  • Cache tokens - Tokens are automatically cached to reduce API calls
  • Cache configuration with php artisan config:cache
  • Use database sessions for better performance
  • Monitor token expiry - Tokens expire every hour

Production Go-Live Checklist

  • ✅ Get live bKash credentials from Developer Portal
  • ✅ Update BKASH_SANDBOX=false
  • ✅ Set BKASH_VERIFY_SSL=true
  • ✅ Set correct APP_URL with HTTPS
  • ✅ Configure callback URL in bKash panel
  • ✅ Test with small real transaction (10 BDT)
  • ✅ Enable logging
  • ✅ Register server IP for refunds (if required)
  • ✅ Create database table for transactions
  • ✅ Set up proper error handling and user feedback

Need Help?

Join the discussion on GitHub Discussions or open an issue for support.
bKash Support: developer@bka.sh