PHP code example of andisiahaan / digiflazz-php

1. Go to this page and download the library: Download andisiahaan/digiflazz-php 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/ */

    

andisiahaan / digiflazz-php example snippets


use AndiSiahaan\Digiflazz\DigiflazzClient;

// Create client with credentials
$client = new DigiflazzClient('your_username', 'your_api_key');

// Check balance
$balance = $client->checkBalance();
print_r($balance);

// Or create from environment variables
$client = DigiflazzClient::fromEnvironment();

$client = DigiflazzClient::fromEnvironment();

use AndiSiahaan\Digiflazz\Config\Configuration;

$config = new Configuration(
    username: 'your_username',
    apiKey: 'your_api_key',
    timeout: 30.0,
    verifySsl: true,
);

$client = new DigiflazzClient($config);

$balance = $client->checkBalance();
// or
$balance = $client->balance()->check();

// Prepaid products
$prepaid = $client->priceListPrepaid();

// Postpaid products
$postpaid = $client->priceListPasca();

// With filters
$filtered = $client->priceList()->prepaid([
    'category' => 'Pulsa',
    'brand' => 'TELKOMSEL',
]);

// Get all at once
$all = $client->priceList()->all();

// Using array
$result = $client->topup([
    'buyer_sku_code' => 'xld10',
    'customer_no' => '087800001230',
    'ref_id' => 'unique-ref-123',
    'testing' => true, // Use sandbox
]);

// Using typed method
$result = $client->transaction()->topup(
    skuCode: 'xld10',
    customerNo: '087800001230',
    refId: 'unique-ref-123',
    testing: true,
);

// Generate unique ref_id
use AndiSiahaan\Digiflazz\Services\TransactionService;
$refId = TransactionService::generateRefId('TRX');

// Step 1: Inquiry (check bill)
$inquiry = $client->inqPasca([
    'buyer_sku_code' => 'pln',
    'customer_no' => '530000000001',
    'ref_id' => 'ref-001',
    'testing' => true,
]);

// Step 2: Pay the bill
if ($inquiry['data']['status'] === 'Sukses') {
    $payment = $client->payPasca([
        'buyer_sku_code' => 'pln',
        'customer_no' => '530000000001',
        'ref_id' => 'ref-001',
        'testing' => true,
    ]);
}

// Check status
$status = $client->statusPasca([...]);

// Quick inquiry
$pln = $client->inquiryPln('530000000001');

// Check if valid
$isValid = $client->pln()->isValidCustomer('530000000001');

$deposit = $client->requestDeposit([
    'amount' => 1000000,
    'Bank' => 'BCA',
    'owner_name' => 'John Doe',
]);

// Or using typed method
$deposit = $client->deposit()->withdraw(1000000, 'BCA', 'John Doe');

use AndiSiahaan\Digiflazz\Exceptions\DigiflazzException;
use AndiSiahaan\Digiflazz\Exceptions\ApiException;
use AndiSiahaan\Digiflazz\Exceptions\HttpException;
use AndiSiahaan\Digiflazz\Exceptions\ValidationException;

try {
    $result = $client->topup([...]);
} catch (ValidationException $e) {
    // Missing or invalid parameters
    echo "Validation error: " . $e->getMessage();
    print_r($e->getErrors());
} catch (ApiException $e) {
    // API returned an error
    echo "API error: " . $e->getMessage();
    echo "Error code: " . $e->getErrorCode();
    
    if ($e->isInsufficientBalance()) {
        echo "Please top up your balance";
    }
    
    if ($e->isRetryable()) {
        // Safe to retry
    }
} catch (HttpException $e) {
    // Network or HTTP error
    echo "HTTP error: " . $e->getMessage();
    echo "Status code: " . $e->getStatusCode();
} catch (DigiflazzException $e) {
    // Base exception (catch all library exceptions)
    echo "Error: " . $e->getMessage();
}

$balanceService = $client->balance();
$transactionService = $client->transaction();
$priceListService = $client->priceList();
$depositService = $client->deposit();
$plnService = $client->pln();
bash
composer 
bash
composer analyse