gonon/laravel-digiflazz
Composer 安装命令:
composer require gonon/laravel-digiflazz
包简介
Laravel integration for the Gonon Digiflazz SDK
README 文档
README
An elegant, idiomatic Laravel integration for the official Gonon Digiflazz PHP SDK.
Requirements
- PHP 8.2+
- Laravel 11+
- gonon/digiflazz ^1.0
Installation
composer require gonon/laravel-digiflazz
Configuration
Publish the configuration file to your application:
php artisan vendor:publish --tag="digiflazz-config"
or
php artisan vendor:publish --provider="Gonon\Digiflazz\Laravel\DigiflazzServiceProvider"
This will create a config/digiflazz.php file in your application where you can customize the default settings.
Next, set up your .env with the credentials from your Digiflazz Dashboard:
DIGIFLAZZ_USERNAME=your_username DIGIFLAZZ_API_KEY=your_api_key DIGIFLAZZ_PRODUCTION=false # Set to true for production
Usage (Facade)
The package provides an expressive Digiflazz facade that hooks directly into the underlying SDK. It handles all authentication and configuration seamlessly.
First, ensure you import the facade and necessary DTOs at the top of your classes:
use Gonon\Digiflazz\Laravel\Facades\Digiflazz;
1. Balance & Deposit
Check your account balance and request deposit instructions.
use Gonon\Digiflazz\DTO\Requests\DepositRequest; // Check Balance $balance = Digiflazz::balance()->check(); echo "Your balance is: " . $balance->deposit; // Request a Deposit Ticket $request = new DepositRequest( amount: 1000000, bank: 'BCA', ownerName: 'John Doe' ); $deposit = Digiflazz::balance()->deposit($request); echo "Transfer exactly {$deposit->amount} to {$deposit->bank} ({$deposit->accountNo})";
2. Products (Price List)
Fetch products, categories, or brands for Prepaid and Postpaid.
// Fetch all prepaid products $prepaidProducts = Digiflazz::products()->getPrepaid(); foreach ($prepaidProducts as $product) { echo $product->productName . ' - Rp ' . $product->price . "\n"; } // Fetch all postpaid products $postpaidProducts = Digiflazz::products()->getPostpaid(); // Fetch available categories $prepaidCategories = Digiflazz::products()->getPrepaidCategories(); // Fetch available brands under a specific category $prepaidBrands = Digiflazz::products()->getPrepaidBrands(category: 'Pulsa');
3. Prepaid Transactions (Topup)
Topup prepaid products (e.g., Pulsa, Data, Token PLN).
use Gonon\Digiflazz\DTO\Requests\PrepaidTopupRequest; use Gonon\Digiflazz\DTO\Requests\TransactionStatusRequest; // Create Topup $topupRequest = new PrepaidTopupRequest( buyerSkuCode: 'xld10', customerNo: '087800001233', refId: 'INV-12345' ); $transaction = Digiflazz::prepaid()->topup($topupRequest); echo $transaction->status; // 'Pending' or 'Sukses' // Check Topup Status $statusRequest = new TransactionStatusRequest( buyerSkuCode: 'xld10', customerNo: '087800001233', refId: 'INV-12345' ); $status = Digiflazz::prepaid()->status($statusRequest);
4. Postpaid Transactions (PPOB)
Postpaid transactions require two steps: Inquiry and Payment.
use Gonon\Digiflazz\DTO\Requests\PostpaidInquiryRequest; use Gonon\Digiflazz\DTO\Requests\PostpaidPaymentRequest; use Gonon\Digiflazz\DTO\Requests\TransactionStatusRequest; // Step 1: Inquiry (Check the bill) $inquiryRequest = new PostpaidInquiryRequest( buyerSkuCode: 'pln', customerNo: '530000000003', refId: 'INV-POST-123' ); $inquiry = Digiflazz::postpaid()->inquiry($inquiryRequest); echo "Your bill is: " . $inquiry->sellingPrice; // Step 2: Pay (Using the tr_id from Inquiry) $payRequest = new PostpaidPaymentRequest( trId: $inquiry->trId ); $payment = Digiflazz::postpaid()->pay($payRequest); echo $payment->status; // 'Sukses' // Check Postpaid Status $statusRequest = new TransactionStatusRequest( buyerSkuCode: 'pln', customerNo: '530000000003', refId: 'INV-POST-123' ); $status = Digiflazz::postpaid()->status($statusRequest);
5. Webhooks
Digiflazz sends callbacks for transaction updates. The SDK securely parses and verifies the payload signature automatically.
Note: Make sure your DIGIFLAZZ_WEBHOOK_SECRET is set in your .env.
use Illuminate\Http\Request; use Gonon\Digiflazz\Exceptions\WebhookException; use Gonon\Digiflazz\Laravel\Facades\Digiflazz; public function handleWebhook(Request $request) { $rawBody = $request->getContent(); $signature = $request->header('X-Hub-Signature') ?? ''; try { $webhookData = Digiflazz::webhook()->process($rawBody, $signature); if ($webhookData->status === 'Sukses') { // Update order status in your database } return response()->json(['success' => true]); } catch (WebhookException $e) { abort(400, 'Invalid Webhook Signature: ' . $e->getMessage()); } }
Advanced: Dependency Injection & Container
If you prefer passing the client via Dependency Injection instead of using the static Facade, the DigiflazzClient is automatically bound to the Service Container as a singleton.
use Gonon\Digiflazz\Client\DigiflazzClient; class DigiflazzController extends Controller { public function __construct( private readonly DigiflazzClient $digiflazz ) {} public function index() { $products = $this->digiflazz->products()->getPrepaid(); } }
You can also resolve the client manually using the app() helper anywhere in your application:
$digiflazz = app(\Gonon\Digiflazz\Client\DigiflazzClient::class); // or via the bound alias $digiflazz = app('digiflazz');
Exceptions
The SDK throws strictly typed exceptions that extend Gonon\Core\Exceptions\GononException.
Gonon\Digiflazz\Exceptions\DigiflazzException: Base exception.Gonon\Digiflazz\Exceptions\TransactionException: Thrown on invalid transaction responses.Gonon\Digiflazz\Exceptions\WebhookException: Thrown when a webhook signature is invalid or parsing fails.
统计信息
- 总下载量: 0
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 1
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-07-09