A simple Duitku payment gateway library for Laravel.
royryando/laravel-duitku is a Laravel package for a simple duitku payment gateway library for laravel..
It currently has 7 GitHub stars and 3.154 downloads on Packagist (latest version v1.0.6).
Install it with composer require royryando/laravel-duitku.
Discover more Laravel packages by royryando
or browse all Laravel packages to compare alternatives.
Last updated
A simple Duitku payment gateway library for Laravel.
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
];
.env
DUITKU_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
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
],
...
]
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', '[email protected]', 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
]
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
]
Ref: https://docs.duitku.com/api/id/#callback
Create a new controller and extend Royryando\Duitku\Http\Controllers\DuitkuBaseController
use 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 onPaymentSuccess function. 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 onPaymentFailed function. 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.php
protected $except = [
'callback/payment',
];