<?php

include_once "../view/partials/template/message.php";
include_once "../view/partials/banner/bannerShoppingCart.php";
if (in_array(96, explode(",", $getItemsCart[0]['evenmepa']))) {
    include_once "../view/partials/template/nequipopup.php";
}
?>


<div class="event-facility pt-3">
    <div class="container">
        <div class="row">
            <div class="col-lg-12">

                <div class="checkout-widget checkout-contact">

                    <h5 class="title">Paga tus boletos reservados</h5>
                    <div class="table-responsive">
                        <table id="dTable" class="table table-hover table-light table-striped table-bordered" style="width:100%">
                            <thead>
                                <tr>
                                    <!--
                                    <th>Evento</th>
                                    -->
                                    <th>Detalles</th>
                                    <th>Total</th>
                                    <th>Pagar</th>
                                </tr>
                            </thead>
                            <tbody>
                                <script>
                                    let mp;
                                </script>
                                <?php
                                $num = 1;
                                //print_r($getItemsCart);
                                foreach ($getItemsCart as $gic) {
                                    //print_r($gic);
                                    $valorTotal = $gic['orcovalo'] * $gic['orcocabo'];
                                    // $hash = $gic['orcotoke'].$valorTotal."00COPtest_integrity_HXrmrppR0wW9yQWZknFYkSLEvq2hML3x";
                                    $hash = $gic['orcotoke'] . $valorTotal . "00COPprod_integrity_moiYKKdS60A3ugUO9GPjrV1pZM9i16zX";

                                    $hashCrypt = hash("sha256", $hash);

                                    #Incluyo controlador mercado pago para instancia a servicio
                                    # Genero el arreglo para su consumo
                                    $array = [
                                        'evennomb' => $gic['evennomb'],
                                        'locanomb' => $gic['locanomb'],
                                        'orcocabo' => $gic['orcocabo'],
                                        'orcovalo' => $gic['orcovalo'],
                                        'orcotoke' => $gic['orcotoke'],
                                        'moneda'   => $gic['cavaaux2']
                                    ];

                                    # Genero la referencia de pago por medio del botón
                                    if (in_array(59, explode(",", $gic['evenmepa'])))
                                        $idReference = $mPago->showMercadoPagoButton($array);

                                ?>
                                    <tr>
                                        <!--
                                        <td><a href="<?= getUrl("events", "Events", "eventDetails", array("idE" => $gic['evenid'])); ?>" style="width:150px;"><img class="img-thumbnail" src="<?= $gic['evenimg1']; ?>"></a></td>
                                        -->
                                        <td>
                                            <?= $gic['evennomb'] . "<br>" . $gic['locanomb']; ?><br>
                                            <a href="<?= getUrl("events", "Events", "eventDetails", array("idE" => $gic['evenid'])); ?>" style="width:80px;"><img class="img-thumbnail" src="<?= $gic['evenimg1']; ?>"></a>
                                        </td>
                                        <td>Cantidad: <?= $gic['orcocabo'] . "<br> Valor unitario: $" . number_format($gic['orcovalo'], 0, ",", ".") . "<br> Moneda: " . $gic['cavaaux2'] . "<hr>Total a pagar:<b> $" . number_format($valorTotal, 0, ",", ".") . "</b>"; ?></td>
                                        <!-- data-public-key="pub_test_eK1pwqYW816XR9yHTsC2VOCOPyXMbJr4"    -->
                                        <td style="vertical-align: middle;">
                                            <?php
                                            if (in_array(60, explode(",", $gic['evenmepa']))) {
                                                $randNumber = random_int(1, 99);
                                            ?>

                                                <form>
                                                    <script src="https://checkout.wompi.co/widget.js" data-render="button" data-public-key="pub_prod_rZH93NcxiwpGU6weiXJysGuujJj173Gz" data-currency="<?= $gic['cavaaux2']; ?>" data-amount-in-cents="<?= $valorTotal . "00"; ?>" data-reference="<?php echo $gic['orcotoke'] . '-' . $randNumber; ?>" data-signature:integrity="<?= $hashCrypt; ?>" data-redirect-url="<?= "https://secure.boletosqubit.co/" . getUrl("shoppingCart", "ShoppingCart", "getWompiPayResponse", array("tokenCompra" => $gic['orcotoke'])); ?>">
                                                    </script>
                                                    <script>

                                                    </script>


                                                </form>

                                                <br>
                                            <?php

                                            }
                                            ?>
                                            <?php
                                            if (in_array(59, explode(",", $gic['evenmepa']))) {
                                            ?>
                                                <div class="cho-container-<?= $num; ?> my-5"></div>
                                                <script src="https://sdk.mercadopago.com/js/v2"></script>
                                                <script>
                                                    mp = new MercadoPago('APP_USR-77d62918-103a-44a6-b876-9a8d1fe06278', {
                                                        locale: 'es-CO'
                                                    });

                                                    // mp = new MercadoPago('TEST-9824a20c-57be-41c6-a9dd-f3ac037f1d89', {
                                                    //     locale: 'es-CO'
                                                    // });

                                                    mp.checkout({
                                                        preference: {
                                                            id: '<?= $idReference; ?>'
                                                        },
                                                        render: {
                                                            container: '.cho-container-<?= $num; ?>',
                                                            type: 'billetera',
                                                            label: 'MercadoPago',
                                                        },
                                                        theme: {
                                                            headerColor: "#8e44ad",
                                                            elementsColor: "#8e44ad",
                                                        }
                                                    });
                                                </script>
                                                <br>
                                            <?php

                                            }
                                            ?>
                                            <!-- Inicio del if de Freepay JFMI 07 jul 2022-->
                                            <?php
                                            if (in_array(74, explode(",", $gic['evenmepa']))) {
                                            ?>

                                                <!-- Registro del pago aprobado -->
                                                <a type="submit" id="btn_free" class="btn btn-block btn-success" data-url="" href="<?= getUrl("shoppingCart", "ShoppingCart", "getFreepayApproved", array("orcoid" => $gic['orcoid'], "orcotoke" => $gic['orcotoke'])); ?>" value="Pago Gratis"> Page Gratis Aquí </a>
                                                <br>
                                                <!-- Fin del if de Freepay -->
                                            <?php

                                            }
                                            ?>

                                            <!-- Inicio Nequi -->

                                            <?php
                                            if (in_array(96, explode(",", $gic['evenmepa']))) {
                                            ?>

                                                <!-- Registro del pago Nequi -->
                                                <a type="submit" id="btn_nequi" class="btn btn-block btn-success" data-url="" href="javascript:throwNequiModal('<?= $_SESSION['id']; ?>','<?= $_SESSION['celular']; ?>','<?= $gic['orcotoke']; ?>','<?= $valorTotal; ?>','<?= $gic['locanomb']; ?>');"> Page Nequi </a>
                                                <br><br>
                                                <!-- Fin del if de Nequi -->
                                            <?php

                                            }
                                            ?>
                                            <a type="submit" id="btn_cancel" class="btn btn-block btn-danger" data-url="" href="<?= getUrl("shoppingCart", "ShoppingCart", "cancelaOrdenCompra", array("orcotoke" => $gic['orcotoke'])); ?>" value="Cancelar Orden">Cancelar Orden</a>

                                        </td>
                                    </tr>
                                <?php $num += 1;
                                } ?>
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
            <div class="row padding-bottom pt-5">

                <?php include_once "../view/partials/template/sponsors.php"; ?>

            </div>
        </div>
    </div>
</div>