PHP code example of gonon / laravel-digiflazz

1. Go to this page and download the library: Download gonon/laravel-digiflazz library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

gonon / laravel-digiflazz example snippets


use Gonon\Digiflazz\Laravel\Facades\Digiflazz;

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})";

// 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');

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);

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);

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());
    }
}

use Gonon\Digiflazz\Client\DigiflazzClient;

class DigiflazzController extends Controller
{
    public function __construct(
        private readonly DigiflazzClient $digiflazz
    ) {}

    public function index()
    {
        $products = $this->digiflazz->products()->getPrepaid();
    }
}

$digiflazz = app(\Gonon\Digiflazz\Client\DigiflazzClient::class);
// or via the bound alias
$digiflazz = app('digiflazz');
bash
php artisan vendor:publish --tag="digiflazz-config"
bash
php artisan vendor:publish --provider="Gonon\Digiflazz\Laravel\DigiflazzServiceProvider"