承接 mainul12501/bkash-payment-b2c 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

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

mainul12501/bkash-payment-b2c

Composer 安装命令:

composer require mainul12501/bkash-payment-b2c

包简介

Laravel 11+ package for BKash checkout, tokenized checkout, B2C, B2B payout, refund, search, and wallet operations.

README 文档

README

Laravel 11, 12, and 13 package for bKash payment gateway integrations, covering the public flows exposed in bKash's current developer docs and guides.

Features

  • Checkout (URL based) Regular sale payment Auth and capture Void Query payment Search transaction Refund
  • Tokenized checkout Grant token Refresh token Create agreement Execute agreement Query agreement Cancel agreement Create payment Execute payment Confirm payment Query payment Search transaction Refund Refund status helper
  • Disbursement and wallet operations B2C payout to customer Organization balance query Intra-account transfer B2B merchant payout B2B payout initiation
  • Integration helpers Automatic token caching and refresh retry Raw request escape hatch for undocumented or newly-added endpoints Webhook payload parsing and optional shared-secret check

Requirements

  • PHP 8.2+
  • Laravel 11, 12, or 13

Installation

composer require mainul12501/bkash-payment-b2c
php artisan vendor:publish --tag=bkash-config

Configuration

Default config file: config/bkash.php

Minimal .env example:

BKASH_ENV=sandbox
BKASH_TIMEOUT=30
BKASH_CONNECT_TIMEOUT=10
BKASH_VERIFY_TLS=true
BKASH_CACHE_STORE=

BKASH_USERNAME=
BKASH_PASSWORD=
BKASH_APP_KEY=
BKASH_APP_SECRET=

BKASH_WEBHOOK_SECRET=
BKASH_WEBHOOK_SECRET_HEADER=X-BKASH-WEBHOOK-SECRET

The sandbox and production URLs have sensible defaults in the config file. Override them only if bKash changes the endpoints:

BKASH_CHECKOUT_SANDBOX_URL=https://checkout.sandbox.bka.sh/v1.2.0-beta
BKASH_CHECKOUT_PRODUCTION_URL=https://checkout.pay.bka.sh/v1.2.0-beta

BKASH_TOKENIZED_SANDBOX_URL=https://tokenized.sandbox.bka.sh/v1.2.0-beta
BKASH_TOKENIZED_PRODUCTION_URL=https://tokenized.pay.bka.sh/v1.2.0-beta

BKASH_PAYOUTS_SANDBOX_URL=https://tokenized.sandbox.bka.sh
BKASH_PAYOUTS_PRODUCTION_URL=https://tokenized.pay.bka.sh

If bKash gives you different credentials per service, set the service-specific keys:

BKASH_CHECKOUT_USERNAME=
BKASH_CHECKOUT_PASSWORD=
BKASH_CHECKOUT_APP_KEY=
BKASH_CHECKOUT_APP_SECRET=

BKASH_TOKENIZED_USERNAME=
BKASH_TOKENIZED_PASSWORD=
BKASH_TOKENIZED_APP_KEY=
BKASH_TOKENIZED_APP_SECRET=

BKASH_PAYOUTS_USERNAME=
BKASH_PAYOUTS_PASSWORD=
BKASH_PAYOUTS_APP_KEY=
BKASH_PAYOUTS_APP_SECRET=

Usage

Facade entry point

use Mainul12501\Bkash\Facades\Bkash;

$checkout = Bkash::checkout();
$tokenized = Bkash::tokenized();
$payouts = Bkash::payouts();

Checkout payment

The public checkout create-payment reference shows these required body fields:

  • amount
  • currency
  • intent
  • merchantInvoiceNumber

Example:

$response = Bkash::checkout()->createPayment([
    'amount' => '150.00',
    'currency' => 'BDT',
    'intent' => 'sale',
    'merchantInvoiceNumber' => 'INV-1001',
    'merchantAssociationInfo' => 'order:1001',
]);

$payment = $response->toArray();

Execute, capture, query, void

