Integrasi gateway pembayaran Duitku untuk Laravel menggunakan package sayyidazizii/payment-gateway.
Payment Gateway List
Duitku : โ
Midtrans : soon
- Install package via Composer:
composer require sayyidazizii/payment-gateway- Publish konfigurasi (opsional):
php artisan vendor:publish --provider="Sayyidzaizii\Duitku\DuitkuServiceProvider"- Set credential di
.env:
DUITKU_MERCHANT_CODE=your_merchant_code
DUITKU_API_KEY=your_api_key
DUITKU_CALLBACK_URL=http://localhost:8000/api/duitku/callback
DUITKU_RETURN_URL=http://localhost:8000/return
DUITKU_ENV=devuse Sayyidzaizii\Duitku\Facades\Duitku;
$data = Duitku::paymentMethods(10000); // jumlah dalam rupiah$data = Duitku::createInvoice(
'ORDER_ID1', // order ID
100000, // jumlah
'M2', // metode pembayaran
'Product Name', // nama produk
'John Doe', // nama customer
'john@example.com', // email customer
120 // waktu kadaluarsa (menit)
);Contoh respons sukses:
{
"success": true,
"reference": "D7999PJ38HNY7TSKHSGX",
"payment_url": "https://url.to.payment.example.com/",
"va_number": "0000123123123",
"amount": 100000,
"message": "SUCCESS"
}Contoh respons gagal:
{
"success": false,
"message": "The selected payment channel not available"
}$data = Duitku::checkInvoiceStatus('ORDER_ID1');Contoh respons:
{
"reference": "D7999PJ38HNY7TSKHSGX",
"amount": 100000,
"message": "SUCCESS",
"code": "00" // 00 => Success, 01 => Pending, 02 => Failed/Expired
}use Sayyidzaizii\Duitku\Http\Controllers\DuitkuBaseController;
class DuitkuController extends DuitkuBaseController
{
protected function onPaymentSuccess(
string $orderId, string $productDetail, int $amount, string $paymentCode,
string $shopeeUserHash, string $reference, string $additionalParam
): void {
// Simpan data pembayaran sukses ke database
}
protected function onPaymentFailed(
string $orderId, string $productDetail, int $amount, string $paymentCode,
string $shopeeUserHash, string $reference, string $additionalParam
): void {
// Simpan data pembayaran gagal ke database
}
}Route::post('callback/payment', [\App\Http\Controllers\DuitkuController::class, 'paymentCallback']);Tambahkan pada file App\Http\Middleware\VerifyCsrfToken.php:
protected $except = [
'callback/payment',
];namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Sayyidzaizii\Duitku\Facades\Duitku;
use Sayyidzaizii\Duitku\Http\Controllers\DuitkuBaseController;
class DuitkuController extends DuitkuBaseController
{
public function paymentMethods(Request $request)
{
$data = Duitku::paymentMethods(10000);
return response()->json($data);
}
public function createPayment(Request $request)
{
$data = Duitku::createInvoice(
'ORDER_ID1', 100000, 'M2', 'Product Name', 'John Doe', 'john@example.com', 120
);
return response()->json($data);
}
protected function onPaymentSuccess(
string $orderId, string $productDetail, int $amount, string $paymentCode,
string $shopeeUserHash, string $reference, string $additionalParam
): void {
// Proses jika pembayaran berhasil
}
protected function onPaymentFailed(
string $orderId, string $productDetail, int $amount, string $paymentCode,
string $shopeeUserHash, string $reference, string $additionalParam
): void {
// Proses jika pembayaran gagal
}
}use App\Http\Controllers\DuitkuController;
Route::get('/duitku/payment-methods', [DuitkuController::class, 'paymentMethods']);
Route::post('/duitku/create-payment', [DuitkuController::class, 'createPayment']);
Route::post('/callback/payment', [DuitkuController::class, 'paymentCallback']);Lihat dokumentasi resmi Duitku untuk referensi API dan parameter:
๐ https://docs.duitku.com/api/id/