Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- //error_reporting(E_ALL);
- //ini_set('display_errors', TRUE);
- //ini_set('display_startup_errors', TRUE);
- /**
- * Plugin Name: Simple VisaNet Payment Gateway
- * Description: Procesador de pago para el API de VisaNet
- * Version: 1.0
- * Author: Archangel Systems
- * Author URI: http://archangelsystems.com
- * Copyright: © 2017 Archangelsystems.
- */
- require_once 'lib/CybsSoapClient.php';
- require_once $_SERVER['DOCUMENT_ROOT'].'/wp-content/plugins/elfotobus-reserva/public/class-elfotobus-reserva-public.php';
- require_once 'settings_page.php';
- add_action('wp_enqueue_scripts', 'ajax_test_enqueue_scripts');
- function ajax_test_enqueue_scripts()
- {
- wp_enqueue_style('bootstrap.form', plugins_url('/css/bootstrap.css', __FILE__));
- wp_enqueue_style('fontawesome', 'https://use.fontawesome.com/releases/v5.2.0/css/all.css');
- wp_enqueue_style('checkout', plugins_url('/css/checkout.css', __FILE__));
- wp_enqueue_script('checkout', plugins_url('/js/checkout.js', __FILE__), array('jquery'), '1.1', true);
- wp_enqueue_script('md5', plugins_url('/js/md5.js', __FILE__), array('jquery'), '1.0', true);
- wp_enqueue_script('jquery.mask', plugins_url('/js/jquery.mask.min.js', __FILE__), array('jquery'), '1.0', true);
- wp_localize_script('checkout', 'checkout', array(
- 'ajax_url' => admin_url('admin-ajax.php'),
- 'home_url' => home_url(),
- ));
- }
- function my_error_notice()
- {
- ?>
- <div class="error notice">
- <p><?php _e('Se creara una opcion nueva', 'my_plugin_textdomain'); ?></p>
- </div>
- <?php
- }
- function check_some_other_plugin()
- {
- if (!is_plugin_active('woocommerce/woocommerce.php')) {
- //add_action( 'admin_notices', 'my_error_notice' );
- } else {
- add_action('plugins_loaded', 'init_visanet_cybersource_gateway_class_simple');
- function init_visanet_cybersource_gateway_class_simple()
- {
- class WC_Gateway_Visanet_CyberSource_Simple_Gateway extends WC_Payment_Gateway
- {
- public function __construct()
- {
- //$this->supports[] = 'default_credit_card_form';
- $this->id = 'visanet';
- $this->has_fields = true;
- $this->method_title = 'VisaNet';
- $this->title = 'VisaNet';
- $this->method_description = 'Metodo de pago usando el puente de Visanet y CyberSource';
- //$this->supports( 'default_credit_card_form' );
- $this->init_form_fields();
- $this->init_settings();
- $this->title = $this->get_option('title');
- add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options'));
- $this->supports = array('default_credit_card_form');
- // load time variable setting
- $this->init_settings();
- // Turn these settings into variables we can use
- foreach ($this->settings as $setting_key => $value) {
- $this->$setting_key = $value;
- }
- }
- public function init_form_fields()
- {
- $this->form_fields = array(
- 'enabled' => array(
- 'title' => __('Enable/Disable', 'woocommerce'),
- 'type' => 'checkbox',
- 'label' => __('Enable VisaNet CyberSource', 'woocommerce'),
- 'default' => 'yes',
- ),
- 'title' => array(
- 'title' => __('Title', 'woocommerce'),
- 'type' => 'text',
- 'description' => __('This controls the title which the user sees during checkout.', 'woocommerce'),
- 'desc_tip' => true,
- ),
- 'description' => array(
- 'title' => __('Customer Message', 'woocommerce'),
- 'type' => 'textarea',
- 'default' => '',
- ),
- 'merchantId' => array(
- 'title' => __('Merchant ID', 'woocommerce'),
- 'type' => 'text',
- 'description' => __('VisaNet Merchant ID'),
- 'desc_tip' => true,
- ),
- 'currency' => array(
- 'title' => __('Payment Currency', 'woocommerce'),
- 'type' => 'text',
- 'description' => __('Moneda de pago en la que se procesaran las compras'),
- 'desc_tip' => true,
- ),
- 'orgId' => array(
- 'title' => __('Org ID', 'woocommerce'),
- 'type' => 'text',
- 'description' => __('Visanet Org ID .', 'woocommerce'),
- 'desc_tip' => true,
- ),
- 'trxId' => array(
- 'title' => __('Transaction Key', 'woocommerce'),
- 'type' => 'textarea',
- 'description' => __('Visanet CyberSource Transaction Key.', 'woocommerce'),
- 'desc_tip' => true,
- 'default' => '',
- ),
- 'endpointUrl' => array(
- 'title' => __('VisaNet SOAP WSDL URL', 'woocommerce'),
- 'type' => 'textarea',
- 'description' => __(' VisaNet SOAP WSDL to use on payment process.', 'woocommerce'),
- 'desc_tip' => true,
- 'default' => '',
- ),
- 'fingerprintUrl' => array(
- 'title' => __('fingerprint scripts URL', 'woocommerce'),
- 'type' => 'textarea',
- 'description' => __('URL to request fingerprint scripts.', 'woocommerce'),
- 'desc_tip' => true,
- 'default' => '',
- ),
- );
- }
- public function process_payment($order_id)
- {
- global $woocommerce;
- if (session_id() == '') {
- session_start();
- }
- require_once 'lib/CybsSoapClient.php';
- $order = new WC_Order($order_id);
- try {
- $order->update_status('on-hold', __('Procesando pago', 'woocommerce'));
- $items = $order->get_items();
- $products = array();
- if (is_array($items)) {
- foreach ($items as $item) {
- $products[] = new WC_Product($item['product_id']);
- }
- }
- $merchantId = get_option('merchantId');
- $trxId = get_option('trxId');
- $endpointUrl = get_option('endpointUrl');
- $currency = get_option('currency');
- $properties = array(
- 'merchant_id' => $merchantId,
- 'transaction_key' => $trxId,
- 'wsdl' => $endpointUrl,
- 'nvp_wsdl' => $endpointUrl,
- );
- $client = new CybsSoapClient($properties);
- $request = $client->createRequest($order_id);
- $ccAuthService = new stdClass();
- $ccAuthService->run = 'true';
- $request->ccAuthService = $ccAuthService;
- $ccCaptureService = new stdClass();
- $ccCaptureService->run = 'true';
- $request->ccCaptureService = $ccCaptureService;
- $billTo = new stdClass();
- $billTo->firstName = $order->billing_first_name;
- $billTo->lastName = $order->billing_last_name;
- $billTo->street1 = $order->billing_address_1.' '.$order->billing_address_2;
- $billTo->city = $order->billing_city;
- $billTo->state = $order->billing_state;
- $billTo->postalCode = $order->billing_postcode;
- $billTo->country = $order->billing_country;
- $billTo->email = $order->billing_email;
- $billTo->phoneNumber = $order->billing_phone;
- $billTo->ipAddress = $_SERVER['REMOTE_ADDR'];
- $request->billTo = $billTo;
- $parts = explode('/', $_POST['visanet-card-expiry']);
- $year = date('Y');
- $year = substr($year, 0, 2).trim($parts[1]);
- $cardnumber = preg_replace('/\s+/', '', $_POST['visanet-card-number']);
- $card = new stdClass();
- $card->accountNumber = strip_tags($cardnumber);
- $card->expirationMonth = trim($parts[0]);
- $card->expirationYear = $year;
- $card->cvNumber = strip_tags($_POST['visanet-card-cvc']);
- $request->card = $card;
- $purchaseTotals = new stdClass();
- $purchaseTotals->currency = $currency;
- $purchaseTotals->grandTotalAmount = $order->get_total();
- $request->purchaseTotals = $purchaseTotals;
- $request->deviceFingerprintID = $_SESSION['requestSessionId'];
- if (is_array($items)) {
- $cartItems = array();
- foreach ($items as $item) {
- $currentProduct = new WC_Product($item['product_id']);
- $currentItem = new stdClass();
- $currentItem->unitPrice = $item['line_total'] / $item['qty'];
- $currentItem->quantity = $item['qty'];
- $currentItem->productCode = $item['product_id'];
- $currentItem->productName = $item['name'];
- $currentItem->productSKU = $item['product_id'];
- $cartItems[] = $currentItem;
- }
- }
- $request->item = $cartItems;
- header('Content-Type: application/json');
- //echo json_encode($_POST);
- //echo json_encode($parts);
- $reply = $client->runTransaction($request);
- $error_message = $reply->decision;
- if ($reply->decision == 'REVIEW') {
- $error_message = __('Pago procesado, pero necesita revision en la plataforma de visanet', 'woocommerce');
- wc_add_notice($error_message, 'notice');
- $order->update_status('on-hold', $error_message);
- $order->reduce_order_stock();
- $woocommerce->cart->empty_cart();
- return array(
- 'result' => 'success',
- 'redirect' => $this->get_return_url($order),
- );
- } elseif ($reply->decision == 'REJECT') {
- $msg = 'El pago fue rechazado ';
- if (isset($reply->invalidField)) {
- $msg = $reply->invalidField.' ';
- }
- $order->update_status('failed', $msg);
- wc_add_notice($msg, 'error');
- return;
- } elseif ($reply->decision == 'ACCEPT') {
- $msg = 'El pago fue procesado, queda pendiente de completar la orden<br/>Autorización No.: ';
- $msg .= $reply->ccAuthReply->authorizationCode;
- wc_add_notice($msg, 'success');
- $order->payment_complete();
- $order->reduce_order_stock();
- return array(
- 'result' => 'success',
- 'redirect' => $this->get_return_url($order),
- );
- }
- } catch (Exception $e) {
- wc_add_notice($e->getMessage(), 'error');
- return;
- }
- }
- }
- function getSimpleCCMonthExpDate($expDate)
- {
- //$parts = explode('/',$expDate);
- return $expDate;
- /*$part = trim($parts[0]);
- if($part<10){
- $part = '0'. $part;
- }
- return $part; */
- }
- function getSimpleYearExpDate($expDate)
- {
- $parts = explode('/', $expDate);
- $part = trim($parts[1]);
- $year = date('Y');
- $part = substr($year, 0, 2).$part;
- return $part;
- }
- }
- function add_visanet_cybersource_gateway_class_simple($methods)
- {
- $methods[] = 'WC_Gateway_Visanet_CyberSource_Simple_Gateway';
- return $methods;
- }
- add_filter('woocommerce_payment_gateways', 'add_visanet_cybersource_gateway_class_simple');
- //WC_Gateway_Visanet_CyberSource_Simple_Gateway
- }
- }
- add_action('admin_init', 'check_some_other_plugin');
- function setCyberSourceRequestSimpleSessionID()
- {
- if (session_id() == '') {
- session_start();
- }
- $_SESSION['requestSessionId'] = md5(rand(99, 9999).time().rand(99, 9999));
- //$_SESSION['requestSessionId'] = md5('25252525');
- }
- function simple_fingerprint_shortcode()
- {
- $options = get_option('simple_visanet_settings');
- if (session_id() == '') {
- session_start();
- }
- ob_start();
- setCyberSourceRequestSimpleSessionID();
- $pluginUrl = plugins_url('/visanet_lib/call/requests.php?', __FILE__);
- //$CSGW = new WC_Gateway_Visanet_CyberSource_Simple_Gateway();
- $merchantId = get_option('merchantId');
- $trxId = get_option('trxId');
- $endpointUrl = get_option('endpointUrl');
- $currency = get_option('currency');
- $orgId = get_option('orgId');
- $_SESSION['SID'] = $_SESSION['requestSessionId'];
- $_SESSION['MID'] = $merchantId;
- $_SESSION['OID'] = $orgId;
- //$query = '?S=' . $SID . '&M='. $MID . '&O=' . $OID;
- //$pluginUrl .= $query;?>
- <script>
- jQuery(function($) {
- setTimeout(function(){showPImage();}, 500);
- function showPImage(){
- jQuery("body").append('<p style="background:url(<?=($pluginUrl.'&src=img1'); ?>)"></p>');
- setTimeout(function(){showImg();}, 500);
- }
- function showImg(){
- jQuery("body").append('<img src="<?=($pluginUrl.'&src=img2'); ?>" alt="">');
- setTimeout(function(){getVNjs();}, 500);
- }
- function getVNjs(){
- $.getScript( "<?=($pluginUrl.'&src=js'); ?>" )
- setTimeout(function(){getVNiframe();}, 500);
- }
- function getVNiframe() {
- jQuery("#vniframe").attr("src", "<?=($pluginUrl.'&src=frame'); ?>");
- jQuery("#paymentFormOverlay").hide();
- }
- });
- </script>
- <object type="application/x-shockwave-flash" data="" width="1" height="1" id="thm_fp">
- <param name="movie" value="<?=($pluginUrl.'&src=swf'); ?>" />
- <div></div>
- </object>
- <noscript>
- <iframe
- id="vniframe"
- style="width: 100px; height: 100px; border: 0; position: absolute; top: -5000px;">
- </iframe>
- </noscript>
- <?php
- return ob_get_clean();
- }
- add_shortcode('simple_visanet_fingerprint', 'simple_fingerprint_shortcode');
- add_action('wp_ajax_nopriv_pay_reservation', 'pay_reservation');
- add_action('wp_ajax_pay_reservation', 'pay_reservation');
- function get_client_ip()
- {
- $ipaddress = '';
- if (isset($_SERVER['HTTP_CLIENT_IP'])) {
- $ipaddress = $_SERVER['HTTP_CLIENT_IP'];
- } elseif (isset($_SERVER['HTTP_X_FORWARDED_FOR'])) {
- $ipaddress = $_SERVER['HTTP_X_FORWARDED_FOR'];
- } elseif (isset($_SERVER['HTTP_X_FORWARDED'])) {
- $ipaddress = $_SERVER['HTTP_X_FORWARDED'];
- } elseif (isset($_SERVER['HTTP_FORWARDED_FOR'])) {
- $ipaddress = $_SERVER['HTTP_FORWARDED_FOR'];
- } elseif (isset($_SERVER['HTTP_FORWARDED'])) {
- $ipaddress = $_SERVER['HTTP_FORWARDED'];
- } elseif (isset($_SERVER['REMOTE_ADDR'])) {
- $ipaddress = $_SERVER['REMOTE_ADDR'];
- } else {
- $ipaddress = 'UNKNOWN';
- }
- return $ipaddress;
- }
- function pay_reservation()
- {
- global $wp;
- //global $woocommerce;
- ini_set('display_errors', 1);
- ini_set('display_startup_errors', 1);
- error_reporting(E_ALL);
- if (session_id() == '') {
- session_start();
- }
- require_once 'lib/CybsSoapClient.php';
- //require_once('../elfotobus-reserva/public/class-elfotobus-reserva-public.php');
- //Validate reservaID
- $order_id = $_POST['orderid'];
- //$efb_class = new Elfotobus_Reserva_Public();
- //$order = $efb_class->find_reserva($_POST['orderid']);
- $order = exec_get_reserva($order_id);
- // 20118008 reserva de prueba;
- //$status_code = 200;
- if ($order) {
- if (isset($_POST['cardNVC'])) {
- $cuotas = [3, 6, 9, 12];
- if (!in_array($_POST['cardNVC'], $cuotas)) {
- $response = ['message' => 'Debe enviar Número de cuotas', 'data' => []];
- $status_code = 404;
- } else {
- $nombre = explode(' ', $_POST['billing_name']);
- $firstname = count($nombre) > 2 ? "{$nombre[0]} {$nombre[1]} " : $nombre[0];
- $lastname = substr($_POST['billing_name'], strlen($firstname), strlen($_POST['billing_name']));
- $billTo = new stdClass();
- $billTo->firstName = $firstname;
- $billTo->lastName = $lastname;
- $billTo->street1 = $_POST['billing_address'];
- $billTo->country = $_POST['billing_country'];
- $billTo->state = $_POST['billing_state'];
- $billTo->city = $_POST['billing_city'];
- $billTo->postalCode = $_POST['billing_postalcode'];
- $billTo->email = $_POST['billing_email'];
- $billTo->phoneNumber = $_POST['billing_phone'];
- $billTo->ipAddress = $_SERVER['REMOTE_ADDR'];
- $curl = curl_init();
- $cardnumber = preg_replace('/\s+/', '', $_POST['ccnumber']);
- $expdate = substr($_POST['ccyexp'], -2).$_POST['ccmexp'];
- $shopperIP = get_client_ip();
- $precio = number_format((($order->precio * 1) * 1.20), 2, '.', '');
- /*$parameters = array(
- 'pan' => strip_tags($cardnumber),
- 'expdate' => $expdate,
- 'amount' => $precio,
- 'cvv2' => strip_tags($_POST['cardCVC']),
- 'shopperIP' => $shopperIP,
- 'merchantServerIP' => $_SERVER['SERVER_ADDR'],
- 'vc' => $_POST['cardNVC'],
- 'type' => 'vc',
- );*/
- // Modificaciones para accesar directamente a la api de visacuotas
- // rap - 2019-01-15
- global $wpdb;
- $url = 'https://epaytestvisanet.com.gt/paymentcommerce.asmx?WSDL';
- $server_host = $_SERVER['HTTP_HOST'];
- $lastTransaction = $wpdb->get_var('SELECT IFNULL(SUM(audit_number), 0) + 1 as audit_number FROM '.$wpdb->prefix.'visacuotas LIMIT 1');
- $table = $wpdb->prefix.'visacuotas';
- if ($lastTransaction > 1) {
- if ($lastTransaction > 99) {
- $lastTransaction = 1;
- $data = ['audit_number' => $lastTransaction];
- $where = '';
- $updated = $wpdb->update($table, $data, $where);
- }
- } elseif ($lastTransaction == 1) {
- $data = ['audit_number' => $lastTransaction];
- $format = array('%d');
- $wpdb->insert($table, $data, $format);
- }
- $amount = str_replace('.', '', $precio);
- $amount = str_replace(',', '', $amount);
- $producto = "vc".str_pad($_POST['cardNVC'], 2, "0", STR_PAD_LEFT);;
- $param = array(
- 'posEntryMode' => '012',
- 'pan' => strip_tags($cardnumber),
- 'expdate' => $expdate, //Debe ser año mes
- 'amount' => $amount,
- 'track2Data' => '', //Se usa solo si se lee la banda magnetica y posEntryMode debera ser 022
- 'cvv2' => strip_tags($_POST['cardCVC']),
- 'paymentgwIP' => '208.68.36.170',
- 'shopperIP' => $server_host, //$data['shopperIP'],
- 'merchantServerIP' => $server_host, //$data['merchantServerIP'],
- 'merchantUser' => '76B925EF7BEC821780B4B21479CE6482EA415896CF43006050B1DAD101669921', //reemplazar por el valor respectivo
- 'merchantPasswd' => 'DD1791DB5B28DDE6FBC2B9951DFED4D97B82EFD622B411F1FC16B88B052232C7', //reemplazar por el valor respectivo
- 'terminalId' => '77788881', //reemplazar por el valor respectivo
- 'merchant' => '00575123', //reemplazar por el valor respectivo
- 'messageType' => '0200',
- 'auditNumber' => str_pad($lastTransaction, '6', '0', STR_PAD_LEFT),
- 'additionalData' => strtoupper($producto),
- );
- $params = array(
- array('AuthorizationRequest' => $param),
- );
- $client = new \SoapClient($url, array(
- //'local_cert' => $local_cert,
- 'connection_timeout' => 5,
- ));
- try {
- //$path = __DIR__.'/../../var/security';
- //$local_cert = "$path/CargaMundial.pem";
- //$client = new \SoapClient($url);
- $client = new \SoapClient($url, array(
- //'local_cert' => $local_cert,
- 'connection_timeout' => 5,
- ));
- $result = $client->__soapCall('AuthorizationRequest', $params);
- $result = $result->response;
- $response = ['response' => (array) $result, 'message' => 'Resultado de la transacción'];
- $response = update_payment_reserva_visacuotas($response, $order_id, $billTo);
- $status_code = 200;
- } catch (SoapFault $e) {
- $err = ['response' => [
- 'code' => $e->getCode(),
- 'file' => $e->getFile(),
- 'line' => $e->getLine(),
- ], 'message' => $e->getMessage()];
- $response = ['message' => 'Ocurrio un error al intentar comunicarse con visanet', 'data' => [$err]];
- $status_code = 500;
- }
- // Fin de modificaciones
- }
- } else {
- //$options = get_option( 'simple_visanet_settings' );
- $merchantId = get_option('merchantId');
- $trxId = get_option('trxId');
- $endpointUrl = get_option('endpointUrl');
- $currency = get_option('currency');
- $properties = array(
- 'merchant_id' => $merchantId,
- 'transaction_key' => $trxId,
- 'wsdl' => $endpointUrl,
- 'nvp_wsdl' => $endpointUrl,
- );
- $client = new CybsSoapClient($properties);
- //var_dump($client);
- //exit;
- $request = $client->createRequest($order_id);
- $ccAuthService = new stdClass();
- $ccAuthService->run = 'true';
- $request->ccAuthService = $ccAuthService;
- $ccCaptureService = new stdClass();
- $ccCaptureService->run = 'true';
- $request->ccCaptureService = $ccCaptureService;
- $nombre = explode(' ', $_POST['billing_name']);
- $firstname = count($nombre) > 2 ? "{$nombre[0]} {$nombre[1]} " : $nombre[0];
- $lastname = substr($_POST['billing_name'], strlen($firstname), strlen($_POST['billing_name']));
- $billTo = new stdClass();
- $billTo->firstName = $firstname;
- $billTo->lastName = $lastname;
- $billTo->street1 = $_POST['billing_address'];
- $billTo->country = $_POST['billing_country'];
- $billTo->state = $_POST['billing_state'];
- $billTo->city = $_POST['billing_city'];
- $billTo->postalCode = $_POST['billing_postalcode'];
- $billTo->email = $_POST['billing_email'];
- $billTo->phoneNumber = $_POST['billing_phone'];
- $billTo->ipAddress = $_SERVER['REMOTE_ADDR'];
- $request->billTo = $billTo;
- $cardnumber = preg_replace('/\s+/', '', $_POST['ccnumber']);
- $card = new stdClass();
- $card->accountNumber = strip_tags($cardnumber);
- $card->expirationMonth = $_POST['ccmexp'];
- $card->expirationYear = $_POST['ccyexp'];
- $card->cvNumber = strip_tags($_POST['cardCVC']);
- $request->card = $card;
- $precio = ($order->precio) * 1.20;
- $purchaseTotals = new stdClass();
- $purchaseTotals->currency = $currency;
- $purchaseTotals->grandTotalAmount = $precio;
- $request->purchaseTotals = $purchaseTotals;
- $request->deviceFingerprintID = $_SESSION['requestSessionId'];
- $items[] = [
- 'line_total' => $precio,
- 'qty' => 1,
- 'product_id' => $order->no_reserva,
- 'name' => 'Pago para la reserva No: '.$order->no_reserva,
- ];
- if (is_array($items)) {
- $cartItems = array();
- foreach ($items as $item) {
- $currentItem = new stdClass();
- $currentItem->unitPrice = $item['line_total'] / $item['qty'];
- $currentItem->quantity = $item['qty'];
- $currentItem->productCode = $item['product_id'];
- $currentItem->productName = $item['name'];
- $currentItem->productSKU = $item['product_id'];
- $cartItems[] = $currentItem;
- }
- }
- $request->item = $cartItems;
- header('Content-Type: application/json');
- //echo json_encode($_POST);
- //echo json_encode($parts);
- $reply = $client->runTransaction($request);
- $error_message = $reply->decision;
- //$response = $reply;
- $status_code = 200;
- $response = update_payment_reserva($request, $reply, $order_id);
- }
- } else {
- $response = ['message' => 'Reserva no existe', 'data' => []];
- $status_code = 404;
- }
- status_header($status_code);
- wp_send_json($response);
- }
- function update_payment_reserva_visacuotas($response, $order_id, $billTo)
- {
- $request = $response->request[0]->AuthorizationRequest;
- $response = $response->response;
- $response_codes = [
- '00' => 'Aprobada',
- '12' => 'Transacción no autorizada, ERROR 12',
- '01' => 'Refiérase al Emisor',
- '02' => 'Refiérase al Emisor',
- '05' => 'Transacción no aceptada',
- '13' => 'Monto Inválido',
- '19' => 'Transaccioón no realizada, intente de nuevo',
- '31' => 'Tarjeta no soportada por SWITCH',
- '41' => 'Tarjeta Extraviada',
- '43' => 'Tarjeta Robada',
- '51' => 'No tiene fondos disponibles',
- '54' => 'Tarjeta Expirada',
- '89' => 'Terminal Invá́lida',
- '91' => 'Emisor NO Disponible',
- '94' => 'Transacción duplicada',
- '96' => 'Error del Sistema, intente más tarde',
- ];
- if ($response->responseCode == '00') {
- $transactionid = $response->referenceNumber;
- $message = 'Transaación Aceptada, Autorización #'.$response->authorizationNumber;
- $response->decision = 'ACCEPT';
- } else {
- $transactionid = $response->responseCode.'-'.$response->referenceNumber;
- $message = $response_codes[$response->responseCode];
- $response->decision = 'REJECT';
- }
- $response->message = $response_codes[$response->responseCode];
- global $wpdb;
- $table_name = $wpdb->prefix.'reserva';
- $sql = "SELECT * from $table_name WHERE no_reserva = {$order_id};";
- $reserva = $wpdb->get_row($wpdb->prepare($sql, array()));
- $wpdb->update($table_name,
- array('tipo_reserva' => 'Visanet en Cuotas', 'observaciones' => "concat(observaciones, '|$message')"),
- array('no_reserva' => $order_id),
- array('%s', '%s'),
- array('%d'));
- $boleta = $transactionid;
- $cod_reserva_real = $reserva->cod_reserva;
- $decimals = substr($request->amount, -2);
- $monto = substr($request->amount, 0, strlen($request->amount) - 2).'.'.$decimals;
- $fecha_hora_deposito = date('Y-m-d H:i');
- $observaciones = $message;
- $wpdb->query("update wp_cr2w7i_registro set no_boleta=concat(no_boleta, '|$boleta') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set banco=concat(banco, '|visanet') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set monto=concat(monto, '|$monto') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set boleta_aceptada=concat(boleta_aceptada, '0') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set fecha_deposito=concat(fecha_deposito, '|$fecha_hora_deposito') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set observaciones=concat(observaciones, '|$observaciones') where cod_reserva=$cod_reserva_real;");
- //$wpdb->query("update wp_cr2w7i_registro set dpi_url='$url' where cod_reserva=$cod_reserva_real;");
- //include 'lib/PHPMailerAutoload.php';
- $subject = 'Pago realizado en ElFotoBus.com';
- $message = 'Se recibio la siguiente informacion: <br />
- Nombre: '.$billTo->firstName.' '.$billTo->lastName.'<br />
- Direccion: '.$billTo->street1.'<br />
- Telefono: '.$billTo->phoneNumber.'<br />
- Email: '.$billTo->email.'<br />
- Descripcion: Pago con Visa Cuotas para la reserva #'.$order_id.'<br />
- Número de Visa Cuotas: '.$request->additionalData.'<br/>
- Tarjeta (4 digitos): '.substr($request->pan, -4).'<br />
- Total: Q '.$monto.'<br />
- Orden Id: '.$order_id.'<br />
- Transaccion Id: '.$transactionid.'<br />
- Respuesta: '.$message;
- $mail = new PHPMailer();
- //$mail->SMTPDebug = 3; // Enable verbose debug output
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'envios@archangelsystems.com'; // SMTP username
- $mail->Password = '$$S3rafin2018'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 587;
- $mail->From = 'no-reply@elfotobus.com';
- $mail->FromName = 'ElFotoBus';
- //$mail->addAddress($billTo->email, $billTo->firstName.' '.$billTo->lastName); // Add a recipient
- //$mail->addAddress('elfotobus@outlook.com'); // Add a recipient
- $mail->addAddress('soporte@archangelsystems.com');
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = $subject;
- $mail->Body = $message;
- $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- if (!$mail->send()) {
- //echo 'Message could not be sent.';
- //echo 'Mailer Error: ' . $mail->ErrorInfo;
- $response['mailer_error'] = $mail->ErrorInfo;
- }
- $response->custom_data = true;
- $response->type = 'visacuotas';
- return $response;
- }
- function update_payment_reserva($request, $reply, $order_id)
- {
- if ($reply->decision == 'REVIEW') {
- $transactionid = $reply->ccAuthReply->authorizationCode;
- $message = 'Aceptada pero necesita revisión en Cybersource Panel, Autorización #'.$reply->ccAuthReply->authorizationCode;
- } elseif ($reply->decision == 'REJECT') {
- $transactionid = 'ERROR: '.$reply->reasonCode;
- $message = 'Transaación Rechazada, Código #'.$reply->reasonCode;
- } elseif ($reply->decision == 'ACCEPT') {
- $transactionid = $reply->ccAuthReply->authorizationCode;
- $message = 'Transaación Aceptada, Autorización #'.$reply->ccAuthReply->authorizationCode;
- }
- global $wpdb;
- $table_name = $wpdb->prefix.'reserva';
- $sql = "SELECT * from $table_name WHERE no_reserva = {$order_id};";
- $reserva = $wpdb->get_row($wpdb->prepare($sql, array()));
- $wpdb->update($table_name,
- array('tipo_reserva' => 'Visanet', 'observaciones' => "concat(observaciones, '|$message')"),
- array('no_reserva' => $order_id),
- array('%s', '%s'),
- array('%d'));
- $boleta = $transactionid;
- $cod_reserva_real = $reserva->cod_reserva;
- $monto = $request->purchaseTotals->grandTotalAmount;
- $fecha_hora_deposito = date('Y-m-d H:i');
- $observaciones = $message;
- $wpdb->query("update wp_cr2w7i_registro set no_boleta=concat(no_boleta, '|$boleta') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set banco=concat(banco, '|visanet') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set monto=concat(monto, '|$monto') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set boleta_aceptada=concat(boleta_aceptada, '0') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set fecha_deposito=concat(fecha_deposito, '|$fecha_hora_deposito') where cod_reserva=$cod_reserva_real;");
- $wpdb->query("update wp_cr2w7i_registro set observaciones=concat(observaciones, '|$observaciones') where cod_reserva=$cod_reserva_real;");
- //$wpdb->query("update wp_cr2w7i_registro set dpi_url='$url' where cod_reserva=$cod_reserva_real;");
- include 'lib/PHPMailerAutoload.php';
- $subject = 'Pago realizado en ElFotoBus.com';
- $message = 'Se recibio la siguiente informacion: <br />
- Nombre: '.$request->billTo->firstName.' '.$request->billTo->lastName.'<br />
- Direccion: '.$request->billTo->street1.'<br />
- Telefono: '.$request->billTo->phoneNumber.'<br />
- Email: '.$request->billTo->email.'<br />
- Descripcion: Pago con tarjeta para la reserva #'.$order_id.'<br />
- Tarjeta (4 digitos): '.substr($request->card->accountNumber, -4).'<br />
- Total: '.$request->purchaseTotals->currency.' '.$request->purchaseTotals->grandTotalAmount.'<br />
- Orden Id: '.$order_id.'<br />
- Transaccion Id: '.$transactionid.'<br />
- Respuesta: '.$message;
- $mail = new PHPMailer();
- //$mail->SMTPDebug = 3; // Enable verbose debug output
- $mail->isSMTP(); // Set mailer to use SMTP
- $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
- $mail->SMTPAuth = true; // Enable SMTP authentication
- $mail->Username = 'envios@archangelsystems.com'; // SMTP username
- $mail->Password = '$$S3rafin2018'; // SMTP password
- $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
- $mail->Port = 587;
- $mail->From = 'no-reply@elfotobus.com';
- $mail->FromName = 'ElFotoBus';
- $mail->addAddress($request->billTo->email, $request->billTo->firstName.' '.$request->billTo->lastName); // Add a recipient
- $mail->addAddress('elfotobus@outlook.com'); // Add a recipient
- $mail->isHTML(true); // Set email format to HTML
- $mail->Subject = $subject;
- $mail->Body = $message;
- $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
- if (!$mail->send()) {
- //echo 'Message could not be sent.';
- //echo 'Mailer Error: ' . $mail->ErrorInfo;
- $reply->mailer_error = $mail->ErrorInfo;
- }
- $reply->custom_data = true;
- $response->type = 'visanet';
- return $reply;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement