Passed
Pull Request — master (#24)
by
unknown
04:20
created
controllers/paymentController.php 1 patch
Spacing   +62 added lines, -63 removed lines patch added patch discarded remove patch
@@ -54,38 +54,38 @@  discard block
 block discarded – undo
54 54
         $this->method_title = ucfirst($this->id);
55 55
 
56 56
         //Useful vars
57
-        $this->template_path = plugin_dir_path(__FILE__) . '../templates/';
57
+        $this->template_path = plugin_dir_path(__FILE__).'../templates/';
58 58
         $this->allowed_currencies = array("EUR");
59
-        $this->mainFileLocation = dirname(plugin_dir_path(__FILE__)) . '/WC_Pagantis.php';
59
+        $this->mainFileLocation = dirname(plugin_dir_path(__FILE__)).'/WC_Pagantis.php';
60 60
         $this->plugin_info = get_file_data($this->mainFileLocation, array('Version' => 'Version'), false);
61 61
         $this->language = strstr(get_locale(), '_', true);
62 62
 
63
-        if ($this->language == 'es' || $this->language == '') {
63
+        if ($this->language=='es' || $this->language=='') {
64 64
             $this->icon = esc_url(plugins_url('../assets/images/logopagamastarde.png', __FILE__));
65 65
         } else {
66 66
             $this->icon = esc_url(plugins_url('../assets/images/logo.png', __FILE__));
67 67
         }
68 68
 
69 69
         //Panel form fields
70
-        $this->form_fields = include(plugin_dir_path(__FILE__).'../includes/settings-pagantis.php');//Panel options
70
+        $this->form_fields = include(plugin_dir_path(__FILE__).'../includes/settings-pagantis.php'); //Panel options
71 71
         $this->init_settings();
72 72
 
73 73
         $this->extraConfig = $this->getExtraConfig();
74 74
         $this->title = __($this->extraConfig['PAGANTIS_TITLE'], 'pagantis');
75 75
         $this->method_description = "Financial Payment Gateway. Enable the possibility for your customers to pay their order in confortable installments with Pagantis.";
76 76
 
77
-        $this->settings['ok_url'] = ($this->extraConfig['PAGANTIS_URL_OK']!='')?$this->extraConfig['PAGANTIS_URL_OK']:$this->generateOkUrl();
78
-        $this->settings['ko_url'] = ($this->extraConfig['PAGANTIS_URL_KO']!='')?$this->extraConfig['PAGANTIS_URL_KO']:$this->generateKoUrl();
77
+        $this->settings['ok_url'] = ($this->extraConfig['PAGANTIS_URL_OK']!='') ? $this->extraConfig['PAGANTIS_URL_OK'] : $this->generateOkUrl();
78
+        $this->settings['ko_url'] = ($this->extraConfig['PAGANTIS_URL_KO']!='') ? $this->extraConfig['PAGANTIS_URL_KO'] : $this->generateKoUrl();
79 79
         foreach ($this->settings as $setting_key => $setting_value) {
80 80
             $this->$setting_key = $setting_value;
81 81
         }
82 82
 
83 83
         //Hooks
84
-        add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this,'process_admin_options')); //Save plugin options
85
-        add_action('admin_notices', array($this, 'pagantisCheckFields'));                          //Check config fields
86
-        add_action('woocommerce_receipt_'.$this->id, array($this, 'pagantisReceiptPage'));          //Pagantis form
87
-        add_action('woocommerce_api_wcpagantisgateway', array($this, 'pagantisNotification'));      //Json Notification
88
-        add_filter('woocommerce_payment_complete_order_status', array($this,'pagantisCompleteStatus'), 10, 3);
84
+        add_action('woocommerce_update_options_payment_gateways_'.$this->id, array($this, 'process_admin_options')); //Save plugin options
85
+        add_action('admin_notices', array($this, 'pagantisCheckFields')); //Check config fields
86
+        add_action('woocommerce_receipt_'.$this->id, array($this, 'pagantisReceiptPage')); //Pagantis form
87
+        add_action('woocommerce_api_wcpagantisgateway', array($this, 'pagantisNotification')); //Json Notification
88
+        add_filter('woocommerce_payment_complete_order_status', array($this, 'pagantisCompleteStatus'), 10, 3);
89 89
         add_filter('load_textdomain_mofile', array($this, 'loadPagantisTranslation'), 10, 2);
