devrkb21/bkash-pgw-laravel 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

devrkb21/bkash-pgw-laravel

Composer 安装命令:

composer require devrkb21/bkash-pgw-laravel

包简介

Production-ready Laravel integration for bKash Tokenized Checkout V2 (auth, payments, webhooks).

README 文档

README

🚀 Production-ready Laravel bKash package for integrating bKash Tokenized Checkout V2 API with secure webhook, token management, and full payment flow.

The most complete and secure bKash integration for Laravel.

PHP Laravel License

🚀 Quick Start (30 seconds)

composer require devrkb21/bkash-pgw-laravel
use Bkash;

$url = Bkash::payment()->createPayment([
    'payerReference' => 'user_123',
    'callbackURL' => route('bkash.callback'),
    'amount' => '100',
    'currency' => 'BDT',
    'intent' => 'sale',
    'merchantInvoiceNumber' => 'INV123456',
]);

return redirect($url->bkash_url);

👉 That’s it. User will be redirected to bKash payment page.

⚙️ Configuration

Publish config:

php artisan vendor:publish --tag=bkash-config

Add credentials:

BKASH_ENV=sandbox

BKASH_SANDBOX_BASE_URL=https://tokenized.sandbox.bka.sh/v2/tokenized-checkout
BKASH_PRODUCTION_BASE_URL=https://tokenized.pay.bka.sh/v2/tokenized-checkout

BKASH_APP_KEY=
BKASH_APP_SECRET=
BKASH_USERNAME=
BKASH_PASSWORD=

BKASH_TIMEOUT=30
BKASH_CACHE=true
BKASH_TOKEN_CACHE_KEY=bkash.token
BKASH_ENABLE_ROUTES=false

Auth APIs

Grant Token - POST /auth/grant-token

Request body keys:

{
    "app_key": "{{bkash_app_key}}",
    "app_secret": "{{bkash_app_secret}}"
}

Response (normalized by the package, expires_at is computed):

{
    "id_token": "string",
    "refresh_token": "string",
    "expires_in": 3600,
    "expires_at": 1730999999
}

Refresh Token - POST /auth/refresh-token

Request body keys:

{
    "app_key": "{{bkash_app_key}}",
    "app_secret": "{{bkash_app_secret}}",
    "refresh_token": "{{bkash_refresh_token}}"
}

Response (normalized by the package, expires_at is computed):

{
    "id_token": "string",
    "refresh_token": "string",
    "expires_in": 3600,
    "expires_at": 1730999999
}

Payment APIs (Without Agreement)

Create Payment - POST /payment/create

Request body keys:

{
    "payerReference": "{{payer_reference}}",
    "callbackURL": "{{callback_url}}",
    "amount": "{{amount}}",
    "currency": "{{currency}}",
    "intent": "{{intent}}",
    "merchantInvoiceNumber": "{{merchant_invoice_number}}",
    "merchantAssociationInfo": "{{merchant_association_info}}"
}

Response (package normalizes common fields):

{
    "paymentID": "payment_123",
    "paymentId": "payment_123",
    "bkashURL": "https://tokenized.sandbox.bka.sh/checkout/..."
}

Execute Payment - POST /payment/execute

Request body keys:

{
    "paymentId": "{{payment_id}}"
}

Response (package normalizes common fields):

{
    "trxID": "trx_123"
}

Query Payment - POST /query/payment

Request body keys:

{
    "paymentID": "{{payment_id}}"
}

Response (raw bKash payload, normalized keys are added when present):

{
    "paymentID": "payment_123",
    "trxID": "trx_123",
    "...": "additional fields may be returned"
}

Capture Payment - POST /payment/capture

Request body keys:

{
    "paymentId": "{{payment_id}}"
}

Response (raw bKash payload, normalized keys are added when present):

{
    "paymentID": "payment_123",
    "trxID": "trx_123",
    "...": "additional fields may be returned"
}

Void Payment - POST /payment/void

Request body keys:

{
    "paymentId": "{{payment_id}}"
}

Response (raw bKash payload, normalized keys are added when present):

{
    "paymentID": "payment_123",
    "trxID": "trx_123",
    "...": "additional fields may be returned"
}

Payment APIs (With Agreement)

Create Payment With Agreement - POST /payment-with-agreement/create

Request body keys:

{
    "agreementId": "{{agreement_id}}",
    "callbackURL": "{{callback_url}}",
    "amount": "{{amount}}",
    "intent": "{{intent}}",
    "currency": "{{currency}}",
    "merchantInvoiceNumber": "{{merchant_invoice_number}}"
}

Response (package normalizes common fields):

