<html>
    <head>
        <meta charset="utf-8" />
        <meta
            name="viewport"
            content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0"
            />

        <!--        <link
                    rel="shortcut icon"
                    href="https://goSellJSLib.b-cdn.net/v1.6.0/imgs/tap-favicon.ico"
                    />-->
        <link
            href="<?= base_url() ?>public/plugins/goSell/gosell.css"
            rel="stylesheet"
            />
        <link href="<?php echo base_url() ?>public/plugins/global/plugins.bundle.css" rel="stylesheet" type="text/css" />
        <link href="<?= base_url() ?>public/plugins/custom/prismjs/prismjs.bundle.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo base_url() ?>public/css/style.bundle_front.css" rel="stylesheet" type="text/css" />
        <link href="<?php echo base_url() ?>public/css/prepay.css" rel="stylesheet" type="text/css" />
        <!--end::Global Theme Styles-->
        <!--begin::Layout Themes(used by all pages)-->
        <link href="<?php echo base_url() ?>public/css/skins/header/base/light.css?v=7.0.4" rel="stylesheet" type="text/css" />
        <link href="<?php echo base_url() ?>public/css/skins/header/menu/light.css?v=7.0.4" rel="stylesheet" type="text/css" />
        <link href="<?php echo base_url() ?>public/css/skins/brand/dark.css?v=7.0.4" rel="stylesheet" type="text/css" />
        <!--end::Layout Themes-->
        <link rel="shortcut icon" href="assets/media/logos/favicon.ico" />
        <title><?= $this->config->item('company_title') . ' | Payment' ?></title>
        <style>
            .success_icon,.error_icon{
                display: none;
                margin-bottom: 1rem;
            }
        </style>
    </head>
    <body id="kt_body" class="page-header-fixed page-container-bg-solid <?= $this->session->userdata('language') == 'arabic' ? 'rtl' : '' ?>" style="background-color: rgb(231, 236, 241);">

        <div class="container">
            <div class="d-flex flex-row mt-10">
                <div class="col-md-3"></div>
                <div class="col-md-6">
                    <!--begin::Profile Card-->
                    <div class="card card-custom card-stretch text-center">
                        <h2 class="mt-4 mb-4 <?= isset($knet_gateway) && $response['PAYMENT_STATUS'] == 'successful' ? 'alert-success' : '' ?> 
                            <?= isset($knet_gateway) && $response['PAYMENT_STATUS'] != 'successful' ? 'alert-danger' : '' ?>" id="payment_result"> 
                            <?php if (!isset($knet_gateway) || (isset($knet_gateway) && $response['PAYMENT_STATUS'] == 'successful')) { ?>
                                <i class="fas fa-check-circle text-success fa-2x success_icon"></i> 
                            <?php } ?>
                            <?php if (!isset($knet_gateway) || (isset($knet_gateway) && $response['PAYMENT_STATUS'] != 'successful')) { ?>
                                <i class="fas fa-times-circle text-danger fa-2x error_icon"></i> 
                            <?php } ?>
                            Payment <span id="payment_status"></span> <br/> <span id="status_desc"><?= isset($knet_gateway) ? $response['PAYMENT_STATUS'] : '' ?></span></h2>

                        <table class="table table-hover table-bordered mt-5">
                            <tr>
                                <td><?= $this->lang->line('transaction_id') ?></td>
                                <td id="trans_id"><?= isset($knet_gateway) && $response['STATUS'] == 'success' ? $response['TRANSACTION_ID'] : '' ?></td>
                            </tr>
                            <?php if (isset($knet_gateway)) { ?>
                                <tr>
                                    <td><?= $this->lang->line('reference_num') ?></td>
                                    <td id="trans_id"><?= isset($knet_gateway) ? $response['REFERENCE_ID'] : '' ?></td>
                                </tr>
                            <?php } ?>
                            <tr>
                                <td><?= $this->lang->line('amount') ?></td>
                                <td id="amount"><?= isset($knet_gateway) ? $response['AMOUNT'] : '' ?></td>
                            </tr>
                            <tr>
                                <td><?= $this->lang->line('description') ?></td>
                                <td id="desc"><?php
                                    if (isset($knet_gateway)) {
                                        $desc = $response['USER_DEFINED_VAR_2'] == 0 ? 'invoice' : $order->desc;
                                        echo $desc;
                                    }
                                    ?></td>
                            </tr>
                            <tr>
                                <td><?= $this->lang->line('client_name') ?></td>
                                <td id="client_name"><?= isset($knet_gateway) ? $order->username : '' ?></td>
                            </tr>
                            <tr>
                                <td><?= $this->lang->line('time') ?></td>
                                <td id="time"><?= isset($knet_gateway) ? date('Y-m-d H:i:s') : '' ?></td>
                            </tr>
                        </table>
                    </div>
                </div>
                <div class="col-md-3"></div>
            </div>
        </div>
    </body>

    <script
        type="text/javascript"
        src="<?= base_url() ?>public/plugins/goSell/gosell.js"
    ></script>

    <div id="root"></div>



    <script src="<?php echo base_url() ?>public/plugins/global/plugins.bundle.js?v=7.0.4"></script>
    <?php if (!isset($knet_gateway)) { ?>
        <script>

    <?php
    if (isset($response)) {
        ?>
                if ("<?= $response->callback->acquirer->response->message ?>" == 'Approved') {
                    $("#payment_result").removeClass('alert-danger');
                    $("#payment_result").addClass('alert-success');
                    $(".success_icon").show();
                } else {
                    $("#payment_result").removeClass('alert-success');
                    $("#payment_result").addClass('alert-danger');
                    $(".error_icon").show();
                }
                $("#payment_status").text("<?= $response->callback->acquirer->response->message ?>");
                $("#status_desc").text("<?= $response->callback->response->message ?>");
                $("#trans_id").text("<?= $response->callback->id ?>");
                $("#amount").text("<?= $response->callback->amount . ' ' . $response->callback->currency ?>");
                $("#desc").text("<?= $response->callback->description ?>");
                $("#client_name").text("<?= $response->callback->customer->first_name ?>");
                $("#time").text("<?= $this->session->userdata('language') == 'arabic' ? date('H:i:s Y/m/d', strtotime($pay_time)) : date('Y/m/d H:i:s', strtotime($pay_time)) ?>");
    <?php } ?>
            goSell.showResult({
                callback: response => {
                    $.ajax({
                        type: "POST",
                        url: "<?php echo base_url() ?>payment/save_response",
                        data: {'response': response},
                    });
                    // console.log(response);
                }
            });

        </script>
    <?php } ?>
</body>
</html>
