abdursoft/laravel-bkash
Composer 安装命令:
composer require abdursoft/laravel-bkash
包简介
This package or Library for Bkash, developed by abdursoft. This library come with MIT license, so you can easily change anything what ever your needs.This package will work for bkash tokenized payment system. If they are updated their version and the library couldn't work properly, please contact wi
README 文档
README
Now you can easily integrate bkash tokenized payment gateway into your PHP and laravel application. Just follow up the below process. Hope you will integrate the Bkash payment gateway successfully in your PHP or Laravel application
Now let's start with abdursoft/laravel-bkash. Run the below command to install the package.
composer require abdursoft/laravel-bkash
After installing the package you have to update .env file from your root folder with the below code.
BKASH_USERNAME=017xxxxxxx BKASH_PASSWORD=D7xxxxxxxx BKASH_APP_KEY=APKxxxxxxxx BKASH_APP_SECRET=APSxxxxxxx
[Note] Remember you have to update these variable with your credentials.
If the package/library successfully installed on your project then make a controller in your laravel project.
php artisan make:controller BkashController
If your controller has been successfully created, open with your text editor and replace all code with below code.
namespace App\Http\Controllers;
use Abdursoft\LaravelBkash\Bkash;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Session;
use Illuminate\Support\Facades\Validator;
class BkashController extends Controller
{
protected $bkash;
public function __construct()
{
$this->bkash = new Bkash(env('BKASH_USERNAME'),env('BKASH_PASSWORD'),env('BKASH_APP_KEY'),env('BKASH_APP_SECRET'),'sandbox',"http://127.0.0.1:8000/bkash/callback"); //use sandbox for sandbox testing and production for production service
}
/**
* Create payment
*/
public function createPayment(Request $request){
$validator = Validator::make($request->all(),[
'amount' => 'required',
'reference' => 'required',
]);
if($validator->fails()){
return response()->json($validator->errors());
}
$payment = $this->bkash->paymentCreate($request->reference,$request->amount,uniqid());
return redirect()->away($payment['bkashURL']);
}
/**
* Refund payment
*/
public function refundPayment(Request $request){
$refund = $this->bkash->refund($request->id,$request->txn,$request->amount,$request->sku,$request->reason);
if($refund['statusCode'] === '0000'){
return redirect('/')->with('success',"Refund process has been completed");
}else{
return redirect('/')->with('error',"Refund process has been faild");
}
}
/**
* Bkash callback
*/
public function callbackResponse(Request $request){
if($request->query('status') == 'success'){
$execute = $this->bkash->paymentExecute($request->query('paymentID'));
Session::put(['paymentExecution' => $execute]);
if($execute['statusCode'] == '0000'){
return redirect('/')->with('success','Payment has been completed');
}elseif($execute['statusCode'] == '2062'){
return redirect('/')->with('success','Payment has already been compeled');
}
}elseif($request->query('status') == 'cancel'){
return redirect('/')->with('error','Payment has been canceled');
}elseif($request->query('status') == 'failure'){
return redirect('/')->with('error','Payment has been faild');
}else{
return redirect('/')->with('error','Payment couldn\'t completed');
}
}
}
At this stage you have to initalize the payment routes for baksh gateway. You can put the below routes or You can create your owns.
Route::prefix('bkash')->group(function(){
Route::post('payment', [BkashController::class, 'createPayment']);
Route::post('refund', [BkashController::class, 'refundPayment']);
Route::get('cancel', [BkashController::class, 'callbackResponse']);
Route::get('callback', [BkashController::class, 'callbackResponse']);
});
Don't forget to add use App\Http\Controllers\BkashController; in your route page.
To create a payment, you have to pass some data such as amount reference merchant_invoice_number callback_url.
``amount`` for the payable amount.
``reference`` for the payment reference.
``merchant_invoice_number`` for futrue tracking the payment and remember it shuold be unique.
``callback_url`` bkash will redirect the user after payment processcing and you have to execute payment with this route's response.
To create a refund, you have to pass some data such as transactionID paymentID amount reason sku
``transactionID`` use from a completed transaction.
``paymentID`` use the paymentID from above transaction.
``amount`` use a valid amount for refund and make sure the amount not bigger than above transaction.
``reason`` for refund the transaction.
``sku`` for the transaction processing.
abdursoft/laravel-bkash 适用场景与选型建议
abdursoft/laravel-bkash 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 22 次下载、GitHub Stars 达 0, 最近一次更新时间为 2024 年 11 月 14 日, 在 PHP 生态内属于活跃度较高的组件。
我们在过去多个企业项目中使用过 abdursoft/laravel-bkash 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 abdursoft/laravel-bkash 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
统计信息
- 总下载量: 22
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 24
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2024-11-14