<?php

  require 'vendor/autoload.php';
  
  $access_token = 'TEST-3311809027950880-061115-e08e384a6c5151c92ddf1f5b4b0e3d66-774035859';           

  MercadoPago\SDK::setAccessToken('TEST-3311809027950880-061115-e08e384a6c5151c92ddf1f5b4b0e3d66-774035859'); 

  
  $preference = new MercadoPago\Preference();
 
  //"https://directoriofitness.com.mx/estaciones/Progymcloud_app/php/mercado_pago/index.php?bd=${widget.bd}&
  //flag=4&id_cliente=${widget.idCliente}&concepto=${widget.plan}&costo=${widget.costo}&idLocker=${widget.locker}
  //&lock_asig=${widget.lockerAsig}&suc=${widget.sucursal}&tipo=locker" 
  
    $bd = $_GET['bd'];
    
    $id_cliente = $_GET['id_cliente'];
    
    $id_servicio = $_GET['plan'];
    
    $plan = $_GET['plan'];
    
    $importe = $_GET['importe'];
    
    $nombre = $_GET['nombre'];
    
    $apellido = $_GET['apellido'];
    
    $fechaN = $_GET['fechaN'];
    
    $email = $_GET['email'];
    
    $tel = $_GET['telefono'];
    
    $domi = $_GET['domi'];
    
    $col = $_GET['colonia'];
    
    $cp = $_GET['cp'];
    
    $genero = $_GET['genero'];
    
    $fechaR = $_GET['fechaR'];
    
    $sucursal = $_GET['sucursal'];
    
    $qr = $_GET['qr'];
    
  //bd=${widget.bd}&flag=4&id_cliente=${widget.idCliente}&concepto=${widget.plan}&costo=${widget.costo}&
  //idLocker=${widget.locker}&lock_asig=${widget.lockerAsig}&suc=${widget.sucursal}&tipo=locker
  
      $url_redirect = 'directoriofitness.com.mx/estaciones/Progymcloud_app/php/mercado_pago/successVisit.php?error=0&bd='.$bd.'&id_cliente='.$id_cliente.'&plan='.$plan.'&importe='
    .$importe.'&nombre='.$nombre.'&apellido='.$apellido.'&fechaN='.$fechaN.'&email='.$email.'&telefono='.$tel.'&domi='.$domi
    .'&colonia='.$col.'&cp='.$cp.'&genero='.$genero.'&fechaR='.$fechaR.'&sucursal='.$sucursal.'&qr='.$qr;
  
  # Building an item
  $preference->back_urls = array(
      "success" => $url_redirect,
      "failure" => "directoriofitness.com.mx/estaciones/Progymcloud_app/php/mercado_pago/failure.php?error=1",
      "pending" => "directoriofitness.com.mx/estaciones/Progymcloud_app/php/mercado_pago/failure.php?error=2"
  );
  
  $item = new MercadoPago\Item();
  $item->id = "00001";
  $item->title = "pago mercado libre"; 
  $item->quantity = 1;
  $item->unit_price = $importe;
  
  $preference->items = array($item);
  
  $preference->save(); # Save the preference and send the HTTP Request to create
  
  //echo json_encode($preference);
  # Return the HTML code for button
 //{"id":775498255,"nickname":"TESTBOISC5EI","password":"qatest8511",
 //"site_status":"active","email":"test_user_54574451@testuser.com"} //vendedor
 
 //{"id":775498915,"nickname":"TETE2436608","password":"qatest785",
    //"site_status":"active","email":"test_user_82460305@testuser.com"} //comprador
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    .padre {

    padding: 0 1rem;
    margin: 1rem;
    }

    .hijo {
        /* IMPORTANTE */
        width: 200px;
        margin-left: auto;
        margin-right: auto;
    }
    .recibo{
        border-style: ridge;
    }
    .boton{
        text-align: center; 
    }
</style>
<body>
    <div classs="padre">
        <div class="hijo">
            <form action="/procesar-pago" method="POST" id="myform" name="myform"> 
                </p class="boton"><script
                    src="https://www.mercadopago.com.mx/integrations/v1/web-payment-checkout.js"
                    data-preference-id="<?= $preference->id ?>"> 
                    
                </script>  </p>
            </form>
            
            <!-- Inicializa el checkout -->
            
            
        </div>
    </div>
</body>
</html>