Changeset 3176106
- Timestamp:
- 10/26/2024 04:27:00 PM (17 months ago)
- Location:
- metrepay/trunk
- Files:
-
- 1 added
- 4 edited
-
assets/metrepay.css (added)
-
assets/metrepay.js (modified) (3 diffs)
-
metrepay.php (modified) (14 diffs)
-
readme.md (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
metrepay/trunk/assets/metrepay.js
r2962760 r3176106 1 1 document.addEventListener('DOMContentLoaded', () => { 2 if (!document.getElementById('activeDA')) return 2 if (!document.getElementById('activeDA')) { 3 console.log('Metrepay Plugin - No element activeDA'); 4 return 5 } 3 6 4 7 const activeDA = … … 8 11 ? parseInt(getCookie('mp_installments_quantity')) 9 12 : null 10 console.log(' currentCartInstallments', currentCartInstallments)13 console.log('Metrepay Plugin - currentCartInstallments', currentCartInstallments) 11 14 12 15 const labelAllowedPaymentMethods = '<br>' + … … 59 62 60 63 if (inputPU.checked) { 61 console.log(' Seleccionado PAGO_UNICO')64 console.log('Metrepay Plugin - Seleccionado PAGO_UNICO') 62 65 } 63 66 64 67 if (activeDA) { 65 68 if (inputDA.checked) { 66 console.log(' Seleccionado DEBITO_AUTOMATICO')69 console.log('Metrepay Plugin - Seleccionado DEBITO_AUTOMATICO') 67 70 } 68 71 } -
metrepay/trunk/metrepay.php
r2963879 r3176106 4 4 Plugin URI: https://wordpress.org/plugins/metrepay 5 5 Description: Pasarela de pago para integracion con MetrePay y Woocomerce 6 Version: 1. 2.06 Version: 1.3.0 7 7 Author: Rugertek 8 8 Author URI: https://rugertek.com/ … … 60 60 // Mandatory variables. 61 61 $this->id = 'metrepay_gateway'; 62 $this->icon = 'https://test.metrepay.com/res/img/logo_metrepay_blanco_sin_margen.png';63 62 $this->has_fields = false; // in case you need a custom credit card form (Direct integration) 64 63 $this->method_title = 'MetrePay Gateway'; … … 82 81 // First, get this param to modify the payment box behavior 83 82 $this->active_da = sanitize_text_field($this->get_option('active_da')); 83 84 84 // Second, depending on the param before, the box behavior will change 85 $this->description = "Pagá con tu tarjeta de crédito o débito. 86 <div id='metrepayselector'></div> 87 <input type='hidden' id='activeDA' value='$this->active_da'>"; 85 $this->description = "Pagá con tu tarjeta de crédito o débito."; 88 86 $this->enabled = sanitize_text_field($this->get_option('enabled')); 89 87 $this->debugging = 'yes' === sanitize_text_field($this->get_option('debugging')); 90 88 $this->auth_token = sanitize_text_field($this->get_option('auth_token')); 91 89 $this->provider_slug = sanitize_text_field($this->get_option('provider_slug')); 92 $this->staging = sanitize_text_field($this->get_option('staging')); 90 $this->instance = sanitize_text_field($this->get_option('instance')); 91 $this->use_site_currency = 'no' === sanitize_text_field($this->get_option('use_site_currency')); 93 92 $this->header_token = $this->mpay_local_generate_string(); 94 93 … … 99 98 100 99 wp_enqueue_script('metrepay_gateway_javascript', plugins_url('/assets/metrepay.js', __FILE__)); 100 wp_enqueue_style('metrepay_gateway_styles', plugins_url('/assets/metrepay.css', __FILE__)); 101 } 102 103 /** 104 * Override al método que prepara el contenido del box de medio de 105 * pago en checkout. Aplicamos override dado que el metodo original 106 * limpia los "<input>" y lo necesitamos para aplicar lógica de 107 * pago unico o débito automático 108 */ 109 public function payment_fields() 110 { 111 // Renderiza la descripción sin modificaciones 112 echo "<div class='description-container'> 113 <img src='https://www.metrepay.com/home/img/logos/full-icon.png'> 114 " . wpautop(wptexturize($this->description)) . " 115 </div>"; 116 117 // Agrega el div y el input adicional sin pasar por filtros de seguridad 118 echo '<div id="metrepayselector"></div>'; 119 echo '<input type="hidden" id="activeDA" value="' . esc_attr($this->active_da) . '">'; 101 120 } 102 121 103 122 public function init_form_fields() 104 123 { 105 106 124 $this->form_fields = array( 107 125 'enabled' => array( … … 126 144 'desc_tip' => true, 127 145 ), 128 'staging' => array( 129 'title' => 'Entorno de desarrollo', 130 'label' => 'Staging', 131 'type' => 'checkbox', 132 'description' => 'Marcar si la plataforma de comercio está en modo de pruebas', 133 'default' => 'yes', 146 'instance' => array( 147 'title' => 'URL MetrePay', 148 'type' => 'text', 149 'description' => 'Dirección URL del sitio MetrePay que utiliza el comercio. Ejemplo: test.metrepay.com', 150 'default' => 'portal.metrepay.com', 134 151 'desc_tip' => true, 135 152 ), … … 143 160 'type' => 'text', 144 161 'description' => 'Información adicional del comercio en MetrePay. Es proveído con el Token API Key.', 162 ), 163 'use_site_currency' => array( 164 'title' => 'Moneda del sitio', 165 'label' => 'Utilizar la moneda configurada en el sitio actual: ' . get_woocommerce_currency(), 166 'type' => 'checkbox', 167 'description' => 'Si se activa, cada link de pago generado será con la moneda configurada en el sitio Woocommerce. Si se desactiva, la moneda será la establecida por defecto en MetrePay. La habilitación de la moneda a utilizarse está sujeta a cuál sitio MetrePay uno esté registrado. En caso de dudas, contacte con su asesor.', 168 'default' => 'no' 145 169 ), 146 170 'active_da' => array( … … 154 178 } 155 179 180 public function get_debugging() 181 { 182 return $this->debugging; 183 } 184 185 public function get_auth_token() 186 { 187 return $this->auth_token; 188 } 189 190 public function get_provider_slug() 191 { 192 return $this->provider_slug; 193 } 194 195 public function get_active_da() 196 { 197 return $this->active_da; 198 } 199 200 public function get_instance() 201 { 202 return $this->instance; 203 } 204 205 public function get_use_site_currency() 206 { 207 return $this->use_site_currency; 208 } 209 156 210 // Conect to the services 157 158 211 public function process_payment($order_id) 159 212 { … … 163 216 if ($this->get_mp_payment_method() == "PAGO_UNICO") { 164 217 $data = array( 165 "label" => "Pago a " . get_bloginfo("name"),166 "amount" => intval($order->get_total()),167 "handleValue" => $order->get_billing_email(),168 "handleLabel" => "{$order->get_billing_first_name()} {$order->get_billing_last_name()}",169 "customIdentifier" => get_post_meta($order->get_id(), 'CIRUC', true),170 218 "singlePayment" => true, 171 219 "creditAndDebitCard" => true, 172 "redirectUrl" => get_bloginfo("url") . "/pago-metrepay/?order_id=" . $order_id,173 220 ); 174 221 } else { … … 180 227 181 228 $data = array( 182 "label" => "Pago a " . get_bloginfo("name"),183 "amount" => intval($order->get_total()),184 "handleValue" => $order->get_billing_email(),185 "handleLabel" => "{$order->get_billing_first_name()} {$order->get_billing_last_name()}",186 "customIdentifier" => get_post_meta($order->get_id(), 'CIRUC', true),187 229 "singlePayment" => false, 188 230 "creditAndDebitCard" => true, … … 193 235 "monthForSecondInstallment" => 1, 194 236 "payWaitHours" => 96, 195 "redirectUrl" => get_bloginfo("url") . "/pago-metrepay/?order_id=" . $order_id,196 237 ); 197 238 } 198 239 199 if ($this->get_staging() == "yes") { 200 $url = "https://test.metrepay.com/api/saleitems/add"; 201 } else { 202 $url = "https://portal.metrepay.com/api/saleitems/add"; 203 } 204 205 $response = $this->mpay_local_data_post($url, $data); 240 // Establece los campos adicionales para el link de pago 241 $data['label'] = "Pago a " . get_bloginfo("name"); 242 $data['amount'] = intval($order->get_total()); 243 $data['handleValue'] = $order->get_billing_email(); 244 $data['handleLabel'] = "{$order->get_billing_first_name()} {$order->get_billing_last_name()}"; 245 $data['customIdentifier'] = get_post_meta($order->get_id(), 'CIRUC', true); 246 247 // Obtiene URL a página de pago de MP en el sitio ecommerce 248 $query = new WP_Query( array( 'pagename' => 'pago-metrepay' ) ); 249 $redirectUrl = get_permalink($query->get_queried_object()); 250 $redirectUrl = add_query_arg('order_id', $order_id, $redirectUrl); 251 $data['redirectUrl'] = $redirectUrl; 252 253 // Según el parámetro del comercio, si quiere o no utilizar la moneda configurada 254 if ($this->get_use_site_currency() == 'yes') { 255 $data['currency'] = get_woocommerce_currency(); 256 } 257 258 $response = $this->mpay_local_data_post($data); 206 259 $result = json_decode($response, true); 207 260 … … 232 285 $installments_quantity = null; 233 286 // If DA is active or not 234 $active_da = $this->get_active_da() ;287 $active_da = $this->get_active_da() == 'yes'; 235 288 236 289 if (!isset(WC()->cart)) { … … 255 308 256 309 if ($can_have_da) { 310 error_log('can_have_da: ' . $can_have_da); 257 311 // We setup the cookie 258 312 $this->mpay_local_set_cookie('mp_installments_quantity', $installments_quantity); … … 274 328 } 275 329 276 public function get_debugging()277 {278 return $this->debugging;279 }280 281 public function get_auth_token()282 {283 return $this->auth_token;284 }285 286 public function get_provider_slug()287 {288 return $this->provider_slug;289 }290 291 public function get_active_da()292 {293 return $this->active_da;294 }295 296 public function get_staging()297 {298 return $this->staging;299 }300 301 302 330 // Helpers 303 331 function mpay_local_generate_string($strength = 16) … … 315 343 } 316 344 317 function mpay_local_data_post($url, $data) { 318 $args = array( 319 'method' => 'POST', 320 'body' => json_encode($data), 321 'timeout' => '5', 322 'httpversion' => '1.0', 323 'blocking' => true, 324 'headers' => array( 325 'Content-Type' => 'application/json', 326 'Api-Token' => $this->get_auth_token() 327 ), 328 ); 329 $response = wp_remote_post($url, $args); 330 return $response['body']; 345 function mpay_local_show_error_to_user() { 346 wc_add_notice(__('El método de pago MetrePay debe ser revisado. Por favor, contacte al administrador'), 'error'); 347 } 348 349 function mpay_local_get_mp_url() { 350 // Obtiene la instancia actual 351 $instance = $this->get_instance(); 352 353 // Valida que la instancia no esté vacía 354 if (empty($instance)) { 355 throw new Exception("Error: No se ha definido una instancia válida. Por favor, contacte al administrador."); 356 } 357 358 // Formatea y sanitiza la URL 359 $instance = trim($instance); // Elimina espacios 360 $instance = filter_var($instance, FILTER_SANITIZE_URL); // Elimina caracteres no válidos en una URL 361 362 // Construye la URL final 363 $url = "https://{$instance}/api/saleitems/add"; 364 365 // Valida la estructura de la URL 366 if (!filter_var($url, FILTER_VALIDATE_URL)) { 367 throw new Exception("Error: La URL generada no es válida. Por favor, contacte al administrador."); 368 } 369 370 return $url; 371 } 372 373 function mpay_local_data_post($data) { 374 try { 375 $url = $this->mpay_local_get_mp_url(); 376 error_log(json_encode($url)); 377 378 $args = array( 379 'method' => 'POST', 380 'body' => json_encode($data), 381 'timeout' => '5', 382 'httpversion' => '1.0', 383 'blocking' => true, 384 'headers' => array( 385 'Content-Type' => 'application/json', 386 'Api-Token' => $this->get_auth_token() 387 ), 388 ); 389 $response = wp_remote_post($url, $args); 390 return $response['body']; 391 392 } catch (Exception $e) { 393 error_log('Message: ' .$e->getMessage()); 394 $this->mpay_local_show_error_to_user(); 395 } 331 396 } 332 397 -
metrepay/trunk/readme.md
r2962760 r3176106 3 3 Contributors: Rugertek 4 4 Requires at least: 5.3 5 Tested up to: 6. 05 Tested up to: 6.6.2 6 6 Requires PHP: 7.3.5 7 7 -
metrepay/trunk/readme.txt
r2963879 r3176106 3 3 Tags: metrepay, payment 4 4 Requires at least: 5.3 5 Tested up to: 6. 3.16 Stable tag: 1. 2.05 Tested up to: 6.6.2 6 Stable tag: 1.3.0 7 7 Requires PHP: 7.3.5 8 8 License: GPLv3 … … 30 30 31 31 = 1.1.2 = 32 * Improve texts into configuration form fields 32 * Improve texts into configuration form fields. 33 33 34 34 = 1.2.0 = 35 * Remove use of iframe to process payment 36 * Update correctly the order status to "completed" 35 * Remove use of iframe to process payment. 36 * Update correctly the order status to "completed". 37 38 = 1.3.0 = 39 * Add configuration parameter to set preferred MetrePay instance. 40 * Add parameter to use (or not) configured site currency. 41 * Remove "staging" configuration parameter. 42 * Fix URL generation considering site permalink to pos-checkout page "pago-metrepay". 43 * Fix checkout box to view options: "Single payment" or "Recurrent payment". 44 * Optimize API request body generation.
Note: See TracChangeset
for help on using the changeset viewer.