itsrafsanjani/laravel-bkash
Composer 安装命令:
composer require itsrafsanjani/laravel-bkash
包简介
Bkash Payment Gateway for Laravel
README 文档
README
Laravel Bkash is a Laravel package for Bkash Payment Gateway. It uses the Tokenized API of Bkash.
Installation
You can install the package via composer:
composer require itsrafsanjani/laravel-bkash
You can publish the config file with:
php artisan vendor:publish --tag="laravel-bkash-config"
This is the contents of the published config file:
return [ 'sandbox' => env('BKASH_SANDBOX', true), // true for testing, false for production 'app_key' => env('BKASH_APP_KEY', ''), 'app_secret' => env('BKASH_APP_SECRET', ''), 'username' => env('BKASH_USERNAME', ''), 'password' => env('BKASH_PASSWORD', ''), // bkash will send data to this url 'callbackURL' => env('BKASH_CALLBACK_URL', 'http://127.0.0.1:8000/bkash/callback'), 'timezone' => 'Asia/Dhaka', ];
Configuration
- Setup
.env
# true for testing, false for production BKASH_SANDBOX=true BKASH_APP_KEY= BKASH_APP_SECRET= BKASH_USERNAME= BKASH_PASSWORD= # bkash will send data to this url BKASH_CALLBACK_URL=http://127.0.0.1:8000/bkash/callback
- Create route for bkash in
routes/web.php
Route::get('/bkash/callback', [PaymentController::class, 'callback']);
- Add exception in
app\Http\Middleware\VerifyCsrfToken.php
protected $except = [ 'bkash/*', ];
Usage
Pay and Callback (Example Code for Controller)
use Illuminate\Http\Request; use ItsRafsanJani\Bkash\Data\CreatePaymentData; use ItsRafsanJani\Bkash\Facades\Bkash; class PaymentController extends Controller { public function pay() { // .. // save payment related data in your database or anything // .. $invoiceId = uniqid(); // could be any string $response = Bkash::createPayment( new CreatePaymentData( amount: 20.50, payerReference: $invoiceId, ) ); // dd($response); return redirect()->away($response->bkashURL); } public function callback(Request $request) { // first you need to execute $executeResponse = Bkash::executePayment($request->paymentID); // then query $queryResponse = Bkash::queryPayment($request->paymentID); // .. // update payment status // .. } }
Available Methods and Response
Create Payment
$invoiceId = uniqid(); // could be any string $response = Bkash::createPayment( new CreatePaymentData( amount: 20.50, payerReference: $invoiceId, ) ); return response()->json($response);
Example Response
{
"statusCode": "0000",
"statusMessage": "Successful",
"paymentID": "TR0011J9EMqSy16948652*****",
"bkashURL": "https://sandbox.payment.bkash.com/redirect/tokenized/?paymentID=TR0011J9EMqSy16948652*****&hash=4kRP(RZBQ8Xn15a_0x4gW79V0EUZoaJJJv!UJmd10(s1Cl3ciz8aolIOsQ!3vlOno*vkq3jO-76BCoN7f4c8Zfykw1vaPsarABG21694865217269&mode=0011&apiVersion=v1.2.0-beta",
"callbackURL": "http://localhost:8000/api/bkash-callback",
"successCallbackURL": "http://localhost:8000/api/bkash-callback?paymentID=TR0011J9EMqSy16948652*****&status=success",
"failureCallbackURL": "http://localhost:8000/api/bkash-callback?paymentID=TR0011J9EMqSy16948652*****&status=failure",
"cancelledCallbackURL": "http://localhost:8000/api/bkash-callback?paymentID=TR0011J9EMqSy16948652*****&status=cancel",
"amount": "10",
"intent": "sale",
"currency": "BDT",
"paymentCreateTime": "2023-09-16T17:53:37:268 GMT+0600",
"transactionStatus": "Initiated",
"merchantInvoiceNumber": "65059731*****"
}
Execute Payment
$response = Bkash::executePayment($request->paymentID); return response()->json($response);
Example Response
{
"statusCode": "0000",
"statusMessage": "Successful",
"paymentID": "TR0011f0CE1zl16944532*****",
"payerReference": "64ff4dd*****",
"customerMsisdn": "018777*****",
"trxID": "AIB10*****",
"amount": "10",
"transactionStatus": "Completed",
"paymentExecuteTime": "2023-09-11T23:31:24:581 GMT+0600",
"currency": "BDT",
"intent": "sale",
"merchantInvoiceNumber": "64ff4dd6*****"
}
Query Payment
$response = Bkash::queryPayment($request->paymentID); return response()->json($response);
Example Response
{
"paymentID": "TR0011f0CE1zl16944532*****",
"mode": "0011",
"paymentCreateTime": "2023-09-11T23:26:49:676 GMT+0600",
"paymentExecuteTime": "2023-09-11T23:31:24:581 GMT+0600",
"amount": "10",
"currency": "BDT",
"intent": "sale",
"merchantInvoice": "64ff4dd6*****",
"trxID": "AIB10DO2ON",
"transactionStatus": "Completed",
"verificationStatus": "Complete",
"statusCode": "0000",
"statusMessage": "Successful",
"payerReference": "64ff4dd*****"
}
Search Transaction
$searchTransactionResponse = Bkash::searchTransaction($response['trxID']); return response()->json($searchTransactionResponse);
Example Response
{
"trxID": "AIB10*****",
"initiationTime": "2023-09-11T23:31:22:000 GMT+0600",
"completedTime": "2023-09-11T23:31:22:000 GMT+0600",
"transactionType": "bKash Tokenized Checkout via API",
"customerMsisdn": "018777*****",
"transactionStatus": "Completed",
"amount": "10",
"currency": "BDT",
"organizationShortCode": "50***",
"statusCode": "0000",
"statusMessage": "Successful"
}
Testing
./vendor/bin/pest
Changelog
Please see CHANGELOG for more information on what has changed recently.
Contributing
Please see CONTRIBUTING for details.
Security Vulnerabilities
Please review our security policy on how to report security vulnerabilities.
Credits
License
The MIT License (MIT). Please see License File for more information.
itsrafsanjani/laravel-bkash 适用场景与选型建议
itsrafsanjani/laravel-bkash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 13 次下载、GitHub Stars 达 2, 最近一次更新时间为 2023 年 09 月 16 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「itsrafsanjani」 「laravel-bkash」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 itsrafsanjani/laravel-bkash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 itsrafsanjani/laravel-bkash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 itsrafsanjani/laravel-bkash 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
This is bKash tokenize payment gateway for laravel
This is my package laravel-bkash
This is bKash payment gateway for laravel
Bkash Payment Integration for Laravel.
bkash payment gateway for Laravel v.1
Alfabank REST API integration
统计信息
- 总下载量: 13
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 2
- 点击次数: 16
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2023-09-16