<?php
    
    
    
    $seller_id = '251206854467';
    $publishable_key = '6965F831-0BFC-4545-A657-1EFA995FAE42';
    $private_key = '3BEFBF06-BF47-4939-9300-82CB343C8E97';
    $currency_code = 'mxn'; 
    
    //4111111111111111
    $localhost = "directoriofitness.com.mx";
    $user = "direct18";
    $passwd = "L4LL4v3M@3str@";
    $bd = $_GET['bd'];
    $flag = $_GET['flag'];
    $id_cliente = $_GET['id_cliente'];
    $id_servicio = $_GET['id_servicio'];
    $costo;
    $plan;
    $concepto;
    $idLocker;
    $lock_asig;
    $sucursal;
    $tipo = $_GET['tipo'];
    $paquete_clase;
    $fecha_visita;
    $opcion;
    $send_php; 
    
    if($tipo == 'planes'){
        $paquete_clase = $_GET['paquete_clase'];
        $fecha_visita = $_GET['fecha_visita'];
        $id_servicio = $_GET['id_servicio'];
        //$costo = $_GET['importe'];
        $plan = $_GET['plan'];
        $costo = $_GET['importe'];
        $opcion =$_GET['opcion'];
    }
    if($tipo == 'locker'){
        
        $concepto = $_GET['concepto'];
        $idLocker = $_GET['idLocker'];
        $lock_asig = $_GET['lock_asig'];
        $sucursal = $_GET['suc'];
        $costo = $_GET['costo'];
        $opcion = $_GET['opcion'];

    }
    
?>

<!DOCTYPE html>
<html lang="es">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Forma de Pago</title>
    
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    
    <script type="text/javascript" src="https://www.2checkout.com/checkout/api/2co.min.js"></script>
    <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.0/jquery.min.js"></script>
    <script src="https://code.jquery.com/jquery-3.4.1.min.js" integrity="sha256-CSXorXvZcTkaix6Yvo6HppcZGetbYMGWSFlBw8HfCJo=" crossorigin="anonymous"></script>
    
    <script defer src="https://use.fontawesome.com/releases/v5.0.13/js/solid.js" integrity="sha384-tzzSw1/Vo+0N5UhStP3bvwWPq+uvzCMfrN1fEFe+xBmv1C/AtVX5K0uZtmcHitFZ" crossorigin="anonymous"></script>
    <script defer src="https://use.fontawesome.com/releases/v5.0.13/js/fontawesome.js" integrity="sha384-6OIrr52G08NpOFSZdxxz1xdNSndlD4vdcf/q2myIUVO0VsqaGHJsB0RaBE01VTOY" crossorigin="anonymous"></script>
    
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    
    <!-- LAS ALERTAS -->
