PHP code example of ndradev / digiflazz-sdk-laravel
1. Go to this page and download the library: Download ndradev/digiflazz-sdk-laravel 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/ */
use NadrDev\Digiflazz\Facades\Digiflazz;
// Mendapatkan daftar harga
$priceList = Digiflazz::getPriceList();
// Mendapatkan saldo
$balance = Digiflazz::getBalance();
// Membuat transaksi
$transaction = Digiflazz::createTransaction([
'buyer_sku_code' => 'TELKOMSEL10',
'customer_number' => '081234567890',
'ref_id' => 'ORDER-' . time(),
]);
use NadrDev\Digiflazz\Http\DigiFlazzClient;
class PaymentController extends Controller
{
private DigiFlazzClient $digiFlazz;
public function __construct(DigiFlazzClient $digiFlazz)
{
$this->digiFlazz = $digiFlazz;
}
public function purchase()
{
$balance = $this->digiFlazz->getBalance();
// ...
}
}
// Semua produk
$priceList = Digiflazz::getPriceList();
// Berdasarkan kategori (pulsa, data, pln, dll)
$priceList = Digiflazz::getPriceList('pulsa');
$priceList = Digiflazz::getPriceList('data');
$priceList = Digiflazz::getPriceList('pln');
use NadrDev\Digiflazz\Models\Balance;
$response = Digiflazz::getBalance();
$balance = Balance::fromArray($response);
echo $balance->getBalanceInRupiah(); // Rp 1.000.000
echo $balance->getBalanceFormatted(); // 1.000.000
$info = Digiflazz::checkPlnPrepayment('123456789012');
// Response berisi:
// - meter_number: Nomor meter
// - customer_name: Nama pelanggan
// - segment_power: Daya listrik
// - status: Status ketersediaan
use NadrDev\Digiflazz\Exceptions\ApiException;
use NadrDev\Digiflazz\Exceptions\ConnectionException;
use NadrDev\Digiflazz\Exceptions\ValidationException;
try {
$result = Digiflazz::createTransaction([
'buyer_sku_code' => 'TELKOMSEL10',
'customer_number' => '081234567890',
]);
} catch (ValidationException $e) {
// Error validasi data
$errors = $e->getErrors();
foreach ($errors as $field => $message) {
logger()->error("Validasi {$field}: {$message}");
}
} catch (ConnectionException $e) {
// Error koneksi ke API
logger()->error('Koneksi ke DigiFlazz gagal: ' . $e->getMessage());
} catch (ApiException $e) {
// Error dari API DigiFlazz
logger()->error('Error dari DigiFlazz: ' . $e->getMessage());
logger()->error('Context: ' . json_encode($e->getContext()));
}
use Illuminate\Support\Facades\Route;
use NadrDev\Digiflazz\Http\Controllers\WebhookController;
use NadrDev\Digiflazz\Http\WebhookHandler;
Route::post('/digiflazz/webhook', function (
Illuminate\Http\Request $request,
WebhookHandler $webhookHandler
) {
$controller = new WebhookController();
return $controller->handle($request, $webhookHandler);
})->name('digiflazz.webhook');
// app/Listeners/DigiFlazzWebhookListener.php
namespace App\Listeners;
use NadrDev\Digiflazz\Events\TransactionStatusChanged;
class DigiFlazzWebhookListener
{
public function handle(TransactionStatusChanged $event): void
{
$transaction = $event->transaction;
// Update status transaksi di database Anda
// Kirim notifikasi ke customer
// dll
}
}