<?
    require_once "/var/www/html/track/tools/FlowApi.class.php";
    require_once "/var/www/html/track/func/fn_st_flow_common.php";
    //Prepara el arreglo de datos
    $params = array(
        "token" => $_POST["token"]
    );
    //Define el metodo a usar
    $serviceName = "payment/getStatus";
    try {
        // Instancia la clase FlowApi
        $flowApi         = new FlowApi();
        // Ejecuta el servicio
        $response        = $flowApi->send($serviceName, $params, "GET");
        $optional        = shortDecode($response["optional"]["Firma"]);
        $optional        = setOptionalParamsKeys($optional);
        $paymentData     = $response["paymentData"];
        $redirect        = $gsValues["URL_ROOT"];
        $date          = $paymentData["date"];
        $amount        = $response["amount"];
        $currency      = $paymentData["currency"] ?? "";
        $media         = $paymentData["media"];
        $subject       = $response["subject"];
        $btnURL        = $gsValues["URL_ROOT"] . "/tracking.php";
    } catch (Exception $e) {
        echo $e->getCode() . " - " . $e->getMessage();
    }
    if ($response["status"] == 2) {
      $page = "
         <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'>
             <link rel='icon' type='image/x-icon' href='/track/favicon.ico'>
             <title>¡Transacción Exitosa!</title>
             <style>
                 .btn {
                     display: inline-block;
                     padding:1em;
                     margin: 1rem auto;
                     color: #FFFFFF;
                     background-color: #9CC602;
                     border-radius: 1em;
                     text-decoration: none;
                     font-size: 1.2rem;
                     opacity: .85;
                     transition: opacity ease-in-out .3s;
                 }
                 .btn:hover {
                     opacity: 1;
                 }
             </style>
         </head>
         <body style='padding:0;margin:0;'>
             <main
                 align='center'
                 style='
                     background-color:#f7f7f7;
                     min-height:100vh;
                     display:flex;
                     justify-content:center;
                     align-items:center;
                 '
             >
                 <div align='center'>
                     <div align='center'>
                         <img
                             src='https://www.gpsimple.cl/track/img/logo.png'
                             align='center'
                             width='250'
                         >
                     </div>
                     <br/>
                     <br/>
                     <div
                         style='
                             margin-top:15px;
                         '
                         align='center'
                     >
                         <font
                             color='#0097D5'
                             face='Helvetica'
                             size='5'
                         >
                             ¡Muchas gracias!
                             <br/>
                             ¡Su compra fué realizada con <strong>éxito!</strong>
                         </font>
                     </div>
                     <div
                         style='
                             font-size:15px;
                             font-style: italic;
                             margin-top:3em;
                             margin-bottom:3em;
                         '
                         align='center'
                     >
                         Fecha de Pago: $date
                     </div>
                     <div
                         align='center'
                     >
                         <div align='center'>
                             <font
                                 style='
                                     font-size:12pt;
                                     font-family:Helvetica;
                                 '
                             >
                                 Tu pago de $$amount $currency por
                                 $subject por medio de
                                 $media fué exitoso!
                             </font>
                         </div>
                         <div align='center'>
                             <a
                                 href='$btnURL'
                                 class='btn'
                             >
                                 Volver a GPSimple
                             </a>
                         </div>
                     </div>
                 </div>
             </main>
         </body>
      ";
    } else {
      $page = "
        <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'>
            <link rel='icon' type='image/x-icon' href='/track/favicon.ico'>
            <title>Transacción Fallida</title>
            <style>
                .btn {
                    display: inline-block;
                    padding:1em;
                    margin: 2rem auto;
                    color: #FFFFFF;
                    background-color: #0097D5;
                    border-radius: 1em;
                    text-decoration: none;
                    font-size: 1.2rem;
                    opacity: .85;
                    transition: opacity ease-in-out .3s;
                }
                .btn:hover {
                    opacity: 1;
                }
            </style>
        </head>
        <body style='padding:0;margin:0;'>
            <main
                align='center'
                style='
                    background-color:#f7f7f7;
                    min-height:100vh;
                    display:flex;
                    justify-content:center;
                    align-items:center;
                '
            >
                <div align='center'>
                    <div align='center'>
                        <img
                            src='https://www.gpsimple.cl/track/img/logo.png'
                            align='center'
                            width='250'
                        >
                    </div>
                    <br/>
                    <br/>
                    <div
                        style='
                            margin-top:1rem;
                            margin-bottom:3rem;
                        '
                        align='center'
                    >
                        <font
                            color='#F26444'
                            face='Helvetica'
                            size='5'
                        >
                                ¡Lo sentimos!
                            <br/>
                            El pago de su compra ha <strong>fallado.</strong>
                        </font>
                    </div>
                    <div
                        align='center'
                    >
                        <div align='center'>
                            <font
                                style='
                                    font-size:12pt;
                                    font-family:Helvetica;
                                '
                            >
                                Tu pago de $$amount $currency por
                                $subject ha fallado.
                            </font>
                        </div>
                        <div
                            align='center'
                        >
                            <a
                                href='$btnURL'
                                class='btn'
                            >
                                Volver a GPSimple
                            </a>
                        </div>
                    </div>
                </div>
            </main>
        </body>
      ";
    }
?>
<!DOCTYPE html>
<html lang="es">
  <?=$page?>
</html>