Ejemplo n.º 1
0
$optionsGS = array('MERCHANT' => '35', 'OPERATIONID' => '02');
$date1 = date("Y-m-d", time() - 60 * 60 * 24 * 30);
$date2 = date("Y-m-d", time());
$optionsRDT = array('MERCHANT' => 2658, "STARTDATE" => $date1, "ENDDATE" => $date2);
$devol = array("Security" => "108fc2b7c8a640f2bdd3ed505817ffde", "Merchant" => "2669", "RequestKey" => "0d801e1c-e6b1-672c-b717-5ddbe5ab97d6", "AMOUNT" => 1.0);
$anul = array("Security" => "108fc2b7c8a640f2bdd3ed505817ffde", "Merchant" => "2669", "RequestKey" => "0d801e1c-e6b1-672c-b717-5ddbe5ab97d6");
//creo instancia de la clase TodoPago
$connector = new Sdk($http_header, "test");
//ejecuto los métodos
$rta = $connector->sendAuthorizeRequest($optionsSAR_comercio, $optionsSAR_operacion);
$rta2 = $connector->getAuthorizeAnswer($optionsGAA);
$rta3 = $connector->getStatus($optionsGS);
$rta4 = $connector->getAllPaymentMethods($optionsGAMP);
$rta5 = $connector->getByRangeDateTime($optionsRDT);
$rta6 = $connector->returnRequest($devol);
$rta7 = $connector->voidRequest($anul);
//Print values
echo "<h3>var_dump de la respuesta de Send Authorize Request</h3>";
var_dump($rta);
echo "<h3>var_dump de la respuesta de Get Authorize Answer</h3>";
var_dump($rta2);
echo "<h3>var_dump de la respuesta de Get Status</h3>";
var_dump($rta3);
echo "<h3>var_dump de la respuesta de GetAllPaymentMethods</h3>";
var_dump($rta4);
echo "<h3>var_dump de la respuesta de GetByRangeDateTime</h3>";
var_dump($rta5);
echo "<h3>var_dump de la respuesta de returnRequest</h3>";
var_dump($rta6);
echo "<h3>var_dump de la respuesta de voidRequest</h3>";
var_dump($rta7);
$refund_type = isset($_POST['refund_type']) ? $_POST['refund_type'] : null;
if ($order_id != null && $refund_type != null) {
    //get configuration data
    $config = $db->Execute('SELECT * FROM ' . TABLE_TP_CONFIGURACION);
    $config = $config->fields;
    $http_header = json_decode($config["authorization"], 1);
    $http_header["user_agent"] = 'PHPSoapClient';
    $connector = new Sdk($http_header, $config["ambiente"] == 'test' ? 'test' : 'prod');
    //get requestKey
    $sql = "SELECT request_key FROM todopago_transaccion WHERE id_orden = " . $order_id;
    $response = $db->Execute($sql);
    $requestKey = $response->fields['request_key'];
    if ($refund_type == "total") {
        //anulacion
        $options = array("Security" => $config['test_security'], "Merchant" => $config['test_merchant'], "RequestKey" => $requestKey);
        $voidResponse = $connector->voidRequest($options);
        if ($voidResponse['StatusCode'] == 2011) {
            //Id status Total Refund
            $sql = "SELECT orders_status_id FROM " . TABLE_ORDERS_STATUS . " where orders_status_name = 'Refund'";
            $response = $db->Execute($sql);
            $new_order_status = $response->fields['orders_status_id'];
            if ($new_order_status == 0) {
                $new_order_status = 1;
            }
            //get void total
            $sql = "SELECT * FROM " . TABLE_ORDERS . " where orders_id = '" . (int) $order_id . "'";
            $response = $db->Execute($sql);
            $todoPagoVoid = $response->fields;
            //add history
            $sql_data_array = array('orders_id' => (int) $order_id, 'orders_status_id' => (int) $new_order_status, 'date_added' => 'now()', 'comments' => 'Devolucion total, monto devuelto: $' . (string) $todoPagoVoid['order_total'], 'customer_notified' => 0);
            zen_db_perform(TABLE_ORDERS_STATUS_HISTORY, $sql_data_array);