<?php
session_start();
$curl = curl_init();

curl_setopt_array($curl, array(
  CURLOPT_URL => 'https://valorcultural.com.br//wp-json/wc/v3/orders/'.$_GET['order_id'],
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_ENCODING => '',
  CURLOPT_MAXREDIRS => 10,
  CURLOPT_TIMEOUT => 3,
  CURLOPT_FOLLOWLOCATION => true,
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
  CURLOPT_CUSTOMREQUEST => 'GET',
  CURLOPT_HTTPHEADER => array(
    'Authorization: Basic Y2tfZWRhNTM2MmYxMjUxOGQwMmZkNTc4MWY3OWZjZDA2OTNiZjU4ZmRhODpjc19kNGM2ZTY2NGRkMjc0NTg1N2E1NGYyNDQwNmU1YzgxZDQyMjcyNTQ2'
  ),
));

$response = curl_exec($curl);

curl_close($curl);
$dados = json_decode($response);
$usuario = $dados->billing->email;
$senha = $_GET['user_pass'];
$nome =  $dados->billing->first_name;
$status = $dados->status;
$id = $dados->customer_id;

if($status == 'active') {
    $_SESSION['WORDPRESS'] = "1";
    $_SESSION['ID_ADMIN'] = $id;
    $_SESSION['NOME_ADMIN'] = $nome;
    $_SESSION['USER_ADMIN'] = $usuario;  
    $_SESSION['SENHA_ADMIN'] = $senha;  
    
    echo "<script> window.location.href='index.php'; </script>";
}
else {
     echo "<script> alert('Assinatura Indisponivel'); window.location.href='https://valorcultural.com.br/minha-conta/view-subscription/".$_GET['order_id']."'; </script>";
}



