<?php
require '../../config.php';
session_start();
$guest = true;
$date = date('Y-m-d H:i:s');
$query_games = mysqli_query($db, "SELECT * FROM games_guest WHERE slug = '$slug'");
if (mysqli_num_rows($query_games) == 0) {
    header('location: '.base_url('id'));
}
$fetch_games = mysqli_fetch_assoc($query_games);

if (!empty($fetch_games['petunjuk'])) {
    if (filter_var($fetch_games['petunjuk'], FILTER_VALIDATE_URL)) {
        $petunjuk = $fetch_games['petunjuk'];
    } else {
        $petunjuk = false;
    }
} else {
    $petunjuk = false;
}
if(isset($_POST['product']) AND isset($_POST['method']) AND isset($_POST['target'])){
    $produk = $_POST['product'];
    $metode = $_POST['method'];
    $target = $_POST['target'];
    $additional_target = $_POST['server'];
    $login = $_POST['login'];
    $userid = $_POST['userid'];
    $pesan = $_POST['pesan'];
    $quantity = '1';
    $wa = $_POST['wa'];
    $query_produk = mysqli_query($db, "SELECT * FROM layanan_pulsa WHERE id = '$produk'");
    if (mysqli_num_rows($query_produk) === 1) {
        $fetch_produk = mysqli_fetch_assoc($query_produk);
        $query_metode = mysqli_query($db, "SELECT * FROM metode_guest WHERE id = '$metode'");
        if(mysqli_num_rows($query_metode) == 1){
            $fetch_metode = mysqli_fetch_assoc($query_metode);
            $next = false;
            $order_id = 'LS' . rand(0000000,9999999);
            $unik = rand(555,999);
            if (isset($_SESSION['user'])) {
                $user_guest = $_SESSION['user']['username'];
                $waa = $_SESSION['user']['phone'];
            } else {
                $user_guest = 'none';
                $waa = $wa;
            }
            $query_harga = mysqli_query($db, "SELECT * FROM harga_guest WHERE layanan_id = '$produk' AND metode_id = '$metode'");
            if (mysqli_num_rows($query_harga) !== 1) {
                $fetch_harga = mysqli_fetch_assoc($query_harga);
                if($_SESSION['user']['level'] == "Reseller"){
                    $harga_real = (int)$fetch_produk['harga_reseller'];
                }else if($_SESSION['user']['level'] == "Vip" || $_SESSION['user']['level'] == "Admin"){
                    $harga_real = (int)$fetch_produk['harga_premium'];
                }else if($_SESSION['user']['level'] !== "Reseller" || $_SESSION['user']['level'] !== "Admin" || $_SESSION['user']['level'] !== "Vip"){
                    $harga_real = (int)$fetch_produk['harga'];
                }
            }else{
                $harga_real = $fetch_harga['harga'];
            }
            $uss = $db->query("SELECT * FROM users WHERE id='".$_SESSION['user']['id']."'")->fetch_assoc();
            if($fetch_metode['metode'] == 'Saldo Akun'){
                if($uss['saldo'] < $harga_real){
                    $_SESSION['alert'] = ['danger','Failed!','Saldo Anda Tidak Mencukupi'];
                    exit(header('location: '.base_url('id/product/'.$slug)));
                    $next = false;
                }else{
                    $saldo = $uss['saldo'] - $harga_real;
                    $db->query("UPDATE users SET saldo='$saldo' WHERE id='".$_SESSION['user']['id']."'");
                    $db->query("INSERT INTO `history_balance`(`id`, `user`, `nominal`, `aksi`, `tanggal`) VALUES ('','$user_guest','$harga_real','-','$date')");
                    $nominal = 
                    $next = true;
                }
            }else if($fetch_metode['metode'] == 'BCA'){
                $harga_real = $harga_real;
                $pay_url = $fetch_metode['rek'];
                $next = true;
            } else if ($fetch_metode['sistem'] == 'Tripay') {
                $Trip = $db->query("SELECT * FROM payment WHERE code='Tripay'")->fetch_assoc();
                $link = 'https://tripay.co.id/api/transaction/create';
                $substr = substr($waa,3);
                $waaa = '08'.$substr;
                $result = $curl->connectTripayPost($link,['Authorization: Bearer '.$Trip['api_key']],['method' => $fetch_metode['kode'],'merchant_ref' => $order_id,'amount' => $harga_real,'customer_name' => $user_guest,'customer_email' => 'cs@lynchstore.xyz','customer_phone' => $waaa,'order_items' => array(['sku' => 'LS','name' => $fetch_produk['layanan'],'price' => $harga_real,'quantity' => 1]),'return_url' => base_url() . 'id/invoice?no=' . $order_id,'expired_time' => (time() + (24 * 60 * 60)),'signature' => hash_hmac('sha256', $Trip['merchant_id'].$order_id.$harga_real, $Trip['api_id'])]);
                if ($result['success'] == true) {
                    if (array_key_exists('qr_string', $result['data'])) {
                        $unik = $result['data']['total_fee'];
                        $isi = $result['data']['qr_string'];
                        $gen = md5(uniqid(random(40),true));
                        $nama = $gen.'.png';
                        $pay_url = $nama;
                        $reference = $result['data']['reference'];
                        QRcode::png($isi,'../../assets/qris/'.$nama,QR_ECLEVEL_L,4);
                    }else if(isset($result['data']['pay_code'])){
                        $pay_url = $result['data']['pay_code'];
                        $unik = $result['data']['total_fee'];
                        $reference = $result['data']['reference'];
                    }else{
                        $pay_url = $result['data']['pay_url'];
                        $unik = $result['data']['total_fee'];
                        $reference = $result['data']['reference'];
                    }
                    $next = true;
                } else{
                    $_SESSION['alert'] = ['danger','Failed',$result['message']];
                    exit(header('location: '.base_url('id/product/'.$slug)));
                }
            } else if($fetch_metode['sistem'] == "Xendit"){
                if($fetch_metode['kode'] == "DANA" || $fetch_metode['kode'] == "OVO" || $fetch_metode['kode'] == "SHOPEEPAY" || $fetch_metode['kode'] == "LINKAJA"){
                    $try = $Xendit->eWallet($order_id,$harga_real+$unik,$fetch_metode['kode'],$waa);
                    $pay_url = $try['payment'];
                    $reference = $try['id'];
                    $next = true;
                }else if($fetch_metode['metode'] == "QRIS"){
                    $try = $Xendit->qris($order_id,$harga_real+$unik);
                    $isi = $try['payment'];
                    $reference = $try['id'];
                    $gen = md5(uniqid(random(40),true));
                    $nama = $gen.'.png';
                    $pay_url = $nama;
                    QRcode::png($isi,'../../assets/qris/'.$nama,QR_ECLEVEL_L,4);
                    $reference = $try['id'];
                    $next = true;
                }else if($fetch_metode['tipe'] == "Convenience Store"){
                    $try = $Xendit->qris($order_id,$harga_real+$unik);
                    $reference = $try['id'];
                    $pay_url = $try['payment'];
                    $next = true;
                }else if($fetch_metode['tipe'] == "Virtual Account"){
                    $try = $Xendit->virtualAccount($order_id,$harga_real+$unik,$fetch_metode['kode'],$user_guest);
                    $reference = $try['id'];
                    $pay_url = $try['payment'];
                    $next = true;
                }
            } else if($fetch_metode['metode'] == "BANK BCA"){
                $harga_real = $harga_real;
                $ps = rand(333,555);
                $unik = $unik+$ps;
                $pay_url = $fetch_metode['rek'];
                $next = true;
            }else {
                $harga_real = $harga_real;
                $pay_url = $fetch_metode['rek'];
                $next = true;
            }
            if ($next === true) {
                if (isset($pay_url)) {
                    $rek = $pay_url;
                } else {
                    $rek = !empty($fetch_metode['rek']) ? $fetch_metode['rek'] : '-';
                }
                
                if($fetch_metode['metode'] == "QRIS"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Download QR Code pada invoice</li>
    <li>Masuk ke aplikasi dompet digital Anda yang telah mendukung QRIS</li>
    <li>Upload QR Code yang telah di download tadi</li>
    <li>Akan muncul detail transaksi. Pastikan data transaksi sudah sesuai</li>
    <li>Selesaikan proses pembayaran Anda<//li>
    <li>Transaksi selesai. Simpan bukti pembayaran Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "Saldo Akun"){
                    $intruksi = '-';
                }else if($fetch_metode['metode'] == "BCA Virtual Account" || $fetch_metode['metode'] == "BANK BCA"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
<li>Login ke internet banking klikbca Anda</li>
<li>Pilih menu Transfer Dana lalu pilih Transfer ke BCA Virtual Account</li>
<li>Pilih Dari Rekening</li>
<li>Masukkan Nomor VA lalu klik Lanjutkan</li>
<li>Detail transaksi akan ditampilkan, pastikan data sudah sesuai lalu masukkan respon Key BCA Appli 1</li>
<li>Klik Kirim</li>
<li>Transaksi sukses, simpan bukti transaksi Anda</li>
</ol>';
                
                }else if($fetch_metode['metode'] == "Indomaret"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Datang ke gerai Indomaret</li>
    <li>Sampaikan ke kasir ingin melakukan pembayaran Linkita</li>
    <li>Berikan kode bayar ke kasir</li>
    <li>Bayar sesuai jumlah yang diinfokan oleh kasir</li>
    <li>Simpan struk bukti pembayaran Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "Alfamidi"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Datang ke Alfamidi</li>
    <li>Sampaikan ke kasir ingin melakukan pembayaran Plasamall</li>
    <li>Berikan kode bayar ke kasir</li>
    <li>Bayar sesuai jumlah yang diinfokan oleh kasir</li>
    <li>Simpan struk bukti pembayaran Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "Alfamart"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Datang ke Alfamart</li>
    <li>Sampaikan ke kasir ingin melakukan pembayaran Plasamall</li>
    <li>Berikan kode bayar ke kasir</li>
    <li>Bayar sesuai jumlah yang diinfokan oleh kasir</li>
    <li>Simpan struk bukti pembayaran Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "BSI Virtual Account"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Masuk ke Internet Banking BSI Anda</li>
    <li>Pilih menu Pembayaran</li>
    <li>Pilih nomor rekening Anda</li>
    <li>Pilih Jenis Pembayaran > Institusi</li>
    <li>Pada opsi Nama Institusi, pilih 9042 Win Pay</li>
    <li>Masukkan kode bayar</li>
    <li>Klik tombol Verifikasi</li>
    <li>Akan ditampikan detail transaksi, pastikan sudah sesuai</li>
    <li>Masukkan TAN & PIN Anda</li>
    <li>Tekan tombol Submit</li>
    <li>Transaksi selesai, simpan bukti pembayaran Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "CIMB Virtual Account"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Login ke CIMB clicks</li>
    <li>Pilih menu Bayar Tagihan / Pay Bills</li>
    <li>Pilih Rekening Sumber / Source Account dan Jenis Pembayaran / Payment Type > Virtual Account</li>
    <li>Masukkan nomor Virtual Account</li>
    <li>Masukkan nominal pembayaran</li>
    <li>Masukkan 6 digit mPIN dan tekan tombol Submit</li>
    <li>Transaksi berhasil, simpan bukti transaksi Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "Muamalat Virtual Account"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Login ke IB Muamalat</li>
    <li>Pilih menu Payment</li>
    <li>pilih rekening Anda dan pilih Virtual Account pada bill type</li>
    <li>masukkan Nomor Va</li>
    <li>Klik Next</li>
    <li>Periksa kembali jumlah pembayaran</li>
    <li>Apabila sudah sesuai, Masukkan mPasscode lalu klik SUBMIT jika setuju dengan informasi pembayaran</li>
    <li>Transaksi Anda selesai. Silahkan cetak bukti transaksi</li>
</ol>';
                }else if($fetch_metode['metode'] == "Sinarmas Virtual Account"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Login ke internet banking Bank Sinarmas Anda</li>
    <li>Pilih menu Transfer Dana lalu pilih menu Rekening Bank Sinarmas</li>
    <li>Masukkan Nomor VA</li>
    <li>Lakukan konfirmasi transaksi seperti memasukkan nomor token atau SMS token untuk melakukan pembayaran</li>
    <li>Simpan bukti transaksi Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "Maybank Virtual Account"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Login ke internet banking Maybank Anda</li>
    <li>Pilih menu Transfer lalu pilih Maybank Virtual Account</li>
    <li>Pilih Rekening Sumber</li>
    <li>Masukkan Nomor VA dan jumlah pembayaran lalu klik Lanjutkan</li>
    <li>Detail transaksi akan ditampilkan, pastikan data sudah sesuai lalu klik Lanjutkan</li>
    <li>Masukkan SMS Token lalu klik Lanjutkan</li>
    <li>Transaksi sukses, simpan bukti transaksi Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "Permata Virtual Account"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Login ke internet banking Bank Permata Anda</li>
    <li>Pilih menu Pembayaran lalu klik menu Pembayaran Tagihan</li>
    <li>Pilih menu Virtual Account</li>
    <li>Pilih Rekening Asal lalu centang Masukkan Daftar Tagihan Baru</li>
    <li>Masukkan Nomor VA lalu klik Lanjutkan</li>
    <li>Detail transaksi akan ditampilkan, pastikan data sudah sesuai lalu klik Lanjutkan</li>
    <li>Masukkan SMS Token Permata, lalu klik Lanjutkan</li>
    <li>Transaksi sukses, simpan bukti transaksi Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "BNI Virtual Account"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Login ke internet banking Bank BNI Anda</li>
    <li>Pilih menu Transaksi lalu klik menu Virtual Account Billing</li>
    <li>Masukkan Nomor VA lalu pilih Rekening Debit</li>
    <li>Detail transaksi akan ditampilkan, pastikan data sudah sesuai</li>
    <li>Masukkan respon key BNI appli 2v
    <li>Transaksi sukses, simpan bukti transaksi Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "BRI Virtual Account"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Login ke internet banking Bank BRI Anda</li>
    <li>Pilih menu Pembayaran lalu klik menu BRIVA</li>
    <li>Pilih rekening sumber dan masukkan Kode Bayar lalu klik Kirim</li>
    <li>Detail transaksi akan ditampilkan, pastikan data sudah sesuai</li>
    <li>Klik Lanjutkan</li>
    <li>Masukkan kata sandi ibanking lalu klik Request untuk mengirim m-PIN ke nomor HP Anda</li>
    <li>Periksa HP Anda dan masukkan m-PIN yang diterima lalu klik Kirim</li>
    <li>Transaksi sukses, simpan bukti transaksi Anda</li>
</ol>';
                }else if($fetch_metode['metode'] == "Mandiri Virtual Account"){
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
    <li>Login ke internet banking Anda</li>
    <li>Pilih menu Pembayaran lalu klik menu Multipayment</li>
    <li>Pilih Penyedia Jasa: Bimasakti</li>
    <li>Masukkan Nomor VA</li>
    <li>Masukkan Nominal</li>
    <li>Detail transaksi akan ditampilkan, pastikan data sudah sesuai</li>
    <li>Klik tombol Konfirmasi</li>
    <li>Periksa aplikasi Mandiri Online di ponsel Anda untuk menyelesaikan persetujuan transaksi</li>
    <li>Transaksi sukses, simpan bukti transaksi Anda</li>
</ol>';
                }else{
                    $intruksi = '<p><b>Cara Pembayaran</b></p>
<ol>
	<li>Salin Rekening dan Harga Total</li>
	<li>Buka Aplikasi M-banking/E-Wallet Anda.</li>
	<li>Masukkan nomor rekening</li>
	<li>Masukkan Harga Total yang ada di invoice (tidak boleh ditambah/dikurangi)</li>
	<li>Lalu Transfer</li>
</ol>';
                }
                $total_harga = $harga_real + $unik;
                if($fetch_metode['metode'] != 'Saldo Akun'){
                    $suc = $db->query("INSERT INTO `pembelian_guest` VALUES ('','$user_guest','$waa','$order_id','$reference','".$fetch_metode['id']."','".$fetch_metode['metode']."','$rek','".$fetch_produk['operator']."','".$fetch_produk['id']."','".$fetch_produk['layanan']."','".$fetch_produk['provider_id']."','$target', '$additional_target','$userid','$login','$pesan','1','0','$harga_real','$unik','$total_harga','Pending','".$fetch_produk['provider']."','-','none','$date','$date','','$intruksi')");
                }else{
                    $suc = $db->query("INSERT INTO `pembelian_guest` VALUES ('','$user_guest','$waa','$order_id','$reference','".$fetch_metode['id']."','".$fetch_metode['metode']."','$rek','".$fetch_produk['operator']."','".$fetch_produk['id']."','".$fetch_produk['layanan']."','".$fetch_produk['provider_id']."','$target', '$additional_target','$userid','$login','$pesan','1','0','$harga_real','0','$total_harga','Waiting','".$fetch_produk['provider']."','Transaksi Pending','none','$date','$date','','$intruksi')");
                }
                if($fetch_metode['metode'] == "Saldo Akun"){
                    $stat = "Waiting";
                }else{
                    $stat = "Pending";
                }
                if(!$additional_target){
                    $targets = $target;
                }else{
                    $targets = $target.'('.$additional_target.')';
                }
                if($fetch_metode['metode'] == "QRIS"){
                    $WhatsApp->sendPicture('https://wa.kspstore.my.id/',opt_get('dHAta2V5'),opt_get('dHAtcGhvbmU='),$waa,"*Rincian Pesanan*\n\n- Order ID: *".$order_id."*\n- User ID: *".$targets."*\n- Layanan: *".$fetch_produk['operator']."*\n- Produk: *".$fetch_produk['layanan']."*\n- Metode: *".$fetch_metode['metode']."*\n- Harga: *Rp ".number_format($harga_real,0,',','.')."*\n- Status: *".$stat."*\n- Tanggal: *".$date."*\n\n*Informasi Selengkapnya Check dibawah ini:*\n".base_url('id/invoice?no='.$order_id)."\n\n*INFO*\nWhatsApp ini merupakan bot notifikasi, jika mengalami kendala atau masalah jangan spam/komplain ke WA ini karena tidak akan dibalas, silahkan hub CP WA Admin wa.me/6285814138627\n\nNote : Pesan dikirim oleh bot.\n\n*BY ".config('web','title_web')."*",base_url('/assets/qris/'.$nama),"image");
                }else if($fetch_metode['metode'] == "Saldo Akun"){
                    $WhatsApp->sendMessage('https://wa.kspstore.my.id/',opt_get('dHAta2V5'),opt_get('dHAtcGhvbmU='),$waa,"*Rincian Pesanan*\n\n- Order ID: *".$order_id."*\n- User ID: *".$targets."*\n- Layanan: *".$fetch_produk['operator']."*\n- Produk: *".$fetch_produk['layanan']."*\n- Metode: *".$fetch_metode['metode']."*\n- Harga: *Rp ".number_format($harga_real,0,',','.')."*\n- Status: *".$stat."*\n- Tanggal: *".$date."*\n\n*Informasi Selengkapnya Check dibawah ini:*\n".base_url('id/invoice?no='.$order_id)."\n\n*INFO*\nWhatsApp ini merupakan bot notifikasi, jika mengalami kendala atau masalah jangan spam/komplain ke WA ini karena tidak akan dibalas, silahkan hub CP WA Admin wa.me/6285814138627\n\nNote : Pesan dikirim oleh bot.\n\n*BY ".config('web','title_web')."*");
                }else{
                    $WhatsApp->sendMessage('https://wa.kspstore.my.id/',opt_get('dHAta2V5'),opt_get('dHAtcGhvbmU='),$waa,"*Rincian Pesanan*\n\n- Order ID: *".$order_id."*\n- User ID: *".$targets."*\n- Layanan: *".$fetch_produk['operator']."*\n- Produk: *".$fetch_produk['layanan']."*\n- Metode: *".$fetch_metode['metode']."*\n- Rekening: *".$rek."*\n- Harga: *Rp ".number_format($harga_real,0,',','.')."*\n- Status: *".$stat."*\n- Tanggal: *".$date."*\n\n*Informasi Selengkapnya Check dibawah ini:*\n".base_url('id/invoice?no='.$order_id)."\n\n*INFO*\nWhatsApp ini merupakan bot notifikasi, jika mengalami kendala atau masalah jangan spam/komplain ke WA ini karena tidak akan dibalas, silahkan hub CP WA Admin wa.me/6285814138627\n\nNote : Pesan dikirim oleh bot.\n\n*BY ".config('web','title_web')."*");
                }
                if ($suc == TRUE) {
                    if(filter_var($pay_url,FILTER_VALIDATE_URL)){
                        header('location: '.$pay_url);
                    }else{
                    exit(header('location: /id/invoice?no=' . $order_id));
                    }
                } else {
                    $_SESSION['alert'] = ['danger','Failed!','Pembelian Gagal Dilakukan'];
                    exit(header('location: '.base_url('id/product/'.$slug)));
                }
            } else {
            $_SESSION['alert'] = ['danger','Failed!','Pembelian Gagal Dilakukan'];
            exit(header('location: '.base_url('id/product/'.$slug)));
            }
        } else {
            $_SESSION['alert'] = ['danger','Failed!','Metode Tidak Ditemukan'];
            exit(header('location: '.base_url('id/product/'.$slug)));
        }
    } else {
        $_SESSION['alert'] = ['danger','Failed!','Layanan Tidak Ditemukan'];
        exit(header('location: '.base_url('id/product/'.$slug)));
    }
}
include '../../layouts/header.php';
?>

        <form id="form-order" class="form-horizontal mb-5" action="?" method="POST">
        <div class="row">
            <div class="col-lg-4 mt-2 mb-2">
                <div class="row">
                    <div class="col-12">
                        <div class="card bg-dark shadow">
                            <div class="card-body">
                                <img alt="" class="shadow rounded bg-dark mx-auto mb-2 d-block" width="120" src="/assets/games/<?= $fetch_games['img']; ?>">
                                <div class="row">
                                    <div class="col">
                                        <h3><?= $fetch_games['name'];?></h3>
                                        <div class="strip-primary"></div><br>
                                            <?= $fetch_games['keterangan'];?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="col mt-3 d-lg-block d-none">
                        <div class="card bg-dark shadow">
                            <div class="card-header">
                                <h5 class="card-title">Produk Lainnya</h5></div>
                                <div class="card-body">
                                    <?php
            	                $query_rec_games = mysqli_query($db, "SELECT * FROM games_guest ORDER BY rand() LIMIT 5"); 
            	                while($fetch_rec_games = mysqli_fetch_assoc($query_rec_games)):
            	                    if($fetch_rec_games['slug'] !== $slug){
            	                ?>
                                    <div class="row mb-2">
                                        <div class="col">
                                            <div class="card flex-row flex-wrap bg-dark">
                                                <div class="card-headers border-0">
                                                    <a href="<?= base_url('id/product/'.$fetch_rec_games['slug']);?>" class="stretched-link">
                                                    <img class="img-njas" alt="LynchStore" src="/assets/games/<?=$fetch_rec_games['img'];?>">
                                                    </a>
                                                </div>
                                                <div class="card-body mt-2">
                                                    <b><?=$fetch_rec_games['name'];?></b>
                                                </div>
                                            </div>
                                        </div>
                                    </div>
                                    <?php } endwhile;?>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-lg-8 mt-2 mb-2">
                    <?php require('../target/'.$fetch_games['sistem_id'].'.php');?>
                    <div class="col-6"> 
                      <center><select name="zone_id" id="zoneID" class="form-control">  
                        <option value="">Jenis Layanan</option></center>
                        <?php
                          $sql_31 = mysqli_query($db,"SELECT * FROM `layanan_pulsa` WHERE operator = '".$fetch_games['product']."' GROUP BY tipe ORDER BY tipe ASC") or die(mysqli_error());
                          while($s31 = mysqli_fetch_array($sql_31)){
                        ?>
                        <option value="<?php echo str_replace(' ','-',$s31['tipe']).'_'.$s31['operator']; ?>"><?php echo strtoupper(str_replace('-',' ',$s31['tipe'])); ?></option>
                        <?php } ?>
                      </select>
                    </div>
                    <div class="row mt-3">
                        <div class="col">
                            <div class="card bg-dark shadow">
                                <div class="card-header">
                                    <h5 class="card-title"><i class="fa-regular fa-circle-2"></i> Pilih Nominal</h5>
                                </div>
                                <div class="card-body">
                                    <div id="tempatNominal">
                                        <div class="row row-cols-2 row-cols-md-3 g-2">
                                            <?php $i = 1; $query_product = mysqli_query($db, "SELECT * FROM layanan_pulsa WHERE operator = '".$fetch_games['product']."' AND tipe='".$fetch_games['tipe_product']."' ORDER BY harga ASC"); while($fetch_product = mysqli_fetch_assoc($query_product)) :?>
                                            <?php if (mysqli_num_rows($query_harga) !== 1) {
                                                $fetch_harga = mysqli_fetch_assoc($query_harga);
                                                if($_SESSION['user']['level'] == "Reseller"){
                                                    $harga_real = (int)$fetch_product['harga_reseller'];
                                                }else if($_SESSION['user']['level'] == "Vip" || $_SESSION['user']['level'] == "Admin"){
                                                    $harga_real = (int)$fetch_product['harga_premium'];
                                                }else if($_SESSION['user']['level'] !== "Reseller" || $_SESSION['user']['level'] !== "Admin" || $_SESSION['user']['level'] !== "Vip"){
                                                    $harga_real = (int)$fetch_product['harga'];
                                                }?>
                                            <?php if($fetch_product['img'] == 0):?>
                                            <div class="col-lg-4 mt-3">
                                                <div class="list-group shadow h-100">
                                                    <input type="radio" name="produk" id="produk-<?= $fetch_product['id'];?>" onclick="pilih_produk('<?= $fetch_product['id']; ?>');">
                                                    <label for="produk-<?= $fetch_product['id'];?>" class="list-group-item h-100">
                                                        <div class="row">
                                                            <div class="col">
                                                                <div class="row">
                                                                    <div class="col name-prod" style="font-weight: 600;"><?= $fetch_product['layanan'];?></div>
                                                                </div>
                                                                <div class="row">
                                                                    <div class="col" style="font-size: 10px; font-weight:100">Rp. <?= number_format($harga_real,0,',','.');?></div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                    </label>
                                                </div>
                                            </div>
                                            <?php else:?>
                                            <div class="col-lg-4 mt-3">
                                                <div class="list-group shadow h-100" id="resultpulsa">
                                                    <input type="radio" name="produk" id="produk-<?= $fetch_product['id'];?>" onclick="pilih_produk('<?= $fetch_product['id']; ?>');">
                                                    <label for="produk-<?= $fetch_product['id'];?>" class="list-group-item h-100">
                                                        <div class="row">
                                                            <div class="col">
                                                                <div class="row">
                                                                    <div class="col name-prod" style="font-weight: 600;"><?php echo str_replace(' ','-',$s31['tipe']).'_'.$s31['operator']; ?>"><?php echo strtoupper(str_replace('-',' ',$s31['tipe'])); ?></div>
                                                                </div>
                                                                <div class="row">
                                                                    <div class="col" style="font-size: 9px; font-weight:100">Rp. <?= number_format($harga_real,0,',','.');?></div>
                                                                </div>
                                                            </div>
                                                            <div class="col-lg-3 col-1 m-auto">
                                                                <img src="<?= base_url('assets/produk/'.$fetch_product['img']);?>" width="36px" style="top: 13%;right: 5%;position: absolute;" alt="LynchStore">
                                                            </div>
                                                        </div>
                                                    </label>
                                                </div>
                                            </div>
                                            <?php endif;?>
                                            <?php } endwhile?>
                                            </div>
                                            <?php if (mysqli_num_rows($query_product) == 0): ?>
                                            <div class="col-12 mt-3">
                                                <div class="alert alert-warning py-1 text-center">
                                                    <b>Produk belum tersedia</b>
                                                </div>
                                            </div>
                                        <?php endif; ?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row mt-3">
                        <div class="col">
                            <div class="card bg-dark shadow">
                                <div class="card-header">
                                    <h5 class="card-title">Pilih Metode Pembayaran</h5>
                                </div>
                                <div class="card-body">
                                    <div class="area-list-payment-method">
                                        <?php if($_SESSION['user']['level'] == "Admin" || $_SESSION['user']['level'] == "Member" || $_SESSION['user']['level'] == "Reseller" || $_SESSION['user']['level'] == "Vip"):?>
                                        <div class="child-box payment-drawwer shadow">
                                            <div class="header short-payment-support-info-head" onclick="openPayment(this)">
                                                <div class="left">
                                                    <b>Saldo Akun</b>
                                                </div>
                                            </div>
                                            <div class="button-action-payment" style="display:none;">
                                                <ul>
                                                    <li>
                                                        <input type="radio" name="metode" id="metode-15" onclick="pilih_metode('15');">
                                                        <label for="metode-15" class="payment-item">
                                                            <div class="info-top">
                                                                <div>
                                                                    <i class="fas fa-wallet"></i>
                                                                </div>
                                                                <b class="d-block" id="payment-15" data-harga="" style="font-size: 11px;"></b>
                                                            </div>
                                                            <div class="info-bottom text-sm-left">Saldo Akun</div>
                                                        </label>
                                                    </li>
                                                </ul>
                                            </div>
                                            <div class="short-payment-support-info" onclick="openPayment(this)">
                                                <i class="fas fa-wallet"></i>
                                                <a class="open-button-action-payment"><i class="fas fa-chevron-down"></i></a>
                                            </div>
                                        </div>
                                        <?php endif;?>
                                        <?php $i = 1; $query_tipe_metode = mysqli_query($db, "SELECT DISTINCT tipe FROM metode_guest"); while($fetch_tipe_metode = mysqli_fetch_assoc($query_tipe_metode)): $query_metode = mysqli_query($db, "SELECT * FROM metode_guest WHERE tipe = '".$fetch_tipe_metode['tipe']."'");?>
                                        <?php if (mysqli_num_rows($query_metode) !== 0 && $fetch_tipe_metode['tipe'] !== "Saldo Akun"): ?>
                                        <div class="child-box payment-drawwer shadow" id="<?= str_replace(' ','-',$fetch_tipe_metode['tipe']);?>">
                                            <div class="header short-payment-support-info-head" onclick="openPayment(this)">
                                                <div class="left">
                                                    <b><?= $fetch_tipe_metode['tipe']; ?></b>
                                                </div>
                                            </div>
                                            <div class="button-action-payment" style="display:none;">
                                                <div class="row row-cols-md-3 p-1">
                                            <?php while($fetch_metode = mysqli_fetch_assoc($query_metode)): ?>
                                                <div class="col-lg-4 p-1 h-100" >
                                                <ul class="list-group h-100">
                                                    <li>
                                                        <input type="radio" name="metode" id="metode-<?= $fetch_metode['id']; ?>" onclick="pilih_metode('<?= $fetch_metode['id']; ?>');">
                                                        <label for="metode-<?= $fetch_metode['id']; ?>" class="payment-item">
                                                            <div class="info-top">
                                                                <div><img alt="" width="60px" src="/assets/metode/<?= $fetch_metode['img']; ?>"></div>
                                                                <b class="d-block" id="payment-<?= $fetch_metode['id']; ?>" data-harga="" style="font-size: 11px;"></b>
                                                            </div>
                                                            <div class="info-bottom text-sm-left"><?= $fetch_metode['ket']; ?></br><b class='lynchstore-cek' id="payment"><?= $fetch_metode['sub_ket']; ?></b></div>
                                                        </label>
                                                    </li>
                                                </ul>
                                            </div>
                                            <?php endwhile?>
                                            </div>
                                            </div>
                                            <div class="short-payment-support-info" onclick="openPayment(this)">
                                                <?php $query_metode_logo = mysqli_query($db, "SELECT * FROM metode_guest WHERE tipe = '".$fetch_tipe_metode['tipe']."'"); while($fetch_metode_logo = mysqli_fetch_assoc($query_metode_logo)):?>
                                                <img class="m-1" id="IMG-<?= $fetch_metode['ket']; ?>" style="background-color:white;border-radius: 3px;height:20px;padding:3px;" src="/assets/metode/<?= $fetch_metode_logo['img']; ?>">
                                                <?php endwhile;?>
                                                <a class="open-button-action-payment"><i class="fas fa-chevron-down"></i></a>
                                            </div>
                                        </div>
                                        <?php endif;?>
                                        <?php endwhile;?>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <input type="hidden" name="product" id="input-produk" value="">
                    <input type="hidden" name="harga" id="input-harga" value="">
                    <input type="hidden" name="method" id="input-metode" value="">
                    <?php if($_SESSION['user']['level'] == ""):?>
                    <div class="row mt-3">
                        <div class="col">
                            <div class="card bg-dark shadow">
                                <div class="card-header">
                                    <h5 class="card-title">Konfirmasi Pembayaran</h5>
                                </div>
                                <div class="card-body">
                                    <div class="form-group mb-3">
                                        <label for="wa">Nomor Whatsapp</label>
                                        <input class="form-control" placeholder="Nomor Whatsapp [628xxxxx]" type="number" name="wa" id="wa" required="">
                                    </div>
                                        <div class="w-100">
                                            <button type="button" onclick="submit_order();" class="btn btn-primary w-100 btn-lg"><i class="fas fa-cart-arrow-down"></i>Order Now</button>
                                        </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <?php else:?>
                    <div class="row mt-3 mb-3">
                        <div class="col-lg-12 clearfix">
                            <div class="w-100">
                                    <button type="button" onclick="submit_order();" class="btn btn-primary w-100 btn-lg"><i class="fas fa-cart-arrow-down"></i>Order Now</button>
                            </div>
                        </div>
                    </div>
                    <?php endif;?>
                </div>
            </div>
        </form>
