sayyidzaizii / payment-gateway
Local payment gateway library 🇮🇩 for Laravel.
v1.0.2
2025-05-13 08:17 UTC
Requires
- php: >=5.5
- ext-json: *
- guzzlehttp/guzzle: ^6.3 || ^7.0
Requires (Dev)
- orchestra/testbench: ^3.1.0
README
Integrasi gateway pembayaran Duitku untuk Laravel menggunakan package sayyidazizii/payment-gateway
.
Payment Gateway List
Duitku : ✅ Midtrans : soon
🔧 Instalasi
- 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=dev
🚀 Contoh Penggunaan
1. Mendapatkan Metode Pembayaran
use Sayyidzaizii\Duitku\Facades\Duitku; $data = Duitku::paymentMethods(10000); // jumlah dalam rupiah
2. Membuat Invoice Pembayaran
$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" }
3. Cek Status Pembayaran
$data = Duitku::checkInvoiceStatus('ORDER_ID1');
Contoh respons:
{ "reference": "D7999PJ38HNY7TSKHSGX", "amount": 100000, "message": "SUCCESS", "code": "00" // 00 => Success, 01 => Pending, 02 => Failed/Expired }
📡 Callback / Webhook Handling
1. Buat Controller
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 } }
2. Tambahkan Route Callback
Route::post('callback/payment', [\App\Http\Controllers\DuitkuController::class, 'paymentCallback']);
3. Kecualikan Route dari CSRF
Tambahkan pada file App\Http\Middleware\VerifyCsrfToken.php
:
protected $except = [ 'callback/payment', ];
📂 Contoh Lengkap Controller
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 } }
🛣️ Contoh Route
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']);
📚 Dokumentasi Resmi
Lihat dokumentasi resmi Duitku untuk referensi API dan parameter:
🔗 https://docs.duitku.com/api/id/