<?php

session_start();
/* REQUITE TODAS AS CLASSES NECESSARIAS */

include '../vendor/autoload.php';
/* ABRE A CLASSE GERENCIANET */
include "../conn/conexao.php";

//echo "Sessao=".$_SESSION["ID"];

use Gerencianet\Exception\GerencianetException;
use Gerencianet\Gerencianet;

$idPedido = 0;

if (isset($_GET["ID"])) {
    $idPedido = $_GET["ID"];
}
/* ADICIONA O JSON QUE CONTEM client_id & client_secret */
$file = file_get_contents('../config.json');
$options = json_decode($file, true); // $charge_id refere-se ao ID da transação gerada anteriormente

$situacao = "";
$params = [
    'id' => $idPedido
];




try {
    $api = new Gerencianet($options);
    $charge = $api->detailCharge($params, []);
    $boleto = ($charge['data']['payment']);
    $metodo=$boleto["banking_billet"];
    $url=$metodo["link"];
    echo "<script>location.href='$url';</script>";
  //  echo $url;
 //   print_r($charge);
} catch (GerencianetException $e) {
    print_r($e->code);
    print_r($e->error);
    print_r($e->errorDescription);
} catch (Exception $e) {
    print_r($e->getMessage());
}
?>