<?php include '../../layouts/footer.php';?>
<div class="modal fade" id="petunjukModal" tabindex="-1" aria-labelledby="petunjukModal" role="dialog">
        <div class="modal-dialog modal-dialog-centered">
            <div class="modal-content">
                <div class="modal-header bg-dark">
                    <h5 class="modal-title text-white" id="petunjukModalLabel">Petunjuk</h5>
                    <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="text-shadow: none; color:white;">&times;</span></button>
                </div>
                <div class="modal-body bg-dark">
                    <div class="text-center">
                        <img src="<?= $petunjuk?>" class="img-fluid">
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php if($fetch_games['validate_id'] !== "Tydacks"):?>
    <div class="modal fade text-left" id="modal-detail-user-detail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true" data-backdrop="static">
        <div class="modal-dialog modal-dialog-centered" id="SModal-size" role="document">
            <div class="modal-content bg-dark">
                <div class="modal-header">
                    <h5 class="modal-title" id="SModal-title">Detail pesanan</h5>
                    <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="text-shadow: none; color:white;">&times;</span></button>
                </div>
                <div class="modal-body" id="SModal-body">
                    <p>Mohon konfirmasi Username anda sudah benar</p>
                    <table class="table">
                        <tr>
                            <th>Username</th>
                            <td id="mdu-user">-</td>
                        </tr>
                        <tr>
                            <th>ID</th>
                            <td id="mdu-target">-</td>
                        </tr>
                        <tr>
                            <th>Product</th>
                            <td id="mdu-product">-</td>
                        </tr>
                        <tr>
                            <th>Metode</th>
                            <td id="mdu-metode">-</td>
                        </tr>
                    </table>
                    <h5 style="padding: 10px 0;">Total pembayaran</h5>
                    <h2 style="float: right;margin-top: -39px;" class="text-warning" id="mdu-harga2">-</h2>
                    <button class="btn btn-primary w-100" type="button" onclick="orders();">Bayar Sekarang</button>
                </div>
            </div>
        </div>
    </div>   
    
    <div class="modal fade text-left" id="modal-detail-user-loading" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true" data-backdrop="static">
        <div class="modal-dialog modal-dialog-centered" id="SModal-size" role="document">
            <div class="modal-content bg-dark">
                <div class="modal-body">
                    <br>
                    <div class="text-center">
                        <img src="https://c.tenor.com/I6kN-6X7nhAAAAAj/loading-buffering.gif" width="80"><br><br>
                        <h5 class="modal-title text-center">Mohon Tunggu</h5>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php else:?>
    <div class="modal fade text-left" id="modal-detail-user-detail" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true" data-backdrop="static">
        <div class="modal-dialog modal-dialog-centered" id="SModal-size" role="document">
            <div class="modal-content bg-dark">
                <div class="modal-header">
                    <h5 class="modal-title" id="SModal-title">Detail pesanan</h5>
                    <button type="button" class="close" data-bs-dismiss="modal" aria-label="Close"><span aria-hidden="true" style="text-shadow: none; color:white;">&times;</span></button>
                </div>
                <div class="modal-body" id="SModal-body">
                    <p>Pastikan ID Player Sudah Benar</p>
                    <table class="table">
                        <tr>
                            <td>ID</td>
                            <td id="mdu-target">-</td>
                        </tr>
                        <tr>
                            <td>Product</td>
                            <td id="mdu-product">-</td>
                        </tr>
                        <tr>
                            <td>Metode</td>
                            <td id="mdu-metode">-</td>
                        </tr>
                    </table>
                    <h5 style="padding: 10px 0;">Total pembayaran</h5>
                    <h2 style="float: right;margin-top: -39px;" class="text-warning" id="mdu-harga2">-</h2>
                    <button class="btn btn-primary w-100" type="button" onclick="orders();">Bayar Sekarang</button>
                </div>
            </div>
        </div>
    </div>
    <?php endif;?>
    <script type="text/javascript">
    function orders(){
            $("#form-order").submit();
    }
    function submit_order(){
        var wa = $("#wa").val();
        var user = $("#target").val();
        var server = $("#server").val();
        var metode = $("#input-metode").val();
        var product = $("#input-produk").val();
        var harga = $("#input-harga").val();
        if (user == '' || server == '') {
            toastr.warning(`Harap mengisi semua data`, "Warning");
        } else if (product == '') {
            toastr.warning(`Harap memilih produk terlebih dahulu`, "Warning");
        } else if (metode == '') {
            toastr.warning(`Harap memilih metode terlebih dahulu`, "Warning");
        } else if(wa == ''){
            toastr.warning(`Form nomor Whatsapp belum di isi`, "Warning");
        } else {
            target = user;
            <?php if ($fetch_games['sistem_id'] !== 'user-id'): ?>
                target = user + ' (' + server +')';
            <?php endif; ?>
            if(user !== "" && server !== ""){
                var val = 'games=<?= $fetch_games['validate_id']; ?>&target='+user+'&server='+server;
            }else{
                var val = 'games=<?= $fetch_games['validate_id']; ?>&target='+user;
            }
            $("#mdu-target").text(target);
            $("#mdu-harga").text(harga);
            $("#mdu-harga2").text(harga);
            <?php if($fetch_games['validate_id'] == "Tydacks"):?>
            $('#modal-detail-user-detail').modal('show');
            <?php else:?>
            $.ajax({
                url: '<?= base_url('lynchstore/lib/games/get-detail.php');?>',
                data: val,
                type: 'POST',
                dataType: 'JSON',
                beforeSend: function() {
                        $("#modal-detail-user-loading").modal('show');
                    },
                error: function() {
                        Swal.fire('Gagal', 'Gagal', 'error');
                },
                success: function(result) {
                    if (result.data.nickname) {
                        var nick = decodeURIComponent(result.data.nickname).replace(/[+]/g, " ");
                        $("#modal-detail-user-loading").modal('hide');
                        $("#mdu-user").text(nick);
                        $('#modal-detail-user-detail').modal('show');
                        Swal.fire('Success!', 'ID Player Ditemukan', 'success');
                    }else{
                        $("#modal-detail-user-loading").modal('hide');
                        Swal.fire("Gagal",result.message,'error');
                    }
                }
            });
            <?php endif;?>
        }
    }
    </script>