Bkash::checkout()->executePayment($paymentId);
Bkash::checkout()->capturePayment($paymentId);
Bkash::checkout()->queryPayment($paymentId);
Bkash::checkout()->voidPayment($paymentId);

Search transaction

$response = Bkash::checkout()->searchTransaction($trxId);

Refund

$response = Bkash::checkout()->refund([
    'paymentID' => $paymentId,
    'amount' => '150.00',
    'trxID' => $trxId,
    'sku' => 'SKU-1001',
    'reason' => 'Customer requested cancellation',
]);

Tokenized checkout

The tokenized reference is structured differently from checkout. The package exposes both generic and convenience methods so you can mirror the exact request body from your bKash onboarding docs.

$agreement = Bkash::tokenized()->createAgreement([
    'mode' => '0000',
    'callbackURL' => route('bkash.callback'),
    'payerReference' => 'customer-1001',
]);

$executedAgreement = Bkash::tokenized()->executeAgreement([
    'paymentID' => $agreement->json('paymentID'),
]);

$payment = Bkash::tokenized()->createPayment([
    'mode' => '0011',
    'callbackURL' => route('bkash.callback'),
    'agreementID' => 'AGREEMENT_ID',
    'payerReference' => 'customer-1001',
    'amount' => '100.00',
    'currency' => 'BDT',
    'intent' => 'sale',
    'merchantInvoiceNumber' => 'INV-2001',
]);

$executedPayment = Bkash::tokenized()->executePayment([
    'paymentID' => $payment->json('paymentID'),
]);

Tokenized agreement and payment queries

Bkash::tokenized()->queryAgreement('AGREEMENT_ID');

Bkash::tokenized()->cancelAgreement('AGREEMENT_ID');

Bkash::tokenized()->confirmPayment('capture', [
    'paymentID' => $paymentId,
]);

Bkash::tokenized()->queryPayment([
    'paymentID' => $paymentId,
]);

Bkash::tokenized()->searchTransaction($trxId);

Tokenized refund and refund status

Bkash::tokenized()->refund([
    'paymentID' => $paymentId,
    'amount' => '10.00',
    'trxID' => $trxId,
    'sku' => 'SKU-2001',
    'reason' => 'Partial refund',
]);

Bkash::tokenized()->refundStatus([
    'paymentId' => $paymentId,
    'trxId' => $trxId,
]);

Note:

  • The current bKash public guide for refund status is not modeled in the same embedded OpenAPI schema as the main reference pages.
  • The guide currently shows {{tokenized_url}}/v2/tokenized-checkout/refund/payment/status.
  • If your merchant onboarding doc uses a different refund-status path, override it per call:
Bkash::tokenized()->refundStatus($payload, '/v2/tokenized-checkout/refund/payment/transaction');

B2C payout

The B2C payout guide documents these required fields:

  • amount
  • currency
  • merchantInvoiceNumber
  • receiverMSISDN
$response = Bkash::checkout()->b2cPayment([
    'amount' => '500.00',
    'currency' => 'BDT',
    'merchantInvoiceNumber' => 'B2C-1001',
    'receiverMSISDN' => '017XXXXXXXX',
]);

Organization balance

$response = Bkash::checkout()->organizationBalance();

Intra-account transfer

The public guide documents transferType as one of:

  • Collection2Disbursement
  • Disbursement2Collection
$response = Bkash::checkout()->intraAccountTransfer([
    'amount' => '1000.00',
    'currency' => 'BDT',
    'transferType' => 'Collection2Disbursement',
]);

B2B payout

The public B2B payout guide is a two-step flow.

Step 1: initiate

$initiate = Bkash::payouts()->initiate([
    'type' => 'B2B',
    'reference' => 'REF-1001',
]);

$payoutId = $initiate->json('payoutID');

Step 2: B2B payout

$transfer = Bkash::payouts()->b2b([
    'payoutID' => $payoutId,
    'amount' => '100.00',
    'currency' => 'BDT',
    'merchantInvoiceNumber' => 'B2B-1001',
    'receiverMSISDN' => '01XXXXXXXXX',
]);

Raw request escape hatch

This package intentionally includes a low-level method because bKash sometimes documents flows in guide pages before the embedded API reference catches up.

