<?php require 'includes/application_top.php'; require_once dirname(__FILE__) . '/../includes/modules/payment/todopago/vendor/autoload.php'; global $db; $mail = filter_var($_POST['mail'], FILTER_SANITIZE_EMAIL); $pass = filter_var($_POST['pass'], FILTER_SANITIZE_STRING); // instancio User use TodoPago\Data\User; $user = new User($mail, $pass); // test : 'http://127.0.0.1:8280/' // prod : 'https://apis.todopago.com.ar/' //obtengo elementos del formulario $sql = "select * from todo_pago_configuracion"; $res = $db->Execute($sql); $config = $res->fields; use TodoPago\Sdk; $Sdk = new Sdk(array(), $config["ambiente"] == 'test' ? 'test' : 'prod'); try { $credentials = $Sdk->getCredentials($user); } catch (Exception $e) { echo json_encode(array('error_message' => $e->getMessage())); exit; } list($partner, $apiKey) = explode(" ", $credentials->getApikey()); echo json_encode(array('merchantId' => $credentials->getMerchant(), 'apiKey' => $apiKey, 'Authorization' => $credentials->getApikey(), 'ambiente' => $config["ambiente"], 'error_message' => '0')); ?>
<?php //include(dirname(__FILE__).'\\..\\..\\vendor\\todopago\\php-sdk\\vendor\\autoload.php'); include dirname(__FILE__) . '/../../vendor/todopago/php-sdk/vendor/autoload.php'; use TodoPago\Sdk; if (isset($_POST['user']) && !empty($_POST['user']) && (isset($_POST['pass']) && !empty($_POST['pass']))) { $userArray = array("user" => trim($_POST['user']), "password" => trim($_POST['pass'])); $http_header = array(); //ambiente developer por defecto $mode = "test"; if ($_POST['mode'] == "Produccion") { $mode = "prod"; } try { $connector = new Sdk($http_header, $mode); $userInstance = new TodoPago\Data\User($userArray); $rta = $connector->getCredentials($userInstance); $security = explode(" ", $rta->getApikey()); $response = array("codigoResultado" => 1, "merchandid" => $rta->getMerchant(), "apikey" => $rta->getApikey(), "security" => $security[1]); } catch (Exception $e) { $response = array("mensajeResultado" => $e->getMessage()); } echo json_encode($response); } else { $response = array("mensajeResultado" => "Ingrese usuario y contraseña de Todo Pago"); echo json_encode($response); }
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);
protected function prepare_connector($prefijo) { //Traigo los settings del servicio (proxy, ubicacion del certificado y timeout $servicioConfig = $this->_getServiceSettings($prefijo); $mode = $this->module->getModo() ? "prod" : "test"; //creo el conector con el valor de Authorization $connector = new Sdk($this->_getAuthorization(), $mode); if (isset($servicioConfig['proxy'])) { // si hay un proxy $connector->setProxyParameters($proxy['host'], $proxy['port'], $proxy['user'], $proxy['pass']); } if ($servicioConfig['certificado'] != '') { //si hay una ubicación de certificado $connector->setLocalCert($servicioConfig['certificado']); } if ($servicioConfig['timeout'] != '') { //si hay un timeout $connector->setConnectionTimeout($servicioConfig['timeout']); } return $connector; }
//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' => "50", 'CURRENCYCODE' => 032, 'AMOUNT' => "54", 'CSBTCITY' => "Villa General Belgrano", 'CSSTCITY' => "Villa General Belgrano", 'CSBTCOUNTRY' => "AR", 'CSSTCOUNTRY' => "AR", 'CSBTEMAIL' => "*****@*****.**", 'CSSTEMAIL' => "*****@*****.**", 'CSBTFIRSTNAME' => "Juan", 'CSSTFIRSTNAME' => "Juan", 'CSBTLASTNAME' => "Perez", 'CSSTLASTNAME' => "Perez", 'CSBTPHONENUMBER' => "541160913988", 'CSSTPHONENUMBER' => "541160913988", 'CSBTPOSTALCODE' => " 1010", 'CSSTPOSTALCODE' => " 1010", 'CSBTSTATE' => "B", 'CSSTSTATE' => "B", 'CSBTSTREET1' => "Cerrito 740", 'CSSTSTREET1' => "Cerrito 740", 'CSBTCUSTOMERID' => "453458", 'CSBTIPADDRESS' => "192.0.0.4", 'CSPTCURRENCY' => "ARS", 'CSPTGRANDTOTALAMOUNT' => "125.38", 'CSMDD7' => "", 'CSMDD8' => "Y", 'CSMDD9' => "", 'CSMDD10' => "", 'CSMDD11' => "", 'CSMDD12' => "", 'CSMDD13' => "", 'CSMDD14' => "", 'CSMDD15' => "", 'CSMDD16' => "", 'CSITPRODUCTCODE' => "electronic_good#chocho", 'CSITPRODUCTDESCRIPTION' => "NOTEBOOK L845 SP4304LA DF TOSHIBA#chocho", 'CSITPRODUCTNAME' => "NOTEBOOK L845 SP4304LA DF TOSHIBA#chocho", 'CSITPRODUCTSKU' => "LEVJNSL36GN#chocho", 'CSITTOTALAMOUNT' => "1254.40#10.00", 'CSITQUANTITY' => "1#1", 'CSITUNITPRICE' => "1254.40#15.00"); //opciones para el método getAuthorizeAnswer $optionsGAA = array('Security' => '0129b065cfb744718166913eba827a2f', 'Merchant' => "35", 'RequestKey' => '710268a7-7688-c8bf-68c9-430107e6b9da', 'AnswerKey' => '693ca9cc-c940-06a4-8d96-1ab0d66f3ee6'); //opciones para el método getAllPaymentMethods $optionsGAMP = array("MERCHANT" => 35); //opciones para el método getStatus $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);
include_once '../../vendor/autoload.php'; //común a todas los métodos $http_header = array('Authorization' => 'TODOPAGO 0129b065cfb744718166913eba827a2f', 'user_agent' => 'PHPSoapClient'); //datos constantes define('CURRENCYCODE', 032); define('MERCHANT', 35); define('ENCODINGMETHOD', 'XML'); define('SECURITY', '0129b065cfb744718166913eba827a2f'); //id de la operacion $operationid = rand(0, 99999999); //opciones para el método sendAuthorizeRequest (datos propios del comercio) $optionsSAR_comercio = array('Security' => SECURITY, 'EncodingMethod' => ENCODINGMETHOD, 'Merchant' => MERCHANT, '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}"); // + opciones para el método sendAuthorizeRequest (datos propios de la operación) $optionsSAR_operacion = $_POST; $optionsSAR_operacion['MERCHANT'] = MERCHANT; /*$optionsSAR_operacion = array ( 'MERCHANT'=> MERCHANT, //dato fijo (número identificador del comercio) 'OPERATIONID'=>'13333456', //número único que identifica la operación 'CURRENCYCODE'=> CURRENCYCODE, //por el momento es el único tipo de moneda aceptada 'AMOUNT'=>$_POST['amount'], ); */ //creo instancia de la clase TodoPago $connector = new Sdk($http_header, "test"); $rta = $connector->sendAuthorizeRequest($optionsSAR_comercio, $optionsSAR_operacion); if ($rta['StatusCode'] != -1) { var_dump($rta); } else { setcookie('RequestKey', $rta["RequestKey"], time() + 86400 * 30, "/"); header("Location: " . $rta["URL_Request"]); }
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']) }
<?php require 'includes/application_top.php'; require DIR_FS_CATALOG . "includes/modules/payment/todopago/vendor/autoload.php"; use TodoPago\Sdk; global $db; $orderId = $_REQUEST["order_id"]; $sql = "select * from todo_pago_configuracion"; $res = $db->Execute($sql); if (!$res->EOF) { $modo = $res->fields["ambiente"] . "_"; $http_header = json_decode($res->fields["authorization"], 1); $http_header["user_agent"] = 'PHPSoapClient'; define('END_POINT', $res->fields[$modo . "endpoint"]); $connector = new Sdk($http_header, $res->fields["ambiente"] == 'test' ? 'test' : 'prod'); $optionsGS = array('MERCHANT' => $res->fields[$modo . "merchant"], 'OPERATIONID' => $orderId); $status = $connector->getStatus($optionsGS); $rta = ''; $refunds = $status['Operations']['REFUNDS']; $auxArray = array("REFUND" => $refunds); if ($refunds != null) { $aux = 'REFUND'; $auxColection = 'REFUNDS'; } if (isset($status['Operations']) && is_array($status['Operations'])) { foreach ($status['Operations'] as $key => $value) { if (is_array($value) && $key == $auxColection) { $rta .= " {$key}: \n"; foreach ($auxArray[$aux] as $key2 => $value2) { $rta .= " {$aux}: \n"; if (is_array($value2)) {
use TodoPago\Sdk; require 'includes/application_top.php'; require 'includes/modules/payment/todopago/includes/todopago_ctes.php'; require 'includes/modules/payment/todopago/includes/loggerFactory.php'; require_once dirname(__FILE__) . '/includes/modules/payment/todopago/includes/Sdk.php'; global $db; $order_id = isset($_POST['order_id']) ? $_POST['order_id'] : null; $amount = isset($_POST['amount']) ? $_POST['amount'] : null; $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;
<?php use TodoPago\Sdk; //importo archivo con SDK include_once '../../vendor/autoload.php'; define('MERCHANT', 35); define('SECURITY', '0129b065cfb744718166913eba827a2f'); $rk = $_COOKIE['RequestKey']; $ak = $_GET['Answer']; $operationid = $_GET['operationid']; $optionsGAA = array('Security' => SECURITY, 'Merchant' => MERCHANT, 'RequestKey' => $rk, 'AnswerKey' => $ak); //común a todas los métodos $http_header = array('Authorization' => 'TODOPAGO 0129b065cfb744718166913eba827a2f'); //creo instancia de la clase TodoPago $connector = new Sdk($http_header, "test"); $rta2 = $connector->getAuthorizeAnswer($optionsGAA); if ($rta2['StatusCode'] == -1) { echo "<h2>OPERACION :" . $_GET['operationid'] . " exitosa</h2>"; } else { header("location: error.php?operationid={$operationid}"); }