90 90
     }
91 91
 
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
      */
98 98
     public function loadPagantisTranslation($mofile, $domain)
99 99
     {
100
-        if ('pagantis' === $domain) {
101
-            $mofile = WP_LANG_DIR . '/../plugins/pagantis/languages/pagantis-' . get_locale() . '.mo';
100
+        if ('pagantis'===$domain) {
101
+            $mofile = WP_LANG_DIR.'/../plugins/pagantis/languages/pagantis-'.get_locale().'.mo';
102 102
         }
103 103
         return $mofile;
104 104
     }
@@ -130,24 +130,24 @@  discard block
 block discarded – undo
130 130
     public function pagantisCheckFields()
131 131
     {
132 132
         $error_string = '';
133
-        if ($this->settings['enabled'] !== 'yes') {
133
+        if ($this->settings['enabled']!=='yes') {
134 134
             return;
135 135
         } elseif (!version_compare(phpversion(), '5.3.0', '>=')) {
136
-            $error_string =  __(' is not compatible with your php and/or curl version', 'pagantis');
136
+            $error_string = __(' is not compatible with your php and/or curl version', 'pagantis');
137 137
             $this->settings['enabled'] = 'no';
138 138
         } elseif ($this->settings['pagantis_public_key']=="" || $this->settings['pagantis_private_key']=="") {
139 139
             $error_string = __(' is not configured correctly, the fields Public Key and Secret Key are mandatory for use this plugin', 'pagantis');
140 140
             $this->settings['enabled'] = 'no';
141 141
         } elseif (!in_array(get_woocommerce_currency(), $this->allowed_currencies)) {
142
-            $error_string =  __(' only can be used in Euros', 'pagantis');
142
+            $error_string = __(' only can be used in Euros', 'pagantis');
143 143
             $this->settings['enabled'] = 'no';
144
-        } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS']<'2'
145
-                  || $this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS']>'12') {
144
+        } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'] < '2'
145
+                  || $this->extraConfig['PAGANTIS_SIMULATOR_MAX_INSTALLMENTS'] > '12') {
146 146
             $error_string = __(' only can be payed from 2 to 12 installments', 'pagantis');
147
-        } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']<'2'
148
-                  || $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS']>'12') {
147
+        } elseif ($this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] < '2'
148
+                  || $this->extraConfig['PAGANTIS_SIMULATOR_START_INSTALLMENTS'] > '12') {
149 149
             $error_string = __(' only can be payed from 2 to 12 installments', 'pagantis');
150
-        } elseif ($this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT']<0) {
150
+        } elseif ($this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] < 0) {
151 151
             $error_string = __(' can not have a minimum amount less than 0', 'pagantis');
152 152
         }
153 153
 
@@ -181,7 +181,7 @@  discard block
 block discarded – undo
181 181
 
182 182
             $shippingAddress = $order->get_address('shipping');
183 183
             $billingAddress = $order->get_address('billing');
