susutawar/laravel-duitku is a Laravel package for duitku api implementation for laravel.
It currently has 1 GitHub stars and 20 downloads on Packagist (latest version 0.0.1).
Install it with composer require susutawar/laravel-duitku.
Discover more Laravel packages by susutawar
or browse all Laravel packages to compare alternatives.
Last updated
DuitKu API implementation in laravel. Initially made for personal use, so it’s a bit biased.
composer install susutawar/duitku-laravel
php artisan vendor:publish --tag="duitku"
add the following to your .env file.
DUITKU_MERCHANT_ID=
DUITKU_API_KEY=
DUITKU_SANDBOX_MODE=
DUITKU_RETURN_URL=
DUITKU_MERCHANT_ID, DUITKU_API_KEY with credentials you obtain from duitku.DUITKU_SANDBOX_MODE to 1 to use DuitKu in sandbox mode, or 0 to use it in production mode.DUITKU_RETURN_URL to any route you have configured. this will be used by DuitKu (see documentation). The value can be a route name or a URL.You can check config/duitku.php for more setting/information.
Get available payment methods from DuitKu. see documentation
use SusuTawar\Facade\Duitku;
// ...
// the result is a Laravel Collection
$paymentMethods = Duitku::getPayments($paymentAmount);
Start a transaction using DuitKu. see documentation
use SusuTawar\Facade\Duitku;
// ...
$paymentMethods = Duitku::makeTransaction(/* params */);
The resulting object contains trx, url, qr, and va:
trx: The transaction number generated by DuitKu. Save this to your system.url: A link to the transaction page on DuitKu.qr: A string representing QRIS. You must generate QR images from this string yourself.va: The virtual account number for payment methods that support it.Check the status of a transaction using your transaction ID. see documentation
use SusuTawar\Facade\Duitku;
// ...
$checkResult = Duitku::check($yourTransactionId);
Instead of returning false or null, when something unexpected occurred we will throw an Exception instead.
You can catch the exception by its specific type or catch all exceptions with Exception, then use the provided message.
DuitKuAuthException: Occurs when the provided authentication credentials cannot be authenticated by DuitKu.DuitKuBadRequestException: Occurs when the provided parameters are not valid according to DuitKu.DuitKuNotFoundException: Occurs when the specified resource is not available in DuitKu.DuitKuPaymentException: Occurs when something goes wrong with the payment.We automatically register the callback route.
To handle the incoming callback, create a class implementing SusuTawar\Interfaces\DuitKuCallbackInterface,
and register it in config/duitku.php under routing.callback_handler
"routing" => [
// ...
"callback_handler" => MyCallbackHandler::class,
]
If you prefer to manually set up the callback, disable this feature by updating the configuration:
"routing" => [
"enabled" => false,
// ...
]
When this feature is disabled, you need to set the callback_url or add DUITKU_CALLBACK_URL
to your .env file. Otherwise, the callback_url will default to home or /.