royryando/laravel-duitku
最新稳定版本:v1.0.6
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
统计信息
- 总下载量: 2.48k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2021-05-12