PHP code example of dhank77 / qris-dinamis

1. Go to this page and download the library: Download dhank77/qris-dinamis 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/ */

    

dhank77 / qris-dinamis example snippets


use QrisDinamis\Qris;

$qris = Qris::convert($qrisStatisToko, 25000);   // → QRIS dinamis Rp 25.000





risDinamis\Qris;

// QRIS statis toko Anda (lihat bagian "Mendapatkan string QRIS statis")
$static = '00020101021126570011ID.DANA.WWW0118936009153022591481...6304ABCD';

// Buat QRIS dinamis Rp 25.000
$dynamic = Qris::convert($static, 25000);

echo $dynamic;
// 00020101021226570011ID.DANA.WWW...5405250005802ID...63040DD1

use QrisDinamis\Qris;

$dynamic = Qris::convert($static, 150000);

$a = Qris::convert($static, 10000);
$b = Qris::convert($a, 20000);   // sekarang Rp 20.000

// Rp 50.000 + biaya tetap Rp 1.500
$qris = Qris::convert($static, 50000, Qris::FEE_FIXED, 1500);

// Rp 50.000 + biaya 0,7%
$qris = Qris::convert($static, 50000, Qris::FEE_PERCENTAGE, 0.7);

$result = Qris::validate($input);
// ['valid' => false, 'errors' => ['CRC mismatch: expected 2982, got ABCD']]

if (Qris::isValid($input)) {
    // ...
}

$data = Qris::parse($static);

$data->merchantName;          // "Warung Sayur"
$data->merchantCity;          // "Kab. Demak"
$data->postalCode;            // "59567"
$data->merchantCategoryCode;  // "5812"
$data->currency;              // "360"
$data->currencyLabel();       // "IDR"
$data->countryCode;           // "ID"
$data->method;                // "static" | "dynamic"
$data->isStatic();            // true
$data->isDynamic();           // false
$data->issuer();              // "ID.DANA.WWW"
$data->nmid();                // "ID1020017611473"
$data->amount;                // null (statis) atau "25000" (dinamis)
$data->amountValue();         // null atau 25000.0
$data->tipIndicator;          // null | "prompt" | "fixed" | "percentage"
$data->tipFixed;              // "1500" atau null
$data->tipPercentage;         // "0.7" atau null
$data->crc;                   // "2982"

foreach ($data->merchantAccountInfo as $info) {
    echo $info['tag'];                // "26"
    echo $info['globallyUniqueId'];   // "ID.DANA.WWW"
    echo $info['merchantId'];         // "936009153022591481"
    echo $info['merchantCriteria'];   // "UMI"
    // $info['fields'] berisi array Tlv lengkap
}

foreach ($data->raw as $tlv) {
    echo "{$tlv->tag} {$tlv->name} {$tlv->value}\n";
    // $tlv->children berisi sub-elemen untuk tag 26–51 dan 62
}

$array = $data->toArray();       // array asosiatif
$json  = json_encode($data);     // JSON (termasuk "issuer" dan "nmid")

use QrisDinamis\Exception\InvalidQrisException;
use QrisDinamis\Qris;

try {
    $qris = Qris::convert($static, $amount, $feeType, $feeValue);
} catch (InvalidQrisException $e) {
    $e->getMessage();   // "Invalid QRIS: CRC mismatch: expected 2982, got ABCD"
    $e->getErrors();    // ['CRC mismatch: expected 2982, got ABCD']
}

use chillerlan\QRCode\QRCode;
use chillerlan\QRCode\QROptions;
use chillerlan\QRCode\Common\EccLevel;
use chillerlan\QRCode\Output\QROutputInterface;
use QrisDinamis\Qris;

$qris = Qris::convert($static, 25000);

// a) Data URI SVG — langsung untuk <img src="...">
$src = (new QRCode())->render($qris);
echo '<img src="' . $src . '" width="280" alt="QRIS">';

// b) File PNG
$png = new QRCode(new QROptions([
    'outputType'    => QROutputInterface::GDIMAGE_PNG,
    'eccLevel'      => EccLevel::M,
    'scale'         => 10,
    'quietzoneSize' => 2,
    'outputBase64'  => false,
]));
file_put_contents('qris.png', $png->render($qris));

// c) Kirim PNG langsung sebagai response
header('Content-Type: image/png');
echo $png->render($qris);

'qris' => [
    'static' => env('QRIS_STATIC'),
],

use chillerlan\QRCode\QRCode;
use QrisDinamis\Qris;

class PaymentController extends Controller
{
    public function show(Order $order)
    {
        $qris = Qris::convert(config('services.qris.static'), $order->total);

        return view('pay', [
            'order'   => $order,
            'qrImage' => (new QRCode())->render($qris),
        ]);
    }
}

namespace App\Controllers;

use chillerlan\QRCode\QRCode;
use QrisDinamis\Exception\InvalidQrisException;
use QrisDinamis\Qris;

class Payment extends BaseController
{
    public function qris()
    {
        $amount = (int) $this->request->getPost('amount');

        try {
            $qris = Qris::convert(env('QRIS_STATIC'), $amount);
        } catch (InvalidQrisException $e) {
            return $this->response->setStatusCode(422)->setJSON(['errors' => $e->getErrors()]);
        }

        return $this->response->setJSON([
            'qris'  => $qris,
            'image' => (new QRCode())->render($qris),
        ]);
    }
}


chillerlan\QRCode\QRCode;
use QrisDinamis\Qris;

$total = 75000;
$qris  = Qris::convert(getenv('QRIS_STATIC'), $total);
bash
composer 
bash
curl -X POST http://localhost:8000/api.php \
  -H 'Content-Type: application/json' \
  -d '{"action":"convert","qris":"000201...","amount":25000,"fee_type":"fixed","fee_value":1000}'
bash
php examples/01-basic-convert.php
php -S localhost:8000 examples/07-checkout-page.php