<script type="text/javascript">
        $("#zoneID").change(function (){
            url = "<?= base_url(); ?>id/ajax/select_prepaid.php?id="+$('#zoneID').val();
            $('#produk').load(url);
            //console.log(url);
            return false;
        });
        $('#wa').on('input', function() {
                if (this.value.startsWith('08')) {
                    this.value = "628";
                }
                this.value = this.value.replace(/[^0-9.]/g, '').replace(/(\..*?)\..*/g, '$1');
            });
        function pilih_produk(id) {
            $.ajax({
                url: '<?= base_url(); ?>id/ajax/get-harga.php',
                data: 'produk=' + id,
                type: 'POST',
                dataType: 'JSON',
                success: function(result) {
                    
                    $("#input-produk").val(id);
                    
                    for(var i = 0; i < result.length; i++) {
                        $("#payment-" + result[i].id).html(result[i].harga);
                        $("#payment-" + result[i].id).attr('data-harga', result[i].harga);
                        $("#mdu-product").text(result[i].produk);
                    }
                }
            });
        }
        function pilih_metode(id) {
            $(".button-action-payment>ul").map(function(){if($(this).children().length == 0){$(this).parent().parent().remove();}});
            $("input[type='radio'][name='metode']").change(function() {
                if ($(this).is(":checked")) {
                    $("li.active").removeClass("active")
                    $(this).parent('li').addClass("active")
                    $("#input-metode").val(id);
                    $("#input-harga").val($("#payment-" + id).attr('data-harga'));
                    $.ajax({
                        url: "<?= base_url('ajax/metode.php');?>",
                        type: 'POST',
                        dataType: 'JSON',
                        data: 'metode_id='+ id,
                        success: function(result) {
                            for(var i = 0; i < result.length; i++) {
                                $("#mdu-metode").text(result[i].metode);
                            }
                        }
                    });
                }
            })
        }
            function openPayment(elem) {
            var $this = $(elem);
            $('.payment-drawwer').not(this).each(function() {
                var today = new Date();
                var pp = today.getHours();
                var $parents = $(this);
                $parents.find('.button-action-payment').slideUp(function() {
                    $parents.removeClass('active');
                });

                $parents.find('.short-payment-support-info').find('img').slideDown();
                $parents.find('.short-payment-support-info').find('.fa-chevron-up').removeClass('fa-chevron-up').addClass(
                    'fa-chevron-down');
            });

            var $parents = $this.parents('.child-box');
            if (!$parents.find('.button-action-payment').is(":hidden")) {
                $parents.find('.button-action-payment').slideUp(function() {
                    $parents.removeClass('active');
                });

                $parents.find('.short-payment-support-info').find('img').slideDown();
                $parents.find('.short-payment-support-info').find('.fa-chevron-up').removeClass('fa-chevron-up').addClass(
                    'fa-chevron-down');

            } else {
                $parents.find('.button-action-payment').slideDown(function() {
                    $parents.addClass('active');
                });
                $parents.find('.short-payment-support-info').find('img').slideUp();
                $parents.find('.short-payment-support-info').find('.fa-chevron-down').addClass('fa-chevron-up').removeClass(
                    'fa-chevron-down');

            }
        }
    </script>