定制 arafatkn/laravel-bkash 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

arafatkn/laravel-bkash

Composer 安装命令:

composer require arafatkn/laravel-bkash

包简介

bKash Tokenized Payment Gateway Implementation for Laravel

README 文档

README

Laravel package for bKash Tokenized Payment Gateway integration.

Requirements

  • PHP ^8.0
  • Laravel ^8.0

Installation

composer require arafatkn/laravel-bkash

The service provider and facade are registered automatically via Laravel's package auto-discovery.

Configuration

Publish the config file:

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

Add the following variables to your .env file:

BKASH_SANDBOX=true
BKASH_APP_KEY=your_app_key
BKASH_APP_SECRET=your_app_secret
BKASH_USERNAME=your_username
BKASH_PASSWORD=your_password

Config Options

Key Default Description
sandbox true Use sandbox or live environment
debug APP_DEBUG Log all requests and responses
app_key '' bKash app key
app_secret '' bKash app secret
username '' bKash username
password '' bKash password
cache.refresh_token_lifetime 604800 Refresh token cache lifetime in seconds (7 days)
default_currency BDT Default payment currency
default_intent sale Default payment intent

Usage

Use the BkashTokenizedPayment facade or resolve Arafatkn\LaravelBkash\Tokenized\Payment from the container.

Create Payment

Initiates a tokenized payment and returns a bkashURL to redirect the customer to.

use BkashTokenizedPayment;

$response = BkashTokenizedPayment::createPayment([
    'amount'                => '100',
    'merchantInvoiceNumber' => 'INV-001',
    'callbackURL'           => route('bkash.callback'),
    'payerReference'        => 'user_123',   // optional
    'currency'              => 'BDT',         // optional, defaults to config
    'intent'                => 'sale',        // optional, defaults to config
]);

// Redirect customer to payment page
return redirect($response['bkashURL']);

Execute Payment

Called from your callback URL after the customer approves the payment.

$paymentID = $request->query('paymentID');

$response = BkashTokenizedPayment::executePayment($paymentID);

if ($response['statusCode'] === '0000') {
    // Payment successful
    $trxID = $response['trxID'];
}

Query Payment

Check the status of a payment by paymentID.

$response = BkashTokenizedPayment::queryPayment($paymentID);

Search Transaction

Look up a transaction by bKash transaction ID.

$response = BkashTokenizedPayment::searchTransaction($trxID);

Refund Transaction

Initiate a refund for a completed payment.

$response = BkashTokenizedPayment::refundPayment(
    'TR0011xxxxxxxxxxx',
    'ADxxxxxxxx',
    [
        'amount' => '100',                           // optional
        'reason' => 'Customer requested refund',     // optional
        'sku'    => 'product-sku',                   // optional, defaults to 'NA'
    ]
);

Token Management

Token management is handled automatically. The package:

  • Grants a new token on first use
  • Caches the id_token based on the API-reported expires_in (minus 10 seconds as a safety buffer)
  • Caches the refresh_token for 7 days
  • Automatically uses the cached refresh_token to obtain a new id_token when it expires, avoiding a full re-authentication

Debugging

To log all bKash API requests and responses, set in your .env:

BKASH_DEBUG=true

Or it will follow APP_DEBUG by default. Logs are written at the debug level via Laravel's Log facade.

Typical Payment Flow

1. createPayment()  → redirect customer to bkashURL
2. Customer approves on bKash
3. bKash redirects to your callbackURL with paymentID
4. executePayment() → confirm the payment
5. searchTransaction() or queryPayment() → verify if needed

License

MIT

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

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

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