184
-            if ($shippingAddress['address_1'] == '') {
184
+            if ($shippingAddress['address_1']=='') {
185 185
                 $shippingAddress = $billingAddress;
186 186
             }
187 187
 
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
                 ->setNationalId($national_id)
209 209
                 ->setTaxId($tax_id)
210 210
             ;
211
-            $orderBillingAddress =  new Address();
211
+            $orderBillingAddress = new Address();
212 212
             $orderBillingAddress
213 213
                 ->setZipCode($billingAddress['postcode'])
214 214
                 ->setFullName($billingAddress['first_name']." ".$billingAddress['last_name'])
@@ -276,12 +276,12 @@  discard block
 block discarded – undo
276 276
                 $details->addProduct($product);
277 277
 
278 278
                 $promotedProduct = $this->isPromoted($item['product_id']);
279
-                if ($promotedProduct == 'true') {
280
-                    $promotedAmount+=$product->getAmount();
281
-                    $promotedMessage = 'Promoted Item: ' . $product->getDescription() .
282
-                                       ' Price: ' . $item['line_total'] .
283
-                                       ' Qty: ' . $product->getQuantity() .
284
-                                       ' Item ID: ' . $item['id_product'];
279
+                if ($promotedProduct=='true') {
280
+                    $promotedAmount += $product->getAmount();
281
+                    $promotedMessage = 'Promoted Item: '.$product->getDescription().
282
+                                       ' Price: '.$item['line_total'].
283
+                                       ' Qty: '.$product->getQuantity().
284
+                                       ' Item ID: '.$item['id_product'];
285 285
                     $metadataOrder->addMetadata('promotedProduct', $promotedMessage);
286 286
                 }
287 287
             }
@@ -353,7 +353,7 @@  discard block
 block discarded – undo
353 353
                 wc_get_template('iframe.php', $template_fields, '', $this->template_path);
354 354
             }
