function call_GAA($order_id, $logger) { $logger->info('second step _ ORDER ID: ' . $order_id); $row = get_post_meta($order_id, 'request_key', true); $esProductivo = $this->ambiente == "prod"; $params_GAA = array('Security' => $esProductivo ? $this->security_prod : $this->security_test, 'Merchant' => strval($esProductivo ? $this->merchant_id_prod : $this->merchant_id_test), 'RequestKey' => $row, 'AnswerKey' => $_GET['Answer']); $logger->info('params GAA ' . json_encode($params_GAA)); $esProductivo = $this->ambiente == "prod"; $http_header = $this->getHttpHeader($esProductivo); $logger->info("HTTP_HEADER: " . json_encode($http_header)); $connector = new Sdk($http_header, $this->ambiente); $logger->info("PARAMETROS GAA: " . json_encode($params_GAA)); $response_GAA = $connector->getAuthorizeAnswer($params_GAA); $logger->info('response GAA ' . json_encode($response_GAA)); $data_GAA['params_GAA'] = $params_GAA; $data_GAA['response_GAA'] = $response_GAA; return $data_GAA; }
use TodoPago\Sdk; //importo archivo con SDK include_once '../../vendor/autoload.php'; //común a todas los métodos $http_header = array('Authorization' => 'TODOPAGO 0129b065cfb744718166913eba827a2f', 'user_agent' => 'PHPSoapClient'); $operationid = rand(1, 100000000); //opciones para el método sendAuthorizeRequest $optionsSAR_comercio = array('Security' => '0129b065cfb744718166913eba827a2f', 'EncodingMethod' => 'XML', 'Merchant' => 35, 'URL_OK' => "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME'])) . "/exito.php?operationid={$operationid}", 'URL_ERROR' => "http://" . $_SERVER['SERVER_NAME'] . ":" . $_SERVER['SERVER_PORT'] . str_replace($_SERVER['DOCUMENT_ROOT'], '', dirname($_SERVER['SCRIPT_FILENAME'])) . "/error.php?operationid={$operationid}"); $optionsSAR_operacion = array('MERCHANT' => "35", 'OPERATIONID' => "01", 'CURRENCYCODE' => 032, 'AMOUNT' => "54"); //opciones para el método getAuthorizeAnswer $optionsGAA = array('Security' => '0129b065cfb744718166913eba827a2f', 'Merchant' => "35", 'RequestKey' => '8496472a-8c87-e35b-dcf2-94d5e31eb12f', 'AnswerKey' => '8496472a-8c87-e35b-dcf2-94d5e31eb12f'); //opciones para el método getAllPaymentMethods $optionsGAMP = array("MERCHANT" => 35); //opciones para el método getStatus $optionsGS = array('MERCHANT' => '35', 'OPERATIONID' => '141120084707'); //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->getAllPaymentMethods($optionsGAMP); $rta4 = $connector->getStatus($optionsGS); //imprimo respuestas 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 All Payment Methods</h3>"; var_dump($rta3); echo "<h3>var_dump de la respuesta de Get Status</h3>"; var_dump($rta4);
function second_step_todopago() { if (isset($_GET['order'])) { $order_id = intval($_GET['order']); $order = new WC_Order($order_id); //var_dump($order); if ($order->payment_method == 'todopago') { $this->_logTodoPago($order_id, 'second step'); global $wpdb; $row = $wpdb->get_row("SELECT meta_value FROM " . $wpdb->postmeta . " WHERE meta_key = 'request_key' AND post_id = {$order_id}"); $esProductivo = $this->ambiente == "prod"; $optionsQuery = array('Security' => $esProductivo ? $this->security_prod : $this->security_test, 'Merchant' => strval($esProductivo ? $this->merchant_id_prod : $this->merchant_id_test), 'RequestKey' => $row->meta_value, 'AnswerKey' => $_GET['Answer']); $this->_logTodoPago($order_id, 'params GAA', json_encode($optionsQuery)); $esProductivo = $this->ambiente == "prod"; $http_header = $this->getHttpHeader($esProductivo); require_once dirname(__FILE__) . '/lib/Sdk.php'; $connector = new Sdk($http_header, $this->ambiente); $rta_GAA = $connector->getAuthorizeAnswer($optionsQuery); $this->_logTodoPago($order_id, 'response GAA', json_encode($rta_GAA)); // Log todopago_transaccion $wpdb->update($wpdb->prefix . 'todopago_transaccion', array('params_GAA' => json_encode($optionsQuery), 'response_GAA' => json_encode($rta_GAA), 'answer_key' => $_GET['Answer']), array('id_orden' => $order_id), array('%s', '%s', '%s'), array('%d')); if ($rta_GAA['StatusCode'] == -1) { $this->setOrderStatus($order, 'estado_aprobacion'); $this->_logTodoPago($order_id, 'estado de orden', $order->post_status); if ($order->post_status == "wc-completed") { //Reducir stock $order->reduce_order_stock(); //Vaciar carrito global $woocommerce; $woocommerce->cart->empty_cart(); } echo "<h2>Operación " . $order_id . " exitosa</h2>"; echo "<script>\n jQuery('.entry-title').html('Compra finalizada');\n </script>"; } else { $this->setOrderStatus($order, 'estado_rechazo'); $this->_printErrorMsg(); } } //End $order->payment_method == 'todopago' } //End isset($_GET['order']) }