{
    "paymentID": "payment_123",
    "paymentId": "payment_123",
    "agreementID": "agreement_123",
    "agreementId": "agreement_123",
    "bkashURL": "https://tokenized.sandbox.bka.sh/checkout/..."
}

Execute Payment With Agreement - POST /payment-with-agreement/execute

Request body keys:

{
    "paymentId": "{{payment_id}}",
    "agreementId": "{{agreement_id}}"
}

Response (package normalizes common fields):

{
    "trxID": "trx_123"
}

Capture Payment With Agreement - POST /payment-with-agreement/capture

Request body keys:

{
    "paymentId": "{{payment_id}}",
    "agreementId": "{{agreement_id}}"
}

Response (raw bKash payload, normalized keys are added when present):

{
    "paymentID": "payment_123",
    "agreementID": "agreement_123",
    "trxID": "trx_123",
    "...": "additional fields may be returned"
}

Void Payment With Agreement - POST /payment-with-agreement/void

Request body keys:

{
    "paymentId": "{{payment_id}}",
    "agreementId": "{{agreement_id}}"
}

Response (raw bKash payload, normalized keys are added when present):

{
    "paymentID": "payment_123",
    "agreementID": "agreement_123",
    "trxID": "trx_123",
    "...": "additional fields may be returned"
}

Agreement APIs

Create Agreement - POST /agreement/create

Request body keys:

{
    "payerReference": "{{payer_reference}}",
    "callbackURL": "{{agreement_callback_url}}"
}

Response (raw bKash payload):

{
    "agreementID": "agreement_123",
    "bkashURL": "https://tokenized.sandbox.bka.sh/checkout/...",
    "...": "additional fields may be returned"
}

Execute Agreement - POST /agreement/execute

Request body keys:

{
    "agreementId": "{{agreement_id}}"
}

Response (raw bKash payload):

{
    "agreementID": "agreement_123",
    "...": "additional fields may be returned"
}

Query Agreement - POST /query/agreement

Request body keys:

{
    "agreementId": "{{agreement_id}}"
}

Response (raw bKash payload):

{
    "agreementID": "agreement_123",
    "...": "additional fields may be returned"
}

Cancel Agreement - POST /agreement/cancel

Request body keys:

{
    "agreementId": "{{agreement_id}}"
}

Response (raw bKash payload):

{
    "agreementID": "agreement_123",
    "...": "additional fields may be returned"
}

Transaction and Refund APIs

Search Transaction - POST /general/search-transaction

Request body keys:

{
    "trxId": "{{trx_id}}"
}

Response (raw bKash payload):

{
    "trxID": "trx_123",
    "...": "additional fields may be returned"
}

Refund Transaction - POST /refund/payment/transaction

Request body keys:

{
    "refundAmount": "{{refund_amount}}",
    "paymentId": "{{payment_id}}",
    "trxId": "{{trx_id}}",
    "sku": "{{sku}}",
    "reason": "{{reason}}"
}

Response (raw bKash payload):

{
    "paymentID": "payment_123",
    "trxID": "trx_123",
    "...": "additional fields may be returned"
}

Refund Status - POST /refund/payment/status

Request body keys:

{
    "paymentId": "{{payment_id}}",
    "trxId": "{{trx_id}}"
}

Response (raw bKash payload):

{
    "paymentID": "payment_123",
    "trxID": "trx_123",
    "...": "additional fields may be returned"
}

Webhook Events (SNS)

Enable the built-in route by setting BKASH_ENABLE_ROUTES=true.

Webhook endpoint:

POST /bkash/webhook

SubscriptionConfirmation Event

Headers:

  • Content-Type: application/json
  • x-amz-sns-message-type: SubscriptionConfirmation

Request body keys:

{
    "Type": "SubscriptionConfirmation",
    "MessageId": "11111111-2222-3333-4444-555555555555",
    "Token": "{{sns_token}}",
    "TopicArn": "{{sns_topic_arn}}",
    "Message": "You have chosen to subscribe to the topic.",
    "SubscribeURL": "{{sns_subscribe_url}}",
    "Timestamp": "2026-04-11T00:00:00.000Z",
    "SignatureVersion": "1",
    "Signature": "{{sns_signature}}",
    "SigningCertURL": "{{sns_signing_cert_url}}"
}

Response (from the package webhook service):

{
    "success": true,
    "type": "SubscriptionConfirmation",
    "data": {
        "subscriptionConfirmed": true,
        "subscribeURL": "https://sns.us-east-1.amazonaws.com/?Action=ConfirmSubscription"
    }
}

Notification Event

Headers:

  • Content-Type: application/json
  • x-amz-sns-message-type: Notification

