require DIR_WS_INCLUDES . 'template_top.php';
$res = tep_db_query("SELECT * FROM " . TABLE_TP_CONFIGURACION);
$fetch_result = tep_db_fetch_array($res);
//set url external form library
$library = "resources/TPHybridForm-v0.1.js";
if ($fetch_result['ambiente'] == "test") {
    $endpoint = "https://developers.todopago.com.ar/";
} else {
    $endpoint = "https://forms.todopago.com.ar/";
}
$endpoint .= $library;
if (isset($_GET['id'])) {
    $id_decode = $_GET['id'];
    if (is_numeric($id_decode)) {
        $tpTransaccion = new TodopagoTransaccion();
        $response = $tpTransaccion->getTransaction($id_decode);
        if ($response['public_request_key'] != null || $response['public_request_key'] != '') {
            $publicKey = $response['public_request_key'];
            //user, mail
            $customer_data = tep_db_query('SELECT * FROM customers');
            $customer_data = tep_db_fetch_array($customer_data);
            $user = $customer_data['customers_firstname'] . " " . $customer_data['customers_lastname'];
            $mail = $customer_data['customers_email_address'];
        } else {
            header('Location: ' . tep_href_link('checkout_shipping_retry.php', '', 'SSL'));
            die;
        }
    } else {
        header('Location: ' . tep_href_link('checkout_shipping_retry.php', '', 'SSL'));
        die;
    }
    $endpoint = "";
    $ambiente = $resultConfig->fields['ambiente'];
    //set url external form library
    $library = "resources/TPHybridForm-v0.1.js";
    if ($ambiente == "test") {
        // developers
        $endpoint = "https://developers.todopago.com.ar/";
    } else {
        // produccion
        $endpoint = "https://forms.todopago.com.ar/";
    }
    $endpoint .= $library;
    $orderId = $_GET['id'];
    //RequestKey
    $tpTransaccion = new TodopagoTransaccion();
    $response = $tpTransaccion->getTransaction($orderId);
    $publicKey = $response['public_request_key'];
    //orderID*/
    $orderId = $_GET['id'];
    //merchatid
    $merchantId = $resultConfig->fields['test_merchant'];
    require 'includes/classes/order.php';
    $order = new order($orderId);
    //name
    $user = $order->customer['name'];
    //email
    $mail = $order->customer['email_address'];
} else {
    $url = str_replace("&", "&", zen_href_link('checkout_payment', '', 'SSL'));
    header('Location:' . $url);
    die;