355 355
         } catch (\Exception $exception) {
356
-            wc_add_notice(__('Payment error ', 'pagantis') . $exception->getMessage(), 'error');
356
+            wc_add_notice(__('Payment error ', 'pagantis').$exception->getMessage(), 'error');
357 357
             $this->insertLog($exception);
358 358
             $checkout_url = get_permalink(wc_get_page_id('checkout'));
359 359
             wp_redirect($checkout_url);
@@ -367,7 +367,7 @@  discard block
 block discarded – undo
367 367
     public function pagantisNotification()
368 368
     {
369 369
         try {
370
-            $origin = ($_SERVER['REQUEST_METHOD'] == 'POST') ? 'Notify' : 'Order';
370
+            $origin = ($_SERVER['REQUEST_METHOD']=='POST') ? 'Notify' : 'Order';
371 371
 
372 372
             include_once('notifyController.php');
373 373
             $notify = new WcPagantisNotify();
@@ -406,10 +406,10 @@  discard block
 block discarded – undo
406 406
      */
407 407
     public function pagantisCompleteStatus($status, $order_id, $order)
408 408
     {
409
-        if ($order->get_payment_method() == WcPagantisGateway::METHOD_ID) {
410
-            if ($order->get_status() == 'failed') {
409
+        if ($order->get_payment_method()==WcPagantisGateway::METHOD_ID) {
410
+            if ($order->get_status()=='failed') {
411 411
                 $status = 'processing';
412
-            } elseif ($order->get_status() == 'pending' && $status=='completed') {
412
+            } elseif ($order->get_status()=='pending' && $status=='completed') {
413 413
                 $status = 'processing';
414 414
             }
415 415
         }
@@ -433,7 +433,7 @@  discard block
 block discarded – undo
433 433
         $allowedCountries = unserialize($this->extraConfig['PAGANTIS_ALLOWED_COUNTRIES']);
434 434
         $allowedCountry = (in_array(strtolower($locale), $allowedCountries));
435 435
         if ($this->enabled==='yes' && $this->pagantis_public_key!='' && $this->pagantis_private_key!='' &&
436
-            (int)$this->get_order_total()>$this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] && $allowedCountry) {
436
+            (int) $this->get_order_total() > $this->extraConfig['PAGANTIS_DISPLAY_MIN_AMOUNT'] && $allowedCountry) {
437 437
             return true;
438 438
         }
439 439
 
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 
462 462
             $redirectUrl = $order->get_checkout_payment_url(true); //pagantisReceiptPage function
463 463
             if (strpos($redirectUrl, 'order-pay=')===false) {
464
-                $redirectUrl.="&order-pay=".$order_id;
464
+                $redirectUrl .= "&order-pay=".$order_id;
465 465
             }
466 466
 
467 467
             return array(
@@ -470,7 +470,7 @@  discard block
 block discarded – undo
470 470
             );
471 471
 
472 472
         } catch (Exception $e) {
473
-            wc_add_notice(__('Payment error ', 'pagantis') . $e->getMessage(), 'error');
473
+            wc_add_notice(__('Payment error ', 'pagantis').$e->getMessage(), 'error');
474 474
             return array();
475 475
         }
476 476
     }
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
     private function generateUrl($url)
532 532
     {
533 533
         $parsed_url = parse_url($url);
534
-        if ($parsed_url !== false) {
534
+        if ($parsed_url!==false) {
535 535
             $parsed_url['query'] = !isset($parsed_url['query']) ? '' : $parsed_url['query'];
536 536
             parse_str($parsed_url['query'], $arrayParams);
537 537
             foreach ($arrayParams as $keyParam => $valueParam) {
@@ -579,11 +579,10 @@  discard block
 block discarded – undo
579 579
     private function getKeysUrl($order, $url)
580 580
     {
581 581
         $defaultFields = (get_class($order)=='WC_Order') ?
582
-            array('order-received'=>$order->get_id(), 'key'=>$order->get_order_key()) :
583
-            array();
582
+            array('order-received'=>$order->get_id(), 'key'=>$order->get_order_key()) : array();
584 583
 
585 584
         $parsedUrl = parse_url($url);
586
-        if ($parsedUrl !== false) {
585
+        if ($parsedUrl!==false) {
587 586
             //Replace parameters from url
588 587
             $parsedUrl['query'] = $this->getKeysParametersUrl($parsedUrl['query'], $defaultFields);
589 588
 
@@ -628,7 +627,7 @@  discard block
 block discarded – undo
628 627
         foreach ($arrayParams as $keyParam => $valueParam) {
629 628
             preg_match('#\{{.*?}\}#', $valueParam, $match);
630 629
             if (count($match)) {
631
-                $key = str_replace(array('{{','}}'), array('',''), $match[0]);
630
+                $key = str_replace(array('{{', '}}'), array('', ''), $match[0]);
632 631
                 $arrayParams[$keyParam] = $defaultFields[$key];
633 632
             }
634 633
         }
@@ -643,13 +642,13 @@  discard block
 block discarded – undo
643 642
      */
644 643
     private function unparseUrl($parsed_url)
645 644
     {
646
-        $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
645
+        $scheme   = isset($parsed_url['scheme']) ? $parsed_url['scheme'].'://' : '';
647 646
         $host     = isset($parsed_url['host']) ? $parsed_url['host'] : '';
648
-        $port     = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
649
-        $query    = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
650
-        $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
647
+        $port     = isset($parsed_url['port']) ? ':'.$parsed_url['port'] : '';
648
+        $query    = isset($parsed_url['query']) ? '?'.$parsed_url['query'] : '';
649
+        $fragment = isset($parsed_url['fragment']) ? '#'.$parsed_url['fragment'] : '';
651 650
         $path     = $parsed_url['path'];
652
-        return $scheme . $host . $port . $path . $query . $fragment;
651
+        return $scheme.$host.$port.$path.$query.$fragment;
653 652
     }
654 653
 
655 654
     /**
@@ -671,20 +670,20 @@  discard block
 block discarded – undo
671 670
             $is_guest = "false";
672 671
             $sign_up = substr($current_user->user_registered, 0, 10);
673 672
             $customer_orders = get_posts(array(
674
-                'numberposts' => - 1,
673
+                'numberposts' => -1,
675 674
                 'meta_key'    => '_customer_user',
676 675
                 'meta_value'  => $current_user->ID,
677
-                'post_type'   => array( 'shop_order' ),
678
-                'post_status' => array( 'wc-completed', 'wc-processing', 'wc-refunded' ),
676
+                'post_type'   => array('shop_order'),
677
+                'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'),
679 678
             ));
680 679
         } else {
681 680
             $is_guest = "true";
682 681
             $customer_orders = get_posts(array(
683
-                'numberposts' => - 1,
682
+                'numberposts' => -1,
684 683
                 'meta_key'    => '_billing_email',
685 684
                 'meta_value'  => $billingEmail,
686
-                'post_type'   => array( 'shop_order' ),
687
-                'post_status' => array( 'wc-completed', 'wc-processing', 'wc-refunded'),
685
+                'post_type'   => array('shop_order'),
686
+                'post_status' => array('wc-completed', 'wc-processing', 'wc-refunded'),
688 687
             ));
689 688
             foreach ($customer_orders as $customer_order) {
690 689
                 if (trim($sign_up)=='' ||
@@ -713,7 +712,7 @@  discard block
 block discarded – undo
713 712
         //Check if id exists
714 713
         $resultsSelect = $wpdb->get_results("select * from $tableName where id='$orderId'");
715 714
         $countResults = count($resultsSelect);
716
-        if ($countResults == 0) {
715
+        if ($countResults==0) {
717 716
             $wpdb->insert(
718 717
                 $tableName,
719 718
                 array('id' => $orderId, 'order_id' => $pagantisOrderId),
@@ -738,7 +737,7 @@  discard block
 block discarded – undo
738 737
         global $wpdb;
739 738
         $tableName = $wpdb->prefix.self::ORDERS_TABLE;
740 739
 
741
-        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
740
+        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'")!=$tableName) {
742 741
             $charset_collate = $wpdb->get_charset_collate();
743 742
             $sql             = "CREATE TABLE $tableName ( id int, order_id varchar(50), wc_order_id varchar(50),  
744 743
                   UNIQUE KEY id (id)) $charset_collate";
@@ -771,9 +770,9 @@  discard block
 block discarded – undo
771 770
      */
772 771
     private function getNationalId($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'] == 'vat_number') {
775
+            if ($data['key']=='vat_number') {
777 776
                 return $data['value'];
778 777
             }
779 778
         }
@@ -788,9 +787,9 @@  discard block
 block discarded – undo
788 787
      */
789 788
     private function getTaxId($order)
790 789
     {
791
-        foreach ((array)$order->get_meta_data() as $mdObject) {
790
+        foreach ((array) $order->get_meta_data() as $mdObject) {
792 791
             $data = $mdObject->get_data();
793
-            if ($data['key'] == 'billing_cfpiva') {
792
+            if ($data['key']=='billing_cfpiva') {
794 793
                 return $data['value'];
795 794
             }
796 795
         }
@@ -820,7 +819,7 @@  discard block
 block discarded – undo
820 819
     {
821 820
         global $wpdb;
822 821
         $tableName = $wpdb->prefix.self::LOGS_TABLE;
823
-        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'") != $tableName) {
822
+        if ($wpdb->get_var("SHOW TABLES LIKE '$tableName'")!=$tableName) {
824 823
             $charset_collate = $wpdb->get_charset_collate();
825 824
             $sql = "CREATE TABLE $tableName ( id int NOT NULL AUTO_INCREMENT, log text NOT NULL, 
826 825
                     createdAt timestamp DEFAULT CURRENT_TIMESTAMP, UNIQUE KEY id (id)) $charset_collate";
@@ -838,7 +837,7 @@  discard block
 block discarded – undo
838 837
     private function isPromoted($product_id)
839 838
     {
840 839
         $metaProduct = get_post_meta($product_id);
841
-        return ($metaProduct['custom_product_pagantis_promoted']['0'] === 'yes') ? 'true' : 'false';
840
+        return ($metaProduct['custom_product_pagantis_promoted']['0']==='yes') ? 'true' : 'false';
842 841
     }
843 842
 
844 843
     /**
@@ -851,8 +850,8 @@  discard block
 block discarded – undo
851 850
         $promotedAmount = 0;
852 851
         foreach ($items as $key => $item) {
853 852
             $promotedProduct = $this->isPromoted($item['product_id']);
854
-            if ($promotedProduct == 'true') {
855
-                $promotedAmount+=$item['line_total'];
853
+            if ($promotedProduct=='true') {
854
+                $promotedAmount += $item['line_total'];
856 855
             }
857 856
         }
858 857
 
Please login to merge, or discard this patch.