royryando/laravel-duitku
Composer 安装命令:
composer require royryando/laravel-duitku
包简介
A simple Duitku payment gateway library for Laravel.
README 文档
README
A simple Duitku payment gateway library for Laravel.
Requirments
- PHP ≥ 5.5
- Laravel ≥ 5.1
Installation
-
Install through composer
composer require royryando/laravel-duitku -
Add the duitku service provider in config/app.php: (Laravel 5.5+ uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider.)
'providers' => [ Royryando\Duitku\DuitkuServiceProvider::class ];
Configure
- Add required variable to
.envDUITKU_MERCHANT_CODE= DUITKU_API_KEY= DUITKU_CALLBACL_URL=https://example.com/callback/payment DUITKU_RETURN_URL=https://example.com/callback/return DUITKU_ENV=dev/production
Usage
Get All Available Payment Method
Ref: https://docs.duitku.com/api/id/#payment-method
Call paymentMethods function from Duitku facade with the integer parameter is amount
Duitku::paymentMethods(100000)
The return is an array of array, example:
[
...
[
'code' => 'M1',
'name' => 'Bank Mandiri',
'image' => 'https://example.com/image.jpg',
'fee' => 0
],
...
]
Create Invoice
Ref: https://docs.duitku.com/api/id/#request-transaction
Create invoice or inquiry by calling createInvoice from Duitku facade with these parameter:
Order Id, amount, payment method, product name, customer name, cutomer email, expiry in minute
Duitku::createInvoice('ORDER_ID', 100000, 'M1', 'Product Name', 'John Doe', 'john@example.com', 120);
The return if success:
[ 'success' => true, 'reference' => 'D7999PJ38HNY7TSKHSGX', 'payment_url' => 'https://url.to.payment.example.com/', 'va_number' => '0000123123123', 'amount' => 100000, 'message' => 'SUCCESS' // message from Duitku ]
The return if not success:
[ 'success' => false, 'message' => 'The selected payment channel not available' // message from Duitku ]
Check Invoice Status
Ref: https://docs.duitku.com/api/id/#check-transaction
Check invoice or inquiry status by calling
Duitku::checkInvoiceStatus('order ID')
The return is an array, example:
[ 'reference' => 'D7999PJ38HNY7TSKHSGX', // reference code from Duitku 'amount' => 100000, 'message' => 'SUCCESS', 'code' => '00', // 00=>Success, 01=>Pending, 02=>Failed/Expired ]
Handle Callback
Ref: https://docs.duitku.com/api/id/#callback
-
Create a new controller and extend
Royryando\Duitku\Http\Controllers\DuitkuBaseControlleruse Royryando\Duitku\Http\Controllers\DuitkuBaseController; class DuitkuController extends DuitkuBaseController { // }
This controller will handle all callback requests from Duitku and store the success/failed payment function
-
Inside the controller, override
onPaymentSuccessfunction. This function will triggered if receiving a successful transaction callback... protected function onPaymentSuccess( string $orderId, string $productDetail, int $amount, string $paymentCode, string $shopeeUserHash, string $reference, string $additionalParam ): void { // Your code here } ...
-
Inside the controller, override
onPaymentFailedfunction. This function will triggered if receiving a failed status from callback... protected function onPaymentFailed( string $orderId, string $productDetail, int $amount, string $paymentCode, string $shopeeUserHash, string $reference, string $additionalParam ): void { // Your code here } ...
-
Add route in your application route web.php with the function of paymentCallback
Route::post('callback/payment', [\App\Http\Controllers\DuitkuController::class, 'paymentCallback']);
-
Exclude the callback route from CSRF verification
Edit
App\Http\Middleware\VerifyCsrfToken.phpprotected $except = [ 'callback/payment', ];
TODO
- Add tests
- Add support for Return Callback
- Add support for Disbursement API
royryando/laravel-duitku 适用场景与选型建议
royryando/laravel-duitku 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2.88k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2021 年 05 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「laravel」 「duitku」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 royryando/laravel-duitku 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 royryando/laravel-duitku 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 royryando/laravel-duitku 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
Alfabank REST API integration
Magento 2 payment module for Duitku Bank Neo Commerce
Magento 2.4 payment module for Duitku BRIVA
Magento 2 payment module for Duitku VA bca
Magento 2 payment module for Duitku VA mandiri Host to Host
Magento 2 payment module for Duitku VA permata
统计信息
- 总下载量: 2.88k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 11
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-12