@@ -53,37 +53,37 @@ discard block |
||
| 53 | 53 | $this->method_title = ucfirst($this->id); |
| 54 | 54 | |
| 55 | 55 | //Useful vars |
| 56 | - $this->template_path = plugin_dir_path(__FILE__) . '../templates/'; |
|
| 56 | + $this->template_path = plugin_dir_path(__FILE__).'../templates/'; |
|
| 57 | 57 | $this->allowed_currencies = array("EUR");
|
| 58 | - $this->mainFileLocation = dirname(plugin_dir_path(__FILE__)) . '/WC_Pagantis.php'; |
|
| 58 | + $this->mainFileLocation = dirname(plugin_dir_path(__FILE__)).'/WC_Pagantis.php'; |
|
| 59 | 59 | $this->plugin_info = get_file_data($this->mainFileLocation, array('Version' => 'Version'), false);
|
| 60 | 60 | $this->language = strstr(get_locale(), '_', true); |
| 61 | 61 | |
| 62 | - if ($this->language == 'es' || $this->language == '') {
|
|
| 62 | + if ($this->language=='es' || $this->language=='') {
|
|
| 63 | 63 | $this->icon = esc_url(plugins_url('../assets/images/logopagamastarde.png', __FILE__));
|
| 64 | 64 | } else {
|
| 65 | 65 | $this->icon = esc_url(plugins_url('../assets/images/logo.png', __FILE__));
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | //Panel form fields |
| 69 | - $this->form_fields = include(plugin_dir_path(__FILE__).'../includes/settings-pagantis.php');//Panel options |
|
| 69 | + $this->form_fields = include(plugin_dir_path(__FILE__).'../includes/settings-pagantis.php'); //Panel options |
|
| 70 | 70 | $this->init_settings(); |
| 71 | 71 | |
| 72 | 72 | $this->extraConfig = $this->getExtraConfig(); |
| 73 | 73 | $this->title = __($this->extraConfig['PAGANTIS_TITLE'], 'pagantis'); |
| 74 | 74 | |
| 75 | - $this->settings['ok_url'] = ($this->extraConfig['PAGANTIS_URL_OK']!='')?$this->extraConfig['PAGANTIS_URL_OK']:$this->generateOkUrl(); |
|
| 76 | - $this->settings['ko_url'] = ($this->extraConfig['PAGANTIS_URL_KO']!='')?$this->extraConfig['PAGANTIS_URL_KO']:$this->generateKoUrl(); |
|
| 75 | + $this->settings['ok_url'] = ($this->extraConfig['PAGANTIS_URL_OK']!='') ? $this->extraConfig['PAGANTIS_URL_OK'] : $this->generateOkUrl(); |
|
| 76 | + $this->settings['ko_url'] = ($this->extraConfig['PAGANTIS_URL_KO']!='') ? $this->extraConfig['PAGANTIS_URL_KO'] : $this->generateKoUrl(); |
|
| 77 | 77 | foreach ($this->settings as $setting_key => $setting_value) {
|
| 78 | 78 | $this->$setting_key = $setting_value; |
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | //Hooks |
| 82 | - add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this,'process_admin_options')); //Save plugin options
|
|
| 83 | - add_action('admin_notices', array($this, 'pagantisCheckFields')); //Check config fields
|
|
| 84 | - add_action('woocommerce_receipt_'.$this->id, array($this, 'pagantisReceiptPage')); //Pagantis form
|
|
| 85 | - add_action('woocommerce_api_wcpagantisgateway', array($this, 'pagantisNotification')); //Json Notification
|
|
| 86 | - add_filter('woocommerce_payment_complete_order_status', array($this,'pagantisCompleteStatus'), 10, 3);
|
|
| 82 | + add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options')); //Save plugin options
|
|
| 83 | + add_action('admin_notices', array($this, 'pagantisCheckFields')); //Check config fields
|
|
| 84 | + add_action('woocommerce_receipt_'.$this->id, array($this, 'pagantisReceiptPage')); //Pagantis form
|
|
| 85 | + add_action('woocommerce_api_wcpagantisgateway', array($this, 'pagantisNotification')); //Json Notification
|
|
| 86 | + add_filter('woocommerce_payment_complete_order_status', array($this, 'pagantisCompleteStatus'), 10, 3);
|
|
| 87 | 87 | add_filter('load_textdomain_mofile', array($this, 'loadPagantisTranslation'), 10, 2);
|
| 88 | 88 | } |
| 89 | 89 | |
@@ -95,8 +95,8 @@ discard block |
||
| 95 | 95 | */ |
| 96 | 96 | public function loadPagantisTranslation($mofile, $domain) |
| 97 | 97 | {
|
| 98 | - if ('pagantis' === $domain) {
|
|
| 99 | - $mofile = WP_LANG_DIR . '/../plugins/pagantis/languages/pagantis-' . get_locale() . '.mo'; |
|
| 98 | + if ('pagantis'===$domain) {
|
|
| 99 | + $mofile = WP_LANG_DIR.'/../plugins/pagantis/languages/pagantis-'.get_locale().'.mo'; |
|
| 100 | 100 | } |
| 101 | 101 | return $mofile; |
| 102 | 102 | } |
@@ -129,24 +129,24 @@ discard block |
||
| 129 | 129 | public function pagantisCheckFields() |
| 130 | 130 | {
|
| 131 | 131 | $error_string = ''; |
| 132 | - if ($this->settings['enabled'] !== 'yes') {
|
|
| 132 | + if ($this->settings['enabled']!=='yes') {
|
|
| 133 | 133 | return; |
| 134 | 134 | } elseif (!version_compare(phpversion(), '5.3.0', '>=')) {
|
| 135 | - $error_string = __(' is not compatible with your php and/or curl version', 'pagantis');
|
|
| 135 | + $error_string = __(' is not compatible with your php and/or curl version', 'pagantis');
|
|
| 136 | 136 | $this->settings['enabled'] = 'no'; |
| 137 | 137 | } elseif ($this->settings['pagantis_public_key']=="" || $this->settings['pagantis_private_key']=="") {
|
| 138 | 138 | $error_string = __(' is not configured correctly, the fields Public Key and Secret Key are mandatory for use this plugin', 'pagantis');
|
| 139 | 139 | $this->settings['enabled'] = 'no'; |
| 140 | 140 | } elseif (!in_array(get_woocommerce_currency(), $this->allowed_currencies)) {
|
| 141 | - $error_string = __(' only can be used in Euros', 'pagantis');
|
|
| 141 | + $error_string = __(' only can be used in Euros', 'pagantis');
|
|
| 142 | 142 | $this->settings['enabled'] = 'no'; |
| 143 | - } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS']<'2' |
|
| 144 | - || $this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS']>'12') {
|
|
| 143 | + } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'] < '2' |
|
| 144 | + || $this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'] > '12') {
|
|
| 145 | 145 | $error_string = __(' only can be payed from 2 to 12 installments', 'pagantis');
|
| 146 | - } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']<'2' |
|
| 147 | - || $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']>'12') {
|
|
| 146 | + } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] < '2' |
|
| 147 | + || $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] > '12') {
|
|
| 148 | 148 | $error_string = __(' only can be payed from 2 to 12 installments', 'pagantis');
|
| 149 | - } elseif ($this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT']<0) {
|
|
| 149 | + } elseif ($this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] < 0) {
|
|
| 150 | 150 | $error_string = __(' can not have a minimum amount less than 0', 'pagantis');
|
| 151 | 151 | } |
| 152 | 152 | |
@@ -180,7 +180,7 @@ discard block |
||
| 180 | 180 | |
| 181 | 181 | $shippingAddress = $order->get_address('shipping');
|
| 182 | 182 | $billingAddress = $order->get_address('billing');
|
| 183 | - if ($shippingAddress['address_1'] == '') {
|
|
| 183 | + if ($shippingAddress['address_1']=='') {
|
|
| 184 | 184 | $shippingAddress = $billingAddress; |
| 185 | 185 | } |
| 186 | 186 | |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | ->setNationalId($national_id) |
| 208 | 208 | ->setTaxId($tax_id) |
| 209 | 209 | ; |
| 210 | - $orderBillingAddress = new Address(); |
|
| 210 | + $orderBillingAddress = new Address(); |
|
| 211 | 211 | $orderBillingAddress |
| 212 | 212 | ->setZipCode($billingAddress['postcode']) |
| 213 | 213 | ->setFullName($billingAddress['first_name']." ".$billingAddress['last_name']) |
@@ -338,7 +338,7 @@ discard block |
||
| 338 | 338 | wc_get_template('iframe.php', $template_fields, '', $this->template_path);
|
| 339 | 339 | } |
| 340 | 340 | } catch (\Exception $exception) {
|
| 341 | - wc_add_notice(__('Payment error ', 'pagantis') . $exception->getMessage(), 'error');
|
|
| 341 | + wc_add_notice(__('Payment error ', 'pagantis').$exception->getMessage(), 'error');
|
|
| 342 | 342 | $this->insertLog($exception); |
| 343 | 343 | $checkout_url = get_permalink(wc_get_page_id('checkout'));
|
| 344 | 344 | wp_redirect($checkout_url); |
@@ -352,7 +352,7 @@ discard block |
||
| 352 | 352 | public function pagantisNotification() |
| 353 | 353 | {
|
| 354 | 354 | try {
|
| 355 | - $origin = ($_SERVER['REQUEST_METHOD'] == 'POST') ? 'Notify' : 'Order'; |
|
| 355 | + $origin = ($_SERVER['REQUEST_METHOD']=='POST') ? 'Notify' : 'Order'; |
|
| 356 | 356 | |
| 357 | 357 | include_once('notifyController.php');
|
| 358 | 358 | $notify = new WcPagantisNotify(); |
@@ -391,10 +391,10 @@ discard block |
||
| 391 | 391 | */ |
| 392 | 392 | public function pagantisCompleteStatus($status, $order_id, $order) |
| 393 | 393 | {
|
| 394 | - if ($order->get_payment_method() == WcPagantisGateway::METHOD_ID) {
|
|
| 395 | - if ($order->get_status() == 'failed') {
|
|
| 394 | + if ($order->get_payment_method()==WcPagantisGateway::METHOD_ID) {
|
|
| 395 | + if ($order->get_status()=='failed') {
|
|
| 396 | 396 | $status = 'processing'; |
| 397 | - } elseif ($order->get_status() == 'pending' && $status=='completed') {
|
|
| 397 | + } elseif ($order->get_status()=='pending' && $status=='completed') {
|
|
| 398 | 398 | $status = 'processing'; |
| 399 | 399 | } |
| 400 | 400 | } |
@@ -418,7 +418,7 @@ discard block |
||
| 418 | 418 | $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']); |
| 419 | 419 | $allowedCountry = (in_array(strtolower($locale), $allowedCountries)); |
| 420 | 420 | if ($this->enabled==='yes' && $this->pagantis_public_key!='' && $this->pagantis_private_key!='' && |
| 421 | - (int)$this->get_order_total()>$this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] && $allowedCountry) {
|
|
| 421 | + (int) $this->get_order_total() > $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] && $allowedCountry) {
|
|
| 422 | 422 | return true; |
| 423 | 423 | } |
| 424 | 424 | |
@@ -446,7 +446,7 @@ discard block |
||
| 446 | 446 | |
| 447 | 447 | $redirectUrl = $order->get_checkout_payment_url(true); //pagantisReceiptPage function |
| 448 | 448 | if (strpos($redirectUrl, 'order-pay=')===false) {
|
| 449 | - $redirectUrl.="&order-pay=".$order_id; |
|
| 449 | + $redirectUrl .= "&order-pay=".$order_id; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | return array( |
@@ -455,7 +455,7 @@ discard block |
||
| 455 | 455 | ); |
| 456 | 456 | |
| 457 | 457 | } catch (Exception $e) {
|
| 458 | - wc_add_notice(__('Payment error ', 'pagantis') . $e->getMessage(), 'error');
|
|
| 458 | + wc_add_notice(__('Payment error ', 'pagantis').$e->getMessage(), 'error');
|
|
| 459 | 459 | return array(); |
| 460 | 460 | } |
| 461 | 461 | } |
@@ -514,7 +514,7 @@ discard block |
||
| 514 | 514 | private function generateUrl($url) |
| 515 | 515 | {
|
| 516 | 516 | $parsed_url = parse_url($url); |
| 517 | - if ($parsed_url !== false) {
|
|
| 517 | + if ($parsed_url!==false) {
|
|
| 518 | 518 | $parsed_url['query'] = !isset($parsed_url['query']) ? '' : $parsed_url['query']; |
| 519 | 519 | parse_str($parsed_url['query'], $arrayParams); |
| 520 | 520 | foreach ($arrayParams as $keyParam => $valueParam) {
|
@@ -562,11 +562,10 @@ discard block |
||
| 562 | 562 | private function getKeysUrl($order, $url) |
| 563 | 563 | {
|
| 564 | 564 | $defaultFields = (get_class($order)=='WC_Order') ? |
| 565 | - array('order-received'=>$order->get_id(), 'key'=>$order->get_order_key()) :
|
|
| 566 | - array(); |
|
| 565 | + array('order-received'=>$order->get_id(), 'key'=>$order->get_order_key()) : array();
|
|
| 567 | 566 | |
| 568 | 567 | $parsedUrl = parse_url($url); |
| 569 | - if ($parsedUrl !== false) {
|
|
| 568 | + if ($parsedUrl!==false) {
|
|
| 570 | 569 | //Replace parameters from url |
| 571 | 570 | $parsedUrl['query'] = $this->getKeysParametersUrl($parsedUrl['query'], $defaultFields); |
| 572 | 571 | |
@@ -611,7 +610,7 @@ discard block |
||
| 611 | 610 | foreach ($arrayParams as $keyParam => $valueParam) {
|
| 612 | 611 | preg_match('#\{{.*?}\}#', $valueParam, $match);
|
| 613 | 612 | if (count($match)) {
|
| 614 | - $key = str_replace(array('{{','}}'), array('',''), $match[0]);
|
|
| 613 | + $key = str_replace(array('{{', '}}'), array('', ''), $match[0]);
|
|
| 615 | 614 | $arrayParams[$keyParam] = $defaultFields[$key]; |
| 616 | 615 | } |
| 617 | 616 | } |
@@ -626,13 +625,13 @@ discard block |
||
| 626 | 625 | */ |
| 627 | 626 | private function unparseUrl($parsed_url) |
| 628 | 627 | {
|
| 629 | - $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : ''; |
|
| 628 | + $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : ''; |
|
| 630 | 629 | $host = isset($parsed_url['host']) ? $parsed_url['host'] : ''; |
| 631 | - $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : ''; |
|
| 632 | - $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : ''; |
|
| 633 | - $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : ''; |
|
| 630 | + $port = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : ''; |
|
| 631 | + $query = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : ''; |
|
| 632 | + $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : ''; |
|
| 634 | 633 | $path = $parsed_url['path']; |
| 635 | - return $scheme . $host . $port . $path . $query . $fragment; |
|
| 634 | + return $scheme.$host.$port.$path.$query.$fragment; |
|
| 636 | 635 | } |
| 637 | 636 | |
| 638 | 637 | /** |
@@ -654,20 +653,20 @@ discard block |
||
| 654 | 653 | $is_guest = "false"; |
| 655 | 654 | $sign_up = substr($current_user->user_registered, 0, 10); |
| 656 | 655 | $customer_orders = get_posts(array( |
| 657 | - 'numberposts' => - 1, |
|
| 656 | + 'numberposts' => -1, |
|
| 658 | 657 | 'meta_key' => '_customer_user', |
| 659 | 658 | 'meta_value' => $current_user->ID, |
| 660 | - 'post_type' => array( 'shop_order' ), |
|
| 661 | - 'post_status' => array( 'wc-completed', 'wc-processing', 'wc-refunded' ), |
|
| 659 | + 'post_type' => array('shop_order'),
|
|
| 660 | + 'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'),
|
|
| 662 | 661 | )); |
| 663 | 662 | } else {
|
| 664 | 663 | $is_guest = "true"; |
| 665 | 664 | $customer_orders = get_posts(array( |
| 666 | - 'numberposts' => - 1, |
|
| 665 | + 'numberposts' => -1, |
|
| 667 | 666 | 'meta_key' => '_billing_email', |
| 668 | 667 | 'meta_value' => $billingEmail, |
| 669 | - 'post_type' => array( 'shop_order' ), |
|
| 670 | - 'post_status' => array( 'wc-completed', 'wc-processing', 'wc-refunded'), |
|
| 668 | + 'post_type' => array('shop_order'),
|
|
| 669 | + 'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'),
|
|
| 671 | 670 | )); |
| 672 | 671 | foreach ($customer_orders as $customer_order) {
|
| 673 | 672 | if (trim($sign_up)=='' || |
@@ -696,7 +695,7 @@ discard block |
||
| 696 | 695 | //Check if id exists |
| 697 | 696 | $resultsSelect = $wpdb->get_results("select * from $tableName where id='$orderId'");
|
| 698 | 697 | $countResults = count($resultsSelect); |
| 699 | - if ($countResults == 0) {
|
|
| 698 | + if ($countResults==0) {
|
|
| 700 | 699 | $wpdb->insert( |
| 701 | 700 | $tableName, |
| 702 | 701 | array('id' => $orderId, 'order_id' => $pagantisOrderId),
|
@@ -721,7 +720,7 @@ discard block |
||
| 721 | 720 | global $wpdb; |
| 722 | 721 | $tableName = $wpdb->prefix.self::ORDERS_TABLE; |
| 723 | 722 | |
| 724 | - if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
|
|
| 723 | + if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'")!=$tableName) {
|
|
| 725 | 724 | $charset_collate = $wpdb->get_charset_collate(); |
| 726 | 725 | $sql = "CREATE TABLE $tableName ( id int, order_id varchar(50), wc_order_id varchar(50), |
| 727 | 726 | UNIQUE KEY id (id)) $charset_collate"; |
@@ -754,9 +753,9 @@ discard block |
||
| 754 | 753 | */ |
| 755 | 754 | private function getNationalId($order) |
| 756 | 755 | {
|
| 757 | - foreach ((array)$order->get_meta_data() as $mdObject) {
|
|
| 756 | + foreach ((array) $order->get_meta_data() as $mdObject) {
|
|
| 758 | 757 | $data = $mdObject->get_data(); |
| 759 | - if ($data['key'] == 'vat_number') {
|
|
| 758 | + if ($data['key']=='vat_number') {
|
|
| 760 | 759 | return $data['value']; |
| 761 | 760 | } |
| 762 | 761 | } |
@@ -771,9 +770,9 @@ discard block |
||
| 771 | 770 | */ |
| 772 | 771 | private function getTaxId($order) |
| 773 | 772 | {
|
| 774 | - foreach ((array)$order->get_meta_data() as $mdObject) {
|
|
| 773 | + foreach ((array) $order->get_meta_data() as $mdObject) {
|
|
| 775 | 774 | $data = $mdObject->get_data(); |
| 776 | - if ($data['key'] == 'billing_cfpiva') {
|
|
| 775 | + if ($data['key']=='billing_cfpiva') {
|
|
| 777 | 776 | return $data['value']; |
| 778 | 777 | } |
| 779 | 778 | } |
@@ -803,7 +802,7 @@ discard block |
||
| 803 | 802 | {
|
| 804 | 803 | global $wpdb; |
| 805 | 804 | $tableName = $wpdb->prefix.self::LOGS_TABLE; |
| 806 | - if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
|
|
| 805 | + if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'")!=$tableName) {
|
|
| 807 | 806 | $charset_collate = $wpdb->get_charset_collate(); |
| 808 | 807 | $sql = "CREATE TABLE $tableName ( id int NOT NULL AUTO_INCREMENT, log text NOT NULL, |
| 809 | 808 | createdAt timestamp DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY id (id)) $charset_collate"; |