<?php
function generate_qrisnya($nominal){
    function ConvertCRC16($str) {
    function charCodeAt($str, $i) {
        return ord(substr($str, $i, 1));
    }
    $crc = 0xFFFF;
    $strlen = strlen($str);
    for($c = 0; $c < $strlen; $c++) {
        $crc ^= charCodeAt($str, $c) << 8;
        for($i = 0; $i < 8; $i++) {
            if($crc & 0x8000) {
                $crc = ($crc << 1) ^ 0x1021;
            } else {
                $crc = $crc << 1;
            }
        }
    }
    $hex = $crc & 0xFFFF;
    $hex = strtoupper(dechex($hex));
    if (strlen($hex) == 3) $hex = "0".$hex;
    return $hex;
    }
$qty = $nominal;
$qris = substr("00020101021126670016COM.NOBUBANK.WWW01189360050300000879140214032169323947070303UMI51440014ID.CO.QRIS.WWW0215ID20243135923940303UMI5204541153033605802ID5923ANUGRAH STORE OK15316736010BALIKPAPAN61057611162070703A016304E8D9", 0, -4);
$step1 = str_replace("010211", "010212", $qris);
$step2 = explode("5802ID", $step1);
$uang = "54".sprintf("%02d", strlen($qty)).$qty;

if (empty($tax)) {
    $uang .= "5802ID";
} else {
    $uang .= $tax."5802ID";
}

$fix = trim($step2[0]).$uang.trim($step2[1]);
$fix .= ConvertCRC16($fix);
    return $fix;
}