PHP code example of triyatna / digiflazz-laravel-4buyer

1. Go to this page and download the library: Download triyatna/digiflazz-laravel-4buyer 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/ */

    

triyatna / digiflazz-laravel-4buyer example snippets


use Triyatna\Digiflazz\Digiflazz;
use Illuminate\Support\Str;

$response = Digiflazz::checkBalance();

if ($response->isSuccess()) {
    return $response->get('deposit');
}

$response = Digiflazz::requestDeposit(50000, 'BCA', 'Budi Santoso');

if ($response->isSuccess()) {
    return [
        'jumlah' => $response->get('amount'),
        'berita' => $response->get('notes'),
    ];
}

$response = Digiflazz::getPriceList('prepaid', ['brand' => 'TELKOMSEL']);

if ($response->isSuccess()) {
    return $response->data();
}

$response = Digiflazz::inquiryPln('1234554321');

if ($response->isSuccess()) {
    return $response->get('name');
}

$refId = 'TRX-' . Str::uuid();

$response = Digiflazz::createPrepaidTransaction('tsel5', '081234567890', $refId);

if ($response->isSuccess()) {
    // sukses
}

$refId = 'INQ-' . Str::uuid();

$response = Digiflazz::checkPostpaidBill('pln', '530000000001', $refId, true);

$response = Digiflazz::payPostpaidBill('pln', '530000000001', $refId, true);

$response = Digiflazz::checkTransactionStatus(
    'TRX-xxxxxxxx-xxxx',
    'prepaid',
    'tsel5',
    '081234567890'
);

if ($response->isSuccess()) {
    // status sukses
}

use App\Http\Controllers\WebhookController;

Route::post('/webhooks/digiflazz', [WebhookController::class, 'handle']);

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Log;
use Triyatna\Digiflazz\Helpers\Webhook;

class WebhookController extends Controller
{
    public function handle(Request $request)
    {
        $signature = $request->header('X-Hub-Signature');
        $payload = $request->getContent();
        $secret = config('digiflazz.webhook_secret');

        if (!Webhook::validate($signature, $payload, $secret)) {
            return response('Validasi gagal.', 403);
        }

        $data = $request->input('data');
        Log::info("Webhook diterima untuk ref_id {$data['ref_id']} dengan status {$data['status']}");

        return response('Webhook diterima.', 200);
    }
}
bash
php artisan ty-digiflazz:install