$response = Bkash::raw(
    service: 'tokenized',
    method: 'POST',
    path: '/tokenized/checkout/payment/status',
    payload: ['paymentID' => $paymentId]
);

For absolute paths outside the service base version:

$response = Bkash::raw(
    service: 'tokenized',
    method: 'POST',
    path: '/v2/tokenized-checkout/refund/payment/status',
    payload: ['paymentId' => $paymentId, 'trxId' => $trxId],
    absolutePath: true
);

Webhooks

The package provides a simple parser and optional shared-secret header check.

use Illuminate\Http\Request;
use Mainul12501\Bkash\Facades\Bkash;

Route::post('/bkash/webhook', function (Request $request) {
    Bkash::webhooks()->assertMatchingSecret($request);

    $payload = Bkash::webhooks()->fromRequest($request);

    // Process webhook payload here.

    return response()->json(['received' => true]);
});

Response handling

All gateway methods return Mainul12501\Bkash\Support\BkashResponse.

$response->status();
$response->successful();
$response->json();
$response->json('paymentID');
$response->toArray();
$response->headers();
$response->body();
$response->collect();
$response->collect('items');
$response->raw();            // underlying Illuminate HTTP response

Error handling

Failed HTTP responses throw Mainul12501\Bkash\Exceptions\BkashRequestException.

use Mainul12501\Bkash\Exceptions\BkashRequestException;

try {
    $response = Bkash::checkout()->createPayment($payload);
} catch (BkashRequestException $exception) {
    $status = $exception->status();
    $response = $exception->response();
}

Notes

  • bKash's product overview currently states TLS 1.2+ only.
  • Sandbox and production use different hostnames.
  • Checkout and tokenized references expose different schemas and path styles.
  • B2B payout is documented in guide pages instead of the same embedded OpenAPI model used by checkout and tokenized reference pages.
  • Subscriptions and add-wallet are mentioned in product overview, but their public API details were not exposed in the fetched docs set above. Use Bkash::raw() when bKash provides merchant-specific endpoint details.

Package API Summary

Bkash::checkout()

  • grantToken(): array
  • refreshToken(): array
  • createPayment(array $payload): BkashResponse
  • executePayment(string $paymentID): BkashResponse
  • capturePayment(string $paymentID): BkashResponse
  • queryPayment(string $paymentID): BkashResponse
  • voidPayment(string $paymentID): BkashResponse
  • searchTransaction(string $trxID): BkashResponse
  • refund(array $payload): BkashResponse
  • b2cPayment(array $payload): BkashResponse
  • organizationBalance(): BkashResponse
  • intraAccountTransfer(array $payload): BkashResponse

Bkash::tokenized()

  • grantToken(): array
  • refreshToken(): array
  • create(array $payload): BkashResponse
  • createAgreement(array $payload): BkashResponse
  • createPayment(array $payload): BkashResponse
  • execute(array $payload): BkashResponse
  • executeAgreement(array $payload): BkashResponse
  • executePayment(array $payload): BkashResponse
  • queryAgreement(array|string $agreement): BkashResponse
  • cancelAgreement(array|string $agreement): BkashResponse
  • confirmPayment(string $confirmationType, array $payload): BkashResponse
  • queryPayment(array $payload): BkashResponse
  • searchTransaction(array|string $trx): BkashResponse
  • refund(array $payload): BkashResponse
  • refundStatus(array $payload, ?string $path = null): BkashResponse

Bkash::payouts()

  • grantToken(): array
  • refreshToken(): array
  • initiate(array $payload): BkashResponse
  • b2b(array $payload): BkashResponse

Bkash::webhooks()

  • parse(string $payload): array
  • fromRequest(Request $request): array
  • hasMatchingSecret(Request $request, ?string $expected = null, ?string $header = null): bool
  • assertMatchingSecret(Request $request, ?string $expected = null, ?string $header = null): void

mainul12501/bkash-payment-b2c 适用场景与选型建议

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

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

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

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

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

BUG 修复 & 性能优化

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

项目外包 & 长期维护

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

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

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-05-01