Request body keys:

{
    "Type": "Notification",
    "MessageId": "aaaaaaaa-bbbb-cccc-dddd-eeeeeeeeeeee",
    "TopicArn": "{{sns_topic_arn}}",
    "Subject": "bKash Payment Notification",
    "Message": "{\"debitMSISDN\":\"{{debit_msisdn}}\",\"creditShortCode\":\"{{credit_shortcode}}\",\"amount\":\"{{amount}}\",\"trxID\":\"{{trx_id}}\",\"currency\":\"{{currency}}\",\"dateTime\":\"20260411093030\",\"transactionType\":\"{{transaction_type}}\",\"transactionStatus\":\"{{transaction_status}}\"}",
    "Timestamp": "2026-04-11T00:05:00.000Z",
    "SignatureVersion": "1",
    "Signature": "{{sns_signature}}",
    "SigningCertURL": "{{sns_signing_cert_url}}"
}

Response (from the package webhook service):

{
    "success": true,
    "type": "Notification",
    "data": {
        "trxID": "trx_123",
        "trxId": "trx_123",
        "amount": "100.00",
        "transactionStatus": "Completed"
    }
}

Checkout SDK

Checkout Script URL - GET

https://scripts.{{bkash_sdk_host}}.bka.sh/versions/{{bkash_sdk_version}}/checkout/bKash-checkout{{bkash_sdk_suffix}}.js

Response: JavaScript file (200/301/302/304/404).

Payout

Initiate Payout - POST /payout/initiate

Request body keys:

{
    "type": "B2C",
    "Rereference": "{{payer_reference}}"
}

Response (raw bKash payload):

{
    "paymentID": "payment_123",
    "...": "additional fields may be returned"
}

💳 Payment Flow

1. Create Payment

Bkash::payment()->createPayment([...]);

2. Handle Callback

Bkash::payment()->handleCallback(request()->all());

3. Query Payment

Bkash::payment()->queryPayment($paymentId);

4. Capture / Void

Bkash::payment()->capturePayment($paymentId);
Bkash::payment()->voidPayment($paymentId);

🔄 Agreement (Saved Wallet)

Bkash::agreement()->createAgreement([...]);
Bkash::agreement()->executeAgreement($agreementId);

💰 Refund API

Bkash::refund()->refundTransaction([
    'paymentId' => $paymentId,
    'trxId' => $trxId,
    'refundAmount' => '10',
    'reason' => 'Customer request',
]);

🔔 Webhook (Secure & Automatic)

Enable in config:

'enable_routes' => true,

Endpoint:

POST /bkash/webhook

Automatically handled:

  • SNS Subscription confirmation
  • Signature verification
  • Replay attack protection
  • Notification parsing

🔐 Why this package?

Most Laravel bKash packages:

  • ❌ No token management
  • ❌ No webhook security
  • ❌ Only basic API wrappers

This package provides:

  • ✅ Automatic token lifecycle (grant + refresh)
  • ✅ Secure SNS webhook verification
  • ✅ Replay attack protection
  • ✅ Retry-safe HTTP client
  • ✅ Full payment + agreement + refund APIs
  • ✅ Clean Laravel integration (Facade + DI)
  • ✅ Test coverage

🧪 Testing

composer test

📦 Requirements

  • PHP 8.1+
  • Laravel 10 / 11 / 12

📈 SEO Keywords

Laravel bKash payment gateway, bKash Laravel package, Bangladesh payment gateway Laravel, bKash Tokenized Checkout V2, Laravel payment integration bKash

🛠 Roadmap

  • Event system (PaymentSuccess, Failed)
  • Queue-based webhook handling
  • Multi-gateway support (bKash + Nagad + SSLCommerz)

🤝 Contributing

PRs are welcome. Please ensure tests pass.

📄 License

MIT License

⭐ Support

If this package helps you, please give it a star ⭐ It helps others discover the project.

☕ Support Development

If you find this package useful, you can support ongoing development:

👉 https://buymeacoffee.com/devrkb21

Your support helps maintain and improve this package ❤️ Buy Me A Coffee

devrkb21/bkash-pgw-laravel 适用场景与选型建议

devrkb21/bkash-pgw-laravel 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 4 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 04 月 19 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「laravel」 「webhook」 「bangladesh」 「payment-gateway」 「bkash」 「tokenized-checkout」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 devrkb21/bkash-pgw-laravel 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 devrkb21/bkash-pgw-laravel 我们能提供哪些服务?
定制开发 / 二次开发

基于 devrkb21/bkash-pgw-laravel 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 4
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 33
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-04-19