<script src="https://unpkg.com/sweetalert/dist/sweetalert.min.js"></script>
<!-- Popper.JS -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.0/umd/popper.min.js" integrity="sha384-cs/chFZiN24E4KMATLdqdvsezGxaGsi4hLGOzlXwp5UZB1LY//20VyM2taTB4QvJ" crossorigin="anonymous"></script>
<!-- Bootstrap JS -->
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.0/js/bootstrap.min.js" integrity="sha384-uefMccjFJAIv6A+rW+L4AHf99KvxDjWSu1z9VI8SKNVmz4sk7buKt/6v9KI65qnm" crossorigin="anonymous"></script>

    
</head>
<style>
body{
    background-color: #079AF3;
}
div.form
{
    display: block;
    text-align: center;
}
form
{
    border-radius: 15px;
    margin-top: 35px;
    background-color: #FFFFFF;
    display: inline-block;
    margin-left: auto;
    margin-right: auto;
    padding: 15px;
    text-align: left;
}
</style>
<body>

    <div class="form">
        
        <form id="myCCForm" action= "payment_planes.php" method="post">
            
            <input id="token" name="token" type="hidden" value="">
            <input value="<?= $bd ?>" name="bd" type="hidden" id="">
            <input value="<?= $id_cliente ?>" name="id_cliente" type="hidden" id="">
            <input value="<?= $id_servicio ?>" name="id_servicio" type="hidden" id="">
            <input value="<?= $plan ?>" name="plan" type="hidden" id="">
            <input value="<?= $tipo ?>" name="tipo" type="hidden" id="">
           
        <?php 
            if($tipo == 'planes'){ 
        ?>
                <input value="<?= $paquete_clase ?>" name="paquete_clase" type="hidden" id="">
                <input value="<?= $fecha_visita ?>" name="fecha_visita" type="hidden" id="">
                <input value="<?= $costo ?>" name="costo" type="hidden" id="">
                <input value="<?= $opcion ?>" name="opcion" type="hidden" id="">

        <?php }else{ ?>
            <input value="<?= $concepto ?>" name="concepto" type="hidden" id="">
            <input value="<?= $idLocker ?>" name="idLocker" type="hidden" id="">
            <input value="<?= $lock_asig ?>" name="lock_asig" type="hidden" id="">
            <input value="<?= $sucursal ?>" name="sucursal" type="hidden" id="">
            <input value="<?= $costo ?>" name="costo" type="hidden" id="">
            <input value="<?= $opcion ?>" name="opcion" type="hidden" id="">
            
        <?php } ?>

            <div class="mb-2">
                <label for="lbInputTarget" class="form-label">Numero de Tarjeta</label>
                <input id="ccNo" type="number" size="20" value="" autocomplete="off" class="form-control" id="lbInputTarget" aria-placeholder="4242 4242 4343 4343" required />
            </div>
            <div class="row g-3">
                <label for="expMonth" class="form-label">Fecha de Vencimiento (MM/YY)</label>
              <div class="col">
                 <input type="number" id="expMonth" class="form-control" aria-label="11" placeholder="11"  required /> 
                <!--<input type="text" class="form-control" placeholder="First name" aria-label="First name">-->
              </div>
              <div class="col">/</div>
              <div class="col" style="margin-left:-150px;">
                <input type="number" id="expYear" class="form-control" aria-label="25" placeholder="25"  required /> 
              </div>
            </div>
            
            <div class="row mt-2">
              
                <div class="col-sm-6" >
                    <div class="row">
                        <label for="lbInputfv" class="form-label">CVC</label>
                        <div class="col-sm-4">
                             
                            <input id="cvv" size="4" type="number" value="" autocomplete="off" class="form-control" id="lbInputcvv" aria-describedby="123" required />
                         </div>
                    </div>
                </div>
            
            </div>
            <div class="mt-2">
                <input type="submit" class="btn btn-primary" value="Pagar">
            </div>
            
        </form>
    </div>
    <script>
        // Called when token created successfully.
        var successCallback = function(data) {
            console.log(data);
            var myForm = document.getElementById('myCCForm');
    
            // Set the token as the value for the token input
            myForm.token.value = data.response.token.token;
    
            // IMPORTANT: Here we call `submit()` on the form element directly instead of using jQuery to prevent and infinite token request loop.
            myForm.submit();
        };
    
        // Called when token creation fails.
        var errorCallback = function(data) {
            if (data.errorCode === 200) {
                console.log('error ' + data);
                tokenRequest();} else {alert(data.errorMsg);}
        };
    
        var tokenRequest = function() {
            // Setup token request arguments
            var args = {
                sellerId: "251206854467",
                publishableKey: "6965F831-0BFC-4545-A657-1EFA995FAE42",
                ccNo: $("#ccNo").val(),
                cvv: $("#cvv").val(),
                expMonth: $("#expMonth").val(),
                expYear: $("#expYear").val()
            };
    
            // Make the token request
            TCO.requestToken(successCallback, errorCallback, args);
        };
    
        $(function() {
            // Pull in the public encryption key for our environment
            TCO.loadPubKey('production');//production
    
            $("#myCCForm").submit(function(e) {
                // Call our token request function
                swal("Estamos Realizando la Transaccion! \nEspere por favor, Gracias...", { button: false, icon: "warning",});
                tokenRequest();
    
                // Prevent form from submitting
                return false;
            });
        });
    </script>
</body>
</html>