Passed
Pull Request — master (#236)
by Patrik
03:27
created
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetSOAP.php 1 patch
Spacing   +6 added lines, -6 removed lines patch added patch discarded remove patch
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
         $string = "";
52 52
         $types = $this->__getTypes();
53 53
         foreach ($types as $type) {
54
-            if (preg_match("/struct /",$type)) {
55
-                $type = preg_replace("/struct /","class ",$type);
56
-                $type = preg_replace("/ (\w+) (\w+);/","    // $1\n    public \$$2;",$type);
57
-                $string .= $type ."\n";
54
+            if (preg_match("/struct /", $type)) {
55
+                $type = preg_replace("/struct /", "class ", $type);
56
+                $type = preg_replace("/ (\w+) (\w+);/", "    // $1\n    public \$$2;", $type);
57
+                $string .= $type . "\n";
58 58
             }
59 59
         }
60 60
         return $string;
@@ -84,13 +84,13 @@  discard block
 block discarded – undo
84 84
      */
85 85
     public function saveSoapDocumentation($path)
86 86
     {
87
-        $string =  "<?php\n";
87
+        $string = "<?php\n";
88 88
         $string .= "/**\n";
89 89
         $string .= " * Auto generated documentation for the AuthorizeNetSOAP API.\n";
90 90
         $string .= " * Generated " . date("m/d/Y") . "\n";
91 91
         $string .= " */\n";
92 92
         $string .= "class AuthorizeNetSOAP\n";
93
-        $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() ."\n\n ?>";
93
+        $string .= "{\n" . $this->getSoapMethods() . "\n}\n\n" . $this->getSoapTypes() . "\n\n ?>";
94 94
         return file_put_contents($path, $string);
95 95
     }
96 96
     
Please login to merge, or discard this patch.
includes/gateways/authorizenet/anet_php_sdk/lib/AuthorizeNetDPM.php 3 patches
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -76,7 +76,7 @@
 block discarded – undo
76 76
             }
77 77
             else
78 78
             {
79
-              echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']);
79
+                echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']);
80 80
             }
81 81
         }
82 82
     }
Please login to merge, or discard this patch.
Spacing   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
                 else
58 58
                 {
59 59
                     // Redirect to error page.
60
-                    $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text;
60
+                    $redirect_url = $url . '?response_code=' . $response->response_code . '&response_reason_text=' . $response->response_reason_text;
61 61
                 }
62 62
                 // Send the Javascript back to AuthorizeNet, which will redirect user back to your site.
63 63
                 echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url);
@@ -179,54 +179,54 @@  discard block
 block discarded – undo
179 179
             -moz-box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75);
180 180
             box-shadow: inset 3px -3px 3px rgba(0,0,0,.5), inset 0 3px 3px rgba(255,255,255,.5), inset -3px 0 3px rgba(255,255,255,.75); }
181 181
         </style>
182
-        <form method="post" action="'.$post_url.'">
183
-                '.$hidden_fields.'
182
+        <form method="post" action="'.$post_url . '">
183
+                '.$hidden_fields . '
184 184
             <fieldset>
185 185
                 <div>
186 186
                     <label>Credit Card Number</label>
187
-                    <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '').'"></input>
187
+                    <input type="text" class="text" size="15" name="x_card_num" value="'.($prefill ? '6011000000000012' : '') . '"></input>
188 188
                 </div>
189 189
                 <div>
190 190
                     <label>Exp.</label>
191
-                    <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '').'"></input>
191
+                    <input type="text" class="text" size="4" name="x_exp_date" value="'.($prefill ? '04/17' : '') . '"></input>
192 192
                 </div>
193 193
                 <div>
194 194
                     <label>CCV</label>
195
-                    <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '').'"></input>
195
+                    <input type="text" class="text" size="4" name="x_card_code" value="'.($prefill ? '782' : '') . '"></input>
196 196
                 </div>
197 197
             </fieldset>
198 198
             <fieldset>
199 199
                 <div>
200 200
                     <label>First Name</label>
201
-                    <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '').'"></input>
201
+                    <input type="text" class="text" size="15" name="x_first_name" value="'.($prefill ? 'John' : '') . '"></input>
202 202
                 </div>
203 203
                 <div>
204 204
                     <label>Last Name</label>
205
-                    <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '').'"></input>
205
+                    <input type="text" class="text" size="14" name="x_last_name" value="'.($prefill ? 'Doe' : '') . '"></input>
206 206
                 </div>
207 207
             </fieldset>
208 208
             <fieldset>
209 209
                 <div>
210 210
                     <label>Address</label>
211
-                    <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '').'"></input>
211
+                    <input type="text" class="text" size="26" name="x_address" value="'.($prefill ? '123 Main Street' : '') . '"></input>
212 212
                 </div>
213 213
                 <div>
214 214
                     <label>City</label>
215
-                    <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '').'"></input>
215
+                    <input type="text" class="text" size="15" name="x_city" value="'.($prefill ? 'Boston' : '') . '"></input>
216 216
                 </div>
217 217
             </fieldset>
218 218
             <fieldset>
219 219
                 <div>
220 220
                     <label>State</label>
221
-                    <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '').'"></input>
221
+                    <input type="text" class="text" size="4" name="x_state" value="'.($prefill ? 'MA' : '') . '"></input>
222 222
                 </div>
223 223
                 <div>
224 224
                     <label>Zip Code</label>
225
-                    <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '').'"></input>
225
+                    <input type="text" class="text" size="9" name="x_zip" value="'.($prefill ? '02142' : '') . '"></input>
226 226
                 </div>
227 227
                 <div>
228 228
                     <label>Country</label>
229
-                    <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '').'"></input>
229
+                    <input type="text" class="text" size="22" name="x_country" value="'.($prefill ? 'US' : '') . '"></input>
230 230
                 </div>
231 231
             </fieldset>
232 232
             <input type="submit" value="BUY" class="submit buy">
Please login to merge, or discard this patch.
Braces   +3 added lines, -6 removed lines patch added patch discarded remove patch
@@ -53,16 +53,14 @@  discard block
 block discarded – undo
53 53
                 {
54 54
                     // Do your processing here.
55 55
                     $redirect_url = $url . '?response_code=1&transaction_id=' . $response->transaction_id; 
56
-                }
57
-                else
56
+                } else
58 57
                 {
59 58
                     // Redirect to error page.
60 59
                     $redirect_url = $url . '?response_code='.$response->response_code . '&response_reason_text=' . $response->response_reason_text;
61 60
                 }
62 61
                 // Send the Javascript back to AuthorizeNet, which will redirect user back to your site.
63 62
                 echo AuthorizeNetDPM::getRelayResponseSnippet($redirect_url);
64
-            }
65
-            else
63
+            } else
66 64
             {
67 65
                 echo "Error -- not AuthorizeNet. Check your MD5 Setting.";
68 66
             }
@@ -73,8 +71,7 @@  discard block
 block discarded – undo
73 71
             if ($_GET['response_code'] == 1)
74 72
             {
75 73
                 echo "Thank you for your purchase! Transaction id: " . htmlentities($_GET['transaction_id']);
76
-            }
77
-            else
74
+            } else
78 75
             {
79 76
               echo "Sorry, an error occurred: " . htmlentities($_GET['response_reason_text']);
80 77
             }
Please login to merge, or discard this patch.
includes/gateways/authorizenet.php 3 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
6 8
 
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -648,6 +648,9 @@
 block discarded – undo
648 648
 }
649 649
 add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 );
650 650
 
651
+/**
652
+ * @param WPInv_Invoice $invoice
653
+ */
651 654
 function wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
652 655
     if ( $transaction_id == $invoice_id ) {
653 656
         $link = $transaction_id;
Please login to merge, or discard this patch.
Spacing   +268 added lines, -268 removed lines patch added patch discarded remove patch
@@ -1,60 +1,60 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_filter( 'wpinv_authorizenet_support_subscription', '__return_true' );
5
+add_filter('wpinv_authorizenet_support_subscription', '__return_true');
6 6
 
7
-function wpinv_authorizenet_cc_form( $invoice_id ) {
8
-    $invoice = wpinv_get_invoice( $invoice_id );
9
-    $cc_owner = !empty( $invoice ) ? esc_attr( $invoice->get_user_full_name() ) : '';
7
+function wpinv_authorizenet_cc_form($invoice_id) {
8
+    $invoice = wpinv_get_invoice($invoice_id);
9
+    $cc_owner = !empty($invoice) ? esc_attr($invoice->get_user_full_name()) : '';
10 10
     ?>
11 11
     <div id="authorizenet_cc_form" class="form-horizontal wpi-cc-form panel panel-default">
12
-        <div class="panel-heading"><h3 class="panel-title"><?php _e( 'Card Details', 'invoicing' ) ;?></h3></div>
12
+        <div class="panel-heading"><h3 class="panel-title"><?php _e('Card Details', 'invoicing'); ?></h3></div>
13 13
         <div class="panel-body">
14 14
             <div class="form-group required">
15
-              <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e( 'Card Owner', 'invoicing' ) ;?></label>
15
+              <label for="auth-input-cc-owner" class="col-sm-3 control-label"><?php _e('Card Owner', 'invoicing'); ?></label>
16 16
               <div class="col-sm-5">
17
-                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e( 'Card Owner', 'invoicing' ) ;?>" value="<?php echo $cc_owner;?>" name="authorizenet[cc_owner]">
17
+                <input type="text" class="form-control" id="auth-input-cc-owner" placeholder="<?php esc_attr_e('Card Owner', 'invoicing'); ?>" value="<?php echo $cc_owner; ?>" name="authorizenet[cc_owner]">
18 18
               </div>
19 19
             </div>
20 20
             <div class="form-group required">
21
-              <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e( 'Card Number', 'invoicing' ) ;?></label>
21
+              <label for="auth-input-cc-number" class="col-sm-3 control-label"><?php _e('Card Number', 'invoicing'); ?></label>
22 22
               <div class="col-sm-5">
23
-                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e( 'Card Number', 'invoicing' ) ;?>" value="" name="authorizenet[cc_number]">
23
+                <input type="text" class="form-control" id="auth-input-cc-number" placeholder="<?php esc_attr_e('Card Number', 'invoicing'); ?>" value="" name="authorizenet[cc_number]">
24 24
               </div>
25 25
             </div>
26 26
             <div class="form-group required">
27
-              <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e( 'Card Expiry Date', 'invoicing' ) ;?></label>
27
+              <label for="auth-input-cc-expire-date" class="col-sm-3 control-label"><?php _e('Card Expiry Date', 'invoicing'); ?></label>
28 28
               <div class="col-sm-2">
29 29
                 <select class="form-control" id="auth-input-cc-expire-date" name="authorizenet[cc_expire_month]">
30
-                    <?php for ( $i = 1; $i <= 12; $i++ ) { $value = str_pad( $i, 2, '0', STR_PAD_LEFT ); ?>
31
-                    <option value="<?php echo $value;?>"><?php echo $value;?></option>
30
+                    <?php for ($i = 1; $i <= 12; $i++) { $value = str_pad($i, 2, '0', STR_PAD_LEFT); ?>
31
+                    <option value="<?php echo $value; ?>"><?php echo $value; ?></option>
32 32
                     <?php } ?>
33 33
                 </select>
34 34
                </div>
35 35
                <div class="col-sm-3">
36 36
                 <select class="form-control" name="authorizenet[cc_expire_year]">
37
-                    <?php $year = date( 'Y' ); for ( $i = $year; $i <= ( $year + 10 ); $i++ ) { ?>
38
-                    <option value="<?php echo $i;?>"><?php echo $i;?></option>
37
+                    <?php $year = date('Y'); for ($i = $year; $i <= ($year + 10); $i++) { ?>
38
+                    <option value="<?php echo $i; ?>"><?php echo $i; ?></option>
39 39
                     <?php } ?>
40 40
                 </select>
41 41
               </div>
42 42
             </div>
43 43
             <div class="form-group required">
44
-              <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e( 'Card Security Code (CVV2)', 'invoicing' ) ;?></label>
44
+              <label for="auth-input-cc-cvv2" class="col-sm-3 control-label"><?php _e('Card Security Code (CVV2)', 'invoicing'); ?></label>
45 45
               <div class="col-sm-5">
46
-                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e( 'Card Security Code (CVV2)', 'invoicing' ) ;?>" value="" name="authorizenet[cc_cvv2]"">
46
+                <input type="text" class="form-control" id="auth-input-cc-cvv2" placeholder="<?php esc_attr_e('Card Security Code (CVV2)', 'invoicing'); ?>" value="" name="authorizenet[cc_cvv2]"">
47 47
               </div>
48 48
             </div>
49 49
       </div>
50 50
     </div>
51 51
     <?php
52 52
 }
53
-add_action( 'wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1 );
53
+add_action('wpinv_authorizenet_cc_form', 'wpinv_authorizenet_cc_form', 10, 1);
54 54
 
55
-function wpinv_process_authorizenet_payment( $purchase_data ) {
56
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
57
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
55
+function wpinv_process_authorizenet_payment($purchase_data) {
56
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
57
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
58 58
     }
59 59
 
60 60
     // Collect payment data
@@ -72,10 +72,10 @@  discard block
 block discarded – undo
72 72
     );
73 73
 
74 74
     // Record the pending payment
75
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
75
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
76 76
 
77
-    if ( !empty( $invoice ) ) {
78
-        $authorizenet_card  = !empty( $_POST['authorizenet'] ) ? $_POST['authorizenet'] : array();
77
+    if (!empty($invoice)) {
78
+        $authorizenet_card  = !empty($_POST['authorizenet']) ? $_POST['authorizenet'] : array();
79 79
         $card_defaults      = array(
80 80
             'cc_owner'          => $invoice->get_user_full_name(),
81 81
             'cc_number'         => false,
@@ -83,192 +83,192 @@  discard block
 block discarded – undo
83 83
             'cc_expire_year'    => false,
84 84
             'cc_cvv2'           => false,
85 85
         );
86
-        $authorizenet_card = wp_parse_args( $authorizenet_card, $card_defaults );
86
+        $authorizenet_card = wp_parse_args($authorizenet_card, $card_defaults);
87 87
 
88
-        if ( empty( $authorizenet_card['cc_owner'] ) ) {
89
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
88
+        if (empty($authorizenet_card['cc_owner'])) {
89
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
90 90
         }
91
-        if ( empty( $authorizenet_card['cc_number'] ) ) {
92
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
91
+        if (empty($authorizenet_card['cc_number'])) {
92
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
93 93
         }
94
-        if ( empty( $authorizenet_card['cc_expire_month'] ) ) {
95
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
94
+        if (empty($authorizenet_card['cc_expire_month'])) {
95
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
96 96
         }
97
-        if ( empty( $authorizenet_card['cc_expire_year'] ) ) {
98
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
97
+        if (empty($authorizenet_card['cc_expire_year'])) {
98
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
99 99
         }
100
-        if ( empty( $authorizenet_card['cc_cvv2'] ) ) {
101
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
100
+        if (empty($authorizenet_card['cc_cvv2'])) {
101
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
102 102
         }
103 103
 
104 104
         $errors = wpinv_get_errors();
105 105
 
106
-        if ( empty( $errors ) ) {
106
+        if (empty($errors)) {
107 107
             $invoice_id = $invoice->ID;
108 108
             $quantities_enabled = wpinv_item_quantities_enabled();
109 109
             $use_taxes          = wpinv_use_taxes();
110 110
 
111 111
             $authorizeAIM = wpinv_authorizenet_AIM();
112
-            $authorizeAIM->first_name       = wpinv_utf8_substr( $invoice->get_first_name(), 0, 50 );
113
-            $authorizeAIM->last_name        = wpinv_utf8_substr( $invoice->get_last_name(), 0, 50 );
114
-            $authorizeAIM->company          = wpinv_utf8_substr( $invoice->company, 0, 50 );
115
-            $authorizeAIM->address          = wpinv_utf8_substr( wp_strip_all_tags( $invoice->get_address(), true ), 0, 60 );
116
-            $authorizeAIM->city             = wpinv_utf8_substr( $invoice->city, 0, 40 );
117
-            $authorizeAIM->state            = wpinv_utf8_substr( $invoice->state, 0, 40 );
118
-            $authorizeAIM->zip              = wpinv_utf8_substr( $invoice->zip, 0, 40 );
119
-            $authorizeAIM->country          = wpinv_utf8_substr( $invoice->country, 0, 60 );
120
-            $authorizeAIM->phone            = wpinv_utf8_substr( $invoice->phone, 0, 25 );
121
-            $authorizeAIM->email            = wpinv_utf8_substr( $invoice->get_email(), 0, 255 );
122
-            $authorizeAIM->amount           = wpinv_sanitize_amount( $invoice->get_total() );
123
-            $authorizeAIM->card_num         = str_replace( ' ', '', sanitize_text_field( $authorizenet_card['cc_number'] ) );
124
-            $authorizeAIM->exp_date         = sanitize_text_field( $authorizenet_card['cc_expire_month'] ) . sanitize_text_field( $authorizenet_card['cc_expire_year'] );
125
-            $authorizeAIM->card_code        = sanitize_text_field( $authorizenet_card['cc_cvv2'] );
112
+            $authorizeAIM->first_name       = wpinv_utf8_substr($invoice->get_first_name(), 0, 50);
113
+            $authorizeAIM->last_name        = wpinv_utf8_substr($invoice->get_last_name(), 0, 50);
114
+            $authorizeAIM->company          = wpinv_utf8_substr($invoice->company, 0, 50);
115
+            $authorizeAIM->address          = wpinv_utf8_substr(wp_strip_all_tags($invoice->get_address(), true), 0, 60);
116
+            $authorizeAIM->city             = wpinv_utf8_substr($invoice->city, 0, 40);
117
+            $authorizeAIM->state            = wpinv_utf8_substr($invoice->state, 0, 40);
118
+            $authorizeAIM->zip              = wpinv_utf8_substr($invoice->zip, 0, 40);
119
+            $authorizeAIM->country          = wpinv_utf8_substr($invoice->country, 0, 60);
120
+            $authorizeAIM->phone            = wpinv_utf8_substr($invoice->phone, 0, 25);
121
+            $authorizeAIM->email            = wpinv_utf8_substr($invoice->get_email(), 0, 255);
122
+            $authorizeAIM->amount           = wpinv_sanitize_amount($invoice->get_total());
123
+            $authorizeAIM->card_num         = str_replace(' ', '', sanitize_text_field($authorizenet_card['cc_number']));
124
+            $authorizeAIM->exp_date         = sanitize_text_field($authorizenet_card['cc_expire_month']) . sanitize_text_field($authorizenet_card['cc_expire_year']);
125
+            $authorizeAIM->card_code        = sanitize_text_field($authorizenet_card['cc_cvv2']);
126 126
             $authorizeAIM->invoice_num      = $invoice->ID;
127 127
 
128 128
             $item_desc = array();
129
-            foreach ( $invoice->get_cart_details() as $item ) {            
130
-                $quantity       = $quantities_enabled && !empty( $item['quantity'] ) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
-                $item_name      = wpinv_utf8_substr( $item['name'], 0, 31 );
132
-                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price( wpinv_format_amount( $item['item_price'] ) ) . ')';
129
+            foreach ($invoice->get_cart_details() as $item) {            
130
+                $quantity       = $quantities_enabled && !empty($item['quantity']) && $item['quantity'] > 0 ? $item['quantity'] : 1;
131
+                $item_name      = wpinv_utf8_substr($item['name'], 0, 31);
132
+                $item_desc[]    = $item_name . ' (' . $quantity . 'x ' . wpinv_price(wpinv_format_amount($item['item_price'])) . ')';
133 133
 
134
-                $authorizeAIM->addLineItem( $item['id'], $item_name, '', $quantity, $item['item_price'], ( $use_taxes && !empty( $item['tax'] ) && $item['tax'] > 0 ? 'Y' : 'N' ) );
134
+                $authorizeAIM->addLineItem($item['id'], $item_name, '', $quantity, $item['item_price'], ($use_taxes && !empty($item['tax']) && $item['tax'] > 0 ? 'Y' : 'N'));
135 135
             }
136 136
 
137
-            $item_desc = '#' . $invoice->get_number() . ': ' . implode( ', ', $item_desc );
137
+            $item_desc = '#' . $invoice->get_number() . ': ' . implode(', ', $item_desc);
138 138
 
139
-            if ( $use_taxes && $invoice->get_tax() > 0 ) {
140
-                $authorizeAIM->tax  = $invoice->get_tax();
139
+            if ($use_taxes && $invoice->get_tax() > 0) {
140
+                $authorizeAIM->tax = $invoice->get_tax();
141 141
 
142
-                $item_desc .= ', ' . wp_sprintf( __( 'Tax: %s', 'invoicing' ), $invoice->get_tax( true ) );
142
+                $item_desc .= ', ' . wp_sprintf(__('Tax: %s', 'invoicing'), $invoice->get_tax(true));
143 143
             }
144 144
 
145
-            if ( $invoice->get_discount() > 0 ) {
146
-                $item_desc .= ', ' . wp_sprintf( __( 'Discount: %s', 'invoicing' ), $invoice->get_discount( true ) );
145
+            if ($invoice->get_discount() > 0) {
146
+                $item_desc .= ', ' . wp_sprintf(__('Discount: %s', 'invoicing'), $invoice->get_discount(true));
147 147
             }
148 148
 
149
-            $item_description = wpinv_utf8_substr( $item_desc, 0, 255 );
150
-            $item_description = html_entity_decode( $item_desc , ENT_QUOTES, 'UTF-8' );
149
+            $item_description = wpinv_utf8_substr($item_desc, 0, 255);
150
+            $item_description = html_entity_decode($item_desc, ENT_QUOTES, 'UTF-8');
151 151
 
152
-            $authorizeAIM->description  = wpinv_utf8_substr( $item_description, 0, 255 );
152
+            $authorizeAIM->description = wpinv_utf8_substr($item_description, 0, 255);
153 153
 
154 154
             $is_recurring = $invoice->is_recurring(); // Recurring payment.
155 155
 
156
-            if ( $is_recurring ) {
156
+            if ($is_recurring) {
157 157
                 $authorizeAIM->recurring_billing = true;
158 158
             }
159 159
 
160 160
             try {
161 161
 
162
-                if ( $is_recurring ) {
162
+                if ($is_recurring) {
163 163
                     $trx_type = wpinv_get_option('authorizenet_transaction_type_recurring', 'authorize_only');
164
-                    if('authorize_capture' == $trx_type){
164
+                    if ('authorize_capture' == $trx_type) {
165 165
                         $response = $authorizeAIM->authorizeAndCapture();
166 166
                     } else {
167 167
                         $response = $authorizeAIM->authorizeOnly();
168 168
                     }
169 169
                 } else {
170 170
                     $trx_type = wpinv_get_option('authorizenet_transaction_type', 'authorize_capture');
171
-                    if('authorize_capture' == $trx_type){
171
+                    if ('authorize_capture' == $trx_type) {
172 172
                         $response = $authorizeAIM->authorizeAndCapture();
173 173
                     } else {
174 174
                         $response = $authorizeAIM->authorizeOnly();
175 175
                     }
176 176
                 }
177 177
 
178
-                if ( $response->approved || $response->held ) {
179
-                    if ( $response->approved ) {
180
-                        wpinv_update_payment_status( $invoice_id, 'publish' );
178
+                if ($response->approved || $response->held) {
179
+                    if ($response->approved) {
180
+                        wpinv_update_payment_status($invoice_id, 'publish');
181 181
                     }
182
-                    wpinv_set_payment_transaction_id( $invoice_id, $response->transaction_id );
182
+                    wpinv_set_payment_transaction_id($invoice_id, $response->transaction_id);
183 183
 
184
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment response: %s', 'invoicing' ), $response->response_reason_text ), '', '', true );
185
-                    wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing' ), $response->transaction_id, strtoupper( $response->transaction_type ), $response->authorization_code ), '', '', true );
184
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment response: %s', 'invoicing'), $response->response_reason_text), '', '', true);
185
+                    wpinv_insert_payment_note($invoice_id, wp_sprintf(__('Authorize.Net payment: Transaction ID %s, Transaction Type %s, Authorization Code %s', 'invoicing'), $response->transaction_id, strtoupper($response->transaction_type), $response->authorization_code), '', '', true);
186 186
 
187
-                    do_action( 'wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card );
187
+                    do_action('wpinv_authorizenet_handle_response', $response, $invoice, $authorizenet_card);
188 188
 
189 189
                     wpinv_clear_errors();
190 190
                     wpinv_empty_cart();
191 191
 
192
-                    wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
192
+                    wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
193 193
                 } else {
194
-                    if ( !empty( $response->response_reason_text ) ) {
195
-                        $error = __( $response->response_reason_text, 'invoicing' );
196
-                    } else if ( !empty( $response->error_message ) ) {
197
-                        $error = __( $response->error_message, 'invoicing' );
194
+                    if (!empty($response->response_reason_text)) {
195
+                        $error = __($response->response_reason_text, 'invoicing');
196
+                    } else if (!empty($response->error_message)) {
197
+                        $error = __($response->error_message, 'invoicing');
198 198
                     } else {
199
-                        $error = wp_sprintf( __( 'Error data: %s', 'invoicing' ), print_r( $response, true ) );
199
+                        $error = wp_sprintf(__('Error data: %s', 'invoicing'), print_r($response, true));
200 200
                     } 
201 201
 
202
-                    $error = wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $error );
202
+                    $error = wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $error);
203 203
 
204
-                    wpinv_set_error( 'payment_error', $error );
205
-                    wpinv_record_gateway_error( $error, $response );
206
-                    wpinv_insert_payment_note( $invoice_id, $error, '', '', true );
204
+                    wpinv_set_error('payment_error', $error);
205
+                    wpinv_record_gateway_error($error, $response);
206
+                    wpinv_insert_payment_note($invoice_id, $error, '', '', true);
207 207
 
208
-                    wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
208
+                    wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
209 209
                 }
210
-            } catch ( AuthorizeNetException $e ) {
211
-                wpinv_set_error( 'request_error', $e->getMessage() );
212
-                wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. %s', 'invoicing' ), $e->getMessage() ) );
213
-                wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
210
+            } catch (AuthorizeNetException $e) {
211
+                wpinv_set_error('request_error', $e->getMessage());
212
+                wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. %s', 'invoicing'), $e->getMessage()));
213
+                wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
214 214
             }
215 215
         } else {
216
-            wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
216
+            wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
217 217
         }
218 218
     } else {
219
-        wpinv_record_gateway_error( wp_sprintf( __( 'Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing' ), print_r( $payment_data, true ) ), $invoice );
220
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
219
+        wpinv_record_gateway_error(wp_sprintf(__('Authorize.Net payment error occurred. Payment creation failed while processing a Authorize.Net payment. Payment data: %s', 'invoicing'), print_r($payment_data, true)), $invoice);
220
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
221 221
     }
222 222
 }
223
-add_action( 'wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment' );
223
+add_action('wpinv_gateway_authorizenet', 'wpinv_process_authorizenet_payment');
224 224
 
225
-function wpinv_authorizenet_cancel_subscription( $subscription_id = '' ) {
226
-    if ( empty( $subscription_id ) ) {
225
+function wpinv_authorizenet_cancel_subscription($subscription_id = '') {
226
+    if (empty($subscription_id)) {
227 227
         return false;
228 228
     }
229 229
 
230 230
     try {
231 231
         $authnetXML = wpinv_authorizenet_XML();
232
-        $authnetXML->ARBCancelSubscriptionRequest( array( 'subscriptionId' => $subscription_id ) );
232
+        $authnetXML->ARBCancelSubscriptionRequest(array('subscriptionId' => $subscription_id));
233 233
         return $authnetXML->isSuccessful();
234
-    } catch( Exception $e ) {
235
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
234
+    } catch (Exception $e) {
235
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
236 236
     }
237 237
 
238 238
     return false;
239 239
 }
240 240
 
241
-function wpinv_recurring_cancel_authorizenet_subscription( $subscription, $valid = false ) {
242
-    if ( ! empty( $valid ) && ! empty( $subscription->profile_id ) ) {
243
-        return wpinv_authorizenet_cancel_subscription( $subscription->profile_id );
241
+function wpinv_recurring_cancel_authorizenet_subscription($subscription, $valid = false) {
242
+    if (!empty($valid) && !empty($subscription->profile_id)) {
243
+        return wpinv_authorizenet_cancel_subscription($subscription->profile_id);
244 244
     }
245 245
     
246 246
     return false;
247 247
 }
248
-add_action( 'wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2 );
248
+add_action('wpinv_recurring_cancel_authorizenet_subscription', 'wpinv_recurring_cancel_authorizenet_subscription', 10, 2);
249 249
 
250
-function wpinv_authorizenet_valid_ipn( $md5_hash, $transaction_id, $amount ) {
251
-    $authorizenet_md5_hash = wpinv_get_option( 'authorizenet_md5_hash' );
252
-    if ( empty( $authorizenet_md5_hash ) ) {
250
+function wpinv_authorizenet_valid_ipn($md5_hash, $transaction_id, $amount) {
251
+    $authorizenet_md5_hash = wpinv_get_option('authorizenet_md5_hash');
252
+    if (empty($authorizenet_md5_hash)) {
253 253
         return true;
254 254
     }
255 255
 
256
-    $compare_md5 = strtoupper( md5( $authorizenet_md5_hash . $transaction_id . $amount ) );
256
+    $compare_md5 = strtoupper(md5($authorizenet_md5_hash . $transaction_id . $amount));
257 257
 
258
-    return hash_equals( $compare_md5, $md5_hash );
258
+    return hash_equals($compare_md5, $md5_hash);
259 259
 }
260 260
 
261 261
 function wpinv_authorizenet_AIM() {
262
-    if ( !class_exists( 'AuthorizeNetException' ) ) {
263
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
262
+    if (!class_exists('AuthorizeNetException')) {
263
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/anet_php_sdk/AuthorizeNet.php';
264 264
     }
265 265
 
266
-    $authorizeAIM = new AuthorizeNetAIM( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ) );
266
+    $authorizeAIM = new AuthorizeNetAIM(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'));
267 267
 
268
-    if ( wpinv_is_test_mode( 'authorizenet' ) ) {
269
-        $authorizeAIM->setSandbox( true );
268
+    if (wpinv_is_test_mode('authorizenet')) {
269
+        $authorizeAIM->setSandbox(true);
270 270
     } else {
271
-        $authorizeAIM->setSandbox( false );
271
+        $authorizeAIM->setSandbox(false);
272 272
     }
273 273
 
274 274
     $authorizeAIM->customer_ip = wpinv_get_ip();
@@ -277,250 +277,250 @@  discard block
 block discarded – undo
277 277
 }
278 278
 
279 279
 function wpinv_authorizenet_XML() {
280
-    if ( !class_exists( 'AuthnetXML' ) ) {
281
-        require_once plugin_dir_path( WPINV_PLUGIN_FILE ) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
280
+    if (!class_exists('AuthnetXML')) {
281
+        require_once plugin_dir_path(WPINV_PLUGIN_FILE) . 'includes/gateways/authorizenet/Authorize.Net-XML/AuthnetXML.class.php';
282 282
     }
283 283
     
284
-    $authnetXML = new AuthnetXML( wpinv_get_option( 'authorizenet_login_id' ), wpinv_get_option( 'authorizenet_transaction_key' ), (bool)wpinv_is_test_mode( 'authorizenet' ) );
284
+    $authnetXML = new AuthnetXML(wpinv_get_option('authorizenet_login_id'), wpinv_get_option('authorizenet_transaction_key'), (bool)wpinv_is_test_mode('authorizenet'));
285 285
     
286 286
     return $authnetXML;
287 287
 }
288 288
 
289
-function wpinv_authorizenet_handle_response( $response, $invoice, $card_info = array() ) {
290
-    if ( empty( $response ) || empty( $invoice ) ) {
289
+function wpinv_authorizenet_handle_response($response, $invoice, $card_info = array()) {
290
+    if (empty($response) || empty($invoice)) {
291 291
         return false;
292 292
     }
293 293
 
294
-    if ( $invoice->is_recurring() && !empty( $response->approved ) ) {
295
-        $subscription = wpinv_authorizenet_create_new_subscription( $invoice, $response, $card_info );
294
+    if ($invoice->is_recurring() && !empty($response->approved)) {
295
+        $subscription = wpinv_authorizenet_create_new_subscription($invoice, $response, $card_info);
296 296
         $success = false;
297
-        if ( wpinv_is_test_mode( 'authorizenet' ) ) {
297
+        if (wpinv_is_test_mode('authorizenet')) {
298 298
             $success = true;
299 299
         } else {
300 300
             $success = $subscription->isSuccessful();
301 301
         }
302 302
 
303
-        if ( !empty( $subscription ) && $success ) {
304
-            do_action( 'wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet' );
303
+        if (!empty($subscription) && $success) {
304
+            do_action('wpinv_recurring_post_create_subscription', $subscription, $invoice, 'authorizenet');
305 305
 
306
-            wpinv_authorizenet_subscription_record_signup( $subscription, $invoice );
306
+            wpinv_authorizenet_subscription_record_signup($subscription, $invoice);
307 307
 
308
-            do_action( 'wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet' );
308
+            do_action('wpinv_recurring_post_record_signup', $subscription, $invoice, 'authorizenet');
309 309
         } else {
310
-            if ( isset( $subscription->messages->message ) ) {
310
+            if (isset($subscription->messages->message)) {
311 311
                 $error = $subscription->messages->message->code . ': ' . $subscription->messages->message->text;
312
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error, 'invoicing' );
312
+                wpinv_set_error('wpinv_authorize_recurring_error', $error, 'invoicing');
313 313
             } else {
314
-                $error = __( 'Your subscription cannot be created due to an error.', 'invoicing' );
315
-                wpinv_set_error( 'wpinv_authorize_recurring_error', $error );
314
+                $error = __('Your subscription cannot be created due to an error.', 'invoicing');
315
+                wpinv_set_error('wpinv_authorize_recurring_error', $error);
316 316
             }
317 317
 
318
-            wpinv_record_gateway_error( $error, $subscription );
318
+            wpinv_record_gateway_error($error, $subscription);
319 319
 
320
-            wpinv_insert_payment_note( $invoice->ID, wp_sprintf( __( 'Authorize.Net subscription error occurred. %s', 'invoicing' ), $error ), '', '', true );
320
+            wpinv_insert_payment_note($invoice->ID, wp_sprintf(__('Authorize.Net subscription error occurred. %s', 'invoicing'), $error), '', '', true);
321 321
         }
322 322
     }
323 323
 }
324
-add_action( 'wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3 );
324
+add_action('wpinv_authorizenet_handle_response', 'wpinv_authorizenet_handle_response', 10, 3);
325 325
 
326
-function wpinv_authorizenet_create_new_subscription( $invoice, $response = array(), $card_info = array() ) {
327
-    if ( empty( $invoice ) ) {
326
+function wpinv_authorizenet_create_new_subscription($invoice, $response = array(), $card_info = array()) {
327
+    if (empty($invoice)) {
328 328
         return false;
329 329
     }
330 330
 
331
-    $params = wpinv_authorizenet_generate_subscription_params( $invoice, $card_info, $response );
331
+    $params = wpinv_authorizenet_generate_subscription_params($invoice, $card_info, $response);
332 332
 
333 333
     try {
334 334
         $authnetXML = wpinv_authorizenet_XML();
335
-        $authnetXML->ARBCreateSubscriptionRequest( $params );
336
-    } catch( Exception $e ) {
335
+        $authnetXML->ARBCreateSubscriptionRequest($params);
336
+    } catch (Exception $e) {
337 337
         $authnetXML = array();
338
-        wpinv_error_log( $e->getMessage(), __( 'Authorize.Net cancel subscription', 'invoicing' ) );
338
+        wpinv_error_log($e->getMessage(), __('Authorize.Net cancel subscription', 'invoicing'));
339 339
     }
340 340
 
341 341
     return $authnetXML;
342 342
 }
343 343
 
344
-function wpinv_authorizenet_generate_subscription_params( $invoice, $card_info = array(), $response = array() ) {
345
-    if ( empty( $invoice ) ) {
344
+function wpinv_authorizenet_generate_subscription_params($invoice, $card_info = array(), $response = array()) {
345
+    if (empty($invoice)) {
346 346
         return false;
347 347
     }
348 348
 
349
-    $subscription_item = $invoice->get_recurring( true );
350
-    if ( empty( $subscription_item->ID ) ) {
349
+    $subscription_item = $invoice->get_recurring(true);
350
+    if (empty($subscription_item->ID)) {
351 351
         return false;
352 352
     }
353 353
 
354
-    $item = $invoice->get_recurring( true );
354
+    $item = $invoice->get_recurring(true);
355 355
 
356
-    if ( empty( $item ) ) {
356
+    if (empty($item)) {
357 357
         $name = '';
358 358
     }
359 359
 
360
-    if ( !( $name = $item->get_name() ) ) {
360
+    if (!($name = $item->get_name())) {
361 361
         $name = $item->post_name;
362 362
     }
363 363
 
364
-    $card_details       = wpinv_authorizenet_generate_card_info( $card_info );
364
+    $card_details       = wpinv_authorizenet_generate_card_info($card_info);
365 365
     $subscription_name  = $invoice->get_subscription_name();
366
-    $initial_amount     = wpinv_round_amount( $invoice->get_total() );
367
-    $recurring_amount   = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
366
+    $initial_amount     = wpinv_round_amount($invoice->get_total());
367
+    $recurring_amount   = wpinv_round_amount($invoice->get_recurring_details('total'));
368 368
     $interval           = $subscription_item->get_recurring_interval();
369 369
     $period             = $subscription_item->get_recurring_period();
370 370
     $bill_times         = (int)$subscription_item->get_recurring_limit();
371 371
     $bill_times         = $bill_times > 0 ? $bill_times : 9999;
372 372
 
373
-    $time_period        = wpinv_authorizenet_get_time_period( $interval, $period );
373
+    $time_period        = wpinv_authorizenet_get_time_period($interval, $period);
374 374
     $interval           = $time_period['interval'];
375 375
     $period             = $time_period['period'];
376 376
 
377 377
     $current_tz = date_default_timezone_get();
378
-    date_default_timezone_set( 'America/Denver' ); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
379
-    $today = date( 'Y-m-d' );
380
-    date_default_timezone_set( $current_tz );
378
+    date_default_timezone_set('America/Denver'); // Set same timezone as Authorize's server (Mountain Time) to prevent conflicts.
379
+    $today = date('Y-m-d');
380
+    date_default_timezone_set($current_tz);
381 381
 
382 382
     $free_trial = $invoice->is_free_trial();
383
-    if ( $free_trial && $subscription_item->has_free_trial() ) {
383
+    if ($free_trial && $subscription_item->has_free_trial()) {
384 384
         $trial_interval    = $subscription_item->get_trial_interval();
385
-        $trial_period      = $subscription_item->get_trial_period( true );
385
+        $trial_period      = $subscription_item->get_trial_period(true);
386 386
     }
387 387
 
388 388
     $subscription = array();
389 389
     $subscription['name'] = $subscription_name;
390 390
 
391 391
     $subscription['paymentSchedule'] = array(
392
-        'interval'         => array( 'length' => $interval, 'unit' => $period ),
392
+        'interval'         => array('length' => $interval, 'unit' => $period),
393 393
         'startDate'        => $today,
394 394
         'totalOccurrences' => $bill_times,
395
-        'trialOccurrences' => $free_trial || ( $initial_amount != $recurring_amount ) ? 1 : 0,
395
+        'trialOccurrences' => $free_trial || ($initial_amount != $recurring_amount) ? 1 : 0,
396 396
     );
397 397
 
398 398
     $subscription['amount'] = $recurring_amount;
399 399
     $subscription['trialAmount'] = $initial_amount;
400
-    $subscription['payment'] = array( 'creditCard' => $card_details );
401
-    $subscription['order'] = array( 'invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number() );
402
-    $subscription['customer'] = array( 'id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone );
400
+    $subscription['payment'] = array('creditCard' => $card_details);
401
+    $subscription['order'] = array('invoiceNumber' => $invoice->ID, 'description' => '#' . $invoice->get_number());
402
+    $subscription['customer'] = array('id' => $invoice->get_user_id(), 'email' => $invoice->get_email(), 'phoneNumber' => $invoice->phone);
403 403
 
404 404
     $subscription['billTo'] = array(
405 405
         'firstName' => $invoice->get_first_name(),
406 406
         'lastName'  => $invoice->get_last_name(),
407 407
         'company'   => $invoice->company,
408
-        'address'   => wp_strip_all_tags( $invoice->get_address(), true ),
408
+        'address'   => wp_strip_all_tags($invoice->get_address(), true),
409 409
         'city'      => $invoice->city,
410 410
         'state'     => $invoice->state,
411 411
         'zip'       => $invoice->zip,
412 412
         'country'   => $invoice->country,
413 413
     );
414 414
 
415
-    $params = array( 'subscription' => $subscription );
415
+    $params = array('subscription' => $subscription);
416 416
 
417
-    return apply_filters( 'wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response );
417
+    return apply_filters('wpinv_authorizenet_generate_subscription_params', $params, $invoice, $card_info, $response);
418 418
 }
419 419
 
420
-function wpinv_authorizenet_generate_card_info( $card_info = array() ) {
421
-    $card_defaults      = array(
420
+function wpinv_authorizenet_generate_card_info($card_info = array()) {
421
+    $card_defaults = array(
422 422
         'cc_owner'          => null,
423 423
         'cc_number'         => null,
424 424
         'cc_expire_month'   => null,
425 425
         'cc_expire_year'    => null,
426 426
         'cc_cvv2'           => null,
427 427
     );
428
-    $card_info = wp_parse_args( $card_info, $card_defaults );
428
+    $card_info = wp_parse_args($card_info, $card_defaults);
429 429
 
430 430
     $card_details = array(
431
-        'cardNumber'     => str_replace( ' ', '', sanitize_text_field( $card_info['cc_number'] ) ),
432
-        'expirationDate' => sanitize_text_field( $card_info['cc_expire_month'] ) . sanitize_text_field( $card_info['cc_expire_year'] ),
433
-        'cardCode'       => sanitize_text_field( $card_info['cc_cvv2'] ),
431
+        'cardNumber'     => str_replace(' ', '', sanitize_text_field($card_info['cc_number'])),
432
+        'expirationDate' => sanitize_text_field($card_info['cc_expire_month']) . sanitize_text_field($card_info['cc_expire_year']),
433
+        'cardCode'       => sanitize_text_field($card_info['cc_cvv2']),
434 434
     );
435 435
 
436 436
     return $card_details;
437 437
 }
438 438
 
439
-function wpinv_authorizenet_subscription_record_signup( $subscription, $invoice ) {
440
-    $parent_invoice_id = absint( $invoice->ID );
439
+function wpinv_authorizenet_subscription_record_signup($subscription, $invoice) {
440
+    $parent_invoice_id = absint($invoice->ID);
441 441
 
442
-    if( empty( $parent_invoice_id ) ) {
442
+    if (empty($parent_invoice_id)) {
443 443
         return;
444 444
     }
445 445
 
446
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
447
-    if ( empty( $invoice ) ) {
446
+    $invoice = wpinv_get_invoice($parent_invoice_id);
447
+    if (empty($invoice)) {
448 448
         return;
449 449
     }
450 450
 
451 451
     $subscriptionId     = (array)$subscription->subscriptionId;
452
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
452
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
453 453
 
454
-    $subscription = wpinv_get_authorizenet_subscription( $subscription, $parent_invoice_id );
454
+    $subscription = wpinv_get_authorizenet_subscription($subscription, $parent_invoice_id);
455 455
 
456
-    if ( false === $subscription ) {
456
+    if (false === $subscription) {
457 457
         return;
458 458
     }
459 459
 
460 460
     // Set payment to complete
461
-    wpinv_update_payment_status( $subscription->parent_payment_id, 'publish' );
461
+    wpinv_update_payment_status($subscription->parent_payment_id, 'publish');
462 462
     sleep(1);
463
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'Authorize.Net Subscription ID: %s', 'invoicing' ) , $subscription_id ), '', '', true );
464
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $subscription_id);
463
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('Authorize.Net Subscription ID: %s', 'invoicing'), $subscription_id), '', '', true);
464
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $subscription_id);
465 465
 
466 466
     $status     = 'trialling' == $subscription->status ? 'trialling' : 'active';
467
-    $diff_days  = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) );
468
-    $created    = date_i18n( 'Y-m-d H:i:s' );
469
-    $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) );
467
+    $diff_days  = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS));
468
+    $created    = date_i18n('Y-m-d H:i:s');
469
+    $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS)));
470 470
 
471 471
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
472
-    $subscription->update( array( 'profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration ) );
472
+    $subscription->update(array('profile_id' => $subscription_id, 'status' => $status, 'created' => $created, 'expiration' => $expiration));
473 473
 }
474 474
 
475
-function wpinv_authorizenet_validate_checkout( $valid_data, $post ) {
476
-    if ( !empty( $post['wpi-gateway'] ) && $post['wpi-gateway'] == 'authorizenet' ) {
475
+function wpinv_authorizenet_validate_checkout($valid_data, $post) {
476
+    if (!empty($post['wpi-gateway']) && $post['wpi-gateway'] == 'authorizenet') {
477 477
         $error = false;
478 478
         
479
-        if ( empty( $post['authorizenet']['cc_owner'] ) ) {
479
+        if (empty($post['authorizenet']['cc_owner'])) {
480 480
             $error = true;
481
-            wpinv_set_error( 'empty_card_name', __( 'You must enter the name on your card!', 'invoicing'));
481
+            wpinv_set_error('empty_card_name', __('You must enter the name on your card!', 'invoicing'));
482 482
         }
483
-        if ( empty( $post['authorizenet']['cc_number'] ) ) {
483
+        if (empty($post['authorizenet']['cc_number'])) {
484 484
             $error = true;
485
-            wpinv_set_error( 'empty_card', __( 'You must enter a card number!', 'invoicing'));
485
+            wpinv_set_error('empty_card', __('You must enter a card number!', 'invoicing'));
486 486
         }
487
-        if ( empty( $post['authorizenet']['cc_expire_month'] ) ) {
487
+        if (empty($post['authorizenet']['cc_expire_month'])) {
488 488
             $error = true;
489
-            wpinv_set_error( 'empty_month', __( 'You must enter an card expiration month!', 'invoicing'));
489
+            wpinv_set_error('empty_month', __('You must enter an card expiration month!', 'invoicing'));
490 490
         }
491
-        if ( empty( $post['authorizenet']['cc_expire_year'] ) ) {
491
+        if (empty($post['authorizenet']['cc_expire_year'])) {
492 492
             $error = true;
493
-            wpinv_set_error( 'empty_year', __( 'You must enter an card expiration year!', 'invoicing'));
493
+            wpinv_set_error('empty_year', __('You must enter an card expiration year!', 'invoicing'));
494 494
         }
495
-        if ( empty( $post['authorizenet']['cc_cvv2'] ) ) {
495
+        if (empty($post['authorizenet']['cc_cvv2'])) {
496 496
             $error = true;
497
-            wpinv_set_error( 'empty_cvv2', __( 'You must enter a valid CVV2!', 'invoicing' ) );
497
+            wpinv_set_error('empty_cvv2', __('You must enter a valid CVV2!', 'invoicing'));
498 498
         }
499 499
 
500
-        if ( $error ) {
500
+        if ($error) {
501 501
             return;
502 502
         }
503 503
 
504 504
         $invoice = wpinv_get_invoice_cart();
505 505
 
506
-        if ( !empty( $invoice ) && $subscription_item = $invoice->get_recurring( true ) ) {
507
-            $subscription_item = $invoice->get_recurring( true );
506
+        if (!empty($invoice) && $subscription_item = $invoice->get_recurring(true)) {
507
+            $subscription_item = $invoice->get_recurring(true);
508 508
 
509 509
             $interval   = $subscription_item->get_recurring_interval();
510 510
             $period     = $subscription_item->get_recurring_period();
511 511
 
512
-            if ( $period == 'D' && ( $interval < 7 || $interval > 365 ) ) {
513
-                wpinv_set_error( 'authorizenet_subscription_error', __( 'Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing' ) );
512
+            if ($period == 'D' && ($interval < 7 || $interval > 365)) {
513
+                wpinv_set_error('authorizenet_subscription_error', __('Interval Length must be a value from 7 through 365 for day based subscriptions.', 'invoicing'));
514 514
             }
515 515
         }
516 516
     }
517 517
 }
518
-add_action( 'wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2 );
518
+add_action('wpinv_checkout_error_checks', 'wpinv_authorizenet_validate_checkout', 11, 2);
519 519
 
520
-function wpinv_authorizenet_get_time_period( $subscription_interval, $subscription_period ) {
521
-    $subscription_interval = absint( $subscription_interval );
520
+function wpinv_authorizenet_get_time_period($subscription_interval, $subscription_period) {
521
+    $subscription_interval = absint($subscription_interval);
522 522
 
523
-    switch( $subscription_period ) {
523
+    switch ($subscription_period) {
524 524
         case 'W':
525 525
         case 'week':
526 526
         case 'weeks':
@@ -530,14 +530,14 @@  discard block
 block discarded – undo
530 530
         case 'M':
531 531
         case 'month':
532 532
         case 'months':
533
-            if ( $subscription_interval > 12 ) {
533
+            if ($subscription_interval > 12) {
534 534
                 $subscription_interval = 12;
535 535
             }
536 536
 
537 537
             $interval = $subscription_interval;
538 538
             $period   = 'months';
539 539
             
540
-            if ( !( $subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12 ) ) {
540
+            if (!($subscription_interval === 1 || $subscription_interval === 2 || $subscription_interval === 3 || $subscription_interval === 6 || $subscription_interval === 12)) {
541 541
                 $interval = $subscription_interval * 30;
542 542
                 $period   = 'days';
543 543
             }
@@ -554,30 +554,30 @@  discard block
 block discarded – undo
554 554
             break;
555 555
     }
556 556
 
557
-    return compact( 'interval', 'period' );
557
+    return compact('interval', 'period');
558 558
 }
559 559
 
560 560
 function wpinv_authorizenet_process_ipn() {
561
-    if ( !( !empty( $_REQUEST['wpi-gateway'] ) && $_REQUEST['wpi-gateway'] == 'authorizenet' ) ) {
561
+    if (!(!empty($_REQUEST['wpi-gateway']) && $_REQUEST['wpi-gateway'] == 'authorizenet')) {
562 562
         return;
563 563
     }
564 564
 
565
-    $subscription_id = !empty( $_POST['x_subscription_id'] ) ? intval( $_POST['x_subscription_id'] ) : false;
565
+    $subscription_id = !empty($_POST['x_subscription_id']) ? intval($_POST['x_subscription_id']) : false;
566 566
 
567
-    if ( $subscription_id ) {
568
-        $response_code  = intval( $_POST['x_response_code'] );
569
-        $reason_code    = intval( $_POST['x_response_reason_code'] );
567
+    if ($subscription_id) {
568
+        $response_code  = intval($_POST['x_response_code']);
569
+        $reason_code    = intval($_POST['x_response_reason_code']);
570 570
 
571
-        $subscription = new WPInv_Subscription( $subscription_id, true );
571
+        $subscription = new WPInv_Subscription($subscription_id, true);
572 572
 
573
-        if ( !$subscription->id ) {
573
+        if (!$subscription->id) {
574 574
             return;
575 575
         }
576 576
 
577
-        if ( 1 == $response_code ) {
577
+        if (1 == $response_code) {
578 578
             // Approved
579
-            $transaction_id = sanitize_text_field( $_POST['x_trans_id'] );
580
-            $renewal_amount = sanitize_text_field( $_POST['x_amount'] );
579
+            $transaction_id = sanitize_text_field($_POST['x_trans_id']);
580
+            $renewal_amount = sanitize_text_field($_POST['x_amount']);
581 581
 
582 582
             $args = array(
583 583
                 'amount'         => $renewal_amount,
@@ -585,63 +585,63 @@  discard block
 block discarded – undo
585 585
                 'gateway'        => 'authorizenet'
586 586
             );
587 587
 
588
-            $subscription->add_payment( $args );
588
+            $subscription->add_payment($args);
589 589
             $subscription->renew();
590 590
 
591
-            do_action( 'wpinv_recurring_authorizenet_silent_post_payment', $subscription );
592
-            do_action( 'wpinv_authorizenet_renewal_payment', $subscription );
593
-        } else if ( 2 == $response_code ) {
591
+            do_action('wpinv_recurring_authorizenet_silent_post_payment', $subscription);
592
+            do_action('wpinv_authorizenet_renewal_payment', $subscription);
593
+        } else if (2 == $response_code) {
594 594
             // Declined
595 595
             $subscription->failing();
596
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
597
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
598
-        } else if ( 3 == $response_code || 8 == $reason_code ) {
596
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
597
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
598
+        } else if (3 == $response_code || 8 == $reason_code) {
599 599
             // An expired card
600 600
             $subscription->failing();
601
-            do_action( 'wpinv_authorizenet_renewal_payment_failed', $subscription );
602
-            do_action( 'wpinv_authorizenet_renewal_error', $subscription );
601
+            do_action('wpinv_authorizenet_renewal_payment_failed', $subscription);
602
+            do_action('wpinv_authorizenet_renewal_error', $subscription);
603 603
         } else {
604 604
             // Other Error
605
-            do_action( 'wpinv_authorizenet_renewal_payment_error', $subscription );
605
+            do_action('wpinv_authorizenet_renewal_payment_error', $subscription);
606 606
         }
607 607
 
608 608
         exit;
609 609
     }
610 610
 }
611
-add_action( 'wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn' );
611
+add_action('wpinv_verify_authorizenet_ipn', 'wpinv_authorizenet_process_ipn');
612 612
 
613 613
 /**
614 614
  * Retrieve the subscription
615 615
  */
616
-function wpinv_get_authorizenet_subscription( $subscription_data = array(), $invoice_id ) {
617
-    $parent_invoice_id = absint( $invoice_id );
616
+function wpinv_get_authorizenet_subscription($subscription_data = array(), $invoice_id) {
617
+    $parent_invoice_id = absint($invoice_id);
618 618
 
619
-    if ( empty( $subscription_data ) ) {
619
+    if (empty($subscription_data)) {
620 620
         return false;
621 621
     }
622 622
 
623
-    if ( empty( $parent_invoice_id ) ) {
623
+    if (empty($parent_invoice_id)) {
624 624
         return false;
625 625
     }
626 626
 
627
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
628
-    if ( empty( $invoice ) ) {
627
+    $invoice = wpinv_get_invoice($parent_invoice_id);
628
+    if (empty($invoice)) {
629 629
         return false;
630 630
     }
631 631
 
632 632
     $subscriptionId     = (array)$subscription_data->subscriptionId;
633
-    $subscription_id    = !empty( $subscriptionId[0] ) ? $subscriptionId[0] : $parent_invoice_id;
633
+    $subscription_id    = !empty($subscriptionId[0]) ? $subscriptionId[0] : $parent_invoice_id;
634 634
 
635
-    $subscription = new WPInv_Subscription( $subscription_id, true );
635
+    $subscription = new WPInv_Subscription($subscription_id, true);
636 636
 
637
-    if ( ! $subscription || $subscription->id < 1 ) {
637
+    if (!$subscription || $subscription->id < 1) {
638 638
         $subs_db      = new WPInv_Subscriptions_DB;
639
-        $subs         = $subs_db->get_subscriptions( array( 'parent_payment_id' => $parent_invoice_id, 'number' => 1 ) );
640
-        $subscription = reset( $subs );
639
+        $subs         = $subs_db->get_subscriptions(array('parent_payment_id' => $parent_invoice_id, 'number' => 1));
640
+        $subscription = reset($subs);
641 641
 
642
-        if ( $subscription && $subscription->id > 0 ) {
642
+        if ($subscription && $subscription->id > 0) {
643 643
             // Update the profile ID so it is set for future renewals
644
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $subscription_id ) ) );
644
+            $subscription->update(array('profile_id' => sanitize_text_field($subscription_id)));
645 645
         } else {
646 646
             // No subscription found with a matching payment ID, bail
647 647
             return false;
@@ -652,67 +652,67 @@  discard block
 block discarded – undo
652 652
 }
653 653
 
654 654
 function wpinv_is_authorizenet_valid_for_use() {
655
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_authorizenet_supported_currencies', array( 'AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR' ) ) );
655
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_authorizenet_supported_currencies', array('AUD', 'CAD', 'CHF', 'DKK', 'EUR', 'GBP', 'JPY', 'NOK', 'NZD', 'PLN', 'SEK', 'USD', 'ZAR')));
656 656
 }
657
-function wpinv_check_authorizenet_currency_support( $gateway_list ) {
658
-    if ( isset( $gateway_list['authorizenet'] ) && ! wpinv_is_authorizenet_valid_for_use() ) {
659
-        unset( $gateway_list['authorizenet'] );
657
+function wpinv_check_authorizenet_currency_support($gateway_list) {
658
+    if (isset($gateway_list['authorizenet']) && !wpinv_is_authorizenet_valid_for_use()) {
659
+        unset($gateway_list['authorizenet']);
660 660
     }
661 661
     return $gateway_list;
662 662
 }
663
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1 );
663
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_authorizenet_currency_support', 10, 1);
664 664
 
665
-function wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
666
-    if ( $transaction_id == $invoice_id ) {
665
+function wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice) {
666
+    if ($transaction_id == $invoice_id) {
667 667
         $link = $transaction_id;
668 668
     } else {
669
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
669
+        if (!empty($invoice) && !empty($invoice->mode)) {
670 670
             $mode = $invoice->mode;
671 671
         } else {
672
-            $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live';
672
+            $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live';
673 673
         }
674 674
 
675 675
         $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/';
676 676
         $url .= 'ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=' . $transaction_id;
677 677
 
678
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $transaction_id . '</a>';
678
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $transaction_id . '</a>';
679 679
     }
680 680
 
681
-    return apply_filters( 'wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice );
681
+    return apply_filters('wpinv_authorizenet_link_payment_details_transaction_id', $link, $transaction_id, $invoice);
682 682
 }
683
-add_filter( 'wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3 );
683
+add_filter('wpinv_payment_details_transaction_id-authorizenet', 'wpinv_authorizenet_link_transaction_id', 10, 3);
684 684
 
685
-function wpinv_authorizenet_transaction_id_link( $transaction_id, $subscription ) {
686
-    if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
687
-        $invoice = wpinv_get_invoice( $invoice_id );
685
+function wpinv_authorizenet_transaction_id_link($transaction_id, $subscription) {
686
+    if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
687
+        $invoice = wpinv_get_invoice($invoice_id);
688 688
 
689
-        if ( ! empty( $invoice ) ) {
690
-            return wpinv_authorizenet_link_transaction_id( $transaction_id, $invoice_id, $invoice );
689
+        if (!empty($invoice)) {
690
+            return wpinv_authorizenet_link_transaction_id($transaction_id, $invoice_id, $invoice);
691 691
         }        
692 692
     }
693 693
     
694 694
     return $transaction_id;
695 695
 }
696
-add_filter( 'wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2 );
696
+add_filter('wpinv_subscription_transaction_link_authorizenet', 'wpinv_authorizenet_transaction_id_link', 10, 2);
697 697
 
698
-function wpinv_authorizenet_profile_id_link( $profile_id, $subscription ) {
698
+function wpinv_authorizenet_profile_id_link($profile_id, $subscription) {
699 699
     $link = $profile_id;
700 700
 
701
-    if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
702
-        $invoice = wpinv_get_invoice( $invoice_id );
701
+    if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
702
+        $invoice = wpinv_get_invoice($invoice_id);
703 703
 
704
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
704
+        if (!empty($invoice) && !empty($invoice->mode)) {
705 705
             $mode = $invoice->mode;
706 706
         } else {
707
-            $mode = wpinv_is_test_mode( 'authorizenet' ) ? 'test' : 'live';
707
+            $mode = wpinv_is_test_mode('authorizenet') ? 'test' : 'live';
708 708
         }
709 709
 
710 710
         $url = $mode == 'test' ? 'https://sandbox.authorize.net/' : 'https://authorize.net/';
711 711
         $url .= 'ui/themes/sandbox/ARB/SubscriptionDetail.aspx?SubscrID=' . $profile_id;
712 712
 
713
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>';
713
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>';
714 714
     }
715 715
     
716
-    return apply_filters( 'wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription );
716
+    return apply_filters('wpinv_authorizenet_profile_id_link', $link, $profile_id, $subscription);
717 717
 }
718
-add_filter( 'wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2 );
719 718
\ No newline at end of file
719
+add_filter('wpinv_subscription_profile_link_authorizenet', 'wpinv_authorizenet_profile_id_link', 10, 2);
720 720
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/manual.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 add_action( 'wpinv_manual_cc_form', '__return_false' );
6 8
 
Please login to merge, or discard this patch.
Spacing   +14 added lines, -14 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_manual_cc_form', '__return_false' );
5
+add_action('wpinv_manual_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_manual_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_manual_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
 
12 12
     /*
@@ -41,22 +41,22 @@  discard block
 block discarded – undo
41 41
     );
42 42
 
43 43
     // Record the pending payment
44
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
44
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
45 45
     
46
-    if ( !empty( $invoice ) ) {        
47
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
48
-        wpinv_update_payment_status( $invoice, 'publish' );
46
+    if (!empty($invoice)) {        
47
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
48
+        wpinv_update_payment_status($invoice, 'publish');
49 49
         
50 50
         // Empty the shopping cart
51 51
         wpinv_empty_cart();
52 52
         
53
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
53
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
54 54
         
55
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
55
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
56 56
     } else {
57
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
57
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a manual (free or test) purchase. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
58 58
         // If errors are present, send the user back to the purchase page so they can be corrected
59
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
59
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
60 60
     }
61 61
 }
62
-add_action( 'wpinv_gateway_manual', 'wpinv_process_manual_payment' );
63 62
\ No newline at end of file
63
+add_action('wpinv_gateway_manual', 'wpinv_process_manual_payment');
64 64
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/bank_transfer.php 2 patches
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 add_action( 'wpinv_bank_transfer_cc_form', '__return_false' );
6 8
 
Please login to merge, or discard this patch.
Spacing   +37 added lines, -37 removed lines patch added patch discarded remove patch
@@ -1,12 +1,12 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_bank_transfer_cc_form', '__return_false' );
5
+add_action('wpinv_bank_transfer_cc_form', '__return_false');
6 6
 
7
-function wpinv_process_bank_transfer_payment( $purchase_data ) {
8
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
9
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
7
+function wpinv_process_bank_transfer_payment($purchase_data) {
8
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
9
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
10 10
     }
11 11
 
12 12
     // Collect payment data
@@ -24,39 +24,39 @@  discard block
 block discarded – undo
24 24
     );
25 25
 
26 26
     // Record the pending payment
27
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
27
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
28 28
     
29
-    if ( !empty( $invoice ) ) {
30
-        wpinv_set_payment_transaction_id( $invoice->ID, $invoice->generate_key() );
31
-        wpinv_update_payment_status( $invoice, 'wpi-pending' );
29
+    if (!empty($invoice)) {
30
+        wpinv_set_payment_transaction_id($invoice->ID, $invoice->generate_key());
31
+        wpinv_update_payment_status($invoice, 'wpi-pending');
32 32
         
33 33
         // Empty the shopping cart
34 34
         wpinv_empty_cart();
35 35
         
36
-        do_action( 'wpinv_send_to_success_page', $invoice->ID, $payment_data );
36
+        do_action('wpinv_send_to_success_page', $invoice->ID, $payment_data);
37 37
         
38
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
38
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
39 39
     } else {
40
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
40
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed while processing a bank transfer payment. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
41 41
         // If errors are present, send the user back to the purchase page so they can be corrected
42
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
42
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
43 43
     }
44 44
 }
45
-add_action( 'wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment' );
45
+add_action('wpinv_gateway_bank_transfer', 'wpinv_process_bank_transfer_payment');
46 46
 
47
-function wpinv_show_bank_info( $invoice ) {
48
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
49
-        $bank_info = wpinv_get_bank_info( true );
47
+function wpinv_show_bank_info($invoice) {
48
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
49
+        $bank_info = wpinv_get_bank_info(true);
50 50
         ?>
51 51
         <div class="wpinv-bank-details">
52
-            <?php if ( $instructions = wpinv_get_bank_instructions() ) { ?>
53
-            <div class="alert bg-info"><?php echo wpautop( wp_kses_post( $instructions ) ); ?></div>
52
+            <?php if ($instructions = wpinv_get_bank_instructions()) { ?>
53
+            <div class="alert bg-info"><?php echo wpautop(wp_kses_post($instructions)); ?></div>
54 54
             <?php } ?>
55
-            <?php if ( !empty( $bank_info ) ) { ?>
56
-            <h3 class="wpinv-bank-t"><?php echo apply_filters( 'wpinv_receipt_bank_details_title', __( 'Our Bank Details', 'invoicing' ) ); ?></h3>
55
+            <?php if (!empty($bank_info)) { ?>
56
+            <h3 class="wpinv-bank-t"><?php echo apply_filters('wpinv_receipt_bank_details_title', __('Our Bank Details', 'invoicing')); ?></h3>
57 57
             <table class="table table-bordered table-sm wpi-bank-details">
58
-                <?php foreach ( $bank_info as $key => $info ) { ?>
59
-                <tr class="wpi-<?php echo sanitize_html_class( $key );?>"><th class="text-left"><?php echo $info['label'] ;?></th><td><?php echo $info['value'] ;?></td></tr>
58
+                <?php foreach ($bank_info as $key => $info) { ?>
59
+                <tr class="wpi-<?php echo sanitize_html_class($key); ?>"><th class="text-left"><?php echo $info['label']; ?></th><td><?php echo $info['value']; ?></td></tr>
60 60
                 <?php } ?>
61 61
             </table>
62 62
             <?php } ?>
@@ -64,37 +64,37 @@  discard block
 block discarded – undo
64 64
         <?php
65 65
     }
66 66
 }
67
-add_action( 'wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1 );
67
+add_action('wpinv_before_receipt_details', 'wpinv_show_bank_info', 10, 1);
68 68
 
69
-function wpinv_invoice_print_bank_info( $invoice ) {
70
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
69
+function wpinv_invoice_print_bank_info($invoice) {
70
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
71 71
         ?>
72 72
         <div class="row wpinv-bank-info">
73
-            <?php echo wpinv_show_bank_info( $invoice ); ?>
73
+            <?php echo wpinv_show_bank_info($invoice); ?>
74 74
         </div>
75 75
         <?php
76 76
     }
77 77
 }
78
-add_action( 'wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1 );
78
+add_action('wpinv_invoice_print_after_top_content', 'wpinv_invoice_print_bank_info', 10, 1);
79 79
 
80
-function wpinv_bank_transfer_send_notification( $invoice_ID, $payment_data = array() ) {
81
-    if ( !empty( $payment_data['gateway'] ) && $payment_data['gateway'] == 'bank_transfer' ) {
80
+function wpinv_bank_transfer_send_notification($invoice_ID, $payment_data = array()) {
81
+    if (!empty($payment_data['gateway']) && $payment_data['gateway'] == 'bank_transfer') {
82 82
         // Send invoice to user.
83
-        wpinv_user_invoice_notification( $invoice_ID );
83
+        wpinv_user_invoice_notification($invoice_ID);
84 84
         
85 85
         // Send invoice to admin.
86
-        wpinv_new_invoice_notification( $invoice_ID );
86
+        wpinv_new_invoice_notification($invoice_ID);
87 87
     }
88 88
 }
89
-add_action( 'wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2 );
89
+add_action('wpinv_send_to_success_page', 'wpinv_bank_transfer_send_notification', 10, 2);
90 90
 
91
-function wpinv_invoice_email_bank_info( $invoice, $email_type = '', $sent_to_admin = false ) {
92
-    if ( !empty( $invoice ) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending' ) {
91
+function wpinv_invoice_email_bank_info($invoice, $email_type = '', $sent_to_admin = false) {
92
+    if (!empty($invoice) && $invoice->gateway == 'bank_transfer' && $invoice->status == 'wpi-pending') {
93 93
         ?>
94 94
         <div class="wpi-email-row">
95
-            <?php echo wpinv_show_bank_info( $invoice ); ?>
95
+            <?php echo wpinv_show_bank_info($invoice); ?>
96 96
         </div>
97 97
         <?php
98 98
     }
99 99
 }
100
-add_action( 'wpinv_email_invoice_details', 'wpinv_invoice_email_bank_info', 9, 3 );
101 100
\ No newline at end of file
101
+add_action('wpinv_email_invoice_details', 'wpinv_invoice_email_bank_info', 9, 3);
102 102
\ No newline at end of file
Please login to merge, or discard this patch.
includes/gateways/paypal.php 4 patches
Braces   +6 added lines, -3 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 add_action( 'wpinv_paypal_cc_form', '__return_false' );
6 8
 add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
@@ -307,8 +309,9 @@  discard block
 block discarded – undo
307 309
 	}
308 310
 
309 311
 	// Check if $post_data_array has been populated
310
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
311
-		return;
312
+	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) ) {
313
+			return;
314
+	}
312 315
 
313 316
 	$defaults = array(
314 317
 		'txn_type'       => '',
Please login to merge, or discard this patch.
Indentation   +255 added lines, -255 removed lines patch added patch discarded remove patch
@@ -218,262 +218,262 @@  discard block
 block discarded – undo
218 218
 add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
219 219
 
220 220
 function wpinv_process_paypal_ipn() {
221
-	// Check the request method is POST
222
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
-		return;
224
-	}
225
-
226
-	// Set initial post data to empty string
227
-	$post_data = '';
228
-
229
-	// Fallback just in case post_max_size is lower than needed
230
-	if ( ini_get( 'allow_url_fopen' ) ) {
231
-		$post_data = file_get_contents( 'php://input' );
232
-	} else {
233
-		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
-		ini_set( 'post_max_size', '12M' );
235
-	}
236
-	// Start the encoded data collection with notification command
237
-	$encoded_data = 'cmd=_notify-validate';
238
-
239
-	// Get current arg separator
240
-	$arg_separator = wpinv_get_php_arg_separator_output();
241
-
242
-	// Verify there is a post_data
243
-	if ( $post_data || strlen( $post_data ) > 0 ) {
244
-		// Append the data
245
-		$encoded_data .= $arg_separator.$post_data;
246
-	} else {
247
-		// Check if POST is empty
248
-		if ( empty( $_POST ) ) {
249
-			// Nothing to do
250
-			return;
251
-		} else {
252
-			// Loop through each POST
253
-			foreach ( $_POST as $key => $value ) {
254
-				// Encode the value and append the data
255
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
-			}
257
-		}
258
-	}
259
-
260
-	// Convert collected post data to an array
261
-	parse_str( $encoded_data, $encoded_data_array );
262
-
263
-	foreach ( $encoded_data_array as $key => $value ) {
264
-		if ( false !== strpos( $key, 'amp;' ) ) {
265
-			$new_key = str_replace( '&amp;', '&', $key );
266
-			$new_key = str_replace( 'amp;', '&' , $new_key );
267
-
268
-			unset( $encoded_data_array[ $key ] );
269
-			$encoded_data_array[ $new_key ] = $value;
270
-		}
271
-	}
272
-
273
-	// Get the PayPal redirect uri
274
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
275
-
276
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
-		// Validate the IPN
278
-
279
-		$remote_post_vars      = array(
280
-			'method'           => 'POST',
281
-			'timeout'          => 45,
282
-			'redirection'      => 5,
283
-			'httpversion'      => '1.1',
284
-			'blocking'         => true,
285
-			'headers'          => array(
286
-				'host'         => 'www.paypal.com',
287
-				'connection'   => 'close',
288
-				'content-type' => 'application/x-www-form-urlencoded',
289
-				'post'         => '/cgi-bin/webscr HTTP/1.1',
290
-
291
-			),
292
-			'sslverify'        => false,
293
-			'body'             => $encoded_data_array
294
-		);
295
-
296
-		// Get response
297
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
-
299
-		if ( is_wp_error( $api_response ) ) {
300
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
-			return; // Something went wrong
302
-		}
303
-
304
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
-			return; // Response not okay
307
-		}
308
-	}
309
-
310
-	// Check if $post_data_array has been populated
311
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
-		return;
313
-
314
-	$defaults = array(
315
-		'txn_type'       => '',
316
-		'payment_status' => ''
317
-	);
318
-
319
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
-
321
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
221
+    // Check the request method is POST
222
+    if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
+        return;
224
+    }
225
+
226
+    // Set initial post data to empty string
227
+    $post_data = '';
228
+
229
+    // Fallback just in case post_max_size is lower than needed
230
+    if ( ini_get( 'allow_url_fopen' ) ) {
231
+        $post_data = file_get_contents( 'php://input' );
232
+    } else {
233
+        // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
234
+        ini_set( 'post_max_size', '12M' );
235
+    }
236
+    // Start the encoded data collection with notification command
237
+    $encoded_data = 'cmd=_notify-validate';
238
+
239
+    // Get current arg separator
240
+    $arg_separator = wpinv_get_php_arg_separator_output();
241
+
242
+    // Verify there is a post_data
243
+    if ( $post_data || strlen( $post_data ) > 0 ) {
244
+        // Append the data
245
+        $encoded_data .= $arg_separator.$post_data;
246
+    } else {
247
+        // Check if POST is empty
248
+        if ( empty( $_POST ) ) {
249
+            // Nothing to do
250
+            return;
251
+        } else {
252
+            // Loop through each POST
253
+            foreach ( $_POST as $key => $value ) {
254
+                // Encode the value and append the data
255
+                $encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
+            }
257
+        }
258
+    }
259
+
260
+    // Convert collected post data to an array
261
+    parse_str( $encoded_data, $encoded_data_array );
262
+
263
+    foreach ( $encoded_data_array as $key => $value ) {
264
+        if ( false !== strpos( $key, 'amp;' ) ) {
265
+            $new_key = str_replace( '&amp;', '&', $key );
266
+            $new_key = str_replace( 'amp;', '&' , $new_key );
267
+
268
+            unset( $encoded_data_array[ $key ] );
269
+            $encoded_data_array[ $new_key ] = $value;
270
+        }
271
+    }
272
+
273
+    // Get the PayPal redirect uri
274
+    $paypal_redirect = wpinv_get_paypal_redirect( true );
275
+
276
+    if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
+        // Validate the IPN
278
+
279
+        $remote_post_vars      = array(
280
+            'method'           => 'POST',
281
+            'timeout'          => 45,
282
+            'redirection'      => 5,
283
+            'httpversion'      => '1.1',
284
+            'blocking'         => true,
285
+            'headers'          => array(
286
+                'host'         => 'www.paypal.com',
287
+                'connection'   => 'close',
288
+                'content-type' => 'application/x-www-form-urlencoded',
289
+                'post'         => '/cgi-bin/webscr HTTP/1.1',
290
+
291
+            ),
292
+            'sslverify'        => false,
293
+            'body'             => $encoded_data_array
294
+        );
295
+
296
+        // Get response
297
+        $api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
+
299
+        if ( is_wp_error( $api_response ) ) {
300
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
301
+            return; // Something went wrong
302
+        }
303
+
304
+        if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
305
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
306
+            return; // Response not okay
307
+        }
308
+    }
309
+
310
+    // Check if $post_data_array has been populated
311
+    if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
+        return;
313
+
314
+    $defaults = array(
315
+        'txn_type'       => '',
316
+        'payment_status' => ''
317
+    );
318
+
319
+    $encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
+
321
+    $invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
322 322
     
323
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
-	wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
325
-
326
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
327
-		// Allow PayPal IPN types to be processed separately
328
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
329
-	} else {
330
-		// Fallback to web accept just in case the txn_type isn't present
331
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
332
-	}
333
-	exit;
323
+    wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
324
+    wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
325
+
326
+    if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
327
+        // Allow PayPal IPN types to be processed separately
328
+        do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
329
+    } else {
330
+        // Fallback to web accept just in case the txn_type isn't present
331
+        do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
332
+    }
333
+    exit;
334 334
 }
335 335
 add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
336 336
 
337 337
 function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
338
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
339
-		return;
340
-	}
341
-
342
-	if( empty( $invoice_id ) ) {
343
-		return;
344
-	}
345
-
346
-	// Collect payment details
347
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
348
-	$paypal_amount  = $data['mc_gross'];
349
-	$payment_status = strtolower( $data['payment_status'] );
350
-	$currency_code  = strtolower( $data['mc_currency'] );
351
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
352
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
353
-
354
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
355
-		return; // this isn't a PayPal standard IPN
356
-	}
357
-
358
-	// Verify payment recipient
359
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
360
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
361
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
362
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
363
-		return;
364
-	}
365
-
366
-	// Verify payment currency
367
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
368
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
369
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
370
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
371
-		return;
372
-	}
373
-
374
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
375
-		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
376
-		// No email associated with purchase, so store from PayPal
377
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
378
-
379
-		// Setup and store the customer's details
380
-		$user_info = array(
381
-			'user_id'    => '-1',
382
-			'email'      => sanitize_text_field( $data['payer_email'] ),
383
-			'first_name' => sanitize_text_field( $data['first_name'] ),
384
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
385
-			'discount'   => '',
386
-		);
387
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
388
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
389
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
390
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
391
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
392
-
393
-		$payment_meta['user_info'] = $user_info;
394
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
395
-	}
396
-
397
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
398
-		// Process a refund
399
-		wpinv_process_paypal_refund( $data, $invoice_id );
400
-	} else {
401
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
402
-			return; // Only paid payments once
403
-		}
404
-
405
-		// Retrieve the total purchase amount (before PayPal)
406
-		$payment_amount = wpinv_payment_total( $invoice_id );
407
-
408
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
409
-			// The prices don't match
410
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
411
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
412
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
413
-			return;
414
-		}
415
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
416
-			// Purchase keys don't match
417
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
418
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
419
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
420
-			return;
421
-		}
422
-
423
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
424
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
425
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
426
-			wpinv_update_payment_status( $invoice_id, 'publish' );
427
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
428
-			// Look for possible pending reasons, such as an echeck
429
-			$note = '';
430
-
431
-			switch( strtolower( $data['pending_reason'] ) ) {
432
-				case 'echeck' :
433
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
434
-					break;
338
+    if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
339
+        return;
340
+    }
341
+
342
+    if( empty( $invoice_id ) ) {
343
+        return;
344
+    }
345
+
346
+    // Collect payment details
347
+    $purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
348
+    $paypal_amount  = $data['mc_gross'];
349
+    $payment_status = strtolower( $data['payment_status'] );
350
+    $currency_code  = strtolower( $data['mc_currency'] );
351
+    $business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
352
+    $payment_meta   = wpinv_get_invoice_meta( $invoice_id );
353
+
354
+    if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
355
+        return; // this isn't a PayPal standard IPN
356
+    }
357
+
358
+    // Verify payment recipient
359
+    if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
360
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
361
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
362
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
363
+        return;
364
+    }
365
+
366
+    // Verify payment currency
367
+    if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
368
+        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
369
+        wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
370
+        wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
371
+        return;
372
+    }
373
+
374
+    if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
375
+        // This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
376
+        // No email associated with purchase, so store from PayPal
377
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
378
+
379
+        // Setup and store the customer's details
380
+        $user_info = array(
381
+            'user_id'    => '-1',
382
+            'email'      => sanitize_text_field( $data['payer_email'] ),
383
+            'first_name' => sanitize_text_field( $data['first_name'] ),
384
+            'last_name'  => sanitize_text_field( $data['last_name'] ),
385
+            'discount'   => '',
386
+        );
387
+        $user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
388
+        $user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
389
+        $user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
390
+        $user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
391
+        $user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
392
+
393
+        $payment_meta['user_info'] = $user_info;
394
+        wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
395
+    }
396
+
397
+    if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
398
+        // Process a refund
399
+        wpinv_process_paypal_refund( $data, $invoice_id );
400
+    } else {
401
+        if ( get_post_status( $invoice_id ) == 'publish' ) {
402
+            return; // Only paid payments once
403
+        }
404
+
405
+        // Retrieve the total purchase amount (before PayPal)
406
+        $payment_amount = wpinv_payment_total( $invoice_id );
407
+
408
+        if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
409
+            // The prices don't match
410
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
411
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
412
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
413
+            return;
414
+        }
415
+        if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
416
+            // Purchase keys don't match
417
+            wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
418
+            wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
419
+            wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
420
+            return;
421
+        }
422
+
423
+        if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
424
+            wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
425
+            wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
426
+            wpinv_update_payment_status( $invoice_id, 'publish' );
427
+        } else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
428
+            // Look for possible pending reasons, such as an echeck
429
+            $note = '';
430
+
431
+            switch( strtolower( $data['pending_reason'] ) ) {
432
+                case 'echeck' :
433
+                    $note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
434
+                    break;
435 435
 				
436 436
                 case 'address' :
437
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
438
-					break;
437
+                    $note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
438
+                    break;
439 439
 				
440 440
                 case 'intl' :
441
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
442
-					break;
441
+                    $note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
442
+                    break;
443 443
 				
444 444
                 case 'multi-currency' :
445
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
446
-					break;
445
+                    $note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
446
+                    break;
447 447
 				
448 448
                 case 'paymentreview' :
449 449
                 case 'regulatory_review' :
450
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
451
-					break;
450
+                    $note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
451
+                    break;
452 452
 				
453 453
                 case 'unilateral' :
454
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
455
-					break;
454
+                    $note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
455
+                    break;
456 456
 				
457 457
                 case 'upgrade' :
458
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
459
-					break;
458
+                    $note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
459
+                    break;
460 460
 				
461 461
                 case 'verify' :
462
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
463
-					break;
464
-
465
-				case 'other' :
466
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
467
-					break;
468
-			}
469
-
470
-			if ( ! empty( $note ) ) {
471
-				wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
472
-			}
473
-		} else {
474
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
475
-		}
476
-	}
462
+                    $note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
463
+                    break;
464
+
465
+                case 'other' :
466
+                    $note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
467
+                    break;
468
+            }
469
+
470
+            if ( ! empty( $note ) ) {
471
+                wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
472
+            }
473
+        } else {
474
+            wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
475
+        }
476
+    }
477 477
 }
478 478
 add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
479 479
 
@@ -661,34 +661,34 @@  discard block
 block discarded – undo
661 661
 }
662 662
 
663 663
 function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
664
-	// Collect payment details
664
+    // Collect payment details
665 665
 
666
-	if( empty( $invoice_id ) ) {
667
-		return;
668
-	}
666
+    if( empty( $invoice_id ) ) {
667
+        return;
668
+    }
669 669
 
670
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
671
-		return; // Only refund payments once
672
-	}
670
+    if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
671
+        return; // Only refund payments once
672
+    }
673 673
 
674
-	$payment_amount = wpinv_payment_total( $invoice_id );
675
-	$refund_amount  = $data['mc_gross'] * -1;
674
+    $payment_amount = wpinv_payment_total( $invoice_id );
675
+    $refund_amount  = $data['mc_gross'] * -1;
676 676
 
677
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
677
+    do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
678 678
 
679
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
680
-		wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
679
+    if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
680
+        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
681 681
 
682
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
682
+        do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
683 683
 
684
-		return; // This is a partial refund
685
-	}
684
+        return; // This is a partial refund
685
+    }
686 686
 
687
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
688
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
689
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
687
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
688
+    wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
689
+    wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
690 690
 
691
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
691
+    do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
692 692
 }
693 693
 
694 694
 function wpinv_get_paypal_redirect( $ssl_check = false ) {
Please login to merge, or discard this patch.
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -757,6 +757,9 @@
 block discarded – undo
757 757
 }
758 758
 add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
759 759
 
760
+/**
761
+ * @param WPInv_Invoice $invoice
762
+ */
760 763
 function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
761 764
     if ( $transaction_id == $invoice_id ) {
762 765
         $transaction_link = $transaction_id;
Please login to merge, or discard this patch.
Spacing   +283 added lines, -283 removed lines patch added patch discarded remove patch
@@ -1,13 +1,13 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-add_action( 'wpinv_paypal_cc_form', '__return_false' );
6
-add_filter( 'wpinv_paypal_support_subscription', '__return_true' );
5
+add_action('wpinv_paypal_cc_form', '__return_false');
6
+add_filter('wpinv_paypal_support_subscription', '__return_true');
7 7
 
8
-function wpinv_process_paypal_payment( $purchase_data ) {
9
-    if( ! wp_verify_nonce( $purchase_data['gateway_nonce'], 'wpi-gateway' ) ) {
10
-        wp_die( __( 'Nonce verification has failed', 'invoicing' ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
8
+function wpinv_process_paypal_payment($purchase_data) {
9
+    if (!wp_verify_nonce($purchase_data['gateway_nonce'], 'wpi-gateway')) {
10
+        wp_die(__('Nonce verification has failed', 'invoicing'), __('Error', 'invoicing'), array('response' => 403));
11 11
     }
12 12
 
13 13
     // Collect payment data
@@ -25,30 +25,30 @@  discard block
 block discarded – undo
25 25
     );
26 26
 
27 27
     // Record the pending payment
28
-    $invoice = wpinv_get_invoice( $purchase_data['invoice_id'] );
28
+    $invoice = wpinv_get_invoice($purchase_data['invoice_id']);
29 29
 
30 30
     // Check payment
31
-    if ( ! $invoice ) {
31
+    if (!$invoice) {
32 32
         // Record the error
33
-        wpinv_record_gateway_error( __( 'Payment Error', 'invoicing' ), sprintf( __( 'Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing' ), json_encode( $payment_data ) ), $invoice );
33
+        wpinv_record_gateway_error(__('Payment Error', 'invoicing'), sprintf(__('Payment creation failed before sending buyer to PayPal. Payment data: %s', 'invoicing'), json_encode($payment_data)), $invoice);
34 34
         // Problems? send back
35
-        wpinv_send_back_to_checkout( '?payment-mode=' . $purchase_data['post_data']['wpi-gateway'] );
35
+        wpinv_send_back_to_checkout('?payment-mode=' . $purchase_data['post_data']['wpi-gateway']);
36 36
     } else {
37 37
         // Only send to PayPal if the pending payment is created successfully
38
-        $listener_url = wpinv_get_ipn_url( 'paypal' );
38
+        $listener_url = wpinv_get_ipn_url('paypal');
39 39
 
40 40
         // Get the success url
41
-        $return_url = add_query_arg( array(
41
+        $return_url = add_query_arg(array(
42 42
                 'payment-confirm' => 'paypal',
43 43
                 'invoice-id' => $invoice->ID
44
-            ), get_permalink( wpinv_get_option( 'success_page', false ) ) );
44
+            ), get_permalink(wpinv_get_option('success_page', false)));
45 45
 
46 46
         // Get the PayPal redirect uri
47
-        $paypal_redirect = trailingslashit( wpinv_get_paypal_redirect() ) . '?';
47
+        $paypal_redirect = trailingslashit(wpinv_get_paypal_redirect()) . '?';
48 48
 
49 49
         // Setup PayPal arguments
50 50
         $paypal_args = array(
51
-            'business'      => wpinv_get_option( 'paypal_email', false ),
51
+            'business'      => wpinv_get_option('paypal_email', false),
52 52
             'email'         => $invoice->get_email(),
53 53
             'first_name'    => $invoice->get_first_name(),
54 54
             'last_name'     => $invoice->get_last_name(),
@@ -57,16 +57,16 @@  discard block
 block discarded – undo
57 57
             'shipping'      => '0',
58 58
             'no_note'       => '1',
59 59
             'currency_code' => wpinv_get_currency(),
60
-            'charset'       => get_bloginfo( 'charset' ),
60
+            'charset'       => get_bloginfo('charset'),
61 61
             'custom'        => $invoice->ID,
62 62
             'rm'            => '2',
63 63
             'return'        => $return_url,
64
-            'cancel_return' => wpinv_get_failed_transaction_uri( '?invoice-id=' . $invoice->ID ),
64
+            'cancel_return' => wpinv_get_failed_transaction_uri('?invoice-id=' . $invoice->ID),
65 65
             'notify_url'    => $listener_url,
66
-            'cbt'           => get_bloginfo( 'name' ),
66
+            'cbt'           => get_bloginfo('name'),
67 67
             'bn'            => 'WPInvoicing_SP',
68 68
             'lc'            => 'US', // this will force paypal site to english
69
-            'landing_page'  => apply_filters( 'wpinv_paypal_standard_landing_page', 'billing', $invoice ), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account.
69
+            'landing_page'  => apply_filters('wpinv_paypal_standard_landing_page', 'billing', $invoice), // 'login' or 'billing'. login - PayPal account login, billing - Non-PayPal account.
70 70
         );
71 71
 
72 72
         $paypal_args['address1'] = $invoice->get_address();
@@ -80,57 +80,57 @@  discard block
 block discarded – undo
80 80
             'upload' => '1'
81 81
         );
82 82
 
83
-        $paypal_args = array_merge( $paypal_extra_args, $paypal_args );
83
+        $paypal_args = array_merge($paypal_extra_args, $paypal_args);
84 84
 
85 85
         // Add cart items
86 86
         $i = 1;
87
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
88
-            foreach ( $purchase_data['cart_details'] as $item ) {
87
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
88
+            foreach ($purchase_data['cart_details'] as $item) {
89 89
                 $item['quantity'] = $item['quantity'] > 0 ? $item['quantity'] : 1;
90
-                $item_amount = wpinv_sanitize_amount( $item['subtotal'] / $item['quantity'], 2 );
90
+                $item_amount = wpinv_sanitize_amount($item['subtotal'] / $item['quantity'], 2);
91 91
 
92
-                if ( $item_amount <= 0 ) {
92
+                if ($item_amount <= 0) {
93 93
                     $item_amount = 0;
94 94
                 }
95 95
 
96
-                $paypal_args['item_number_' . $i ]      = $item['id'];
97
-                $paypal_args['item_name_' . $i ]        = stripslashes_deep( html_entity_decode( wpinv_get_cart_item_name( $item ), ENT_COMPAT, 'UTF-8' ) );
98
-                $paypal_args['quantity_' . $i ]         = $item['quantity'];
99
-                $paypal_args['amount_' . $i ]           = $item_amount;
100
-                $paypal_args['discount_amount_' . $i ]  = wpinv_sanitize_amount( $item['discount'], 2 );
96
+                $paypal_args['item_number_' . $i]      = $item['id'];
97
+                $paypal_args['item_name_' . $i]        = stripslashes_deep(html_entity_decode(wpinv_get_cart_item_name($item), ENT_COMPAT, 'UTF-8'));
98
+                $paypal_args['quantity_' . $i]         = $item['quantity'];
99
+                $paypal_args['amount_' . $i]           = $item_amount;
100
+                $paypal_args['discount_amount_' . $i]  = wpinv_sanitize_amount($item['discount'], 2);
101 101
 
102 102
                 $i++;
103 103
             }
104 104
         }
105 105
 
106 106
         // Add taxes to the cart
107
-        if ( wpinv_use_taxes() ) {
108
-            $paypal_args['tax_cart'] = wpinv_sanitize_amount( (float)$invoice->get_tax(), 2 );
107
+        if (wpinv_use_taxes()) {
108
+            $paypal_args['tax_cart'] = wpinv_sanitize_amount((float)$invoice->get_tax(), 2);
109 109
         }
110 110
 
111
-        $paypal_args = apply_filters( 'wpinv_paypal_args', $paypal_args, $purchase_data, $invoice );
111
+        $paypal_args = apply_filters('wpinv_paypal_args', $paypal_args, $purchase_data, $invoice);
112 112
 
113 113
         // Build query
114
-        $paypal_redirect .= http_build_query( $paypal_args );
114
+        $paypal_redirect .= http_build_query($paypal_args);
115 115
 
116 116
         // Fix for some sites that encode the entities
117
-        $paypal_redirect = str_replace( '&amp;', '&', $paypal_redirect );
117
+        $paypal_redirect = str_replace('&amp;', '&', $paypal_redirect);
118 118
 
119 119
         // Get rid of cart contents
120 120
         wpinv_empty_cart();
121 121
         
122 122
         // Redirect to PayPal
123
-        wp_redirect( $paypal_redirect );
123
+        wp_redirect($paypal_redirect);
124 124
         exit;
125 125
     }
126 126
 }
127
-add_action( 'wpinv_gateway_paypal', 'wpinv_process_paypal_payment' );
127
+add_action('wpinv_gateway_paypal', 'wpinv_process_paypal_payment');
128 128
 
129
-function wpinv_get_paypal_recurring_args( $paypal_args, $purchase_data, $invoice ) {
130
-    if ( $invoice->is_recurring() && $item_id = $invoice->get_recurring() ) {
131
-        $item   = new WPInv_Item( $item_id );
129
+function wpinv_get_paypal_recurring_args($paypal_args, $purchase_data, $invoice) {
130
+    if ($invoice->is_recurring() && $item_id = $invoice->get_recurring()) {
131
+        $item = new WPInv_Item($item_id);
132 132
         
133
-        if ( empty( $item ) ) {
133
+        if (empty($item)) {
134 134
             return $paypal_args;
135 135
         }
136 136
 
@@ -138,25 +138,25 @@  discard block
 block discarded – undo
138 138
         $interval           = $item->get_recurring_interval();
139 139
         $bill_times         = (int)$item->get_recurring_limit();
140 140
         
141
-        $initial_amount     = wpinv_sanitize_amount( $invoice->get_total(), 2 );
142
-        $recurring_amount   = wpinv_sanitize_amount( $invoice->get_recurring_details( 'total' ), 2 );
141
+        $initial_amount     = wpinv_sanitize_amount($invoice->get_total(), 2);
142
+        $recurring_amount   = wpinv_sanitize_amount($invoice->get_recurring_details('total'), 2);
143 143
         
144 144
         $paypal_args['cmd'] = '_xclick-subscriptions';
145 145
         $paypal_args['sra'] = '1';
146 146
         $paypal_args['src'] = '1';
147 147
         
148 148
         // Set item description
149
-        $item_name                  = sprintf( '[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name( array( 'id' => $item->ID ) ) );
150
-        $paypal_args['item_name']   = stripslashes_deep( html_entity_decode( $item_name, ENT_COMPAT, 'UTF-8' ) );
149
+        $item_name                  = sprintf('[%s] %s', $invoice->get_number(), wpinv_get_cart_item_name(array('id' => $item->ID)));
150
+        $paypal_args['item_name']   = stripslashes_deep(html_entity_decode($item_name, ENT_COMPAT, 'UTF-8'));
151 151
         
152
-        if ( $invoice->is_free_trial() && $item->has_free_trial() ) {
152
+        if ($invoice->is_free_trial() && $item->has_free_trial()) {
153 153
             $paypal_args['a1']  = $initial_amount;
154 154
             $paypal_args['p1']  = $item->get_trial_interval();
155 155
             $paypal_args['t1']  = $item->get_trial_period();
156 156
             
157 157
             // Set the recurring amount
158 158
             $paypal_args['a3']  = $recurring_amount;
159
-        } else if ( $initial_amount != $recurring_amount && $bill_times != 1 ) {
159
+        } else if ($initial_amount != $recurring_amount && $bill_times != 1) {
160 160
             $paypal_args['a1']  = $initial_amount;
161 161
             $paypal_args['p1']  = $interval;
162 162
             $paypal_args['t1']  = $period;
@@ -164,63 +164,63 @@  discard block
 block discarded – undo
164 164
             // Set the recurring amount
165 165
             $paypal_args['a3']  = $recurring_amount;
166 166
             
167
-            if ( $bill_times > 1 ) {
167
+            if ($bill_times > 1) {
168 168
                 $bill_times--;
169 169
             }
170 170
         } else {
171
-            $paypal_args['a3']  = $initial_amount;
171
+            $paypal_args['a3'] = $initial_amount;
172 172
         }
173 173
         
174 174
         $paypal_args['p3']  = $interval;
175 175
         $paypal_args['t3']  = $period;
176 176
         
177
-        if ( $bill_times > 1 ) {
177
+        if ($bill_times > 1) {
178 178
             // Make sure it's not over the max of 52
179
-            $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
179
+            $paypal_args['srt'] = ($bill_times <= 52 ? absint($bill_times) : 52);
180 180
         }
181 181
                 
182 182
         // Remove cart items
183 183
         $i = 1;
184
-        if( is_array( $purchase_data['cart_details'] ) && ! empty( $purchase_data['cart_details'] ) ) {
185
-            foreach ( $purchase_data['cart_details'] as $item ) {                
186
-                if ( isset( $paypal_args['item_number_' . $i] ) ) {
187
-                    unset( $paypal_args['item_number_' . $i] );
184
+        if (is_array($purchase_data['cart_details']) && !empty($purchase_data['cart_details'])) {
185
+            foreach ($purchase_data['cart_details'] as $item) {                
186
+                if (isset($paypal_args['item_number_' . $i])) {
187
+                    unset($paypal_args['item_number_' . $i]);
188 188
                 }
189
-                if ( isset( $paypal_args['item_name_' . $i] ) ) {
190
-                    unset( $paypal_args['item_name_' . $i] );
189
+                if (isset($paypal_args['item_name_' . $i])) {
190
+                    unset($paypal_args['item_name_' . $i]);
191 191
                 }
192
-                if ( isset( $paypal_args['quantity_' . $i] ) ) {
193
-                    unset( $paypal_args['quantity_' . $i] );
192
+                if (isset($paypal_args['quantity_' . $i])) {
193
+                    unset($paypal_args['quantity_' . $i]);
194 194
                 }
195
-                if ( isset( $paypal_args['amount_' . $i] ) ) {
196
-                    unset( $paypal_args['amount_' . $i] );
195
+                if (isset($paypal_args['amount_' . $i])) {
196
+                    unset($paypal_args['amount_' . $i]);
197 197
                 }
198
-                if ( isset( $paypal_args['discount_amount_' . $i] ) ) {
199
-                    unset( $paypal_args['discount_amount_' . $i] );
198
+                if (isset($paypal_args['discount_amount_' . $i])) {
199
+                    unset($paypal_args['discount_amount_' . $i]);
200 200
                 }
201 201
 
202 202
                 $i++;
203 203
             }
204 204
         }
205 205
         
206
-        if ( isset( $paypal_args['tax_cart'] ) ) {
207
-            unset( $paypal_args['tax_cart'] );
206
+        if (isset($paypal_args['tax_cart'])) {
207
+            unset($paypal_args['tax_cart']);
208 208
         }
209 209
                 
210
-        if ( isset( $paypal_args['upload'] ) ) {
211
-            unset( $paypal_args['upload'] );
210
+        if (isset($paypal_args['upload'])) {
211
+            unset($paypal_args['upload']);
212 212
         }
213 213
         
214
-        $paypal_args = apply_filters( 'wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice );
214
+        $paypal_args = apply_filters('wpinv_paypal_recurring_args', $paypal_args, $purchase_data, $invoice);
215 215
     }
216 216
     
217 217
     return $paypal_args;
218 218
 }
219
-add_filter( 'wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3 );
219
+add_filter('wpinv_paypal_args', 'wpinv_get_paypal_recurring_args', 10, 3);
220 220
 
221 221
 function wpinv_process_paypal_ipn() {
222 222
 	// Check the request method is POST
223
-	if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
223
+	if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
224 224
 		return;
225 225
 	}
226 226
 
@@ -228,11 +228,11 @@  discard block
 block discarded – undo
228 228
 	$post_data = '';
229 229
 
230 230
 	// Fallback just in case post_max_size is lower than needed
231
-	if ( ini_get( 'allow_url_fopen' ) ) {
232
-		$post_data = file_get_contents( 'php://input' );
231
+	if (ini_get('allow_url_fopen')) {
232
+		$post_data = file_get_contents('php://input');
233 233
 	} else {
234 234
 		// If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
235
-		ini_set( 'post_max_size', '12M' );
235
+		ini_set('post_max_size', '12M');
236 236
 	}
237 237
 	// Start the encoded data collection with notification command
238 238
 	$encoded_data = 'cmd=_notify-validate';
@@ -241,43 +241,43 @@  discard block
 block discarded – undo
241 241
 	$arg_separator = wpinv_get_php_arg_separator_output();
242 242
 
243 243
 	// Verify there is a post_data
244
-	if ( $post_data || strlen( $post_data ) > 0 ) {
244
+	if ($post_data || strlen($post_data) > 0) {
245 245
 		// Append the data
246
-		$encoded_data .= $arg_separator.$post_data;
246
+		$encoded_data .= $arg_separator . $post_data;
247 247
 	} else {
248 248
 		// Check if POST is empty
249
-		if ( empty( $_POST ) ) {
249
+		if (empty($_POST)) {
250 250
 			// Nothing to do
251 251
 			return;
252 252
 		} else {
253 253
 			// Loop through each POST
254
-			foreach ( $_POST as $key => $value ) {
254
+			foreach ($_POST as $key => $value) {
255 255
 				// Encode the value and append the data
256
-				$encoded_data .= $arg_separator."$key=" . urlencode( $value );
256
+				$encoded_data .= $arg_separator . "$key=" . urlencode($value);
257 257
 			}
258 258
 		}
259 259
 	}
260 260
 
261 261
 	// Convert collected post data to an array
262
-	parse_str( $encoded_data, $encoded_data_array );
262
+	parse_str($encoded_data, $encoded_data_array);
263 263
 
264
-	foreach ( $encoded_data_array as $key => $value ) {
265
-		if ( false !== strpos( $key, 'amp;' ) ) {
266
-			$new_key = str_replace( '&amp;', '&', $key );
267
-			$new_key = str_replace( 'amp;', '&' , $new_key );
264
+	foreach ($encoded_data_array as $key => $value) {
265
+		if (false !== strpos($key, 'amp;')) {
266
+			$new_key = str_replace('&amp;', '&', $key);
267
+			$new_key = str_replace('amp;', '&', $new_key);
268 268
 
269
-			unset( $encoded_data_array[ $key ] );
270
-			$encoded_data_array[ $new_key ] = $value;
269
+			unset($encoded_data_array[$key]);
270
+			$encoded_data_array[$new_key] = $value;
271 271
 		}
272 272
 	}
273 273
 
274 274
 	// Get the PayPal redirect uri
275
-	$paypal_redirect = wpinv_get_paypal_redirect( true );
275
+	$paypal_redirect = wpinv_get_paypal_redirect(true);
276 276
 
277
-	if ( !wpinv_get_option( 'disable_paypal_verification', false ) ) {
277
+	if (!wpinv_get_option('disable_paypal_verification', false)) {
278 278
 		// Validate the IPN
279 279
 
280
-		$remote_post_vars      = array(
280
+		$remote_post_vars = array(
281 281
 			'method'           => 'POST',
282 282
 			'timeout'          => 45,
283 283
 			'redirection'      => 5,
@@ -295,21 +295,21 @@  discard block
 block discarded – undo
295 295
 		);
296 296
 
297 297
 		// Get response
298
-		$api_response = wp_remote_post( wpinv_get_paypal_redirect(), $remote_post_vars );
298
+		$api_response = wp_remote_post(wpinv_get_paypal_redirect(), $remote_post_vars);
299 299
 
300
-		if ( is_wp_error( $api_response ) ) {
301
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
300
+		if (is_wp_error($api_response)) {
301
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
302 302
 			return; // Something went wrong
303 303
 		}
304 304
 
305
-		if ( $api_response['body'] !== 'VERIFIED' && wpinv_get_option( 'disable_paypal_verification', false ) ) {
306
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid IPN verification response. IPN data: %s', 'invoicing' ), json_encode( $api_response ) ) );
305
+		if ($api_response['body'] !== 'VERIFIED' && wpinv_get_option('disable_paypal_verification', false)) {
306
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid IPN verification response. IPN data: %s', 'invoicing'), json_encode($api_response)));
307 307
 			return; // Response not okay
308 308
 		}
309 309
 	}
310 310
 
311 311
 	// Check if $post_data_array has been populated
312
-	if ( !is_array( $encoded_data_array ) && !empty( $encoded_data_array ) )
312
+	if (!is_array($encoded_data_array) && !empty($encoded_data_array))
313 313
 		return;
314 314
 
315 315
 	$defaults = array(
@@ -317,265 +317,265 @@  discard block
 block discarded – undo
317 317
 		'payment_status' => ''
318 318
 	);
319 319
 
320
-	$encoded_data_array = wp_parse_args( $encoded_data_array, $defaults );
320
+	$encoded_data_array = wp_parse_args($encoded_data_array, $defaults);
321 321
 
322
-	$invoice_id = isset( $encoded_data_array['custom'] ) ? absint( $encoded_data_array['custom'] ) : 0;
322
+	$invoice_id = isset($encoded_data_array['custom']) ? absint($encoded_data_array['custom']) : 0;
323 323
     
324
-	wpinv_error_log( $encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__ );
325
-	wpinv_error_log( $encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__ );
324
+	wpinv_error_log($encoded_data_array['txn_type'], 'PayPal txn_type', __FILE__, __LINE__);
325
+	wpinv_error_log($encoded_data_array, 'PayPal IPN response', __FILE__, __LINE__);
326 326
 
327
-	if ( has_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'] ) ) {
327
+	if (has_action('wpinv_paypal_' . $encoded_data_array['txn_type'])) {
328 328
 		// Allow PayPal IPN types to be processed separately
329
-		do_action( 'wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id );
329
+		do_action('wpinv_paypal_' . $encoded_data_array['txn_type'], $encoded_data_array, $invoice_id);
330 330
 	} else {
331 331
 		// Fallback to web accept just in case the txn_type isn't present
332
-		do_action( 'wpinv_paypal_web_accept', $encoded_data_array, $invoice_id );
332
+		do_action('wpinv_paypal_web_accept', $encoded_data_array, $invoice_id);
333 333
 	}
334 334
 	exit;
335 335
 }
336
-add_action( 'wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn' );
336
+add_action('wpinv_verify_paypal_ipn', 'wpinv_process_paypal_ipn');
337 337
 
338
-function wpinv_process_paypal_web_accept_and_cart( $data, $invoice_id ) {
339
-	if ( $data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded' ) {
338
+function wpinv_process_paypal_web_accept_and_cart($data, $invoice_id) {
339
+	if ($data['txn_type'] != 'web_accept' && $data['txn_type'] != 'cart' && $data['payment_status'] != 'Refunded') {
340 340
 		return;
341 341
 	}
342 342
 
343
-	if( empty( $invoice_id ) ) {
343
+	if (empty($invoice_id)) {
344 344
 		return;
345 345
 	}
346 346
 
347 347
 	// Collect payment details
348
-	$purchase_key   = isset( $data['invoice'] ) ? $data['invoice'] : $data['item_number'];
348
+	$purchase_key   = isset($data['invoice']) ? $data['invoice'] : $data['item_number'];
349 349
 	$paypal_amount  = $data['mc_gross'];
350
-	$payment_status = strtolower( $data['payment_status'] );
351
-	$currency_code  = strtolower( $data['mc_currency'] );
352
-	$business_email = isset( $data['business'] ) && is_email( $data['business'] ) ? trim( $data['business'] ) : trim( $data['receiver_email'] );
353
-	$payment_meta   = wpinv_get_invoice_meta( $invoice_id );
350
+	$payment_status = strtolower($data['payment_status']);
351
+	$currency_code  = strtolower($data['mc_currency']);
352
+	$business_email = isset($data['business']) && is_email($data['business']) ? trim($data['business']) : trim($data['receiver_email']);
353
+	$payment_meta   = wpinv_get_invoice_meta($invoice_id);
354 354
 
355
-	if ( wpinv_get_payment_gateway( $invoice_id ) != 'paypal' ) {
355
+	if (wpinv_get_payment_gateway($invoice_id) != 'paypal') {
356 356
 		return; // this isn't a PayPal standard IPN
357 357
 	}
358 358
 
359 359
 	// Verify payment recipient
360
-	if ( strcasecmp( $business_email, trim( wpinv_get_option( 'paypal_email', false ) ) ) != 0 ) {
361
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid business email in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
362
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
363
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid PayPal business email.', 'invoicing' ), '', '', true );
360
+	if (strcasecmp($business_email, trim(wpinv_get_option('paypal_email', false))) != 0) {
361
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid business email in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
362
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
363
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid PayPal business email.', 'invoicing'), '', '', true);
364 364
 		return;
365 365
 	}
366 366
 
367 367
 	// Verify payment currency
368
-	if ( $currency_code != strtolower( $payment_meta['currency'] ) ) {
369
-		wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
370
-		wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
371
-		wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid currency in PayPal IPN.', 'invoicing' ), '', '', true );
368
+	if ($currency_code != strtolower($payment_meta['currency'])) {
369
+		wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
370
+		wpinv_update_payment_status($invoice_id, 'wpi-failed');
371
+		wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid currency in PayPal IPN.', 'invoicing'), '', '', true);
372 372
 		return;
373 373
 	}
374 374
 
375
-	if ( !wpinv_get_payment_user_email( $invoice_id ) ) {
375
+	if (!wpinv_get_payment_user_email($invoice_id)) {
376 376
 		// This runs when a Buy Now purchase was made. It bypasses checkout so no personal info is collected until PayPal
377 377
 		// No email associated with purchase, so store from PayPal
378
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_email', $data['payer_email'] );
378
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_email', $data['payer_email']);
379 379
 
380 380
 		// Setup and store the customer's details
381 381
 		$user_info = array(
382 382
 			'user_id'    => '-1',
383
-			'email'      => sanitize_text_field( $data['payer_email'] ),
384
-			'first_name' => sanitize_text_field( $data['first_name'] ),
385
-			'last_name'  => sanitize_text_field( $data['last_name'] ),
383
+			'email'      => sanitize_text_field($data['payer_email']),
384
+			'first_name' => sanitize_text_field($data['first_name']),
385
+			'last_name'  => sanitize_text_field($data['last_name']),
386 386
 			'discount'   => '',
387 387
 		);
388
-		$user_info['address'] = ! empty( $data['address_street']       ) ? sanitize_text_field( $data['address_street'] )       : false;
389
-		$user_info['city']    = ! empty( $data['address_city']         ) ? sanitize_text_field( $data['address_city'] )         : false;
390
-		$user_info['state']   = ! empty( $data['address_state']        ) ? sanitize_text_field( $data['address_state'] )        : false;
391
-		$user_info['country'] = ! empty( $data['address_country_code'] ) ? sanitize_text_field( $data['address_country_code'] ) : false;
392
-		$user_info['zip']     = ! empty( $data['address_zip']          ) ? sanitize_text_field( $data['address_zip'] )          : false;
388
+		$user_info['address'] = !empty($data['address_street']) ? sanitize_text_field($data['address_street']) : false;
389
+		$user_info['city']    = !empty($data['address_city']) ? sanitize_text_field($data['address_city']) : false;
390
+		$user_info['state']   = !empty($data['address_state']) ? sanitize_text_field($data['address_state']) : false;
391
+		$user_info['country'] = !empty($data['address_country_code']) ? sanitize_text_field($data['address_country_code']) : false;
392
+		$user_info['zip']     = !empty($data['address_zip']) ? sanitize_text_field($data['address_zip']) : false;
393 393
 
394 394
 		$payment_meta['user_info'] = $user_info;
395
-		wpinv_update_invoice_meta( $invoice_id, '_wpinv_payment_meta', $payment_meta );
395
+		wpinv_update_invoice_meta($invoice_id, '_wpinv_payment_meta', $payment_meta);
396 396
 	}
397 397
 
398
-	if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
398
+	if ($payment_status == 'refunded' || $payment_status == 'reversed') {
399 399
 		// Process a refund
400
-		wpinv_process_paypal_refund( $data, $invoice_id );
400
+		wpinv_process_paypal_refund($data, $invoice_id);
401 401
 	} else {
402
-		if ( get_post_status( $invoice_id ) == 'publish' ) {
402
+		if (get_post_status($invoice_id) == 'publish') {
403 403
 			return; // Only paid payments once
404 404
 		}
405 405
 
406 406
 		// Retrieve the total purchase amount (before PayPal)
407
-		$payment_amount = wpinv_payment_total( $invoice_id );
407
+		$payment_amount = wpinv_payment_total($invoice_id);
408 408
 
409
-		if ( number_format( (float) $paypal_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
409
+		if (number_format((float)$paypal_amount, 2) < number_format((float)$payment_amount, 2)) {
410 410
 			// The prices don't match
411
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid payment amount in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
412
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
413
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid amount in PayPal IPN.', 'invoicing' ), '', '', true );
411
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid payment amount in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
412
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
413
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid amount in PayPal IPN.', 'invoicing'), '', '', true);
414 414
 			return;
415 415
 		}
416
-		if ( $purchase_key != wpinv_get_payment_key( $invoice_id ) ) {
416
+		if ($purchase_key != wpinv_get_payment_key($invoice_id)) {
417 417
 			// Purchase keys don't match
418
-			wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid purchase key in IPN response. IPN data: %s', 'invoicing' ), json_encode( $data ) ), $invoice_id );
419
-			wpinv_update_payment_status( $invoice_id, 'wpi-failed' );
420
-			wpinv_insert_payment_note( $invoice_id, __( 'Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing' ), '', '', true );
418
+			wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid purchase key in IPN response. IPN data: %s', 'invoicing'), json_encode($data)), $invoice_id);
419
+			wpinv_update_payment_status($invoice_id, 'wpi-failed');
420
+			wpinv_insert_payment_note($invoice_id, __('Payment failed due to invalid purchase key in PayPal IPN.', 'invoicing'), '', '', true);
421 421
 			return;
422 422
 		}
423 423
 
424
-		if ( 'complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode( 'paypal' ) ) {
425
-			wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $data['txn_id'] ), '', '', true );
426
-			wpinv_set_payment_transaction_id( $invoice_id, $data['txn_id'] );
427
-			wpinv_update_payment_status( $invoice_id, 'publish' );
428
-		} else if ( 'pending' == $payment_status && isset( $data['pending_reason'] ) ) {
424
+		if ('complete' == $payment_status || 'completed' == $payment_status || 'processed' == $payment_status || wpinv_is_test_mode('paypal')) {
425
+			wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
426
+			wpinv_set_payment_transaction_id($invoice_id, $data['txn_id']);
427
+			wpinv_update_payment_status($invoice_id, 'publish');
428
+		} else if ('pending' == $payment_status && isset($data['pending_reason'])) {
429 429
 			// Look for possible pending reasons, such as an echeck
430 430
 			$note = '';
431 431
 
432
-			switch( strtolower( $data['pending_reason'] ) ) {
432
+			switch (strtolower($data['pending_reason'])) {
433 433
 				case 'echeck' :
434
-					$note = __( 'Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing' );
434
+					$note = __('Payment made via eCheck and will clear automatically in 5-8 days', 'invoicing');
435 435
 					break;
436 436
 				
437 437
                 case 'address' :
438
-					$note = __( 'Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing' );
438
+					$note = __('Payment requires a confirmed customer address and must be accepted manually through PayPal', 'invoicing');
439 439
 					break;
440 440
 				
441 441
                 case 'intl' :
442
-					$note = __( 'Payment must be accepted manually through PayPal due to international account regulations', 'invoicing' );
442
+					$note = __('Payment must be accepted manually through PayPal due to international account regulations', 'invoicing');
443 443
 					break;
444 444
 				
445 445
                 case 'multi-currency' :
446
-					$note = __( 'Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing' );
446
+					$note = __('Payment received in non-shop currency and must be accepted manually through PayPal', 'invoicing');
447 447
 					break;
448 448
 				
449 449
                 case 'paymentreview' :
450 450
                 case 'regulatory_review' :
451
-					$note = __( 'Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing' );
451
+					$note = __('Payment is being reviewed by PayPal staff as high-risk or in possible violation of government regulations', 'invoicing');
452 452
 					break;
453 453
 				
454 454
                 case 'unilateral' :
455
-					$note = __( 'Payment was sent to non-confirmed or non-registered email address.', 'invoicing' );
455
+					$note = __('Payment was sent to non-confirmed or non-registered email address.', 'invoicing');
456 456
 					break;
457 457
 				
458 458
                 case 'upgrade' :
459
-					$note = __( 'PayPal account must be upgraded before this payment can be accepted', 'invoicing' );
459
+					$note = __('PayPal account must be upgraded before this payment can be accepted', 'invoicing');
460 460
 					break;
461 461
 				
462 462
                 case 'verify' :
463
-					$note = __( 'PayPal account is not verified. Verify account in order to accept this payment', 'invoicing' );
463
+					$note = __('PayPal account is not verified. Verify account in order to accept this payment', 'invoicing');
464 464
 					break;
465 465
 
466 466
 				case 'other' :
467
-					$note = __( 'Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing' );
467
+					$note = __('Payment is pending for unknown reasons. Contact PayPal support for assistance', 'invoicing');
468 468
 					break;
469 469
 			}
470 470
 
471
-			if ( ! empty( $note ) ) {
472
-				wpinv_insert_payment_note( $invoice_id, $note, '', '', true );
471
+			if (!empty($note)) {
472
+				wpinv_insert_payment_note($invoice_id, $note, '', '', true);
473 473
 			}
474 474
 		} else {
475
-			wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal IPN has been received with invalid payment status: %s', 'invoicing' ), $payment_status ), '', '', true );
475
+			wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal IPN has been received with invalid payment status: %s', 'invoicing'), $payment_status), '', '', true);
476 476
 		}
477 477
 	}
478 478
 }
479
-add_action( 'wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2 );
479
+add_action('wpinv_paypal_web_accept', 'wpinv_process_paypal_web_accept_and_cart', 10, 2);
480 480
 
481 481
 // Process PayPal subscription sign ups
482
-add_action( 'wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup' );
482
+add_action('wpinv_paypal_subscr_signup', 'wpinv_process_paypal_subscr_signup');
483 483
 
484 484
 // Process PayPal subscription payments
485
-add_action( 'wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment' );
485
+add_action('wpinv_paypal_subscr_payment', 'wpinv_process_paypal_subscr_payment');
486 486
 
487 487
 // Process PayPal subscription cancellations
488
-add_action( 'wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel' );
488
+add_action('wpinv_paypal_subscr_cancel', 'wpinv_process_paypal_subscr_cancel');
489 489
 
490 490
 // Process PayPal subscription end of term notices
491
-add_action( 'wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot' );
491
+add_action('wpinv_paypal_subscr_eot', 'wpinv_process_paypal_subscr_eot');
492 492
 
493 493
 // Process PayPal payment failed
494
-add_action( 'wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed' );
494
+add_action('wpinv_paypal_subscr_failed', 'wpinv_process_paypal_subscr_failed');
495 495
 
496 496
 
497 497
 /**
498 498
  * Process the subscription started IPN.
499 499
  */
500
-function wpinv_process_paypal_subscr_signup( $ipn_data ) {
501
-    $parent_invoice_id = absint( $ipn_data['custom'] );
502
-    if( empty( $parent_invoice_id ) ) {
500
+function wpinv_process_paypal_subscr_signup($ipn_data) {
501
+    $parent_invoice_id = absint($ipn_data['custom']);
502
+    if (empty($parent_invoice_id)) {
503 503
         return;
504 504
     }
505 505
 
506
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
507
-    if ( empty( $invoice ) ) {
506
+    $invoice = wpinv_get_invoice($parent_invoice_id);
507
+    if (empty($invoice)) {
508 508
         return;
509 509
     }
510 510
 
511
-    if ( $invoice->is_free_trial() && !empty( $ipn_data['invoice'] ) ) {
512
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Invoice ID: %s', 'invoicing' ) , $ipn_data['invoice'] ), '', '', true);
513
-        if ( !empty( $ipn_data['txn_id'] ) ) {
514
-            wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
511
+    if ($invoice->is_free_trial() && !empty($ipn_data['invoice'])) {
512
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Invoice ID: %s', 'invoicing'), $ipn_data['invoice']), '', '', true);
513
+        if (!empty($ipn_data['txn_id'])) {
514
+            wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
515 515
         }
516 516
     }
517 517
 
518
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
519
-    if ( false === $subscription ) {
518
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
519
+    if (false === $subscription) {
520 520
         return;
521 521
     }
522 522
     
523
-    wpinv_update_payment_status( $parent_invoice_id, 'publish' );
523
+    wpinv_update_payment_status($parent_invoice_id, 'publish');
524 524
     sleep(1);
525
-    wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
526
-    update_post_meta($parent_invoice_id,'_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
525
+    wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
526
+    update_post_meta($parent_invoice_id, '_wpinv_subscr_profile_id', $ipn_data['subscr_id']);
527 527
 
528 528
     $status     = 'trialling' == $subscription->status ? 'trialling' : 'active';
529
-    $diff_days  = absint( ( ( strtotime( $subscription->expiration ) - strtotime( $subscription->created ) ) / DAY_IN_SECONDS ) );
530
-    $created    = date_i18n( 'Y-m-d H:i:s' );
531
-    $expiration = date_i18n( 'Y-m-d 23:59:59', ( strtotime( $created ) + ( $diff_days * DAY_IN_SECONDS ) ) );
529
+    $diff_days  = absint(((strtotime($subscription->expiration) - strtotime($subscription->created)) / DAY_IN_SECONDS));
530
+    $created    = date_i18n('Y-m-d H:i:s');
531
+    $expiration = date_i18n('Y-m-d 23:59:59', (strtotime($created) + ($diff_days * DAY_IN_SECONDS)));
532 532
 
533 533
     // Retrieve pending subscription from database and update it's status to active and set proper profile ID
534
-    $subscription->update( array( 'profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration ) );
534
+    $subscription->update(array('profile_id' => $ipn_data['subscr_id'], 'status' => $status, 'created' => $created, 'expiration' => $expiration));
535 535
 }
536 536
 
537 537
 /**
538 538
  * Process the subscription payment received IPN.
539 539
  */
540
-function wpinv_process_paypal_subscr_payment( $ipn_data ) {
541
-    $parent_invoice_id = absint( $ipn_data['custom'] );
540
+function wpinv_process_paypal_subscr_payment($ipn_data) {
541
+    $parent_invoice_id = absint($ipn_data['custom']);
542 542
 
543
-    $parent_invoice = wpinv_get_invoice( $parent_invoice_id );
544
-    if ( empty( $parent_invoice ) ) {
543
+    $parent_invoice = wpinv_get_invoice($parent_invoice_id);
544
+    if (empty($parent_invoice)) {
545 545
         return;
546 546
     }
547 547
 
548
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
549
-    if ( false === $subscription ) {
548
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
549
+    if (false === $subscription) {
550 550
         return;
551 551
     }
552 552
 
553
-    $transaction_id = wpinv_get_payment_transaction_id( $parent_invoice_id );
553
+    $transaction_id = wpinv_get_payment_transaction_id($parent_invoice_id);
554 554
     $times_billed   = $subscription->get_times_billed();
555
-    $signup_date    = strtotime( $subscription->created );
556
-    $today          = date( 'Ynd', $signup_date ) == date( 'Ynd', strtotime( $ipn_data['payment_date'] ) );
555
+    $signup_date    = strtotime($subscription->created);
556
+    $today          = date('Ynd', $signup_date) == date('Ynd', strtotime($ipn_data['payment_date']));
557 557
 
558 558
     // Look to see if payment is same day as signup and we have set the transaction ID on the parent payment yet.
559
-    if ( (empty($times_billed) || $today) && ( !$transaction_id || $transaction_id == $parent_invoice_id ) ) {
560
-        wpinv_update_payment_status( $parent_invoice_id, 'publish' );
559
+    if ((empty($times_billed) || $today) && (!$transaction_id || $transaction_id == $parent_invoice_id)) {
560
+        wpinv_update_payment_status($parent_invoice_id, 'publish');
561 561
         sleep(1);
562 562
         
563 563
         // This is the very first payment
564
-        wpinv_set_payment_transaction_id( $parent_invoice_id, $ipn_data['txn_id'] );
565
-        wpinv_insert_payment_note( $parent_invoice_id, sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
564
+        wpinv_set_payment_transaction_id($parent_invoice_id, $ipn_data['txn_id']);
565
+        wpinv_insert_payment_note($parent_invoice_id, sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
566 566
         return;
567 567
     }
568 568
 
569
-    if ( wpinv_get_id_by_transaction_id( $ipn_data['txn_id'] ) ) {
569
+    if (wpinv_get_id_by_transaction_id($ipn_data['txn_id'])) {
570 570
         return; // Payment already recorded
571 571
     }
572 572
 
573
-    $currency_code = strtolower( $ipn_data['mc_currency'] );
573
+    $currency_code = strtolower($ipn_data['mc_currency']);
574 574
 
575 575
     // verify details
576
-    if ( $currency_code != strtolower( wpinv_get_currency() ) ) {
576
+    if ($currency_code != strtolower(wpinv_get_currency())) {
577 577
         // the currency code is invalid
578
-        wpinv_record_gateway_error( __( 'IPN Error', 'invoicing' ), sprintf( __( 'Invalid currency in IPN response. IPN data: ', 'invoicing' ), json_encode( $ipn_data ) ) );
578
+        wpinv_record_gateway_error(__('IPN Error', 'invoicing'), sprintf(__('Invalid currency in IPN response. IPN data: ', 'invoicing'), json_encode($ipn_data)));
579 579
         return;
580 580
     }
581 581
 
@@ -585,11 +585,11 @@  discard block
 block discarded – undo
585 585
         'gateway'        => 'paypal'
586 586
     );
587 587
     
588
-    $invoice_id = $subscription->add_payment( $args );
588
+    $invoice_id = $subscription->add_payment($args);
589 589
 
590
-    if ( $invoice_id > 0 ) {
591
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $ipn_data['txn_id'] ), '', '', true );
592
-        wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $ipn_data['subscr_id'] ), '', '', true );
590
+    if ($invoice_id > 0) {
591
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $ipn_data['txn_id']), '', '', true);
592
+        wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $ipn_data['subscr_id']), '', '', true);
593 593
 
594 594
         $subscription->renew();
595 595
     }
@@ -598,10 +598,10 @@  discard block
 block discarded – undo
598 598
 /**
599 599
  * Process the subscription canceled IPN.
600 600
  */
601
-function wpinv_process_paypal_subscr_cancel( $ipn_data ) {
602
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
601
+function wpinv_process_paypal_subscr_cancel($ipn_data) {
602
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
603 603
 
604
-    if( false === $subscription ) {
604
+    if (false === $subscription) {
605 605
         return;
606 606
     }
607 607
 
@@ -611,10 +611,10 @@  discard block
 block discarded – undo
611 611
 /**
612 612
  * Process the subscription expired IPN.
613 613
  */
614
-function wpinv_process_paypal_subscr_eot( $ipn_data ) {
615
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
614
+function wpinv_process_paypal_subscr_eot($ipn_data) {
615
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
616 616
 
617
-    if( false === $subscription ) {
617
+    if (false === $subscription) {
618 618
         return;
619 619
     }
620 620
 
@@ -624,40 +624,40 @@  discard block
 block discarded – undo
624 624
 /**
625 625
  * Process the subscription payment failed IPN.
626 626
  */
627
-function wpinv_process_paypal_subscr_failed( $ipn_data ) {
628
-    $subscription = wpinv_get_paypal_subscription( $ipn_data );
627
+function wpinv_process_paypal_subscr_failed($ipn_data) {
628
+    $subscription = wpinv_get_paypal_subscription($ipn_data);
629 629
 
630
-    if( false === $subscription ) {
630
+    if (false === $subscription) {
631 631
         return;
632 632
     }
633 633
 
634 634
     $subscription->failing();
635 635
 
636
-    do_action( 'wpinv_recurring_payment_failed', $subscription );
636
+    do_action('wpinv_recurring_payment_failed', $subscription);
637 637
 }
638 638
 
639 639
 /**
640 640
  * Retrieve the subscription this IPN notice is for.
641 641
  */
642
-function wpinv_get_paypal_subscription( $ipn_data = array() ) {
643
-    $parent_invoice_id = absint( $ipn_data['custom'] );
642
+function wpinv_get_paypal_subscription($ipn_data = array()) {
643
+    $parent_invoice_id = absint($ipn_data['custom']);
644 644
 
645
-    if( empty( $parent_invoice_id ) ) {
645
+    if (empty($parent_invoice_id)) {
646 646
         return false;
647 647
     }
648 648
 
649
-    $invoice = wpinv_get_invoice( $parent_invoice_id );
650
-    if ( empty( $invoice ) ) {
649
+    $invoice = wpinv_get_invoice($parent_invoice_id);
650
+    if (empty($invoice)) {
651 651
         return false;
652 652
     }
653 653
 
654
-    $subscription = new WPInv_Subscription( $ipn_data['subscr_id'], true );
654
+    $subscription = new WPInv_Subscription($ipn_data['subscr_id'], true);
655 655
 
656
-    if ( ! ( ! empty( $subscription ) && $subscription->id > 0 ) ) {
657
-        $subscription = wpinv_get_subscription( $parent_invoice_id );
656
+    if (!(!empty($subscription) && $subscription->id > 0)) {
657
+        $subscription = wpinv_get_subscription($parent_invoice_id);
658 658
 
659
-        if ( ! empty( $subscription ) && $subscription->id > 0 ) {
660
-            $subscription->update( array( 'profile_id' => sanitize_text_field( $ipn_data['subscr_id'] ) ) );
659
+        if (!empty($subscription) && $subscription->id > 0) {
660
+            $subscription->update(array('profile_id' => sanitize_text_field($ipn_data['subscr_id'])));
661 661
         } else {
662 662
             return false;
663 663
         }
@@ -667,46 +667,46 @@  discard block
 block discarded – undo
667 667
 
668 668
 }
669 669
 
670
-function wpinv_process_paypal_refund( $data, $invoice_id = 0 ) {
670
+function wpinv_process_paypal_refund($data, $invoice_id = 0) {
671 671
 	// Collect payment details
672 672
 
673
-	if( empty( $invoice_id ) ) {
673
+	if (empty($invoice_id)) {
674 674
 		return;
675 675
 	}
676 676
 
677
-	if ( get_post_status( $invoice_id ) == 'wpi-refunded' ) {
677
+	if (get_post_status($invoice_id) == 'wpi-refunded') {
678 678
 		return; // Only refund payments once
679 679
 	}
680 680
 
681
-	$payment_amount = wpinv_payment_total( $invoice_id );
681
+	$payment_amount = wpinv_payment_total($invoice_id);
682 682
 	$refund_amount  = $data['mc_gross'] * -1;
683 683
 
684
-	do_action( 'wpinv_paypal_refund_request', $data, $invoice_id );
684
+	do_action('wpinv_paypal_refund_request', $data, $invoice_id);
685 685
 
686
-	if ( number_format( (float) $refund_amount, 2 ) < number_format( (float) $payment_amount, 2 ) ) {
687
-		wpinv_insert_payment_note( $invoice_id, wp_sprintf( __( 'PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing' ), (float)$refund_amount . ' '. $data['mc_currency'], $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
686
+	if (number_format((float)$refund_amount, 2) < number_format((float)$payment_amount, 2)) {
687
+		wpinv_insert_payment_note($invoice_id, wp_sprintf(__('PayPal partial refund of %s processed for transaction #%s for reason: %s', 'invoicing'), (float)$refund_amount . ' ' . $data['mc_currency'], $data['parent_txn_id'], $data['reason_code']), '', '', true);
688 688
 
689
-		do_action( 'wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount );
689
+		do_action('wpinv_paypal_invoice_partially_refunded', $data, $invoice_id, $refund_amount);
690 690
 
691 691
 		return; // This is a partial refund
692 692
 	}
693 693
 
694
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Payment #%s Refunded for reason: %s', 'invoicing' ), $data['parent_txn_id'], $data['reason_code'] ), '', '', true );
695
-	wpinv_insert_payment_note( $invoice_id, sprintf( __( 'PayPal Refund Transaction ID: %s', 'invoicing' ), $data['txn_id'] ), '', '', true );
696
-	wpinv_update_payment_status( $invoice_id, 'wpi-refunded' );
694
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Payment #%s Refunded for reason: %s', 'invoicing'), $data['parent_txn_id'], $data['reason_code']), '', '', true);
695
+	wpinv_insert_payment_note($invoice_id, sprintf(__('PayPal Refund Transaction ID: %s', 'invoicing'), $data['txn_id']), '', '', true);
696
+	wpinv_update_payment_status($invoice_id, 'wpi-refunded');
697 697
 
698
-	do_action( 'wpinv_paypal_invoice_fully_refunded', $data, $invoice_id );
698
+	do_action('wpinv_paypal_invoice_fully_refunded', $data, $invoice_id);
699 699
 }
700 700
 
701
-function wpinv_get_paypal_redirect( $ssl_check = false ) {
702
-    if ( is_ssl() || ! $ssl_check ) {
701
+function wpinv_get_paypal_redirect($ssl_check = false) {
702
+    if (is_ssl() || !$ssl_check) {
703 703
         $protocol = 'https://';
704 704
     } else {
705 705
         $protocol = 'http://';
706 706
     }
707 707
 
708 708
     // Check the current payment mode
709
-    if ( wpinv_is_test_mode( 'paypal' ) ) {
709
+    if (wpinv_is_test_mode('paypal')) {
710 710
         // Test mode
711 711
         $paypal_uri = $protocol . 'www.sandbox.paypal.com/cgi-bin/webscr';
712 712
     } else {
@@ -714,120 +714,120 @@  discard block
 block discarded – undo
714 714
         $paypal_uri = $protocol . 'www.paypal.com/cgi-bin/webscr';
715 715
     }
716 716
 
717
-    return apply_filters( 'wpinv_paypal_uri', $paypal_uri );
717
+    return apply_filters('wpinv_paypal_uri', $paypal_uri);
718 718
 }
719 719
 
720
-function wpinv_paypal_success_page_content( $content ) {
720
+function wpinv_paypal_success_page_content($content) {
721 721
     global $wpi_invoice;
722 722
     
723 723
     $session = wpinv_get_checkout_session();
724 724
 
725
-    if ( empty( $_GET['invoice-id'] ) && empty( $session['invoice_key'] )  ) {
725
+    if (empty($_GET['invoice-id']) && empty($session['invoice_key'])) {
726 726
         return $content;
727 727
     }
728 728
 
729
-    $invoice_id = !empty( $_GET['invoice-id'] ) ? absint( $_GET['invoice-id'] ) : wpinv_get_invoice_id_by_key( $session['invoice_key'] );
729
+    $invoice_id = !empty($_GET['invoice-id']) ? absint($_GET['invoice-id']) : wpinv_get_invoice_id_by_key($session['invoice_key']);
730 730
 
731
-    if ( empty(  $invoice_id ) ) {
731
+    if (empty($invoice_id)) {
732 732
         return $content;
733 733
     }
734 734
 
735
-    $wpi_invoice = wpinv_get_invoice( $invoice_id );
735
+    $wpi_invoice = wpinv_get_invoice($invoice_id);
736 736
     
737
-    if ( !empty( $wpi_invoice ) && 'wpi-pending' == $wpi_invoice->status ) {
737
+    if (!empty($wpi_invoice) && 'wpi-pending' == $wpi_invoice->status) {
738 738
         // Payment is still pending so show processing indicator to fix the Race Condition, issue #
739 739
         ob_start();
740
-        wpinv_get_template_part( 'wpinv-payment-processing' );
740
+        wpinv_get_template_part('wpinv-payment-processing');
741 741
         $content = ob_get_clean();
742 742
     }
743 743
 
744 744
     return $content;
745 745
 }
746
-add_filter( 'wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content' );
746
+add_filter('wpinv_payment_confirm_paypal', 'wpinv_paypal_success_page_content');
747 747
 
748
-function wpinv_paypal_get_transaction_id( $invoice_id ) {
748
+function wpinv_paypal_get_transaction_id($invoice_id) {
749 749
     $transaction_id = '';
750
-    $notes = wpinv_get_invoice_notes( $invoice_id );
750
+    $notes = wpinv_get_invoice_notes($invoice_id);
751 751
 
752
-    foreach ( $notes as $note ) {
753
-        if ( preg_match( '/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match ) ) {
752
+    foreach ($notes as $note) {
753
+        if (preg_match('/^PayPal Transaction ID: ([^\s]+)/', $note->comment_content, $match)) {
754 754
             $transaction_id = $match[1];
755 755
             continue;
756 756
         }
757 757
     }
758 758
 
759
-    return apply_filters( 'wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id );
759
+    return apply_filters('wpinv_paypal_set_transaction_id', $transaction_id, $invoice_id);
760 760
 }
761
-add_filter( 'wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1 );
761
+add_filter('wpinv_payment_get_transaction_id-paypal', 'wpinv_paypal_get_transaction_id', 10, 1);
762 762
 
763
-function wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice ) {
764
-    if ( $transaction_id == $invoice_id ) {
763
+function wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice) {
764
+    if ($transaction_id == $invoice_id) {
765 765
         $transaction_link = $transaction_id;
766 766
     } else {
767
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
767
+        if (!empty($invoice) && !empty($invoice->mode)) {
768 768
             $mode = $invoice->mode;
769 769
         } else {
770
-            $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live';
770
+            $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live';
771 771
         }
772 772
 
773 773
         $sandbox = $mode == 'test' ? '.sandbox' : '';
774 774
         $transaction_url = 'https://www' . $sandbox . '.paypal.com/webscr?cmd=_history-details-from-hub&id=' . $transaction_id;
775 775
 
776
-        $transaction_link = '<a href="' . esc_url( $transaction_url ) . '" target="_blank">' . $transaction_id . '</a>';
776
+        $transaction_link = '<a href="' . esc_url($transaction_url) . '" target="_blank">' . $transaction_id . '</a>';
777 777
     }
778 778
 
779
-    return apply_filters( 'wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice );
779
+    return apply_filters('wpinv_paypal_link_payment_details_transaction_id', $transaction_link, $transaction_id, $invoice);
780 780
 }
781
-add_filter( 'wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3 );
781
+add_filter('wpinv_payment_details_transaction_id-paypal', 'wpinv_paypal_link_transaction_id', 10, 3);
782 782
 
783
-function wpinv_paypal_profile_id_link( $profile_id, $subscription ) {
783
+function wpinv_paypal_profile_id_link($profile_id, $subscription) {
784 784
     $link = $profile_id;
785 785
 
786
-    if ( ! empty( $profile_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
787
-        $invoice = wpinv_get_invoice( $invoice_id );
786
+    if (!empty($profile_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
787
+        $invoice = wpinv_get_invoice($invoice_id);
788 788
 
789
-        if ( ! empty( $invoice ) && ! empty( $invoice->mode ) ) {
789
+        if (!empty($invoice) && !empty($invoice->mode)) {
790 790
             $mode = $invoice->mode;
791 791
         } else {
792
-            $mode = wpinv_is_test_mode( 'paypal' ) ? 'test' : 'live';
792
+            $mode = wpinv_is_test_mode('paypal') ? 'test' : 'live';
793 793
         }
794 794
 
795 795
         $sandbox = $mode == 'test' ? '.sandbox' : '';
796 796
         $url = 'https://www' . $sandbox . '.paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=' . $profile_id;
797 797
 
798
-        $link = '<a href="' . esc_url( $url ) . '" target="_blank">' . $profile_id . '</a>';
798
+        $link = '<a href="' . esc_url($url) . '" target="_blank">' . $profile_id . '</a>';
799 799
     }
800 800
     
801
-    return apply_filters( 'wpinv_paypal_profile_id_link', $link, $profile_id, $subscription );
801
+    return apply_filters('wpinv_paypal_profile_id_link', $link, $profile_id, $subscription);
802 802
 }
803
-add_filter( 'wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2 );
803
+add_filter('wpinv_subscription_profile_link_paypal', 'wpinv_paypal_profile_id_link', 10, 2);
804 804
 
805
-function wpinv_paypal_transaction_id_link( $transaction_id, $subscription ) {
806
-    if ( ! empty( $transaction_id ) && ! empty( $subscription ) && ( $invoice_id = $subscription->get_original_payment_id() ) ) {
807
-        $invoice = wpinv_get_invoice( $invoice_id );
805
+function wpinv_paypal_transaction_id_link($transaction_id, $subscription) {
806
+    if (!empty($transaction_id) && !empty($subscription) && ($invoice_id = $subscription->get_original_payment_id())) {
807
+        $invoice = wpinv_get_invoice($invoice_id);
808 808
 
809
-        if ( ! empty( $invoice ) ) {
810
-            return wpinv_paypal_link_transaction_id( $transaction_id, $invoice_id, $invoice );
809
+        if (!empty($invoice)) {
810
+            return wpinv_paypal_link_transaction_id($transaction_id, $invoice_id, $invoice);
811 811
         }        
812 812
     }
813 813
     
814 814
     return $transaction_id;
815 815
 }
816
-add_filter( 'wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2 );
816
+add_filter('wpinv_subscription_transaction_link_paypal', 'wpinv_paypal_transaction_id_link', 10, 2);
817 817
 
818 818
 function wpinv_is_paypal_valid_for_use() {
819
-    return in_array( wpinv_get_currency(), apply_filters( 'wpinv_paypal_supported_currencies', array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' ) ) );
819
+    return in_array(wpinv_get_currency(), apply_filters('wpinv_paypal_supported_currencies', array('AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR')));
820 820
 }
821 821
 
822
-function wpinv_check_paypal_currency_support( $gateway_list ) {
823
-    if ( isset( $gateway_list['paypal'] ) && ! wpinv_is_paypal_valid_for_use() ) {
824
-        unset( $gateway_list['paypal'] );
822
+function wpinv_check_paypal_currency_support($gateway_list) {
823
+    if (isset($gateway_list['paypal']) && !wpinv_is_paypal_valid_for_use()) {
824
+        unset($gateway_list['paypal']);
825 825
     }
826 826
     return $gateway_list;
827 827
 }
828
-add_filter( 'wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1 );
828
+add_filter('wpinv_enabled_payment_gateways', 'wpinv_check_paypal_currency_support', 10, 1);
829 829
 
830
-function wpinv_gateway_paypal_button_label( $label ) {
831
-    return __( 'Proceed to PayPal', 'invoicing' );
830
+function wpinv_gateway_paypal_button_label($label) {
831
+    return __('Proceed to PayPal', 'invoicing');
832 832
 }
833
-add_filter( 'wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1 );
834 833
\ No newline at end of file
834
+add_filter('wpinv_gateway_paypal_button_label', 'wpinv_gateway_paypal_button_label', 10, 1);
835 835
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-address-functions.php 3 patches
Braces   +12 added lines, -8 removed lines patch added patch discarded remove patch
@@ -95,20 +95,24 @@
 block discarded – undo
95 95
     }
96 96
 
97 97
     if ( !empty( $user_info ) ) {
98
-        if( empty( $address['first_name'] ) )
99
-            $address['first_name'] = $user_info->first_name;
98
+        if( empty( $address['first_name'] ) ) {
99
+                    $address['first_name'] = $user_info->first_name;
100
+        }
100 101
         
101
-        if( empty( $address['last_name'] ) )
102
-            $address['last_name'] = $user_info->last_name;
102
+        if( empty( $address['last_name'] ) ) {
103
+                    $address['last_name'] = $user_info->last_name;
104
+        }
103 105
     }
104 106
     
105 107
     $address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," );
106 108
     
107
-    if( empty( $address['state'] ) && $with_default )
108
-        $address['state'] = wpinv_get_default_state();
109
+    if( empty( $address['state'] ) && $with_default ) {
110
+            $address['state'] = wpinv_get_default_state();
111
+    }
109 112
 
110
-    if( empty( $address['country'] ) && $with_default )
111
-        $address['country'] = wpinv_get_default_country();
113
+    if( empty( $address['country'] ) && $with_default ) {
114
+            $address['country'] = wpinv_get_default_country();
115
+    }
112 116
 
113 117
 
114 118
     return $address;
Please login to merge, or discard this patch.
Indentation   +278 added lines, -278 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+    $country = wpinv_get_option( 'default_country', 'UK' );
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+    return apply_filters( 'wpinv_default_country', $country );
19 19
 }
20 20
 
21 21
 function wpinv_is_base_country( $country ) {
@@ -40,9 +40,9 @@  discard block
 block discarded – undo
40 40
 }
41 41
 
42 42
 function wpinv_get_default_state() {
43
-	$state = wpinv_get_option( 'default_state', false );
43
+    $state = wpinv_get_option( 'default_state', false );
44 44
 
45
-	return apply_filters( 'wpinv_default_state', $state );
45
+    return apply_filters( 'wpinv_default_state', $state );
46 46
 }
47 47
 
48 48
 function wpinv_state_name( $state_code = '', $country_code = '' ) {
@@ -115,260 +115,260 @@  discard block
 block discarded – undo
115 115
 }
116 116
 
117 117
 function wpinv_get_country_list( $first_empty = false ) {
118
-	$countries = array(
119
-		'US' => __('United States', 'invoicing'),
120
-		'CA' => __('Canada', 'invoicing'),
121
-		'GB' => __('United Kingdom', 'invoicing'),
122
-		'AF' => __('Afghanistan', 'invoicing'),
123
-		'AX' => __('Aland Islands', 'invoicing'),
124
-		'AL' => __('Albania', 'invoicing'),
125
-		'DZ' => __('Algeria', 'invoicing'),
126
-		'AS' => __('American Samoa', 'invoicing'),
127
-		'AD' => __('Andorra', 'invoicing'),
128
-		'AO' => __('Angola', 'invoicing'),
129
-		'AI' => __('Anguilla', 'invoicing'),
130
-		'AQ' => __('Antarctica', 'invoicing'),
131
-		'AG' => __('Antigua and Barbuda', 'invoicing'),
132
-		'AR' => __('Argentina', 'invoicing'),
133
-		'AM' => __('Armenia', 'invoicing'),
134
-		'AW' => __('Aruba', 'invoicing'),
135
-		'AU' => __('Australia', 'invoicing'),
136
-		'AT' => __('Austria', 'invoicing'),
137
-		'AZ' => __('Azerbaijan', 'invoicing'),
138
-		'BS' => __('Bahamas', 'invoicing'),
139
-		'BH' => __('Bahrain', 'invoicing'),
140
-		'BD' => __('Bangladesh', 'invoicing'),
141
-		'BB' => __('Barbados', 'invoicing'),
142
-		'BY' => __('Belarus', 'invoicing'),
143
-		'BE' => __('Belgium', 'invoicing'),
144
-		'BZ' => __('Belize', 'invoicing'),
145
-		'BJ' => __('Benin', 'invoicing'),
146
-		'BM' => __('Bermuda', 'invoicing'),
147
-		'BT' => __('Bhutan', 'invoicing'),
148
-		'BO' => __('Bolivia', 'invoicing'),
149
-		'BQ' => __('Bonaire, Saint Eustatius and Saba', 'invoicing'),
150
-		'BA' => __('Bosnia and Herzegovina', 'invoicing'),
151
-		'BW' => __('Botswana', 'invoicing'),
152
-		'BV' => __('Bouvet Island', 'invoicing'),
153
-		'BR' => __('Brazil', 'invoicing'),
154
-		'IO' => __('British Indian Ocean Territory', 'invoicing'),
155
-		'BN' => __('Brunei Darrussalam', 'invoicing'),
156
-		'BG' => __('Bulgaria', 'invoicing'),
157
-		'BF' => __('Burkina Faso', 'invoicing'),
158
-		'BI' => __('Burundi', 'invoicing'),
159
-		'KH' => __('Cambodia', 'invoicing'),
160
-		'CM' => __('Cameroon', 'invoicing'),
161
-		'CV' => __('Cape Verde', 'invoicing'),
162
-		'KY' => __('Cayman Islands', 'invoicing'),
163
-		'CF' => __('Central African Republic', 'invoicing'),
164
-		'TD' => __('Chad', 'invoicing'),
165
-		'CL' => __('Chile', 'invoicing'),
166
-		'CN' => __('China', 'invoicing'),
167
-		'CX' => __('Christmas Island', 'invoicing'),
168
-		'CC' => __('Cocos Islands', 'invoicing'),
169
-		'CO' => __('Colombia', 'invoicing'),
170
-		'KM' => __('Comoros', 'invoicing'),
171
-		'CD' => __('Congo, Democratic People\'s Republic', 'invoicing'),
172
-		'CG' => __('Congo, Republic of', 'invoicing'),
173
-		'CK' => __('Cook Islands', 'invoicing'),
174
-		'CR' => __('Costa Rica', 'invoicing'),
175
-		'CI' => __('Cote d\'Ivoire', 'invoicing'),
176
-		'HR' => __('Croatia/Hrvatska', 'invoicing'),
177
-		'CU' => __('Cuba', 'invoicing'),
178
-		'CW' => __('Cura&Ccedil;ao', 'invoicing'),
179
-		'CY' => __('Cyprus', 'invoicing'),
180
-		'CZ' => __('Czech Republic', 'invoicing'),
181
-		'DK' => __('Denmark', 'invoicing'),
182
-		'DJ' => __('Djibouti', 'invoicing'),
183
-		'DM' => __('Dominica', 'invoicing'),
184
-		'DO' => __('Dominican Republic', 'invoicing'),
185
-		'TP' => __('East Timor', 'invoicing'),
186
-		'EC' => __('Ecuador', 'invoicing'),
187
-		'EG' => __('Egypt', 'invoicing'),
188
-		'GQ' => __('Equatorial Guinea', 'invoicing'),
189
-		'SV' => __('El Salvador', 'invoicing'),
190
-		'ER' => __('Eritrea', 'invoicing'),
191
-		'EE' => __('Estonia', 'invoicing'),
192
-		'ET' => __('Ethiopia', 'invoicing'),
193
-		'FK' => __('Falkland Islands', 'invoicing'),
194
-		'FO' => __('Faroe Islands', 'invoicing'),
195
-		'FJ' => __('Fiji', 'invoicing'),
196
-		'FI' => __('Finland', 'invoicing'),
197
-		'FR' => __('France', 'invoicing'),
198
-		'GF' => __('French Guiana', 'invoicing'),
199
-		'PF' => __('French Polynesia', 'invoicing'),
200
-		'TF' => __('French Southern Territories', 'invoicing'),
201
-		'GA' => __('Gabon', 'invoicing'),
202
-		'GM' => __('Gambia', 'invoicing'),
203
-		'GE' => __('Georgia', 'invoicing'),
204
-		'DE' => __('Germany', 'invoicing'),
205
-		'GR' => __('Greece', 'invoicing'),
206
-		'GH' => __('Ghana', 'invoicing'),
207
-		'GI' => __('Gibraltar', 'invoicing'),
208
-		'GL' => __('Greenland', 'invoicing'),
209
-		'GD' => __('Grenada', 'invoicing'),
210
-		'GP' => __('Guadeloupe', 'invoicing'),
211
-		'GU' => __('Guam', 'invoicing'),
212
-		'GT' => __('Guatemala', 'invoicing'),
213
-		'GG' => __('Guernsey', 'invoicing'),
214
-		'GN' => __('Guinea', 'invoicing'),
215
-		'GW' => __('Guinea-Bissau', 'invoicing'),
216
-		'GY' => __('Guyana', 'invoicing'),
217
-		'HT' => __('Haiti', 'invoicing'),
218
-		'HM' => __('Heard and McDonald Islands', 'invoicing'),
219
-		'VA' => __('Holy See (City Vatican State)', 'invoicing'),
220
-		'HN' => __('Honduras', 'invoicing'),
221
-		'HK' => __('Hong Kong', 'invoicing'),
222
-		'HU' => __('Hungary', 'invoicing'),
223
-		'IS' => __('Iceland', 'invoicing'),
224
-		'IN' => __('India', 'invoicing'),
225
-		'ID' => __('Indonesia', 'invoicing'),
226
-		'IR' => __('Iran', 'invoicing'),
227
-		'IQ' => __('Iraq', 'invoicing'),
228
-		'IE' => __('Ireland', 'invoicing'),
229
-		'IM' => __('Isle of Man', 'invoicing'),
230
-		'IL' => __('Israel', 'invoicing'),
231
-		'IT' => __('Italy', 'invoicing'),
232
-		'JM' => __('Jamaica', 'invoicing'),
233
-		'JP' => __('Japan', 'invoicing'),
234
-		'JE' => __('Jersey', 'invoicing'),
235
-		'JO' => __('Jordan', 'invoicing'),
236
-		'KZ' => __('Kazakhstan', 'invoicing'),
237
-		'KE' => __('Kenya', 'invoicing'),
238
-		'KI' => __('Kiribati', 'invoicing'),
239
-		'KW' => __('Kuwait', 'invoicing'),
240
-		'KG' => __('Kyrgyzstan', 'invoicing'),
241
-		'LA' => __('Lao People\'s Democratic Republic', 'invoicing'),
242
-		'LV' => __('Latvia', 'invoicing'),
243
-		'LB' => __('Lebanon', 'invoicing'),
244
-		'LS' => __('Lesotho', 'invoicing'),
245
-		'LR' => __('Liberia', 'invoicing'),
246
-		'LY' => __('Libyan Arab Jamahiriya', 'invoicing'),
247
-		'LI' => __('Liechtenstein', 'invoicing'),
248
-		'LT' => __('Lithuania', 'invoicing'),
249
-		'LU' => __('Luxembourg', 'invoicing'),
250
-		'MO' => __('Macau', 'invoicing'),
251
-		'MK' => __('Macedonia', 'invoicing'),
252
-		'MG' => __('Madagascar', 'invoicing'),
253
-		'MW' => __('Malawi', 'invoicing'),
254
-		'MY' => __('Malaysia', 'invoicing'),
255
-		'MV' => __('Maldives', 'invoicing'),
256
-		'ML' => __('Mali', 'invoicing'),
257
-		'MT' => __('Malta', 'invoicing'),
258
-		'MH' => __('Marshall Islands', 'invoicing'),
259
-		'MQ' => __('Martinique', 'invoicing'),
260
-		'MR' => __('Mauritania', 'invoicing'),
261
-		'MU' => __('Mauritius', 'invoicing'),
262
-		'YT' => __('Mayotte', 'invoicing'),
263
-		'MX' => __('Mexico', 'invoicing'),
264
-		'FM' => __('Micronesia', 'invoicing'),
265
-		'MD' => __('Moldova, Republic of', 'invoicing'),
266
-		'MC' => __('Monaco', 'invoicing'),
267
-		'MN' => __('Mongolia', 'invoicing'),
268
-		'ME' => __('Montenegro', 'invoicing'),
269
-		'MS' => __('Montserrat', 'invoicing'),
270
-		'MA' => __('Morocco', 'invoicing'),
271
-		'MZ' => __('Mozambique', 'invoicing'),
272
-		'MM' => __('Myanmar', 'invoicing'),
273
-		'NA' => __('Namibia', 'invoicing'),
274
-		'NR' => __('Nauru', 'invoicing'),
275
-		'NP' => __('Nepal', 'invoicing'),
276
-		'NL' => __('Netherlands', 'invoicing'),
277
-		'AN' => __('Netherlands Antilles', 'invoicing'),
278
-		'NC' => __('New Caledonia', 'invoicing'),
279
-		'NZ' => __('New Zealand', 'invoicing'),
280
-		'NI' => __('Nicaragua', 'invoicing'),
281
-		'NE' => __('Niger', 'invoicing'),
282
-		'NG' => __('Nigeria', 'invoicing'),
283
-		'NU' => __('Niue', 'invoicing'),
284
-		'NF' => __('Norfolk Island', 'invoicing'),
285
-		'KP' => __('North Korea', 'invoicing'),
286
-		'MP' => __('Northern Mariana Islands', 'invoicing'),
287
-		'NO' => __('Norway', 'invoicing'),
288
-		'OM' => __('Oman', 'invoicing'),
289
-		'PK' => __('Pakistan', 'invoicing'),
290
-		'PW' => __('Palau', 'invoicing'),
291
-		'PS' => __('Palestinian Territories', 'invoicing'),
292
-		'PA' => __('Panama', 'invoicing'),
293
-		'PG' => __('Papua New Guinea', 'invoicing'),
294
-		'PY' => __('Paraguay', 'invoicing'),
295
-		'PE' => __('Peru', 'invoicing'),
296
-		'PH' => __('Phillipines', 'invoicing'),
297
-		'PN' => __('Pitcairn Island', 'invoicing'),
298
-		'PL' => __('Poland', 'invoicing'),
299
-		'PT' => __('Portugal', 'invoicing'),
300
-		'PR' => __('Puerto Rico', 'invoicing'),
301
-		'QA' => __('Qatar', 'invoicing'),
302
-		'XK' => __('Republic of Kosovo', 'invoicing'),
303
-		'RE' => __('Reunion Island', 'invoicing'),
304
-		'RO' => __('Romania', 'invoicing'),
305
-		'RU' => __('Russian Federation', 'invoicing'),
306
-		'RW' => __('Rwanda', 'invoicing'),
307
-		'BL' => __('Saint Barth&eacute;lemy', 'invoicing'),
308
-		'SH' => __('Saint Helena', 'invoicing'),
309
-		'KN' => __('Saint Kitts and Nevis', 'invoicing'),
310
-		'LC' => __('Saint Lucia', 'invoicing'),
311
-		'MF' => __('Saint Martin (French)', 'invoicing'),
312
-		'SX' => __('Saint Martin (Dutch)', 'invoicing'),
313
-		'PM' => __('Saint Pierre and Miquelon', 'invoicing'),
314
-		'VC' => __('Saint Vincent and the Grenadines', 'invoicing'),
315
-		'SM' => __('San Marino', 'invoicing'),
316
-		'ST' => __('S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'invoicing'),
317
-		'SA' => __('Saudi Arabia', 'invoicing'),
318
-		'SN' => __('Senegal', 'invoicing'),
319
-		'RS' => __('Serbia', 'invoicing'),
320
-		'SC' => __('Seychelles', 'invoicing'),
321
-		'SL' => __('Sierra Leone', 'invoicing'),
322
-		'SG' => __('Singapore', 'invoicing'),
323
-		'SK' => __('Slovak Republic', 'invoicing'),
324
-		'SI' => __('Slovenia', 'invoicing'),
325
-		'SB' => __('Solomon Islands', 'invoicing'),
326
-		'SO' => __('Somalia', 'invoicing'),
327
-		'ZA' => __('South Africa', 'invoicing'),
328
-		'GS' => __('South Georgia', 'invoicing'),
329
-		'KR' => __('South Korea', 'invoicing'),
330
-		'SS' => __('South Sudan', 'invoicing'),
331
-		'ES' => __('Spain', 'invoicing'),
332
-		'LK' => __('Sri Lanka', 'invoicing'),
333
-		'SD' => __('Sudan', 'invoicing'),
334
-		'SR' => __('Suriname', 'invoicing'),
335
-		'SJ' => __('Svalbard and Jan Mayen Islands', 'invoicing'),
336
-		'SZ' => __('Swaziland', 'invoicing'),
337
-		'SE' => __('Sweden', 'invoicing'),
338
-		'CH' => __('Switzerland', 'invoicing'),
339
-		'SY' => __('Syrian Arab Republic', 'invoicing'),
340
-		'TW' => __('Taiwan', 'invoicing'),
341
-		'TJ' => __('Tajikistan', 'invoicing'),
342
-		'TZ' => __('Tanzania', 'invoicing'),
343
-		'TH' => __('Thailand', 'invoicing'),
344
-		'TL' => __('Timor-Leste', 'invoicing'),
345
-		'TG' => __('Togo', 'invoicing'),
346
-		'TK' => __('Tokelau', 'invoicing'),
347
-		'TO' => __('Tonga', 'invoicing'),
348
-		'TT' => __('Trinidad and Tobago', 'invoicing'),
349
-		'TN' => __('Tunisia', 'invoicing'),
350
-		'TR' => __('Turkey', 'invoicing'),
351
-		'TM' => __('Turkmenistan', 'invoicing'),
352
-		'TC' => __('Turks and Caicos Islands', 'invoicing'),
353
-		'TV' => __('Tuvalu', 'invoicing'),
354
-		'UG' => __('Uganda', 'invoicing'),
355
-		'UA' => __('Ukraine', 'invoicing'),
356
-		'AE' => __('United Arab Emirates', 'invoicing'),
357
-		'UY' => __('Uruguay', 'invoicing'),
358
-		'UM' => __('US Minor Outlying Islands', 'invoicing'),
359
-		'UZ' => __('Uzbekistan', 'invoicing'),
360
-		'VU' => __('Vanuatu', 'invoicing'),
361
-		'VE' => __('Venezuela', 'invoicing'),
362
-		'VN' => __('Vietnam', 'invoicing'),
363
-		'VG' => __('Virgin Islands (British)', 'invoicing'),
364
-		'VI' => __('Virgin Islands (USA)', 'invoicing'),
365
-		'WF' => __('Wallis and Futuna Islands', 'invoicing'),
366
-		'EH' => __('Western Sahara', 'invoicing'),
367
-		'WS' => __('Western Samoa', 'invoicing'),
368
-		'YE' => __('Yemen', 'invoicing'),
369
-		'ZM' => __('Zambia', 'invoicing'),
370
-		'ZW' => __('Zimbabwe', 'invoicing'),
371
-	);
118
+    $countries = array(
119
+        'US' => __('United States', 'invoicing'),
120
+        'CA' => __('Canada', 'invoicing'),
121
+        'GB' => __('United Kingdom', 'invoicing'),
122
+        'AF' => __('Afghanistan', 'invoicing'),
123
+        'AX' => __('Aland Islands', 'invoicing'),
124
+        'AL' => __('Albania', 'invoicing'),
125
+        'DZ' => __('Algeria', 'invoicing'),
126
+        'AS' => __('American Samoa', 'invoicing'),
127
+        'AD' => __('Andorra', 'invoicing'),
128
+        'AO' => __('Angola', 'invoicing'),
129
+        'AI' => __('Anguilla', 'invoicing'),
130
+        'AQ' => __('Antarctica', 'invoicing'),
131
+        'AG' => __('Antigua and Barbuda', 'invoicing'),
132
+        'AR' => __('Argentina', 'invoicing'),
133
+        'AM' => __('Armenia', 'invoicing'),
134
+        'AW' => __('Aruba', 'invoicing'),
135
+        'AU' => __('Australia', 'invoicing'),
136
+        'AT' => __('Austria', 'invoicing'),
137
+        'AZ' => __('Azerbaijan', 'invoicing'),
138
+        'BS' => __('Bahamas', 'invoicing'),
139
+        'BH' => __('Bahrain', 'invoicing'),
140
+        'BD' => __('Bangladesh', 'invoicing'),
141
+        'BB' => __('Barbados', 'invoicing'),
142
+        'BY' => __('Belarus', 'invoicing'),
143
+        'BE' => __('Belgium', 'invoicing'),
144
+        'BZ' => __('Belize', 'invoicing'),
145
+        'BJ' => __('Benin', 'invoicing'),
146
+        'BM' => __('Bermuda', 'invoicing'),
147
+        'BT' => __('Bhutan', 'invoicing'),
148
+        'BO' => __('Bolivia', 'invoicing'),
149
+        'BQ' => __('Bonaire, Saint Eustatius and Saba', 'invoicing'),
150
+        'BA' => __('Bosnia and Herzegovina', 'invoicing'),
151
+        'BW' => __('Botswana', 'invoicing'),
152
+        'BV' => __('Bouvet Island', 'invoicing'),
153
+        'BR' => __('Brazil', 'invoicing'),
154
+        'IO' => __('British Indian Ocean Territory', 'invoicing'),
155
+        'BN' => __('Brunei Darrussalam', 'invoicing'),
156
+        'BG' => __('Bulgaria', 'invoicing'),
157
+        'BF' => __('Burkina Faso', 'invoicing'),
158
+        'BI' => __('Burundi', 'invoicing'),
159
+        'KH' => __('Cambodia', 'invoicing'),
160
+        'CM' => __('Cameroon', 'invoicing'),
161
+        'CV' => __('Cape Verde', 'invoicing'),
162
+        'KY' => __('Cayman Islands', 'invoicing'),
163
+        'CF' => __('Central African Republic', 'invoicing'),
164
+        'TD' => __('Chad', 'invoicing'),
165
+        'CL' => __('Chile', 'invoicing'),
166
+        'CN' => __('China', 'invoicing'),
167
+        'CX' => __('Christmas Island', 'invoicing'),
168
+        'CC' => __('Cocos Islands', 'invoicing'),
169
+        'CO' => __('Colombia', 'invoicing'),
170
+        'KM' => __('Comoros', 'invoicing'),
171
+        'CD' => __('Congo, Democratic People\'s Republic', 'invoicing'),
172
+        'CG' => __('Congo, Republic of', 'invoicing'),
173
+        'CK' => __('Cook Islands', 'invoicing'),
174
+        'CR' => __('Costa Rica', 'invoicing'),
175
+        'CI' => __('Cote d\'Ivoire', 'invoicing'),
176
+        'HR' => __('Croatia/Hrvatska', 'invoicing'),
177
+        'CU' => __('Cuba', 'invoicing'),
178
+        'CW' => __('Cura&Ccedil;ao', 'invoicing'),
179
+        'CY' => __('Cyprus', 'invoicing'),
180
+        'CZ' => __('Czech Republic', 'invoicing'),
181
+        'DK' => __('Denmark', 'invoicing'),
182
+        'DJ' => __('Djibouti', 'invoicing'),
183
+        'DM' => __('Dominica', 'invoicing'),
184
+        'DO' => __('Dominican Republic', 'invoicing'),
185
+        'TP' => __('East Timor', 'invoicing'),
186
+        'EC' => __('Ecuador', 'invoicing'),
187
+        'EG' => __('Egypt', 'invoicing'),
188
+        'GQ' => __('Equatorial Guinea', 'invoicing'),
189
+        'SV' => __('El Salvador', 'invoicing'),
190
+        'ER' => __('Eritrea', 'invoicing'),
191
+        'EE' => __('Estonia', 'invoicing'),
192
+        'ET' => __('Ethiopia', 'invoicing'),
193
+        'FK' => __('Falkland Islands', 'invoicing'),
194
+        'FO' => __('Faroe Islands', 'invoicing'),
195
+        'FJ' => __('Fiji', 'invoicing'),
196
+        'FI' => __('Finland', 'invoicing'),
197
+        'FR' => __('France', 'invoicing'),
198
+        'GF' => __('French Guiana', 'invoicing'),
199
+        'PF' => __('French Polynesia', 'invoicing'),
200
+        'TF' => __('French Southern Territories', 'invoicing'),
201
+        'GA' => __('Gabon', 'invoicing'),
202
+        'GM' => __('Gambia', 'invoicing'),
203
+        'GE' => __('Georgia', 'invoicing'),
204
+        'DE' => __('Germany', 'invoicing'),
205
+        'GR' => __('Greece', 'invoicing'),
206
+        'GH' => __('Ghana', 'invoicing'),
207
+        'GI' => __('Gibraltar', 'invoicing'),
208
+        'GL' => __('Greenland', 'invoicing'),
209
+        'GD' => __('Grenada', 'invoicing'),
210
+        'GP' => __('Guadeloupe', 'invoicing'),
211
+        'GU' => __('Guam', 'invoicing'),
212
+        'GT' => __('Guatemala', 'invoicing'),
213
+        'GG' => __('Guernsey', 'invoicing'),
214
+        'GN' => __('Guinea', 'invoicing'),
215
+        'GW' => __('Guinea-Bissau', 'invoicing'),
216
+        'GY' => __('Guyana', 'invoicing'),
217
+        'HT' => __('Haiti', 'invoicing'),
218
+        'HM' => __('Heard and McDonald Islands', 'invoicing'),
219
+        'VA' => __('Holy See (City Vatican State)', 'invoicing'),
220
+        'HN' => __('Honduras', 'invoicing'),
221
+        'HK' => __('Hong Kong', 'invoicing'),
222
+        'HU' => __('Hungary', 'invoicing'),
223
+        'IS' => __('Iceland', 'invoicing'),
224
+        'IN' => __('India', 'invoicing'),
225
+        'ID' => __('Indonesia', 'invoicing'),
226
+        'IR' => __('Iran', 'invoicing'),
227
+        'IQ' => __('Iraq', 'invoicing'),
228
+        'IE' => __('Ireland', 'invoicing'),
229
+        'IM' => __('Isle of Man', 'invoicing'),
230
+        'IL' => __('Israel', 'invoicing'),
231
+        'IT' => __('Italy', 'invoicing'),
232
+        'JM' => __('Jamaica', 'invoicing'),
233
+        'JP' => __('Japan', 'invoicing'),
234
+        'JE' => __('Jersey', 'invoicing'),
235
+        'JO' => __('Jordan', 'invoicing'),
236
+        'KZ' => __('Kazakhstan', 'invoicing'),
237
+        'KE' => __('Kenya', 'invoicing'),
238
+        'KI' => __('Kiribati', 'invoicing'),
239
+        'KW' => __('Kuwait', 'invoicing'),
240
+        'KG' => __('Kyrgyzstan', 'invoicing'),
241
+        'LA' => __('Lao People\'s Democratic Republic', 'invoicing'),
242
+        'LV' => __('Latvia', 'invoicing'),
243
+        'LB' => __('Lebanon', 'invoicing'),
244
+        'LS' => __('Lesotho', 'invoicing'),
245
+        'LR' => __('Liberia', 'invoicing'),
246
+        'LY' => __('Libyan Arab Jamahiriya', 'invoicing'),
247
+        'LI' => __('Liechtenstein', 'invoicing'),
248
+        'LT' => __('Lithuania', 'invoicing'),
249
+        'LU' => __('Luxembourg', 'invoicing'),
250
+        'MO' => __('Macau', 'invoicing'),
251
+        'MK' => __('Macedonia', 'invoicing'),
252
+        'MG' => __('Madagascar', 'invoicing'),
253
+        'MW' => __('Malawi', 'invoicing'),
254
+        'MY' => __('Malaysia', 'invoicing'),
255
+        'MV' => __('Maldives', 'invoicing'),
256
+        'ML' => __('Mali', 'invoicing'),
257
+        'MT' => __('Malta', 'invoicing'),
258
+        'MH' => __('Marshall Islands', 'invoicing'),
259
+        'MQ' => __('Martinique', 'invoicing'),
260
+        'MR' => __('Mauritania', 'invoicing'),
261
+        'MU' => __('Mauritius', 'invoicing'),
262
+        'YT' => __('Mayotte', 'invoicing'),
263
+        'MX' => __('Mexico', 'invoicing'),
264
+        'FM' => __('Micronesia', 'invoicing'),
265
+        'MD' => __('Moldova, Republic of', 'invoicing'),
266
+        'MC' => __('Monaco', 'invoicing'),
267
+        'MN' => __('Mongolia', 'invoicing'),
268
+        'ME' => __('Montenegro', 'invoicing'),
269
+        'MS' => __('Montserrat', 'invoicing'),
270
+        'MA' => __('Morocco', 'invoicing'),
271
+        'MZ' => __('Mozambique', 'invoicing'),
272
+        'MM' => __('Myanmar', 'invoicing'),
273
+        'NA' => __('Namibia', 'invoicing'),
274
+        'NR' => __('Nauru', 'invoicing'),
275
+        'NP' => __('Nepal', 'invoicing'),
276
+        'NL' => __('Netherlands', 'invoicing'),
277
+        'AN' => __('Netherlands Antilles', 'invoicing'),
278
+        'NC' => __('New Caledonia', 'invoicing'),
279
+        'NZ' => __('New Zealand', 'invoicing'),
280
+        'NI' => __('Nicaragua', 'invoicing'),
281
+        'NE' => __('Niger', 'invoicing'),
282
+        'NG' => __('Nigeria', 'invoicing'),
283
+        'NU' => __('Niue', 'invoicing'),
284
+        'NF' => __('Norfolk Island', 'invoicing'),
285
+        'KP' => __('North Korea', 'invoicing'),
286
+        'MP' => __('Northern Mariana Islands', 'invoicing'),
287
+        'NO' => __('Norway', 'invoicing'),
288
+        'OM' => __('Oman', 'invoicing'),
289
+        'PK' => __('Pakistan', 'invoicing'),
290
+        'PW' => __('Palau', 'invoicing'),
291
+        'PS' => __('Palestinian Territories', 'invoicing'),
292
+        'PA' => __('Panama', 'invoicing'),
293
+        'PG' => __('Papua New Guinea', 'invoicing'),
294
+        'PY' => __('Paraguay', 'invoicing'),
295
+        'PE' => __('Peru', 'invoicing'),
296
+        'PH' => __('Phillipines', 'invoicing'),
297
+        'PN' => __('Pitcairn Island', 'invoicing'),
298
+        'PL' => __('Poland', 'invoicing'),
299
+        'PT' => __('Portugal', 'invoicing'),
300
+        'PR' => __('Puerto Rico', 'invoicing'),
301
+        'QA' => __('Qatar', 'invoicing'),
302
+        'XK' => __('Republic of Kosovo', 'invoicing'),
303
+        'RE' => __('Reunion Island', 'invoicing'),
304
+        'RO' => __('Romania', 'invoicing'),
305
+        'RU' => __('Russian Federation', 'invoicing'),
306
+        'RW' => __('Rwanda', 'invoicing'),
307
+        'BL' => __('Saint Barth&eacute;lemy', 'invoicing'),
308
+        'SH' => __('Saint Helena', 'invoicing'),
309
+        'KN' => __('Saint Kitts and Nevis', 'invoicing'),
310
+        'LC' => __('Saint Lucia', 'invoicing'),
311
+        'MF' => __('Saint Martin (French)', 'invoicing'),
312
+        'SX' => __('Saint Martin (Dutch)', 'invoicing'),
313
+        'PM' => __('Saint Pierre and Miquelon', 'invoicing'),
314
+        'VC' => __('Saint Vincent and the Grenadines', 'invoicing'),
315
+        'SM' => __('San Marino', 'invoicing'),
316
+        'ST' => __('S&atilde;o Tom&eacute; and Pr&iacute;ncipe', 'invoicing'),
317
+        'SA' => __('Saudi Arabia', 'invoicing'),
318
+        'SN' => __('Senegal', 'invoicing'),
319
+        'RS' => __('Serbia', 'invoicing'),
320
+        'SC' => __('Seychelles', 'invoicing'),
321
+        'SL' => __('Sierra Leone', 'invoicing'),
322
+        'SG' => __('Singapore', 'invoicing'),
323
+        'SK' => __('Slovak Republic', 'invoicing'),
324
+        'SI' => __('Slovenia', 'invoicing'),
325
+        'SB' => __('Solomon Islands', 'invoicing'),
326
+        'SO' => __('Somalia', 'invoicing'),
327
+        'ZA' => __('South Africa', 'invoicing'),
328
+        'GS' => __('South Georgia', 'invoicing'),
329
+        'KR' => __('South Korea', 'invoicing'),
330
+        'SS' => __('South Sudan', 'invoicing'),
331
+        'ES' => __('Spain', 'invoicing'),
332
+        'LK' => __('Sri Lanka', 'invoicing'),
333
+        'SD' => __('Sudan', 'invoicing'),
334
+        'SR' => __('Suriname', 'invoicing'),
335
+        'SJ' => __('Svalbard and Jan Mayen Islands', 'invoicing'),
336
+        'SZ' => __('Swaziland', 'invoicing'),
337
+        'SE' => __('Sweden', 'invoicing'),
338
+        'CH' => __('Switzerland', 'invoicing'),
339
+        'SY' => __('Syrian Arab Republic', 'invoicing'),
340
+        'TW' => __('Taiwan', 'invoicing'),
341
+        'TJ' => __('Tajikistan', 'invoicing'),
342
+        'TZ' => __('Tanzania', 'invoicing'),
343
+        'TH' => __('Thailand', 'invoicing'),
344
+        'TL' => __('Timor-Leste', 'invoicing'),
345
+        'TG' => __('Togo', 'invoicing'),
346
+        'TK' => __('Tokelau', 'invoicing'),
347
+        'TO' => __('Tonga', 'invoicing'),
348
+        'TT' => __('Trinidad and Tobago', 'invoicing'),
349
+        'TN' => __('Tunisia', 'invoicing'),
350
+        'TR' => __('Turkey', 'invoicing'),
351
+        'TM' => __('Turkmenistan', 'invoicing'),
352
+        'TC' => __('Turks and Caicos Islands', 'invoicing'),
353
+        'TV' => __('Tuvalu', 'invoicing'),
354
+        'UG' => __('Uganda', 'invoicing'),
355
+        'UA' => __('Ukraine', 'invoicing'),
356
+        'AE' => __('United Arab Emirates', 'invoicing'),
357
+        'UY' => __('Uruguay', 'invoicing'),
358
+        'UM' => __('US Minor Outlying Islands', 'invoicing'),
359
+        'UZ' => __('Uzbekistan', 'invoicing'),
360
+        'VU' => __('Vanuatu', 'invoicing'),
361
+        'VE' => __('Venezuela', 'invoicing'),
362
+        'VN' => __('Vietnam', 'invoicing'),
363
+        'VG' => __('Virgin Islands (British)', 'invoicing'),
364
+        'VI' => __('Virgin Islands (USA)', 'invoicing'),
365
+        'WF' => __('Wallis and Futuna Islands', 'invoicing'),
366
+        'EH' => __('Western Sahara', 'invoicing'),
367
+        'WS' => __('Western Samoa', 'invoicing'),
368
+        'YE' => __('Yemen', 'invoicing'),
369
+        'ZM' => __('Zambia', 'invoicing'),
370
+        'ZW' => __('Zimbabwe', 'invoicing'),
371
+    );
372 372
     
373 373
     if ( $first_empty ) {
374 374
         $countries = array_merge( array( '' => '' ), $countries );
@@ -1537,30 +1537,30 @@  discard block
 block discarded – undo
1537 1537
 }
1538 1538
 
1539 1539
 function wpinv_get_states_field() {
1540
-	if( empty( $_POST['country'] ) ) {
1541
-		$_POST['country'] = wpinv_get_default_country();
1542
-	}
1543
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
1540
+    if( empty( $_POST['country'] ) ) {
1541
+        $_POST['country'] = wpinv_get_default_country();
1542
+    }
1543
+    $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
1544 1544
 
1545
-	if( !empty( $states ) ) {
1546
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
1545
+    if( !empty( $states ) ) {
1546
+        $sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
1547 1547
         
1548 1548
         $args = array(
1549
-			'name'    => $sanitized_field_name,
1550
-			'id'      => $sanitized_field_name,
1551
-			'class'   => $sanitized_field_name . ' wpinv-select wpi_select2',
1552
-			'options' => array_merge( array( '' => '' ), $states ),
1553
-			'show_option_all'  => false,
1554
-			'show_option_none' => false
1555
-		);
1556
-
1557
-		$response = wpinv_html_select( $args );
1558
-
1559
-	} else {
1560
-		$response = 'nostates';
1561
-	}
1549
+            'name'    => $sanitized_field_name,
1550
+            'id'      => $sanitized_field_name,
1551
+            'class'   => $sanitized_field_name . ' wpinv-select wpi_select2',
1552
+            'options' => array_merge( array( '' => '' ), $states ),
1553
+            'show_option_all'  => false,
1554
+            'show_option_none' => false
1555
+        );
1556
+
1557
+        $response = wpinv_html_select( $args );
1558
+
1559
+    } else {
1560
+        $response = 'nostates';
1561
+    }
1562 1562
 
1563
-	return $response;
1563
+    return $response;
1564 1564
 }
1565 1565
 
1566 1566
 function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
Please login to merge, or discard this patch.
Spacing   +979 added lines, -979 removed lines patch added patch discarded remove patch
@@ -7,67 +7,67 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21
-function wpinv_is_base_country( $country ) {
21
+function wpinv_is_base_country($country) {
22 22
     $base_country = wpinv_get_default_country();
23 23
     
24
-    if ( $base_country === 'UK' ) {
24
+    if ($base_country === 'UK') {
25 25
         $base_country = 'GB';
26 26
     }
27
-    if ( $country == 'UK' ) {
27
+    if ($country == 'UK') {
28 28
         $country = 'GB';
29 29
     }
30 30
 
31
-    return ( $country && $country === $base_country ) ? true : false;
31
+    return ($country && $country === $base_country) ? true : false;
32 32
 }
33 33
 
34
-function wpinv_country_name( $country_code = '' ) { 
34
+function wpinv_country_name($country_code = '') { 
35 35
     $countries = wpinv_get_country_list();
36 36
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
37
-    $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code;
37
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
38 38
 
39
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
39
+    return apply_filters('wpinv_country_name', $country, $country_code);
40 40
 }
41 41
 
42 42
 function wpinv_get_default_state() {
43
-	$state = wpinv_get_option( 'default_state', false );
43
+	$state = wpinv_get_option('default_state', false);
44 44
 
45
-	return apply_filters( 'wpinv_default_state', $state );
45
+	return apply_filters('wpinv_default_state', $state);
46 46
 }
47 47
 
48
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
48
+function wpinv_state_name($state_code = '', $country_code = '') {
49 49
     $state = $state_code;
50 50
     
51
-    if ( !empty( $country_code ) ) {
52
-        $states = wpinv_get_country_states( $country_code );
51
+    if (!empty($country_code)) {
52
+        $states = wpinv_get_country_states($country_code);
53 53
         
54
-        $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state;
54
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
55 55
     }
56 56
 
57
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
57
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
58 58
 }
59 59
 
60 60
 function wpinv_store_address() {
61
-    $address = wpinv_get_option( 'store_address', '' );
61
+    $address = wpinv_get_option('store_address', '');
62 62
 
63
-    return apply_filters( 'wpinv_store_address', $address );
63
+    return apply_filters('wpinv_store_address', $address);
64 64
 }
65 65
 
66
-function wpinv_get_user_address( $user_id = 0, $with_default = true ) {
66
+function wpinv_get_user_address($user_id = 0, $with_default = true) {
67 67
     global $wpi_userID;
68 68
     
69
-    if( empty( $user_id ) ) {
70
-        $user_id = !empty( $wpi_userID ) ? $wpi_userID : get_current_user_id();
69
+    if (empty($user_id)) {
70
+        $user_id = !empty($wpi_userID) ? $wpi_userID : get_current_user_id();
71 71
     }
72 72
     
73 73
     $address_fields = array(
@@ -85,36 +85,36 @@  discard block
 block discarded – undo
85 85
         'zip',
86 86
     );
87 87
     
88
-    $user_info = get_userdata( $user_id );
88
+    $user_info = get_userdata($user_id);
89 89
     
90 90
     $address = array();
91 91
     $address['user_id'] = $user_id;
92
-    $address['email'] = !empty( $user_info ) ? $user_info->user_email : '';
93
-    foreach ( $address_fields as $field ) {
94
-        $address[$field] = get_user_meta( $user_id, '_wpinv_' . $field, true );
92
+    $address['email'] = !empty($user_info) ? $user_info->user_email : '';
93
+    foreach ($address_fields as $field) {
94
+        $address[$field] = get_user_meta($user_id, '_wpinv_' . $field, true);
95 95
     }
96 96
 
97
-    if ( !empty( $user_info ) ) {
98
-        if( empty( $address['first_name'] ) )
97
+    if (!empty($user_info)) {
98
+        if (empty($address['first_name']))
99 99
             $address['first_name'] = $user_info->first_name;
100 100
         
101
-        if( empty( $address['last_name'] ) )
101
+        if (empty($address['last_name']))
102 102
             $address['last_name'] = $user_info->last_name;
103 103
     }
104 104
     
105
-    $address['name'] = trim( trim( $address['first_name'] . ' ' . $address['last_name'] ), "," );
105
+    $address['name'] = trim(trim($address['first_name'] . ' ' . $address['last_name']), ",");
106 106
     
107
-    if( empty( $address['state'] ) && $with_default )
107
+    if (empty($address['state']) && $with_default)
108 108
         $address['state'] = wpinv_get_default_state();
109 109
 
110
-    if( empty( $address['country'] ) && $with_default )
110
+    if (empty($address['country']) && $with_default)
111 111
         $address['country'] = wpinv_get_default_country();
112 112
 
113 113
 
114 114
     return $address;
115 115
 }
116 116
 
117
-function wpinv_get_country_list( $first_empty = false ) {
117
+function wpinv_get_country_list($first_empty = false) {
118 118
 	$countries = array(
119 119
 		'US' => __('United States', 'invoicing'),
120 120
 		'CA' => __('Canada', 'invoicing'),
@@ -370,23 +370,23 @@  discard block
 block discarded – undo
370 370
 		'ZW' => __('Zimbabwe', 'invoicing'),
371 371
 	);
372 372
     
373
-    if ( $first_empty ) {
374
-        $countries = array_merge( array( '' => '' ), $countries );
373
+    if ($first_empty) {
374
+        $countries = array_merge(array('' => ''), $countries);
375 375
     }
376 376
     
377
-    $countries = apply_filters( 'wpinv_countries', $countries );
377
+    $countries = apply_filters('wpinv_countries', $countries);
378 378
     
379 379
     asort($countries);
380 380
 
381 381
     return $countries;
382 382
 }
383 383
 
384
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
385
-    if ( empty( $country ) ) {
384
+function wpinv_get_country_states($country = null, $first_empty = false) {
385
+    if (empty($country)) {
386 386
         $country = wpinv_get_default_country();
387 387
     }
388 388
 
389
-    switch( $country ) {
389
+    switch ($country) {
390 390
         case 'US' :
391 391
             $states = wpinv_get_us_states_list();
392 392
             break;
@@ -461,11 +461,11 @@  discard block
 block discarded – undo
461 461
             break;
462 462
     }
463 463
     
464
-    if ( !empty( $states ) && $first_empty ) {
465
-        $states = array_merge( array( '' => '' ), $states );
464
+    if (!empty($states) && $first_empty) {
465
+        $states = array_merge(array('' => ''), $states);
466 466
     }
467 467
     
468
-    $states = apply_filters( 'wpinv_country_states', $states, $country );
468
+    $states = apply_filters('wpinv_country_states', $states, $country);
469 469
     
470 470
     asort($states);
471 471
 
@@ -474,1087 +474,1087 @@  discard block
 block discarded – undo
474 474
 
475 475
 function wpinv_get_us_states_list() {
476 476
     $states = array(
477
-        'AL' => __( 'Alabama', 'invoicing' ),
478
-        'AK' => __( 'Alaska', 'invoicing' ),
479
-        'AZ' => __( 'Arizona', 'invoicing' ),
480
-        'AR' => __( 'Arkansas', 'invoicing' ),
481
-        'CA' => __( 'California', 'invoicing' ),
482
-        'CO' => __( 'Colorado', 'invoicing' ),
483
-        'CT' => __( 'Connecticut', 'invoicing' ),
484
-        'DE' => __( 'Delaware', 'invoicing' ),
485
-        'DC' => __( 'District of Columbia', 'invoicing' ),
486
-        'FL' => __( 'Florida', 'invoicing' ),
487
-        'GA' => __( 'Georgia', 'invoicing' ),
488
-        'HI' => __( 'Hawaii', 'invoicing' ),
489
-        'ID' => __( 'Idaho', 'invoicing' ),
490
-        'IL' => __( 'Illinois', 'invoicing' ),
491
-        'IN' => __( 'Indiana', 'invoicing' ),
492
-        'IA' => __( 'Iowa', 'invoicing' ),
493
-        'KS' => __( 'Kansas', 'invoicing' ),
494
-        'KY' => __( 'Kentucky', 'invoicing' ),
495
-        'LA' => __( 'Louisiana', 'invoicing' ),
496
-        'ME' => __( 'Maine', 'invoicing' ),
497
-        'MD' => __( 'Maryland', 'invoicing' ),
498
-        'MA' => __( 'Massachusetts', 'invoicing' ),
499
-        'MI' => __( 'Michigan', 'invoicing' ),
500
-        'MN' => __( 'Minnesota', 'invoicing' ),
501
-        'MS' => __( 'Mississippi', 'invoicing' ),
502
-        'MO' => __( 'Missouri', 'invoicing' ),
503
-        'MT' => __( 'Montana', 'invoicing' ),
504
-        'NE' => __( 'Nebraska', 'invoicing' ),
505
-        'NV' => __( 'Nevada', 'invoicing' ),
506
-        'NH' => __( 'New Hampshire', 'invoicing' ),
507
-        'NJ' => __( 'New Jersey', 'invoicing' ),
508
-        'NM' => __( 'New Mexico', 'invoicing' ),
509
-        'NY' => __( 'New York', 'invoicing' ),
510
-        'NC' => __( 'North Carolina', 'invoicing' ),
511
-        'ND' => __( 'North Dakota', 'invoicing' ),
512
-        'OH' => __( 'Ohio', 'invoicing' ),
513
-        'OK' => __( 'Oklahoma', 'invoicing' ),
514
-        'OR' => __( 'Oregon', 'invoicing' ),
515
-        'PA' => __( 'Pennsylvania', 'invoicing' ),
516
-        'RI' => __( 'Rhode Island', 'invoicing' ),
517
-        'SC' => __( 'South Carolina', 'invoicing' ),
518
-        'SD' => __( 'South Dakota', 'invoicing' ),
519
-        'TN' => __( 'Tennessee', 'invoicing' ),
520
-        'TX' => __( 'Texas', 'invoicing' ),
521
-        'UT' => __( 'Utah', 'invoicing' ),
522
-        'VT' => __( 'Vermont', 'invoicing' ),
523
-        'VA' => __( 'Virginia', 'invoicing' ),
524
-        'WA' => __( 'Washington', 'invoicing' ),
525
-        'WV' => __( 'West Virginia', 'invoicing' ),
526
-        'WI' => __( 'Wisconsin', 'invoicing' ),
527
-        'WY' => __( 'Wyoming', 'invoicing' ),
528
-        'AS' => __( 'American Samoa', 'invoicing' ),
529
-        'CZ' => __( 'Canal Zone', 'invoicing' ),
530
-        'CM' => __( 'Commonwealth of the Northern Mariana Islands', 'invoicing' ),
531
-        'FM' => __( 'Federated States of Micronesia', 'invoicing' ),
532
-        'GU' => __( 'Guam', 'invoicing' ),
533
-        'MH' => __( 'Marshall Islands', 'invoicing' ),
534
-        'MP' => __( 'Northern Mariana Islands', 'invoicing' ),
535
-        'PW' => __( 'Palau', 'invoicing' ),
536
-        'PI' => __( 'Philippine Islands', 'invoicing' ),
537
-        'PR' => __( 'Puerto Rico', 'invoicing' ),
538
-        'TT' => __( 'Trust Territory of the Pacific Islands', 'invoicing' ),
539
-        'VI' => __( 'Virgin Islands', 'invoicing' ),
540
-        'AA' => __( 'Armed Forces - Americas', 'invoicing' ),
541
-        'AE' => __( 'Armed Forces - Europe, Canada, Middle East, Africa', 'invoicing' ),
542
-        'AP' => __( 'Armed Forces - Pacific', 'invoicing' )
477
+        'AL' => __('Alabama', 'invoicing'),
478
+        'AK' => __('Alaska', 'invoicing'),
479
+        'AZ' => __('Arizona', 'invoicing'),
480
+        'AR' => __('Arkansas', 'invoicing'),
481
+        'CA' => __('California', 'invoicing'),
482
+        'CO' => __('Colorado', 'invoicing'),
483
+        'CT' => __('Connecticut', 'invoicing'),
484
+        'DE' => __('Delaware', 'invoicing'),
485
+        'DC' => __('District of Columbia', 'invoicing'),
486
+        'FL' => __('Florida', 'invoicing'),
487
+        'GA' => __('Georgia', 'invoicing'),
488
+        'HI' => __('Hawaii', 'invoicing'),
489
+        'ID' => __('Idaho', 'invoicing'),
490
+        'IL' => __('Illinois', 'invoicing'),
491
+        'IN' => __('Indiana', 'invoicing'),
492
+        'IA' => __('Iowa', 'invoicing'),
493
+        'KS' => __('Kansas', 'invoicing'),
494
+        'KY' => __('Kentucky', 'invoicing'),
495
+        'LA' => __('Louisiana', 'invoicing'),
496
+        'ME' => __('Maine', 'invoicing'),
497
+        'MD' => __('Maryland', 'invoicing'),
498
+        'MA' => __('Massachusetts', 'invoicing'),
499
+        'MI' => __('Michigan', 'invoicing'),
500
+        'MN' => __('Minnesota', 'invoicing'),
501
+        'MS' => __('Mississippi', 'invoicing'),
502
+        'MO' => __('Missouri', 'invoicing'),
503
+        'MT' => __('Montana', 'invoicing'),
504
+        'NE' => __('Nebraska', 'invoicing'),
505
+        'NV' => __('Nevada', 'invoicing'),
506
+        'NH' => __('New Hampshire', 'invoicing'),
507
+        'NJ' => __('New Jersey', 'invoicing'),
508
+        'NM' => __('New Mexico', 'invoicing'),
509
+        'NY' => __('New York', 'invoicing'),
510
+        'NC' => __('North Carolina', 'invoicing'),
511
+        'ND' => __('North Dakota', 'invoicing'),
512
+        'OH' => __('Ohio', 'invoicing'),
513
+        'OK' => __('Oklahoma', 'invoicing'),
514
+        'OR' => __('Oregon', 'invoicing'),
515
+        'PA' => __('Pennsylvania', 'invoicing'),
516
+        'RI' => __('Rhode Island', 'invoicing'),
517
+        'SC' => __('South Carolina', 'invoicing'),
518
+        'SD' => __('South Dakota', 'invoicing'),
519
+        'TN' => __('Tennessee', 'invoicing'),
520
+        'TX' => __('Texas', 'invoicing'),
521
+        'UT' => __('Utah', 'invoicing'),
522
+        'VT' => __('Vermont', 'invoicing'),
523
+        'VA' => __('Virginia', 'invoicing'),
524
+        'WA' => __('Washington', 'invoicing'),
525
+        'WV' => __('West Virginia', 'invoicing'),
526
+        'WI' => __('Wisconsin', 'invoicing'),
527
+        'WY' => __('Wyoming', 'invoicing'),
528
+        'AS' => __('American Samoa', 'invoicing'),
529
+        'CZ' => __('Canal Zone', 'invoicing'),
530
+        'CM' => __('Commonwealth of the Northern Mariana Islands', 'invoicing'),
531
+        'FM' => __('Federated States of Micronesia', 'invoicing'),
532
+        'GU' => __('Guam', 'invoicing'),
533
+        'MH' => __('Marshall Islands', 'invoicing'),
534
+        'MP' => __('Northern Mariana Islands', 'invoicing'),
535
+        'PW' => __('Palau', 'invoicing'),
536
+        'PI' => __('Philippine Islands', 'invoicing'),
537
+        'PR' => __('Puerto Rico', 'invoicing'),
538
+        'TT' => __('Trust Territory of the Pacific Islands', 'invoicing'),
539
+        'VI' => __('Virgin Islands', 'invoicing'),
540
+        'AA' => __('Armed Forces - Americas', 'invoicing'),
541
+        'AE' => __('Armed Forces - Europe, Canada, Middle East, Africa', 'invoicing'),
542
+        'AP' => __('Armed Forces - Pacific', 'invoicing')
543 543
     );
544 544
 
545
-    return apply_filters( 'wpinv_us_states', $states );
545
+    return apply_filters('wpinv_us_states', $states);
546 546
 }
547 547
 
548 548
 function wpinv_get_canada_states_list() {
549 549
     $states = array(
550
-        'AB' => __( 'Alberta', 'invoicing' ),
551
-        'BC' => __( 'British Columbia', 'invoicing' ),
552
-        'MB' => __( 'Manitoba', 'invoicing' ),
553
-        'NB' => __( 'New Brunswick', 'invoicing' ),
554
-        'NL' => __( 'Newfoundland and Labrador', 'invoicing' ),
555
-        'NS' => __( 'Nova Scotia', 'invoicing' ),
556
-        'NT' => __( 'Northwest Territories', 'invoicing' ),
557
-        'NU' => __( 'Nunavut', 'invoicing' ),
558
-        'ON' => __( 'Ontario', 'invoicing' ),
559
-        'PE' => __( 'Prince Edward Island', 'invoicing' ),
560
-        'QC' => __( 'Quebec', 'invoicing' ),
561
-        'SK' => __( 'Saskatchewan', 'invoicing' ),
562
-        'YT' => __( 'Yukon', 'invoicing' )
550
+        'AB' => __('Alberta', 'invoicing'),
551
+        'BC' => __('British Columbia', 'invoicing'),
552
+        'MB' => __('Manitoba', 'invoicing'),
553
+        'NB' => __('New Brunswick', 'invoicing'),
554
+        'NL' => __('Newfoundland and Labrador', 'invoicing'),
555
+        'NS' => __('Nova Scotia', 'invoicing'),
556
+        'NT' => __('Northwest Territories', 'invoicing'),
557
+        'NU' => __('Nunavut', 'invoicing'),
558
+        'ON' => __('Ontario', 'invoicing'),
559
+        'PE' => __('Prince Edward Island', 'invoicing'),
560
+        'QC' => __('Quebec', 'invoicing'),
561
+        'SK' => __('Saskatchewan', 'invoicing'),
562
+        'YT' => __('Yukon', 'invoicing')
563 563
     );
564 564
 
565
-    return apply_filters( 'wpinv_canada_provinces', $states );
565
+    return apply_filters('wpinv_canada_provinces', $states);
566 566
 }
567 567
 
568 568
 function wpinv_get_australia_states_list() {
569 569
     $states = array(
570
-        'ACT' => __( 'Australian Capital Territory', 'invoicing' ),
571
-        'NSW' => __( 'New South Wales', 'invoicing' ),
572
-        'NT'  => __( 'Northern Territory', 'invoicing' ),
573
-        'QLD' => __( 'Queensland', 'invoicing' ),
574
-        'SA'  => __( 'South Australia', 'invoicing' ),
575
-        'TAS' => __( 'Tasmania', 'invoicing' ),
576
-        'VIC' => __( 'Victoria', 'invoicing' ),
577
-        'WA'  => __( 'Western Australia', 'invoicing' )
570
+        'ACT' => __('Australian Capital Territory', 'invoicing'),
571
+        'NSW' => __('New South Wales', 'invoicing'),
572
+        'NT'  => __('Northern Territory', 'invoicing'),
573
+        'QLD' => __('Queensland', 'invoicing'),
574
+        'SA'  => __('South Australia', 'invoicing'),
575
+        'TAS' => __('Tasmania', 'invoicing'),
576
+        'VIC' => __('Victoria', 'invoicing'),
577
+        'WA'  => __('Western Australia', 'invoicing')
578 578
     );
579 579
 
580
-    return apply_filters( 'wpinv_australia_states', $states );
580
+    return apply_filters('wpinv_australia_states', $states);
581 581
 }
582 582
 
583 583
 function wpinv_get_bangladesh_states_list() {
584 584
     $states = array(
585
-        'BAG' => __( 'Bagerhat', 'invoicing' ),
586
-        'BAN' => __( 'Bandarban', 'invoicing' ),
587
-        'BAR' => __( 'Barguna', 'invoicing' ),
588
-        'BARI'=> __( 'Barisal', 'invoicing' ),
589
-        'BHO' => __( 'Bhola', 'invoicing' ),
590
-        'BOG' => __( 'Bogra', 'invoicing' ),
591
-        'BRA' => __( 'Brahmanbaria', 'invoicing' ),
592
-        'CHA' => __( 'Chandpur', 'invoicing' ),
593
-        'CHI' => __( 'Chittagong', 'invoicing' ),
594
-        'CHU' => __( 'Chuadanga', 'invoicing' ),
595
-        'COM' => __( 'Comilla', 'invoicing' ),
596
-        'COX' => __( 'Cox\'s Bazar', 'invoicing' ),
597
-        'DHA' => __( 'Dhaka', 'invoicing' ),
598
-        'DIN' => __( 'Dinajpur', 'invoicing' ),
599
-        'FAR' => __( 'Faridpur', 'invoicing' ),
600
-        'FEN' => __( 'Feni', 'invoicing' ),
601
-        'GAI' => __( 'Gaibandha', 'invoicing' ),
602
-        'GAZI'=> __( 'Gazipur', 'invoicing' ),
603
-        'GOP' => __( 'Gopalganj', 'invoicing' ),
604
-        'HAB' => __( 'Habiganj', 'invoicing' ),
605
-        'JAM' => __( 'Jamalpur', 'invoicing' ),
606
-        'JES' => __( 'Jessore', 'invoicing' ),
607
-        'JHA' => __( 'Jhalokati', 'invoicing' ),
608
-        'JHE' => __( 'Jhenaidah', 'invoicing' ),
609
-        'JOY' => __( 'Joypurhat', 'invoicing' ),
610
-        'KHA' => __( 'Khagrachhari', 'invoicing' ),
611
-        'KHU' => __( 'Khulna', 'invoicing' ),
612
-        'KIS' => __( 'Kishoreganj', 'invoicing' ),
613
-        'KUR' => __( 'Kurigram', 'invoicing' ),
614
-        'KUS' => __( 'Kushtia', 'invoicing' ),
615
-        'LAK' => __( 'Lakshmipur', 'invoicing' ),
616
-        'LAL' => __( 'Lalmonirhat', 'invoicing' ),
617
-        'MAD' => __( 'Madaripur', 'invoicing' ),
618
-        'MAG' => __( 'Magura', 'invoicing' ),
619
-        'MAN' => __( 'Manikganj', 'invoicing' ),
620
-        'MEH' => __( 'Meherpur', 'invoicing' ),
621
-        'MOU' => __( 'Moulvibazar', 'invoicing' ),
622
-        'MUN' => __( 'Munshiganj', 'invoicing' ),
623
-        'MYM' => __( 'Mymensingh', 'invoicing' ),
624
-        'NAO' => __( 'Naogaon', 'invoicing' ),
625
-        'NAR' => __( 'Narail', 'invoicing' ),
626
-        'NARG'=> __( 'Narayanganj', 'invoicing' ),
627
-        'NARD'=> __( 'Narsingdi', 'invoicing' ),
628
-        'NAT' => __( 'Natore', 'invoicing' ),
629
-        'NAW' => __( 'Nawabganj', 'invoicing' ),
630
-        'NET' => __( 'Netrakona', 'invoicing' ),
631
-        'NIL' => __( 'Nilphamari', 'invoicing' ),
632
-        'NOA' => __( 'Noakhali', 'invoicing' ),
633
-        'PAB' => __( 'Pabna', 'invoicing' ),
634
-        'PAN' => __( 'Panchagarh', 'invoicing' ),
635
-        'PAT' => __( 'Patuakhali', 'invoicing' ),
636
-        'PIR' => __( 'Pirojpur', 'invoicing' ),
637
-        'RAJB'=> __( 'Rajbari', 'invoicing' ),
638
-        'RAJ' => __( 'Rajshahi', 'invoicing' ),
639
-        'RAN' => __( 'Rangamati', 'invoicing' ),
640
-        'RANP'=> __( 'Rangpur', 'invoicing' ),
641
-        'SAT' => __( 'Satkhira', 'invoicing' ),
642
-        'SHA' => __( 'Shariatpur', 'invoicing' ),
643
-        'SHE' => __( 'Sherpur', 'invoicing' ),
644
-        'SIR' => __( 'Sirajganj', 'invoicing' ),
645
-        'SUN' => __( 'Sunamganj', 'invoicing' ),
646
-        'SYL' => __( 'Sylhet', 'invoicing' ),
647
-        'TAN' => __( 'Tangail', 'invoicing' ),
648
-        'THA' => __( 'Thakurgaon', 'invoicing' )
585
+        'BAG' => __('Bagerhat', 'invoicing'),
586
+        'BAN' => __('Bandarban', 'invoicing'),
587
+        'BAR' => __('Barguna', 'invoicing'),
588
+        'BARI'=> __('Barisal', 'invoicing'),
589
+        'BHO' => __('Bhola', 'invoicing'),
590
+        'BOG' => __('Bogra', 'invoicing'),
591
+        'BRA' => __('Brahmanbaria', 'invoicing'),
592
+        'CHA' => __('Chandpur', 'invoicing'),
593
+        'CHI' => __('Chittagong', 'invoicing'),
594
+        'CHU' => __('Chuadanga', 'invoicing'),
595
+        'COM' => __('Comilla', 'invoicing'),
596
+        'COX' => __('Cox\'s Bazar', 'invoicing'),
597
+        'DHA' => __('Dhaka', 'invoicing'),
598
+        'DIN' => __('Dinajpur', 'invoicing'),
599
+        'FAR' => __('Faridpur', 'invoicing'),
600
+        'FEN' => __('Feni', 'invoicing'),
601
+        'GAI' => __('Gaibandha', 'invoicing'),
602
+        'GAZI'=> __('Gazipur', 'invoicing'),
603
+        'GOP' => __('Gopalganj', 'invoicing'),
604
+        'HAB' => __('Habiganj', 'invoicing'),
605
+        'JAM' => __('Jamalpur', 'invoicing'),
606
+        'JES' => __('Jessore', 'invoicing'),
607
+        'JHA' => __('Jhalokati', 'invoicing'),
608
+        'JHE' => __('Jhenaidah', 'invoicing'),
609
+        'JOY' => __('Joypurhat', 'invoicing'),
610
+        'KHA' => __('Khagrachhari', 'invoicing'),
611
+        'KHU' => __('Khulna', 'invoicing'),
612
+        'KIS' => __('Kishoreganj', 'invoicing'),
613
+        'KUR' => __('Kurigram', 'invoicing'),
614
+        'KUS' => __('Kushtia', 'invoicing'),
615
+        'LAK' => __('Lakshmipur', 'invoicing'),
616
+        'LAL' => __('Lalmonirhat', 'invoicing'),
617
+        'MAD' => __('Madaripur', 'invoicing'),
618
+        'MAG' => __('Magura', 'invoicing'),
619
+        'MAN' => __('Manikganj', 'invoicing'),
620
+        'MEH' => __('Meherpur', 'invoicing'),
621
+        'MOU' => __('Moulvibazar', 'invoicing'),
622
+        'MUN' => __('Munshiganj', 'invoicing'),
623
+        'MYM' => __('Mymensingh', 'invoicing'),
624
+        'NAO' => __('Naogaon', 'invoicing'),
625
+        'NAR' => __('Narail', 'invoicing'),
626
+        'NARG'=> __('Narayanganj', 'invoicing'),
627
+        'NARD'=> __('Narsingdi', 'invoicing'),
628
+        'NAT' => __('Natore', 'invoicing'),
629
+        'NAW' => __('Nawabganj', 'invoicing'),
630
+        'NET' => __('Netrakona', 'invoicing'),
631
+        'NIL' => __('Nilphamari', 'invoicing'),
632
+        'NOA' => __('Noakhali', 'invoicing'),
633
+        'PAB' => __('Pabna', 'invoicing'),
634
+        'PAN' => __('Panchagarh', 'invoicing'),
635
+        'PAT' => __('Patuakhali', 'invoicing'),
636
+        'PIR' => __('Pirojpur', 'invoicing'),
637
+        'RAJB'=> __('Rajbari', 'invoicing'),
638
+        'RAJ' => __('Rajshahi', 'invoicing'),
639
+        'RAN' => __('Rangamati', 'invoicing'),
640
+        'RANP'=> __('Rangpur', 'invoicing'),
641
+        'SAT' => __('Satkhira', 'invoicing'),
642
+        'SHA' => __('Shariatpur', 'invoicing'),
643
+        'SHE' => __('Sherpur', 'invoicing'),
644
+        'SIR' => __('Sirajganj', 'invoicing'),
645
+        'SUN' => __('Sunamganj', 'invoicing'),
646
+        'SYL' => __('Sylhet', 'invoicing'),
647
+        'TAN' => __('Tangail', 'invoicing'),
648
+        'THA' => __('Thakurgaon', 'invoicing')
649 649
     );
650 650
 
651
-    return apply_filters( 'wpinv_bangladesh_states', $states );
651
+    return apply_filters('wpinv_bangladesh_states', $states);
652 652
 }
653 653
 
654 654
 function wpinv_get_brazil_states_list() {
655 655
     $states = array(
656
-        'AC' => __( 'Acre', 'invoicing' ),
657
-        'AL' => __( 'Alagoas', 'invoicing' ),
658
-        'AP' => __( 'Amap&aacute;', 'invoicing' ),
659
-        'AM' => __( 'Amazonas', 'invoicing' ),
660
-        'BA' => __( 'Bahia', 'invoicing' ),
661
-        'CE' => __( 'Cear&aacute;', 'invoicing' ),
662
-        'DF' => __( 'Distrito Federal', 'invoicing' ),
663
-        'ES' => __( 'Esp&iacute;rito Santo', 'invoicing' ),
664
-        'GO' => __( 'Goi&aacute;s', 'invoicing' ),
665
-        'MA' => __( 'Maranh&atilde;o', 'invoicing' ),
666
-        'MT' => __( 'Mato Grosso', 'invoicing' ),
667
-        'MS' => __( 'Mato Grosso do Sul', 'invoicing' ),
668
-        'MG' => __( 'Minas Gerais', 'invoicing' ),
669
-        'PA' => __( 'Par&aacute;', 'invoicing' ),
670
-        'PB' => __( 'Para&iacute;ba', 'invoicing' ),
671
-        'PR' => __( 'Paran&aacute;', 'invoicing' ),
672
-        'PE' => __( 'Pernambuco', 'invoicing' ),
673
-        'PI' => __( 'Piau&iacute;', 'invoicing' ),
674
-        'RJ' => __( 'Rio de Janeiro', 'invoicing' ),
675
-        'RN' => __( 'Rio Grande do Norte', 'invoicing' ),
676
-        'RS' => __( 'Rio Grande do Sul', 'invoicing' ),
677
-        'RO' => __( 'Rond&ocirc;nia', 'invoicing' ),
678
-        'RR' => __( 'Roraima', 'invoicing' ),
679
-        'SC' => __( 'Santa Catarina', 'invoicing' ),
680
-        'SP' => __( 'S&atilde;o Paulo', 'invoicing' ),
681
-        'SE' => __( 'Sergipe', 'invoicing' ),
682
-        'TO' => __( 'Tocantins', 'invoicing' )
656
+        'AC' => __('Acre', 'invoicing'),
657
+        'AL' => __('Alagoas', 'invoicing'),
658
+        'AP' => __('Amap&aacute;', 'invoicing'),
659
+        'AM' => __('Amazonas', 'invoicing'),
660
+        'BA' => __('Bahia', 'invoicing'),
661
+        'CE' => __('Cear&aacute;', 'invoicing'),
662
+        'DF' => __('Distrito Federal', 'invoicing'),
663
+        'ES' => __('Esp&iacute;rito Santo', 'invoicing'),
664
+        'GO' => __('Goi&aacute;s', 'invoicing'),
665
+        'MA' => __('Maranh&atilde;o', 'invoicing'),
666
+        'MT' => __('Mato Grosso', 'invoicing'),
667
+        'MS' => __('Mato Grosso do Sul', 'invoicing'),
668
+        'MG' => __('Minas Gerais', 'invoicing'),
669
+        'PA' => __('Par&aacute;', 'invoicing'),
670
+        'PB' => __('Para&iacute;ba', 'invoicing'),
671
+        'PR' => __('Paran&aacute;', 'invoicing'),
672
+        'PE' => __('Pernambuco', 'invoicing'),
673
+        'PI' => __('Piau&iacute;', 'invoicing'),
674
+        'RJ' => __('Rio de Janeiro', 'invoicing'),
675
+        'RN' => __('Rio Grande do Norte', 'invoicing'),
676
+        'RS' => __('Rio Grande do Sul', 'invoicing'),
677
+        'RO' => __('Rond&ocirc;nia', 'invoicing'),
678
+        'RR' => __('Roraima', 'invoicing'),
679
+        'SC' => __('Santa Catarina', 'invoicing'),
680
+        'SP' => __('S&atilde;o Paulo', 'invoicing'),
681
+        'SE' => __('Sergipe', 'invoicing'),
682
+        'TO' => __('Tocantins', 'invoicing')
683 683
     );
684 684
 
685
-    return apply_filters( 'wpinv_brazil_states', $states );
685
+    return apply_filters('wpinv_brazil_states', $states);
686 686
 }
687 687
 
688 688
 function wpinv_get_bulgaria_states_list() {
689 689
     $states = array(
690
-        'BG-01' => __( 'Blagoevgrad', 'invoicing' ),
691
-        'BG-02' => __( 'Burgas', 'invoicing' ),
692
-        'BG-08' => __( 'Dobrich', 'invoicing' ),
693
-        'BG-07' => __( 'Gabrovo', 'invoicing' ),
694
-        'BG-26' => __( 'Haskovo', 'invoicing' ),
695
-        'BG-09' => __( 'Kardzhali', 'invoicing' ),
696
-        'BG-10' => __( 'Kyustendil', 'invoicing' ),
697
-        'BG-11' => __( 'Lovech', 'invoicing' ),
698
-        'BG-12' => __( 'Montana', 'invoicing' ),
699
-        'BG-13' => __( 'Pazardzhik', 'invoicing' ),
700
-        'BG-14' => __( 'Pernik', 'invoicing' ),
701
-        'BG-15' => __( 'Pleven', 'invoicing' ),
702
-        'BG-16' => __( 'Plovdiv', 'invoicing' ),
703
-        'BG-17' => __( 'Razgrad', 'invoicing' ),
704
-        'BG-18' => __( 'Ruse', 'invoicing' ),
705
-        'BG-27' => __( 'Shumen', 'invoicing' ),
706
-        'BG-19' => __( 'Silistra', 'invoicing' ),
707
-        'BG-20' => __( 'Sliven', 'invoicing' ),
708
-        'BG-21' => __( 'Smolyan', 'invoicing' ),
709
-        'BG-23' => __( 'Sofia', 'invoicing' ),
710
-        'BG-22' => __( 'Sofia-Grad', 'invoicing' ),
711
-        'BG-24' => __( 'Stara Zagora', 'invoicing' ),
712
-        'BG-25' => __( 'Targovishte', 'invoicing' ),
713
-        'BG-03' => __( 'Varna', 'invoicing' ),
714
-        'BG-04' => __( 'Veliko Tarnovo', 'invoicing' ),
715
-        'BG-05' => __( 'Vidin', 'invoicing' ),
716
-        'BG-06' => __( 'Vratsa', 'invoicing' ),
717
-        'BG-28' => __( 'Yambol', 'invoicing' )
690
+        'BG-01' => __('Blagoevgrad', 'invoicing'),
691
+        'BG-02' => __('Burgas', 'invoicing'),
692
+        'BG-08' => __('Dobrich', 'invoicing'),
693
+        'BG-07' => __('Gabrovo', 'invoicing'),
694
+        'BG-26' => __('Haskovo', 'invoicing'),
695
+        'BG-09' => __('Kardzhali', 'invoicing'),
696
+        'BG-10' => __('Kyustendil', 'invoicing'),
697
+        'BG-11' => __('Lovech', 'invoicing'),
698
+        'BG-12' => __('Montana', 'invoicing'),
699
+        'BG-13' => __('Pazardzhik', 'invoicing'),
700
+        'BG-14' => __('Pernik', 'invoicing'),
701
+        'BG-15' => __('Pleven', 'invoicing'),
702
+        'BG-16' => __('Plovdiv', 'invoicing'),
703
+        'BG-17' => __('Razgrad', 'invoicing'),
704
+        'BG-18' => __('Ruse', 'invoicing'),
705
+        'BG-27' => __('Shumen', 'invoicing'),
706
+        'BG-19' => __('Silistra', 'invoicing'),
707
+        'BG-20' => __('Sliven', 'invoicing'),
708
+        'BG-21' => __('Smolyan', 'invoicing'),
709
+        'BG-23' => __('Sofia', 'invoicing'),
710
+        'BG-22' => __('Sofia-Grad', 'invoicing'),
711
+        'BG-24' => __('Stara Zagora', 'invoicing'),
712
+        'BG-25' => __('Targovishte', 'invoicing'),
713
+        'BG-03' => __('Varna', 'invoicing'),
714
+        'BG-04' => __('Veliko Tarnovo', 'invoicing'),
715
+        'BG-05' => __('Vidin', 'invoicing'),
716
+        'BG-06' => __('Vratsa', 'invoicing'),
717
+        'BG-28' => __('Yambol', 'invoicing')
718 718
     );
719 719
 
720
-    return apply_filters( 'wpinv_bulgaria_states', $states );
720
+    return apply_filters('wpinv_bulgaria_states', $states);
721 721
 }
722 722
 
723 723
 function wpinv_get_hong_kong_states_list() {
724 724
     $states = array(
725
-        'HONG KONG'       => __( 'Hong Kong Island', 'invoicing' ),
726
-        'KOWLOON'         => __( 'Kowloon', 'invoicing' ),
727
-        'NEW TERRITORIES' => __( 'New Territories', 'invoicing' )
725
+        'HONG KONG'       => __('Hong Kong Island', 'invoicing'),
726
+        'KOWLOON'         => __('Kowloon', 'invoicing'),
727
+        'NEW TERRITORIES' => __('New Territories', 'invoicing')
728 728
     );
729 729
 
730
-    return apply_filters( 'wpinv_hong_kong_states', $states );
730
+    return apply_filters('wpinv_hong_kong_states', $states);
731 731
 }
732 732
 
733 733
 function wpinv_get_hungary_states_list() {
734 734
     $states = array(
735
-        'BK' => __( 'Bács-Kiskun', 'invoicing' ),
736
-        'BE' => __( 'Békés', 'invoicing' ),
737
-        'BA' => __( 'Baranya', 'invoicing' ),
738
-        'BZ' => __( 'Borsod-Abaúj-Zemplén', 'invoicing' ),
739
-        'BU' => __( 'Budapest', 'invoicing' ),
740
-        'CS' => __( 'Csongrád', 'invoicing' ),
741
-        'FE' => __( 'Fejér', 'invoicing' ),
742
-        'GS' => __( 'Győr-Moson-Sopron', 'invoicing' ),
743
-        'HB' => __( 'Hajdú-Bihar', 'invoicing' ),
744
-        'HE' => __( 'Heves', 'invoicing' ),
745
-        'JN' => __( 'Jász-Nagykun-Szolnok', 'invoicing' ),
746
-        'KE' => __( 'Komárom-Esztergom', 'invoicing' ),
747
-        'NO' => __( 'Nógrád', 'invoicing' ),
748
-        'PE' => __( 'Pest', 'invoicing' ),
749
-        'SO' => __( 'Somogy', 'invoicing' ),
750
-        'SZ' => __( 'Szabolcs-Szatmár-Bereg', 'invoicing' ),
751
-        'TO' => __( 'Tolna', 'invoicing' ),
752
-        'VA' => __( 'Vas', 'invoicing' ),
753
-        'VE' => __( 'Veszprém', 'invoicing' ),
754
-        'ZA' => __( 'Zala', 'invoicing' )
735
+        'BK' => __('Bács-Kiskun', 'invoicing'),
736
+        'BE' => __('Békés', 'invoicing'),
737
+        'BA' => __('Baranya', 'invoicing'),
738
+        'BZ' => __('Borsod-Abaúj-Zemplén', 'invoicing'),
739
+        'BU' => __('Budapest', 'invoicing'),
740
+        'CS' => __('Csongrád', 'invoicing'),
741
+        'FE' => __('Fejér', 'invoicing'),
742
+        'GS' => __('Győr-Moson-Sopron', 'invoicing'),
743
+        'HB' => __('Hajdú-Bihar', 'invoicing'),
744
+        'HE' => __('Heves', 'invoicing'),
745
+        'JN' => __('Jász-Nagykun-Szolnok', 'invoicing'),
746
+        'KE' => __('Komárom-Esztergom', 'invoicing'),
747
+        'NO' => __('Nógrád', 'invoicing'),
748
+        'PE' => __('Pest', 'invoicing'),
749
+        'SO' => __('Somogy', 'invoicing'),
750
+        'SZ' => __('Szabolcs-Szatmár-Bereg', 'invoicing'),
751
+        'TO' => __('Tolna', 'invoicing'),
752
+        'VA' => __('Vas', 'invoicing'),
753
+        'VE' => __('Veszprém', 'invoicing'),
754
+        'ZA' => __('Zala', 'invoicing')
755 755
     );
756 756
 
757
-    return apply_filters( 'wpinv_hungary_states', $states );
757
+    return apply_filters('wpinv_hungary_states', $states);
758 758
 }
759 759
 
760 760
 function wpinv_get_japan_states_list() {
761 761
     $states = array(
762
-        'JP01' => __( 'Hokkaido', 'invoicing' ),
763
-        'JP02' => __( 'Aomori', 'invoicing' ),
764
-        'JP03' => __( 'Iwate', 'invoicing' ),
765
-        'JP04' => __( 'Miyagi', 'invoicing' ),
766
-        'JP05' => __( 'Akita', 'invoicing' ),
767
-        'JP06' => __( 'Yamagata', 'invoicing' ),
768
-        'JP07' => __( 'Fukushima', 'invoicing' ),
769
-        'JP08' => __( 'Ibaraki', 'invoicing' ),
770
-        'JP09' => __( 'Tochigi', 'invoicing' ),
771
-        'JP10' => __( 'Gunma', 'invoicing' ),
772
-        'JP11' => __( 'Saitama', 'invoicing' ),
773
-        'JP12' => __( 'Chiba', 'invoicing' ),
774
-        'JP13' => __( 'Tokyo', 'invoicing' ),
775
-        'JP14' => __( 'Kanagawa', 'invoicing' ),
776
-        'JP15' => __( 'Niigata', 'invoicing' ),
777
-        'JP16' => __( 'Toyama', 'invoicing' ),
778
-        'JP17' => __( 'Ishikawa', 'invoicing' ),
779
-        'JP18' => __( 'Fukui', 'invoicing' ),
780
-        'JP19' => __( 'Yamanashi', 'invoicing' ),
781
-        'JP20' => __( 'Nagano', 'invoicing' ),
782
-        'JP21' => __( 'Gifu', 'invoicing' ),
783
-        'JP22' => __( 'Shizuoka', 'invoicing' ),
784
-        'JP23' => __( 'Aichi', 'invoicing' ),
785
-        'JP24' => __( 'Mie', 'invoicing' ),
786
-        'JP25' => __( 'Shiga', 'invoicing' ),
787
-        'JP26' => __( 'Kyouto', 'invoicing' ),
788
-        'JP27' => __( 'Osaka', 'invoicing' ),
789
-        'JP28' => __( 'Hyougo', 'invoicing' ),
790
-        'JP29' => __( 'Nara', 'invoicing' ),
791
-        'JP30' => __( 'Wakayama', 'invoicing' ),
792
-        'JP31' => __( 'Tottori', 'invoicing' ),
793
-        'JP32' => __( 'Shimane', 'invoicing' ),
794
-        'JP33' => __( 'Okayama', 'invoicing' ),
795
-        'JP34' => __( 'Hiroshima', 'invoicing' ),
796
-        'JP35' => __( 'Yamaguchi', 'invoicing' ),
797
-        'JP36' => __( 'Tokushima', 'invoicing' ),
798
-        'JP37' => __( 'Kagawa', 'invoicing' ),
799
-        'JP38' => __( 'Ehime', 'invoicing' ),
800
-        'JP39' => __( 'Kochi', 'invoicing' ),
801
-        'JP40' => __( 'Fukuoka', 'invoicing' ),
802
-        'JP41' => __( 'Saga', 'invoicing' ),
803
-        'JP42' => __( 'Nagasaki', 'invoicing' ),
804
-        'JP43' => __( 'Kumamoto', 'invoicing' ),
805
-        'JP44' => __( 'Oita', 'invoicing' ),
806
-        'JP45' => __( 'Miyazaki', 'invoicing' ),
807
-        'JP46' => __( 'Kagoshima', 'invoicing' ),
808
-        'JP47' => __( 'Okinawa', 'invoicing' )
762
+        'JP01' => __('Hokkaido', 'invoicing'),
763
+        'JP02' => __('Aomori', 'invoicing'),
764
+        'JP03' => __('Iwate', 'invoicing'),
765
+        'JP04' => __('Miyagi', 'invoicing'),
766
+        'JP05' => __('Akita', 'invoicing'),
767
+        'JP06' => __('Yamagata', 'invoicing'),
768
+        'JP07' => __('Fukushima', 'invoicing'),
769
+        'JP08' => __('Ibaraki', 'invoicing'),
770
+        'JP09' => __('Tochigi', 'invoicing'),
771
+        'JP10' => __('Gunma', 'invoicing'),
772
+        'JP11' => __('Saitama', 'invoicing'),
773
+        'JP12' => __('Chiba', 'invoicing'),
774
+        'JP13' => __('Tokyo', 'invoicing'),
775
+        'JP14' => __('Kanagawa', 'invoicing'),
776
+        'JP15' => __('Niigata', 'invoicing'),
777
+        'JP16' => __('Toyama', 'invoicing'),
778
+        'JP17' => __('Ishikawa', 'invoicing'),
779
+        'JP18' => __('Fukui', 'invoicing'),
780
+        'JP19' => __('Yamanashi', 'invoicing'),
781
+        'JP20' => __('Nagano', 'invoicing'),
782
+        'JP21' => __('Gifu', 'invoicing'),
783
+        'JP22' => __('Shizuoka', 'invoicing'),
784
+        'JP23' => __('Aichi', 'invoicing'),
785
+        'JP24' => __('Mie', 'invoicing'),
786
+        'JP25' => __('Shiga', 'invoicing'),
787
+        'JP26' => __('Kyouto', 'invoicing'),
788
+        'JP27' => __('Osaka', 'invoicing'),
789
+        'JP28' => __('Hyougo', 'invoicing'),
790
+        'JP29' => __('Nara', 'invoicing'),
791
+        'JP30' => __('Wakayama', 'invoicing'),
792
+        'JP31' => __('Tottori', 'invoicing'),
793
+        'JP32' => __('Shimane', 'invoicing'),
794
+        'JP33' => __('Okayama', 'invoicing'),
795
+        'JP34' => __('Hiroshima', 'invoicing'),
796
+        'JP35' => __('Yamaguchi', 'invoicing'),
797
+        'JP36' => __('Tokushima', 'invoicing'),
798
+        'JP37' => __('Kagawa', 'invoicing'),
799
+        'JP38' => __('Ehime', 'invoicing'),
800
+        'JP39' => __('Kochi', 'invoicing'),
801
+        'JP40' => __('Fukuoka', 'invoicing'),
802
+        'JP41' => __('Saga', 'invoicing'),
803
+        'JP42' => __('Nagasaki', 'invoicing'),
804
+        'JP43' => __('Kumamoto', 'invoicing'),
805
+        'JP44' => __('Oita', 'invoicing'),
806
+        'JP45' => __('Miyazaki', 'invoicing'),
807
+        'JP46' => __('Kagoshima', 'invoicing'),
808
+        'JP47' => __('Okinawa', 'invoicing')
809 809
     );
810 810
 
811
-    return apply_filters( 'wpinv_japan_states', $states );
811
+    return apply_filters('wpinv_japan_states', $states);
812 812
 }
813 813
 
814 814
 function wpinv_get_china_states_list() {
815 815
     $states = array(
816
-        'CN1'  => __( 'Yunnan / &#20113;&#21335;', 'invoicing' ),
817
-        'CN2'  => __( 'Beijing / &#21271;&#20140;', 'invoicing' ),
818
-        'CN3'  => __( 'Tianjin / &#22825;&#27941;', 'invoicing' ),
819
-        'CN4'  => __( 'Hebei / &#27827;&#21271;', 'invoicing' ),
820
-        'CN5'  => __( 'Shanxi / &#23665;&#35199;', 'invoicing' ),
821
-        'CN6'  => __( 'Inner Mongolia / &#20839;&#33945;&#21476;', 'invoicing' ),
822
-        'CN7'  => __( 'Liaoning / &#36797;&#23425;', 'invoicing' ),
823
-        'CN8'  => __( 'Jilin / &#21513;&#26519;', 'invoicing' ),
824
-        'CN9'  => __( 'Heilongjiang / &#40657;&#40857;&#27743;', 'invoicing' ),
825
-        'CN10' => __( 'Shanghai / &#19978;&#28023;', 'invoicing' ),
826
-        'CN11' => __( 'Jiangsu / &#27743;&#33487;', 'invoicing' ),
827
-        'CN12' => __( 'Zhejiang / &#27993;&#27743;', 'invoicing' ),
828
-        'CN13' => __( 'Anhui / &#23433;&#24509;', 'invoicing' ),
829
-        'CN14' => __( 'Fujian / &#31119;&#24314;', 'invoicing' ),
830
-        'CN15' => __( 'Jiangxi / &#27743;&#35199;', 'invoicing' ),
831
-        'CN16' => __( 'Shandong / &#23665;&#19996;', 'invoicing' ),
832
-        'CN17' => __( 'Henan / &#27827;&#21335;', 'invoicing' ),
833
-        'CN18' => __( 'Hubei / &#28246;&#21271;', 'invoicing' ),
834
-        'CN19' => __( 'Hunan / &#28246;&#21335;', 'invoicing' ),
835
-        'CN20' => __( 'Guangdong / &#24191;&#19996;', 'invoicing' ),
836
-        'CN21' => __( 'Guangxi Zhuang / &#24191;&#35199;&#22766;&#26063;', 'invoicing' ),
837
-        'CN22' => __( 'Hainan / &#28023;&#21335;', 'invoicing' ),
838
-        'CN23' => __( 'Chongqing / &#37325;&#24198;', 'invoicing' ),
839
-        'CN24' => __( 'Sichuan / &#22235;&#24029;', 'invoicing' ),
840
-        'CN25' => __( 'Guizhou / &#36149;&#24030;', 'invoicing' ),
841
-        'CN26' => __( 'Shaanxi / &#38485;&#35199;', 'invoicing' ),
842
-        'CN27' => __( 'Gansu / &#29976;&#32899;', 'invoicing' ),
843
-        'CN28' => __( 'Qinghai / &#38738;&#28023;', 'invoicing' ),
844
-        'CN29' => __( 'Ningxia Hui / &#23425;&#22799;', 'invoicing' ),
845
-        'CN30' => __( 'Macau / &#28595;&#38376;', 'invoicing' ),
846
-        'CN31' => __( 'Tibet / &#35199;&#34255;', 'invoicing' ),
847
-        'CN32' => __( 'Xinjiang / &#26032;&#30086;', 'invoicing' )
816
+        'CN1'  => __('Yunnan / &#20113;&#21335;', 'invoicing'),
817
+        'CN2'  => __('Beijing / &#21271;&#20140;', 'invoicing'),
818
+        'CN3'  => __('Tianjin / &#22825;&#27941;', 'invoicing'),
819
+        'CN4'  => __('Hebei / &#27827;&#21271;', 'invoicing'),
820
+        'CN5'  => __('Shanxi / &#23665;&#35199;', 'invoicing'),
821
+        'CN6'  => __('Inner Mongolia / &#20839;&#33945;&#21476;', 'invoicing'),
822
+        'CN7'  => __('Liaoning / &#36797;&#23425;', 'invoicing'),
823
+        'CN8'  => __('Jilin / &#21513;&#26519;', 'invoicing'),
824
+        'CN9'  => __('Heilongjiang / &#40657;&#40857;&#27743;', 'invoicing'),
825
+        'CN10' => __('Shanghai / &#19978;&#28023;', 'invoicing'),
826
+        'CN11' => __('Jiangsu / &#27743;&#33487;', 'invoicing'),
827
+        'CN12' => __('Zhejiang / &#27993;&#27743;', 'invoicing'),
828
+        'CN13' => __('Anhui / &#23433;&#24509;', 'invoicing'),
829
+        'CN14' => __('Fujian / &#31119;&#24314;', 'invoicing'),
830
+        'CN15' => __('Jiangxi / &#27743;&#35199;', 'invoicing'),
831
+        'CN16' => __('Shandong / &#23665;&#19996;', 'invoicing'),
832
+        'CN17' => __('Henan / &#27827;&#21335;', 'invoicing'),
833
+        'CN18' => __('Hubei / &#28246;&#21271;', 'invoicing'),
834
+        'CN19' => __('Hunan / &#28246;&#21335;', 'invoicing'),
835
+        'CN20' => __('Guangdong / &#24191;&#19996;', 'invoicing'),
836
+        'CN21' => __('Guangxi Zhuang / &#24191;&#35199;&#22766;&#26063;', 'invoicing'),
837
+        'CN22' => __('Hainan / &#28023;&#21335;', 'invoicing'),
838
+        'CN23' => __('Chongqing / &#37325;&#24198;', 'invoicing'),
839
+        'CN24' => __('Sichuan / &#22235;&#24029;', 'invoicing'),
840
+        'CN25' => __('Guizhou / &#36149;&#24030;', 'invoicing'),
841
+        'CN26' => __('Shaanxi / &#38485;&#35199;', 'invoicing'),
842
+        'CN27' => __('Gansu / &#29976;&#32899;', 'invoicing'),
843
+        'CN28' => __('Qinghai / &#38738;&#28023;', 'invoicing'),
844
+        'CN29' => __('Ningxia Hui / &#23425;&#22799;', 'invoicing'),
845
+        'CN30' => __('Macau / &#28595;&#38376;', 'invoicing'),
846
+        'CN31' => __('Tibet / &#35199;&#34255;', 'invoicing'),
847
+        'CN32' => __('Xinjiang / &#26032;&#30086;', 'invoicing')
848 848
     );
849 849
 
850
-    return apply_filters( 'wpinv_china_states', $states );
850
+    return apply_filters('wpinv_china_states', $states);
851 851
 }
852 852
 
853 853
 function wpinv_get_new_zealand_states_list() {
854 854
     $states = array(
855
-        'AK' => __( 'Auckland', 'invoicing' ),
856
-        'BP' => __( 'Bay of Plenty', 'invoicing' ),
857
-        'CT' => __( 'Canterbury', 'invoicing' ),
858
-        'HB' => __( 'Hawke&rsquo;s Bay', 'invoicing' ),
859
-        'MW' => __( 'Manawatu-Wanganui', 'invoicing' ),
860
-        'MB' => __( 'Marlborough', 'invoicing' ),
861
-        'NS' => __( 'Nelson', 'invoicing' ),
862
-        'NL' => __( 'Northland', 'invoicing' ),
863
-        'OT' => __( 'Otago', 'invoicing' ),
864
-        'SL' => __( 'Southland', 'invoicing' ),
865
-        'TK' => __( 'Taranaki', 'invoicing' ),
866
-        'TM' => __( 'Tasman', 'invoicing' ),
867
-        'WA' => __( 'Waikato', 'invoicing' ),
868
-        'WR' => __( 'Wairarapa', 'invoicing' ),
869
-        'WE' => __( 'Wellington', 'invoicing' ),
870
-        'WC' => __( 'West Coast', 'invoicing' )
855
+        'AK' => __('Auckland', 'invoicing'),
856
+        'BP' => __('Bay of Plenty', 'invoicing'),
857
+        'CT' => __('Canterbury', 'invoicing'),
858
+        'HB' => __('Hawke&rsquo;s Bay', 'invoicing'),
859
+        'MW' => __('Manawatu-Wanganui', 'invoicing'),
860
+        'MB' => __('Marlborough', 'invoicing'),
861
+        'NS' => __('Nelson', 'invoicing'),
862
+        'NL' => __('Northland', 'invoicing'),
863
+        'OT' => __('Otago', 'invoicing'),
864
+        'SL' => __('Southland', 'invoicing'),
865
+        'TK' => __('Taranaki', 'invoicing'),
866
+        'TM' => __('Tasman', 'invoicing'),
867
+        'WA' => __('Waikato', 'invoicing'),
868
+        'WR' => __('Wairarapa', 'invoicing'),
869
+        'WE' => __('Wellington', 'invoicing'),
870
+        'WC' => __('West Coast', 'invoicing')
871 871
     );
872 872
 
873
-    return apply_filters( 'wpinv_new_zealand_states', $states );
873
+    return apply_filters('wpinv_new_zealand_states', $states);
874 874
 }
875 875
 
876 876
 function wpinv_get_peru_states_list() {
877 877
     $states = array(
878
-        'CAL' => __( 'El Callao', 'invoicing' ),
879
-        'LMA' => __( 'Municipalidad Metropolitana de Lima', 'invoicing' ),
880
-        'AMA' => __( 'Amazonas', 'invoicing' ),
881
-        'ANC' => __( 'Ancash', 'invoicing' ),
882
-        'APU' => __( 'Apur&iacute;mac', 'invoicing' ),
883
-        'ARE' => __( 'Arequipa', 'invoicing' ),
884
-        'AYA' => __( 'Ayacucho', 'invoicing' ),
885
-        'CAJ' => __( 'Cajamarca', 'invoicing' ),
886
-        'CUS' => __( 'Cusco', 'invoicing' ),
887
-        'HUV' => __( 'Huancavelica', 'invoicing' ),
888
-        'HUC' => __( 'Hu&aacute;nuco', 'invoicing' ),
889
-        'ICA' => __( 'Ica', 'invoicing' ),
890
-        'JUN' => __( 'Jun&iacute;n', 'invoicing' ),
891
-        'LAL' => __( 'La Libertad', 'invoicing' ),
892
-        'LAM' => __( 'Lambayeque', 'invoicing' ),
893
-        'LIM' => __( 'Lima', 'invoicing' ),
894
-        'LOR' => __( 'Loreto', 'invoicing' ),
895
-        'MDD' => __( 'Madre de Dios', 'invoicing' ),
896
-        'MOQ' => __( 'Moquegua', 'invoicing' ),
897
-        'PAS' => __( 'Pasco', 'invoicing' ),
898
-        'PIU' => __( 'Piura', 'invoicing' ),
899
-        'PUN' => __( 'Puno', 'invoicing' ),
900
-        'SAM' => __( 'San Mart&iacute;n', 'invoicing' ),
901
-        'TAC' => __( 'Tacna', 'invoicing' ),
902
-        'TUM' => __( 'Tumbes', 'invoicing' ),
903
-        'UCA' => __( 'Ucayali', 'invoicing' )
878
+        'CAL' => __('El Callao', 'invoicing'),
879
+        'LMA' => __('Municipalidad Metropolitana de Lima', 'invoicing'),
880
+        'AMA' => __('Amazonas', 'invoicing'),
881
+        'ANC' => __('Ancash', 'invoicing'),
882
+        'APU' => __('Apur&iacute;mac', 'invoicing'),
883
+        'ARE' => __('Arequipa', 'invoicing'),
884
+        'AYA' => __('Ayacucho', 'invoicing'),
885
+        'CAJ' => __('Cajamarca', 'invoicing'),
886
+        'CUS' => __('Cusco', 'invoicing'),
887
+        'HUV' => __('Huancavelica', 'invoicing'),
888
+        'HUC' => __('Hu&aacute;nuco', 'invoicing'),
889
+        'ICA' => __('Ica', 'invoicing'),
890
+        'JUN' => __('Jun&iacute;n', 'invoicing'),
891
+        'LAL' => __('La Libertad', 'invoicing'),
892
+        'LAM' => __('Lambayeque', 'invoicing'),
893
+        'LIM' => __('Lima', 'invoicing'),
894
+        'LOR' => __('Loreto', 'invoicing'),
895
+        'MDD' => __('Madre de Dios', 'invoicing'),
896
+        'MOQ' => __('Moquegua', 'invoicing'),
897
+        'PAS' => __('Pasco', 'invoicing'),
898
+        'PIU' => __('Piura', 'invoicing'),
899
+        'PUN' => __('Puno', 'invoicing'),
900
+        'SAM' => __('San Mart&iacute;n', 'invoicing'),
901
+        'TAC' => __('Tacna', 'invoicing'),
902
+        'TUM' => __('Tumbes', 'invoicing'),
903
+        'UCA' => __('Ucayali', 'invoicing')
904 904
     );
905 905
 
906
-    return apply_filters( 'wpinv_peru_states', $states );
906
+    return apply_filters('wpinv_peru_states', $states);
907 907
 }
908 908
 
909 909
 function wpinv_get_indonesia_states_list() {
910
-    $states  = array(
911
-        'AC' => __( 'Daerah Istimewa Aceh', 'invoicing' ),
912
-        'SU' => __( 'Sumatera Utara', 'invoicing' ),
913
-        'SB' => __( 'Sumatera Barat', 'invoicing' ),
914
-        'RI' => __( 'Riau', 'invoicing' ),
915
-        'KR' => __( 'Kepulauan Riau', 'invoicing' ),
916
-        'JA' => __( 'Jambi', 'invoicing' ),
917
-        'SS' => __( 'Sumatera Selatan', 'invoicing' ),
918
-        'BB' => __( 'Bangka Belitung', 'invoicing' ),
919
-        'BE' => __( 'Bengkulu', 'invoicing' ),
920
-        'LA' => __( 'Lampung', 'invoicing' ),
921
-        'JK' => __( 'DKI Jakarta', 'invoicing' ),
922
-        'JB' => __( 'Jawa Barat', 'invoicing' ),
923
-        'BT' => __( 'Banten', 'invoicing' ),
924
-        'JT' => __( 'Jawa Tengah', 'invoicing' ),
925
-        'JI' => __( 'Jawa Timur', 'invoicing' ),
926
-        'YO' => __( 'Daerah Istimewa Yogyakarta', 'invoicing' ),
927
-        'BA' => __( 'Bali', 'invoicing' ),
928
-        'NB' => __( 'Nusa Tenggara Barat', 'invoicing' ),
929
-        'NT' => __( 'Nusa Tenggara Timur', 'invoicing' ),
930
-        'KB' => __( 'Kalimantan Barat', 'invoicing' ),
931
-        'KT' => __( 'Kalimantan Tengah', 'invoicing' ),
932
-        'KI' => __( 'Kalimantan Timur', 'invoicing' ),
933
-        'KS' => __( 'Kalimantan Selatan', 'invoicing' ),
934
-        'KU' => __( 'Kalimantan Utara', 'invoicing' ),
935
-        'SA' => __( 'Sulawesi Utara', 'invoicing' ),
936
-        'ST' => __( 'Sulawesi Tengah', 'invoicing' ),
937
-        'SG' => __( 'Sulawesi Tenggara', 'invoicing' ),
938
-        'SR' => __( 'Sulawesi Barat', 'invoicing' ),
939
-        'SN' => __( 'Sulawesi Selatan', 'invoicing' ),
940
-        'GO' => __( 'Gorontalo', 'invoicing' ),
941
-        'MA' => __( 'Maluku', 'invoicing' ),
942
-        'MU' => __( 'Maluku Utara', 'invoicing' ),
943
-        'PA' => __( 'Papua', 'invoicing' ),
944
-        'PB' => __( 'Papua Barat', 'invoicing' )
910
+    $states = array(
911
+        'AC' => __('Daerah Istimewa Aceh', 'invoicing'),
912
+        'SU' => __('Sumatera Utara', 'invoicing'),
913
+        'SB' => __('Sumatera Barat', 'invoicing'),
914
+        'RI' => __('Riau', 'invoicing'),
915
+        'KR' => __('Kepulauan Riau', 'invoicing'),
916
+        'JA' => __('Jambi', 'invoicing'),
917
+        'SS' => __('Sumatera Selatan', 'invoicing'),
918
+        'BB' => __('Bangka Belitung', 'invoicing'),
919
+        'BE' => __('Bengkulu', 'invoicing'),
920
+        'LA' => __('Lampung', 'invoicing'),
921
+        'JK' => __('DKI Jakarta', 'invoicing'),
922
+        'JB' => __('Jawa Barat', 'invoicing'),
923
+        'BT' => __('Banten', 'invoicing'),
924
+        'JT' => __('Jawa Tengah', 'invoicing'),
925
+        'JI' => __('Jawa Timur', 'invoicing'),
926
+        'YO' => __('Daerah Istimewa Yogyakarta', 'invoicing'),
927
+        'BA' => __('Bali', 'invoicing'),
928
+        'NB' => __('Nusa Tenggara Barat', 'invoicing'),
929
+        'NT' => __('Nusa Tenggara Timur', 'invoicing'),
930
+        'KB' => __('Kalimantan Barat', 'invoicing'),
931
+        'KT' => __('Kalimantan Tengah', 'invoicing'),
932
+        'KI' => __('Kalimantan Timur', 'invoicing'),
933
+        'KS' => __('Kalimantan Selatan', 'invoicing'),
934
+        'KU' => __('Kalimantan Utara', 'invoicing'),
935
+        'SA' => __('Sulawesi Utara', 'invoicing'),
936
+        'ST' => __('Sulawesi Tengah', 'invoicing'),
937
+        'SG' => __('Sulawesi Tenggara', 'invoicing'),
938
+        'SR' => __('Sulawesi Barat', 'invoicing'),
939
+        'SN' => __('Sulawesi Selatan', 'invoicing'),
940
+        'GO' => __('Gorontalo', 'invoicing'),
941
+        'MA' => __('Maluku', 'invoicing'),
942
+        'MU' => __('Maluku Utara', 'invoicing'),
943
+        'PA' => __('Papua', 'invoicing'),
944
+        'PB' => __('Papua Barat', 'invoicing')
945 945
     );
946 946
 
947
-    return apply_filters( 'wpinv_indonesia_states', $states );
947
+    return apply_filters('wpinv_indonesia_states', $states);
948 948
 }
949 949
 
950 950
 function wpinv_get_india_states_list() {
951 951
     $states = array(
952
-        'AP' => __( 'Andhra Pradesh', 'invoicing' ),
953
-        'AR' => __( 'Arunachal Pradesh', 'invoicing' ),
954
-        'AS' => __( 'Assam', 'invoicing' ),
955
-        'BR' => __( 'Bihar', 'invoicing' ),
956
-        'CT' => __( 'Chhattisgarh', 'invoicing' ),
957
-        'GA' => __( 'Goa', 'invoicing' ),
958
-        'GJ' => __( 'Gujarat', 'invoicing' ),
959
-        'HR' => __( 'Haryana', 'invoicing' ),
960
-        'HP' => __( 'Himachal Pradesh', 'invoicing' ),
961
-        'JK' => __( 'Jammu and Kashmir', 'invoicing' ),
962
-        'JH' => __( 'Jharkhand', 'invoicing' ),
963
-        'KA' => __( 'Karnataka', 'invoicing' ),
964
-        'KL' => __( 'Kerala', 'invoicing' ),
965
-        'MP' => __( 'Madhya Pradesh', 'invoicing' ),
966
-        'MH' => __( 'Maharashtra', 'invoicing' ),
967
-        'MN' => __( 'Manipur', 'invoicing' ),
968
-        'ML' => __( 'Meghalaya', 'invoicing' ),
969
-        'MZ' => __( 'Mizoram', 'invoicing' ),
970
-        'NL' => __( 'Nagaland', 'invoicing' ),
971
-        'OR' => __( 'Orissa', 'invoicing' ),
972
-        'PB' => __( 'Punjab', 'invoicing' ),
973
-        'RJ' => __( 'Rajasthan', 'invoicing' ),
974
-        'SK' => __( 'Sikkim', 'invoicing' ),
975
-        'TN' => __( 'Tamil Nadu', 'invoicing' ),
976
-        'TG' => __( 'Telangana', 'invoicing' ),
977
-        'TR' => __( 'Tripura', 'invoicing' ),
978
-        'UT' => __( 'Uttarakhand', 'invoicing' ),
979
-        'UP' => __( 'Uttar Pradesh', 'invoicing' ),
980
-        'WB' => __( 'West Bengal', 'invoicing' ),
981
-        'AN' => __( 'Andaman and Nicobar Islands', 'invoicing' ),
982
-        'CH' => __( 'Chandigarh', 'invoicing' ),
983
-        'DN' => __( 'Dadar and Nagar Haveli', 'invoicing' ),
984
-        'DD' => __( 'Daman and Diu', 'invoicing' ),
985
-        'DL' => __( 'Delhi', 'invoicing' ),
986
-        'LD' => __( 'Lakshadweep', 'invoicing' ),
987
-        'PY' => __( 'Pondicherry (Puducherry)', 'invoicing' )
952
+        'AP' => __('Andhra Pradesh', 'invoicing'),
953
+        'AR' => __('Arunachal Pradesh', 'invoicing'),
954
+        'AS' => __('Assam', 'invoicing'),
955
+        'BR' => __('Bihar', 'invoicing'),
956
+        'CT' => __('Chhattisgarh', 'invoicing'),
957
+        'GA' => __('Goa', 'invoicing'),
958
+        'GJ' => __('Gujarat', 'invoicing'),
959
+        'HR' => __('Haryana', 'invoicing'),
960
+        'HP' => __('Himachal Pradesh', 'invoicing'),
961
+        'JK' => __('Jammu and Kashmir', 'invoicing'),
962
+        'JH' => __('Jharkhand', 'invoicing'),
963
+        'KA' => __('Karnataka', 'invoicing'),
964
+        'KL' => __('Kerala', 'invoicing'),
965
+        'MP' => __('Madhya Pradesh', 'invoicing'),
966
+        'MH' => __('Maharashtra', 'invoicing'),
967
+        'MN' => __('Manipur', 'invoicing'),
968
+        'ML' => __('Meghalaya', 'invoicing'),
969
+        'MZ' => __('Mizoram', 'invoicing'),
970
+        'NL' => __('Nagaland', 'invoicing'),
971
+        'OR' => __('Orissa', 'invoicing'),
972
+        'PB' => __('Punjab', 'invoicing'),
973
+        'RJ' => __('Rajasthan', 'invoicing'),
974
+        'SK' => __('Sikkim', 'invoicing'),
975
+        'TN' => __('Tamil Nadu', 'invoicing'),
976
+        'TG' => __('Telangana', 'invoicing'),
977
+        'TR' => __('Tripura', 'invoicing'),
978
+        'UT' => __('Uttarakhand', 'invoicing'),
979
+        'UP' => __('Uttar Pradesh', 'invoicing'),
980
+        'WB' => __('West Bengal', 'invoicing'),
981
+        'AN' => __('Andaman and Nicobar Islands', 'invoicing'),
982
+        'CH' => __('Chandigarh', 'invoicing'),
983
+        'DN' => __('Dadar and Nagar Haveli', 'invoicing'),
984
+        'DD' => __('Daman and Diu', 'invoicing'),
985
+        'DL' => __('Delhi', 'invoicing'),
986
+        'LD' => __('Lakshadweep', 'invoicing'),
987
+        'PY' => __('Pondicherry (Puducherry)', 'invoicing')
988 988
     );
989 989
 
990
-    return apply_filters( 'wpinv_india_states', $states );
990
+    return apply_filters('wpinv_india_states', $states);
991 991
 }
992 992
 
993 993
 function wpinv_get_iran_states_list() {
994 994
     $states = array(
995
-        'KHZ' => __( 'Khuzestan', 'invoicing' ),
996
-        'THR' => __( 'Tehran', 'invoicing' ),
997
-        'ILM' => __( 'Ilaam', 'invoicing' ),
998
-        'BHR' => __( 'Bushehr', 'invoicing' ),
999
-        'ADL' => __( 'Ardabil', 'invoicing' ),
1000
-        'ESF' => __( 'Isfahan', 'invoicing' ),
1001
-        'YZD' => __( 'Yazd', 'invoicing' ),
1002
-        'KRH' => __( 'Kermanshah', 'invoicing' ),
1003
-        'KRN' => __( 'Kerman', 'invoicing' ),
1004
-        'HDN' => __( 'Hamadan', 'invoicing' ),
1005
-        'GZN' => __( 'Ghazvin', 'invoicing' ),
1006
-        'ZJN' => __( 'Zanjan', 'invoicing' ),
1007
-        'LRS' => __( 'Luristan', 'invoicing' ),
1008
-        'ABZ' => __( 'Alborz', 'invoicing' ),
1009
-        'EAZ' => __( 'East Azerbaijan', 'invoicing' ),
1010
-        'WAZ' => __( 'West Azerbaijan', 'invoicing' ),
1011
-        'CHB' => __( 'Chaharmahal and Bakhtiari', 'invoicing' ),
1012
-        'SKH' => __( 'South Khorasan', 'invoicing' ),
1013
-        'RKH' => __( 'Razavi Khorasan', 'invoicing' ),
1014
-        'NKH' => __( 'North Khorasan', 'invoicing' ),
1015
-        'SMN' => __( 'Semnan', 'invoicing' ),
1016
-        'FRS' => __( 'Fars', 'invoicing' ),
1017
-        'QHM' => __( 'Qom', 'invoicing' ),
1018
-        'KRD' => __( 'Kurdistan', 'invoicing' ),
1019
-        'KBD' => __( 'Kohgiluyeh and BoyerAhmad', 'invoicing' ),
1020
-        'GLS' => __( 'Golestan', 'invoicing' ),
1021
-        'GIL' => __( 'Gilan', 'invoicing' ),
1022
-        'MZN' => __( 'Mazandaran', 'invoicing' ),
1023
-        'MKZ' => __( 'Markazi', 'invoicing' ),
1024
-        'HRZ' => __( 'Hormozgan', 'invoicing' ),
1025
-        'SBN' => __( 'Sistan and Baluchestan', 'invoicing' )
995
+        'KHZ' => __('Khuzestan', 'invoicing'),
996
+        'THR' => __('Tehran', 'invoicing'),
997
+        'ILM' => __('Ilaam', 'invoicing'),
998
+        'BHR' => __('Bushehr', 'invoicing'),
999
+        'ADL' => __('Ardabil', 'invoicing'),
1000
+        'ESF' => __('Isfahan', 'invoicing'),
1001
+        'YZD' => __('Yazd', 'invoicing'),
1002
+        'KRH' => __('Kermanshah', 'invoicing'),
1003
+        'KRN' => __('Kerman', 'invoicing'),
1004
+        'HDN' => __('Hamadan', 'invoicing'),
1005
+        'GZN' => __('Ghazvin', 'invoicing'),
1006
+        'ZJN' => __('Zanjan', 'invoicing'),
1007
+        'LRS' => __('Luristan', 'invoicing'),
1008
+        'ABZ' => __('Alborz', 'invoicing'),
1009
+        'EAZ' => __('East Azerbaijan', 'invoicing'),
1010
+        'WAZ' => __('West Azerbaijan', 'invoicing'),
1011
+        'CHB' => __('Chaharmahal and Bakhtiari', 'invoicing'),
1012
+        'SKH' => __('South Khorasan', 'invoicing'),
1013
+        'RKH' => __('Razavi Khorasan', 'invoicing'),
1014
+        'NKH' => __('North Khorasan', 'invoicing'),
1015
+        'SMN' => __('Semnan', 'invoicing'),
1016
+        'FRS' => __('Fars', 'invoicing'),
1017
+        'QHM' => __('Qom', 'invoicing'),
1018
+        'KRD' => __('Kurdistan', 'invoicing'),
1019
+        'KBD' => __('Kohgiluyeh and BoyerAhmad', 'invoicing'),
1020
+        'GLS' => __('Golestan', 'invoicing'),
1021
+        'GIL' => __('Gilan', 'invoicing'),
1022
+        'MZN' => __('Mazandaran', 'invoicing'),
1023
+        'MKZ' => __('Markazi', 'invoicing'),
1024
+        'HRZ' => __('Hormozgan', 'invoicing'),
1025
+        'SBN' => __('Sistan and Baluchestan', 'invoicing')
1026 1026
     );
1027 1027
 
1028
-    return apply_filters( 'wpinv_iran_states', $states );
1028
+    return apply_filters('wpinv_iran_states', $states);
1029 1029
 }
1030 1030
 
1031 1031
 function wpinv_get_italy_states_list() {
1032 1032
     $states = array(
1033
-        'AG' => __( 'Agrigento', 'invoicing' ),
1034
-        'AL' => __( 'Alessandria', 'invoicing' ),
1035
-        'AN' => __( 'Ancona', 'invoicing' ),
1036
-        'AO' => __( 'Aosta', 'invoicing' ),
1037
-        'AR' => __( 'Arezzo', 'invoicing' ),
1038
-        'AP' => __( 'Ascoli Piceno', 'invoicing' ),
1039
-        'AT' => __( 'Asti', 'invoicing' ),
1040
-        'AV' => __( 'Avellino', 'invoicing' ),
1041
-        'BA' => __( 'Bari', 'invoicing' ),
1042
-        'BT' => __( 'Barletta-Andria-Trani', 'invoicing' ),
1043
-        'BL' => __( 'Belluno', 'invoicing' ),
1044
-        'BN' => __( 'Benevento', 'invoicing' ),
1045
-        'BG' => __( 'Bergamo', 'invoicing' ),
1046
-        'BI' => __( 'Biella', 'invoicing' ),
1047
-        'BO' => __( 'Bologna', 'invoicing' ),
1048
-        'BZ' => __( 'Bolzano', 'invoicing' ),
1049
-        'BS' => __( 'Brescia', 'invoicing' ),
1050
-        'BR' => __( 'Brindisi', 'invoicing' ),
1051
-        'CA' => __( 'Cagliari', 'invoicing' ),
1052
-        'CL' => __( 'Caltanissetta', 'invoicing' ),
1053
-        'CB' => __( 'Campobasso', 'invoicing' ),
1054
-        'CI' => __( 'Caltanissetta', 'invoicing' ),
1055
-        'CE' => __( 'Caserta', 'invoicing' ),
1056
-        'CT' => __( 'Catania', 'invoicing' ),
1057
-        'CZ' => __( 'Catanzaro', 'invoicing' ),
1058
-        'CH' => __( 'Chieti', 'invoicing' ),
1059
-        'CO' => __( 'Como', 'invoicing' ),
1060
-        'CS' => __( 'Cosenza', 'invoicing' ),
1061
-        'CR' => __( 'Cremona', 'invoicing' ),
1062
-        'KR' => __( 'Crotone', 'invoicing' ),
1063
-        'CN' => __( 'Cuneo', 'invoicing' ),
1064
-        'EN' => __( 'Enna', 'invoicing' ),
1065
-        'FM' => __( 'Fermo', 'invoicing' ),
1066
-        'FE' => __( 'Ferrara', 'invoicing' ),
1067
-        'FI' => __( 'Firenze', 'invoicing' ),
1068
-        'FG' => __( 'Foggia', 'invoicing' ),
1069
-        'FC' => __( 'Forli-Cesena', 'invoicing' ),
1070
-        'FR' => __( 'Frosinone', 'invoicing' ),
1071
-        'GE' => __( 'Genova', 'invoicing' ),
1072
-        'GO' => __( 'Gorizia', 'invoicing' ),
1073
-        'GR' => __( 'Grosseto', 'invoicing' ),
1074
-        'IM' => __( 'Imperia', 'invoicing' ),
1075
-        'IS' => __( 'Isernia', 'invoicing' ),
1076
-        'SP' => __( 'La Spezia', 'invoicing' ),
1077
-        'AQ' => __( 'L&apos;Aquila', 'invoicing' ),
1078
-        'LT' => __( 'Latina', 'invoicing' ),
1079
-        'LE' => __( 'Lecce', 'invoicing' ),
1080
-        'LC' => __( 'Lecco', 'invoicing' ),
1081
-        'LI' => __( 'Livorno', 'invoicing' ),
1082
-        'LO' => __( 'Lodi', 'invoicing' ),
1083
-        'LU' => __( 'Lucca', 'invoicing' ),
1084
-        'MC' => __( 'Macerata', 'invoicing' ),
1085
-        'MN' => __( 'Mantova', 'invoicing' ),
1086
-        'MS' => __( 'Massa-Carrara', 'invoicing' ),
1087
-        'MT' => __( 'Matera', 'invoicing' ),
1088
-        'ME' => __( 'Messina', 'invoicing' ),
1089
-        'MI' => __( 'Milano', 'invoicing' ),
1090
-        'MO' => __( 'Modena', 'invoicing' ),
1091
-        'MB' => __( 'Monza e della Brianza', 'invoicing' ),
1092
-        'NA' => __( 'Napoli', 'invoicing' ),
1093
-        'NO' => __( 'Novara', 'invoicing' ),
1094
-        'NU' => __( 'Nuoro', 'invoicing' ),
1095
-        'OT' => __( 'Olbia-Tempio', 'invoicing' ),
1096
-        'OR' => __( 'Oristano', 'invoicing' ),
1097
-        'PD' => __( 'Padova', 'invoicing' ),
1098
-        'PA' => __( 'Palermo', 'invoicing' ),
1099
-        'PR' => __( 'Parma', 'invoicing' ),
1100
-        'PV' => __( 'Pavia', 'invoicing' ),
1101
-        'PG' => __( 'Perugia', 'invoicing' ),
1102
-        'PU' => __( 'Pesaro e Urbino', 'invoicing' ),
1103
-        'PE' => __( 'Pescara', 'invoicing' ),
1104
-        'PC' => __( 'Piacenza', 'invoicing' ),
1105
-        'PI' => __( 'Pisa', 'invoicing' ),
1106
-        'PT' => __( 'Pistoia', 'invoicing' ),
1107
-        'PN' => __( 'Pordenone', 'invoicing' ),
1108
-        'PZ' => __( 'Potenza', 'invoicing' ),
1109
-        'PO' => __( 'Prato', 'invoicing' ),
1110
-        'RG' => __( 'Ragusa', 'invoicing' ),
1111
-        'RA' => __( 'Ravenna', 'invoicing' ),
1112
-        'RC' => __( 'Reggio Calabria', 'invoicing' ),
1113
-        'RE' => __( 'Reggio Emilia', 'invoicing' ),
1114
-        'RI' => __( 'Rieti', 'invoicing' ),
1115
-        'RN' => __( 'Rimini', 'invoicing' ),
1116
-        'RM' => __( 'Roma', 'invoicing' ),
1117
-        'RO' => __( 'Rovigo', 'invoicing' ),
1118
-        'SA' => __( 'Salerno', 'invoicing' ),
1119
-        'VS' => __( 'Medio Campidano', 'invoicing' ),
1120
-        'SS' => __( 'Sassari', 'invoicing' ),
1121
-        'SV' => __( 'Savona', 'invoicing' ),
1122
-        'SI' => __( 'Siena', 'invoicing' ),
1123
-        'SR' => __( 'Siracusa', 'invoicing' ),
1124
-        'SO' => __( 'Sondrio', 'invoicing' ),
1125
-        'TA' => __( 'Taranto', 'invoicing' ),
1126
-        'TE' => __( 'Teramo', 'invoicing' ),
1127
-        'TR' => __( 'Terni', 'invoicing' ),
1128
-        'TO' => __( 'Torino', 'invoicing' ),
1129
-        'OG' => __( 'Ogliastra', 'invoicing' ),
1130
-        'TP' => __( 'Trapani', 'invoicing' ),
1131
-        'TN' => __( 'Trento', 'invoicing' ),
1132
-        'TV' => __( 'Treviso', 'invoicing' ),
1133
-        'TS' => __( 'Trieste', 'invoicing' ),
1134
-        'UD' => __( 'Udine', 'invoicing' ),
1135
-        'VA' => __( 'Varesa', 'invoicing' ),
1136
-        'VE' => __( 'Venezia', 'invoicing' ),
1137
-        'VB' => __( 'Verbano-Cusio-Ossola', 'invoicing' ),
1138
-        'VC' => __( 'Vercelli', 'invoicing' ),
1139
-        'VR' => __( 'Verona', 'invoicing' ),
1140
-        'VV' => __( 'Vibo Valentia', 'invoicing' ),
1141
-        'VI' => __( 'Vicenza', 'invoicing' ),
1142
-        'VT' => __( 'Viterbo', 'invoicing' )
1033
+        'AG' => __('Agrigento', 'invoicing'),
1034
+        'AL' => __('Alessandria', 'invoicing'),
1035
+        'AN' => __('Ancona', 'invoicing'),
1036
+        'AO' => __('Aosta', 'invoicing'),
1037
+        'AR' => __('Arezzo', 'invoicing'),
1038
+        'AP' => __('Ascoli Piceno', 'invoicing'),
1039
+        'AT' => __('Asti', 'invoicing'),
1040
+        'AV' => __('Avellino', 'invoicing'),
1041
+        'BA' => __('Bari', 'invoicing'),
1042
+        'BT' => __('Barletta-Andria-Trani', 'invoicing'),
1043
+        'BL' => __('Belluno', 'invoicing'),
1044
+        'BN' => __('Benevento', 'invoicing'),
1045
+        'BG' => __('Bergamo', 'invoicing'),
1046
+        'BI' => __('Biella', 'invoicing'),
1047
+        'BO' => __('Bologna', 'invoicing'),
1048
+        'BZ' => __('Bolzano', 'invoicing'),
1049
+        'BS' => __('Brescia', 'invoicing'),
1050
+        'BR' => __('Brindisi', 'invoicing'),
1051
+        'CA' => __('Cagliari', 'invoicing'),
1052
+        'CL' => __('Caltanissetta', 'invoicing'),
1053
+        'CB' => __('Campobasso', 'invoicing'),
1054
+        'CI' => __('Caltanissetta', 'invoicing'),
1055
+        'CE' => __('Caserta', 'invoicing'),
1056
+        'CT' => __('Catania', 'invoicing'),
1057
+        'CZ' => __('Catanzaro', 'invoicing'),
1058
+        'CH' => __('Chieti', 'invoicing'),
1059
+        'CO' => __('Como', 'invoicing'),
1060
+        'CS' => __('Cosenza', 'invoicing'),
1061
+        'CR' => __('Cremona', 'invoicing'),
1062
+        'KR' => __('Crotone', 'invoicing'),
1063
+        'CN' => __('Cuneo', 'invoicing'),
1064
+        'EN' => __('Enna', 'invoicing'),
1065
+        'FM' => __('Fermo', 'invoicing'),
1066
+        'FE' => __('Ferrara', 'invoicing'),
1067
+        'FI' => __('Firenze', 'invoicing'),
1068
+        'FG' => __('Foggia', 'invoicing'),
1069
+        'FC' => __('Forli-Cesena', 'invoicing'),
1070
+        'FR' => __('Frosinone', 'invoicing'),
1071
+        'GE' => __('Genova', 'invoicing'),
1072
+        'GO' => __('Gorizia', 'invoicing'),
1073
+        'GR' => __('Grosseto', 'invoicing'),
1074
+        'IM' => __('Imperia', 'invoicing'),
1075
+        'IS' => __('Isernia', 'invoicing'),
1076
+        'SP' => __('La Spezia', 'invoicing'),
1077
+        'AQ' => __('L&apos;Aquila', 'invoicing'),
1078
+        'LT' => __('Latina', 'invoicing'),
1079
+        'LE' => __('Lecce', 'invoicing'),
1080
+        'LC' => __('Lecco', 'invoicing'),
1081
+        'LI' => __('Livorno', 'invoicing'),
1082
+        'LO' => __('Lodi', 'invoicing'),
1083
+        'LU' => __('Lucca', 'invoicing'),
1084
+        'MC' => __('Macerata', 'invoicing'),
1085
+        'MN' => __('Mantova', 'invoicing'),
1086
+        'MS' => __('Massa-Carrara', 'invoicing'),
1087
+        'MT' => __('Matera', 'invoicing'),
1088
+        'ME' => __('Messina', 'invoicing'),
1089
+        'MI' => __('Milano', 'invoicing'),
1090
+        'MO' => __('Modena', 'invoicing'),
1091
+        'MB' => __('Monza e della Brianza', 'invoicing'),
1092
+        'NA' => __('Napoli', 'invoicing'),
1093
+        'NO' => __('Novara', 'invoicing'),
1094
+        'NU' => __('Nuoro', 'invoicing'),
1095
+        'OT' => __('Olbia-Tempio', 'invoicing'),
1096
+        'OR' => __('Oristano', 'invoicing'),
1097
+        'PD' => __('Padova', 'invoicing'),
1098
+        'PA' => __('Palermo', 'invoicing'),
1099
+        'PR' => __('Parma', 'invoicing'),
1100
+        'PV' => __('Pavia', 'invoicing'),
1101
+        'PG' => __('Perugia', 'invoicing'),
1102
+        'PU' => __('Pesaro e Urbino', 'invoicing'),
1103
+        'PE' => __('Pescara', 'invoicing'),
1104
+        'PC' => __('Piacenza', 'invoicing'),
1105
+        'PI' => __('Pisa', 'invoicing'),
1106
+        'PT' => __('Pistoia', 'invoicing'),
1107
+        'PN' => __('Pordenone', 'invoicing'),
1108
+        'PZ' => __('Potenza', 'invoicing'),
1109
+        'PO' => __('Prato', 'invoicing'),
1110
+        'RG' => __('Ragusa', 'invoicing'),
1111
+        'RA' => __('Ravenna', 'invoicing'),
1112
+        'RC' => __('Reggio Calabria', 'invoicing'),
1113
+        'RE' => __('Reggio Emilia', 'invoicing'),
1114
+        'RI' => __('Rieti', 'invoicing'),
1115
+        'RN' => __('Rimini', 'invoicing'),
1116
+        'RM' => __('Roma', 'invoicing'),
1117
+        'RO' => __('Rovigo', 'invoicing'),
1118
+        'SA' => __('Salerno', 'invoicing'),
1119
+        'VS' => __('Medio Campidano', 'invoicing'),
1120
+        'SS' => __('Sassari', 'invoicing'),
1121
+        'SV' => __('Savona', 'invoicing'),
1122
+        'SI' => __('Siena', 'invoicing'),
1123
+        'SR' => __('Siracusa', 'invoicing'),
1124
+        'SO' => __('Sondrio', 'invoicing'),
1125
+        'TA' => __('Taranto', 'invoicing'),
1126
+        'TE' => __('Teramo', 'invoicing'),
1127
+        'TR' => __('Terni', 'invoicing'),
1128
+        'TO' => __('Torino', 'invoicing'),
1129
+        'OG' => __('Ogliastra', 'invoicing'),
1130
+        'TP' => __('Trapani', 'invoicing'),
1131
+        'TN' => __('Trento', 'invoicing'),
1132
+        'TV' => __('Treviso', 'invoicing'),
1133
+        'TS' => __('Trieste', 'invoicing'),
1134
+        'UD' => __('Udine', 'invoicing'),
1135
+        'VA' => __('Varesa', 'invoicing'),
1136
+        'VE' => __('Venezia', 'invoicing'),
1137
+        'VB' => __('Verbano-Cusio-Ossola', 'invoicing'),
1138
+        'VC' => __('Vercelli', 'invoicing'),
1139
+        'VR' => __('Verona', 'invoicing'),
1140
+        'VV' => __('Vibo Valentia', 'invoicing'),
1141
+        'VI' => __('Vicenza', 'invoicing'),
1142
+        'VT' => __('Viterbo', 'invoicing')
1143 1143
     );
1144 1144
 
1145
-    return apply_filters( 'wpinv_italy_states', $states );
1145
+    return apply_filters('wpinv_italy_states', $states);
1146 1146
 }
1147 1147
 
1148 1148
 function wpinv_get_malaysia_states_list() {
1149 1149
     $states = array(
1150
-        'JHR' => __( 'Johor', 'invoicing' ),
1151
-        'KDH' => __( 'Kedah', 'invoicing' ),
1152
-        'KTN' => __( 'Kelantan', 'invoicing' ),
1153
-        'MLK' => __( 'Melaka', 'invoicing' ),
1154
-        'NSN' => __( 'Negeri Sembilan', 'invoicing' ),
1155
-        'PHG' => __( 'Pahang', 'invoicing' ),
1156
-        'PRK' => __( 'Perak', 'invoicing' ),
1157
-        'PLS' => __( 'Perlis', 'invoicing' ),
1158
-        'PNG' => __( 'Pulau Pinang', 'invoicing' ),
1159
-        'SBH' => __( 'Sabah', 'invoicing' ),
1160
-        'SWK' => __( 'Sarawak', 'invoicing' ),
1161
-        'SGR' => __( 'Selangor', 'invoicing' ),
1162
-        'TRG' => __( 'Terengganu', 'invoicing' ),
1163
-        'KUL' => __( 'W.P. Kuala Lumpur', 'invoicing' ),
1164
-        'LBN' => __( 'W.P. Labuan', 'invoicing' ),
1165
-        'PJY' => __( 'W.P. Putrajaya', 'invoicing' )
1150
+        'JHR' => __('Johor', 'invoicing'),
1151
+        'KDH' => __('Kedah', 'invoicing'),
1152
+        'KTN' => __('Kelantan', 'invoicing'),
1153
+        'MLK' => __('Melaka', 'invoicing'),
1154
+        'NSN' => __('Negeri Sembilan', 'invoicing'),
1155
+        'PHG' => __('Pahang', 'invoicing'),
1156
+        'PRK' => __('Perak', 'invoicing'),
1157
+        'PLS' => __('Perlis', 'invoicing'),
1158
+        'PNG' => __('Pulau Pinang', 'invoicing'),
1159
+        'SBH' => __('Sabah', 'invoicing'),
1160
+        'SWK' => __('Sarawak', 'invoicing'),
1161
+        'SGR' => __('Selangor', 'invoicing'),
1162
+        'TRG' => __('Terengganu', 'invoicing'),
1163
+        'KUL' => __('W.P. Kuala Lumpur', 'invoicing'),
1164
+        'LBN' => __('W.P. Labuan', 'invoicing'),
1165
+        'PJY' => __('W.P. Putrajaya', 'invoicing')
1166 1166
     );
1167 1167
 
1168
-    return apply_filters( 'wpinv_malaysia_states', $states );
1168
+    return apply_filters('wpinv_malaysia_states', $states);
1169 1169
 }
1170 1170
 
1171 1171
 function wpinv_get_mexico_states_list() {
1172 1172
     $states = array(
1173
-        'DIF' => __( 'Distrito Federal', 'invoicing' ),
1174
-        'JAL' => __( 'Jalisco', 'invoicing' ),
1175
-        'NLE' => __( 'Nuevo Le&oacute;n', 'invoicing' ),
1176
-        'AGU' => __( 'Aguascalientes', 'invoicing' ),
1177
-        'BCN' => __( 'Baja California Norte', 'invoicing' ),
1178
-        'BCS' => __( 'Baja California Sur', 'invoicing' ),
1179
-        'CAM' => __( 'Campeche', 'invoicing' ),
1180
-        'CHP' => __( 'Chiapas', 'invoicing' ),
1181
-        'CHH' => __( 'Chihuahua', 'invoicing' ),
1182
-        'COA' => __( 'Coahuila', 'invoicing' ),
1183
-        'COL' => __( 'Colima', 'invoicing' ),
1184
-        'DUR' => __( 'Durango', 'invoicing' ),
1185
-        'GUA' => __( 'Guanajuato', 'invoicing' ),
1186
-        'GRO' => __( 'Guerrero', 'invoicing' ),
1187
-        'HID' => __( 'Hidalgo', 'invoicing' ),
1188
-        'MEX' => __( 'Edo. de M&eacute;xico', 'invoicing' ),
1189
-        'MIC' => __( 'Michoac&aacute;n', 'invoicing' ),
1190
-        'MOR' => __( 'Morelos', 'invoicing' ),
1191
-        'NAY' => __( 'Nayarit', 'invoicing' ),
1192
-        'OAX' => __( 'Oaxaca', 'invoicing' ),
1193
-        'PUE' => __( 'Puebla', 'invoicing' ),
1194
-        'QUE' => __( 'Quer&eacute;taro', 'invoicing' ),
1195
-        'ROO' => __( 'Quintana Roo', 'invoicing' ),
1196
-        'SLP' => __( 'San Luis Potos&iacute;', 'invoicing' ),
1197
-        'SIN' => __( 'Sinaloa', 'invoicing' ),
1198
-        'SON' => __( 'Sonora', 'invoicing' ),
1199
-        'TAB' => __( 'Tabasco', 'invoicing' ),
1200
-        'TAM' => __( 'Tamaulipas', 'invoicing' ),
1201
-        'TLA' => __( 'Tlaxcala', 'invoicing' ),
1202
-        'VER' => __( 'Veracruz', 'invoicing' ),
1203
-        'YUC' => __( 'Yucat&aacute;n', 'invoicing' ),
1204
-        'ZAC' => __( 'Zacatecas', 'invoicing' )
1173
+        'DIF' => __('Distrito Federal', 'invoicing'),
1174
+        'JAL' => __('Jalisco', 'invoicing'),
1175
+        'NLE' => __('Nuevo Le&oacute;n', 'invoicing'),
1176
+        'AGU' => __('Aguascalientes', 'invoicing'),
1177
+        'BCN' => __('Baja California Norte', 'invoicing'),
1178
+        'BCS' => __('Baja California Sur', 'invoicing'),
1179
+        'CAM' => __('Campeche', 'invoicing'),
1180
+        'CHP' => __('Chiapas', 'invoicing'),
1181
+        'CHH' => __('Chihuahua', 'invoicing'),
1182
+        'COA' => __('Coahuila', 'invoicing'),
1183
+        'COL' => __('Colima', 'invoicing'),
1184
+        'DUR' => __('Durango', 'invoicing'),
1185
+        'GUA' => __('Guanajuato', 'invoicing'),
1186
+        'GRO' => __('Guerrero', 'invoicing'),
1187
+        'HID' => __('Hidalgo', 'invoicing'),
1188
+        'MEX' => __('Edo. de M&eacute;xico', 'invoicing'),
1189
+        'MIC' => __('Michoac&aacute;n', 'invoicing'),
1190
+        'MOR' => __('Morelos', 'invoicing'),
1191
+        'NAY' => __('Nayarit', 'invoicing'),
1192
+        'OAX' => __('Oaxaca', 'invoicing'),
1193
+        'PUE' => __('Puebla', 'invoicing'),
1194
+        'QUE' => __('Quer&eacute;taro', 'invoicing'),
1195
+        'ROO' => __('Quintana Roo', 'invoicing'),
1196
+        'SLP' => __('San Luis Potos&iacute;', 'invoicing'),
1197
+        'SIN' => __('Sinaloa', 'invoicing'),
1198
+        'SON' => __('Sonora', 'invoicing'),
1199
+        'TAB' => __('Tabasco', 'invoicing'),
1200
+        'TAM' => __('Tamaulipas', 'invoicing'),
1201
+        'TLA' => __('Tlaxcala', 'invoicing'),
1202
+        'VER' => __('Veracruz', 'invoicing'),
1203
+        'YUC' => __('Yucat&aacute;n', 'invoicing'),
1204
+        'ZAC' => __('Zacatecas', 'invoicing')
1205 1205
     );
1206 1206
 
1207
-    return apply_filters( 'wpinv_mexico_states', $states );
1207
+    return apply_filters('wpinv_mexico_states', $states);
1208 1208
 }
1209 1209
 
1210 1210
 function wpinv_get_nepal_states_list() {
1211 1211
     $states = array(
1212
-        'ILL' => __( 'Illam', 'invoicing' ),
1213
-        'JHA' => __( 'Jhapa', 'invoicing' ),
1214
-        'PAN' => __( 'Panchthar', 'invoicing' ),
1215
-        'TAP' => __( 'Taplejung', 'invoicing' ),
1216
-        'BHO' => __( 'Bhojpur', 'invoicing' ),
1217
-        'DKA' => __( 'Dhankuta', 'invoicing' ),
1218
-        'MOR' => __( 'Morang', 'invoicing' ),
1219
-        'SUN' => __( 'Sunsari', 'invoicing' ),
1220
-        'SAN' => __( 'Sankhuwa', 'invoicing' ),
1221
-        'TER' => __( 'Terhathum', 'invoicing' ),
1222
-        'KHO' => __( 'Khotang', 'invoicing' ),
1223
-        'OKH' => __( 'Okhaldhunga', 'invoicing' ),
1224
-        'SAP' => __( 'Saptari', 'invoicing' ),
1225
-        'SIR' => __( 'Siraha', 'invoicing' ),
1226
-        'SOL' => __( 'Solukhumbu', 'invoicing' ),
1227
-        'UDA' => __( 'Udayapur', 'invoicing' ),
1228
-        'DHA' => __( 'Dhanusa', 'invoicing' ),
1229
-        'DLK' => __( 'Dolakha', 'invoicing' ),
1230
-        'MOH' => __( 'Mohottari', 'invoicing' ),
1231
-        'RAM' => __( 'Ramechha', 'invoicing' ),
1232
-        'SAR' => __( 'Sarlahi', 'invoicing' ),
1233
-        'SIN' => __( 'Sindhuli', 'invoicing' ),
1234
-        'BHA' => __( 'Bhaktapur', 'invoicing' ),
1235
-        'DHD' => __( 'Dhading', 'invoicing' ),
1236
-        'KTM' => __( 'Kathmandu', 'invoicing' ),
1237
-        'KAV' => __( 'Kavrepalanchowk', 'invoicing' ),
1238
-        'LAL' => __( 'Lalitpur', 'invoicing' ),
1239
-        'NUW' => __( 'Nuwakot', 'invoicing' ),
1240
-        'RAS' => __( 'Rasuwa', 'invoicing' ),
1241
-        'SPC' => __( 'Sindhupalchowk', 'invoicing' ),
1242
-        'BAR' => __( 'Bara', 'invoicing' ),
1243
-        'CHI' => __( 'Chitwan', 'invoicing' ),
1244
-        'MAK' => __( 'Makwanpur', 'invoicing' ),
1245
-        'PAR' => __( 'Parsa', 'invoicing' ),
1246
-        'RAU' => __( 'Rautahat', 'invoicing' ),
1247
-        'GOR' => __( 'Gorkha', 'invoicing' ),
1248
-        'KAS' => __( 'Kaski', 'invoicing' ),
1249
-        'LAM' => __( 'Lamjung', 'invoicing' ),
1250
-        'MAN' => __( 'Manang', 'invoicing' ),
1251
-        'SYN' => __( 'Syangja', 'invoicing' ),
1252
-        'TAN' => __( 'Tanahun', 'invoicing' ),
1253
-        'BAG' => __( 'Baglung', 'invoicing' ),
1254
-        'PBT' => __( 'Parbat', 'invoicing' ),
1255
-        'MUS' => __( 'Mustang', 'invoicing' ),
1256
-        'MYG' => __( 'Myagdi', 'invoicing' ),
1257
-        'AGR' => __( 'Agrghakanchi', 'invoicing' ),
1258
-        'GUL' => __( 'Gulmi', 'invoicing' ),
1259
-        'KAP' => __( 'Kapilbastu', 'invoicing' ),
1260
-        'NAW' => __( 'Nawalparasi', 'invoicing' ),
1261
-        'PAL' => __( 'Palpa', 'invoicing' ),
1262
-        'RUP' => __( 'Rupandehi', 'invoicing' ),
1263
-        'DAN' => __( 'Dang', 'invoicing' ),
1264
-        'PYU' => __( 'Pyuthan', 'invoicing' ),
1265
-        'ROL' => __( 'Rolpa', 'invoicing' ),
1266
-        'RUK' => __( 'Rukum', 'invoicing' ),
1267
-        'SAL' => __( 'Salyan', 'invoicing' ),
1268
-        'BAN' => __( 'Banke', 'invoicing' ),
1269
-        'BDA' => __( 'Bardiya', 'invoicing' ),
1270
-        'DAI' => __( 'Dailekh', 'invoicing' ),
1271
-        'JAJ' => __( 'Jajarkot', 'invoicing' ),
1272
-        'SUR' => __( 'Surkhet', 'invoicing' ),
1273
-        'DOL' => __( 'Dolpa', 'invoicing' ),
1274
-        'HUM' => __( 'Humla', 'invoicing' ),
1275
-        'JUM' => __( 'Jumla', 'invoicing' ),
1276
-        'KAL' => __( 'Kalikot', 'invoicing' ),
1277
-        'MUG' => __( 'Mugu', 'invoicing' ),
1278
-        'ACH' => __( 'Achham', 'invoicing' ),
1279
-        'BJH' => __( 'Bajhang', 'invoicing' ),
1280
-        'BJU' => __( 'Bajura', 'invoicing' ),
1281
-        'DOT' => __( 'Doti', 'invoicing' ),
1282
-        'KAI' => __( 'Kailali', 'invoicing' ),
1283
-        'BAI' => __( 'Baitadi', 'invoicing' ),
1284
-        'DAD' => __( 'Dadeldhura', 'invoicing' ),
1285
-        'DAR' => __( 'Darchula', 'invoicing' ),
1286
-        'KAN' => __( 'Kanchanpur', 'invoicing' )
1212
+        'ILL' => __('Illam', 'invoicing'),
1213
+        'JHA' => __('Jhapa', 'invoicing'),
1214
+        'PAN' => __('Panchthar', 'invoicing'),
1215
+        'TAP' => __('Taplejung', 'invoicing'),
1216
+        'BHO' => __('Bhojpur', 'invoicing'),
1217
+        'DKA' => __('Dhankuta', 'invoicing'),
1218
+        'MOR' => __('Morang', 'invoicing'),
1219
+        'SUN' => __('Sunsari', 'invoicing'),
1220
+        'SAN' => __('Sankhuwa', 'invoicing'),
1221
+        'TER' => __('Terhathum', 'invoicing'),
1222
+        'KHO' => __('Khotang', 'invoicing'),
1223
+        'OKH' => __('Okhaldhunga', 'invoicing'),
1224
+        'SAP' => __('Saptari', 'invoicing'),
1225
+        'SIR' => __('Siraha', 'invoicing'),
1226
+        'SOL' => __('Solukhumbu', 'invoicing'),
1227
+        'UDA' => __('Udayapur', 'invoicing'),
1228
+        'DHA' => __('Dhanusa', 'invoicing'),
1229
+        'DLK' => __('Dolakha', 'invoicing'),
1230
+        'MOH' => __('Mohottari', 'invoicing'),
1231
+        'RAM' => __('Ramechha', 'invoicing'),
1232
+        'SAR' => __('Sarlahi', 'invoicing'),
1233
+        'SIN' => __('Sindhuli', 'invoicing'),
1234
+        'BHA' => __('Bhaktapur', 'invoicing'),
1235
+        'DHD' => __('Dhading', 'invoicing'),
1236
+        'KTM' => __('Kathmandu', 'invoicing'),
1237
+        'KAV' => __('Kavrepalanchowk', 'invoicing'),
1238
+        'LAL' => __('Lalitpur', 'invoicing'),
1239
+        'NUW' => __('Nuwakot', 'invoicing'),
1240
+        'RAS' => __('Rasuwa', 'invoicing'),
1241
+        'SPC' => __('Sindhupalchowk', 'invoicing'),
1242
+        'BAR' => __('Bara', 'invoicing'),
1243
+        'CHI' => __('Chitwan', 'invoicing'),
1244
+        'MAK' => __('Makwanpur', 'invoicing'),
1245
+        'PAR' => __('Parsa', 'invoicing'),
1246
+        'RAU' => __('Rautahat', 'invoicing'),
1247
+        'GOR' => __('Gorkha', 'invoicing'),
1248
+        'KAS' => __('Kaski', 'invoicing'),
1249
+        'LAM' => __('Lamjung', 'invoicing'),
1250
+        'MAN' => __('Manang', 'invoicing'),
1251
+        'SYN' => __('Syangja', 'invoicing'),
1252
+        'TAN' => __('Tanahun', 'invoicing'),
1253
+        'BAG' => __('Baglung', 'invoicing'),
1254
+        'PBT' => __('Parbat', 'invoicing'),
1255
+        'MUS' => __('Mustang', 'invoicing'),
1256
+        'MYG' => __('Myagdi', 'invoicing'),
1257
+        'AGR' => __('Agrghakanchi', 'invoicing'),
1258
+        'GUL' => __('Gulmi', 'invoicing'),
1259
+        'KAP' => __('Kapilbastu', 'invoicing'),
1260
+        'NAW' => __('Nawalparasi', 'invoicing'),
1261
+        'PAL' => __('Palpa', 'invoicing'),
1262
+        'RUP' => __('Rupandehi', 'invoicing'),
1263
+        'DAN' => __('Dang', 'invoicing'),
1264
+        'PYU' => __('Pyuthan', 'invoicing'),
1265
+        'ROL' => __('Rolpa', 'invoicing'),
1266
+        'RUK' => __('Rukum', 'invoicing'),
1267
+        'SAL' => __('Salyan', 'invoicing'),
1268
+        'BAN' => __('Banke', 'invoicing'),
1269
+        'BDA' => __('Bardiya', 'invoicing'),
1270
+        'DAI' => __('Dailekh', 'invoicing'),
1271
+        'JAJ' => __('Jajarkot', 'invoicing'),
1272
+        'SUR' => __('Surkhet', 'invoicing'),
1273
+        'DOL' => __('Dolpa', 'invoicing'),
1274
+        'HUM' => __('Humla', 'invoicing'),
1275
+        'JUM' => __('Jumla', 'invoicing'),
1276
+        'KAL' => __('Kalikot', 'invoicing'),
1277
+        'MUG' => __('Mugu', 'invoicing'),
1278
+        'ACH' => __('Achham', 'invoicing'),
1279
+        'BJH' => __('Bajhang', 'invoicing'),
1280
+        'BJU' => __('Bajura', 'invoicing'),
1281
+        'DOT' => __('Doti', 'invoicing'),
1282
+        'KAI' => __('Kailali', 'invoicing'),
1283
+        'BAI' => __('Baitadi', 'invoicing'),
1284
+        'DAD' => __('Dadeldhura', 'invoicing'),
1285
+        'DAR' => __('Darchula', 'invoicing'),
1286
+        'KAN' => __('Kanchanpur', 'invoicing')
1287 1287
     );
1288 1288
 
1289
-    return apply_filters( 'wpinv_nepal_states', $states );
1289
+    return apply_filters('wpinv_nepal_states', $states);
1290 1290
 }
1291 1291
 
1292 1292
 function wpinv_get_south_africa_states_list() {
1293 1293
     $states = array(
1294
-        'EC'  => __( 'Eastern Cape', 'invoicing' ),
1295
-        'FS'  => __( 'Free State', 'invoicing' ),
1296
-        'GP'  => __( 'Gauteng', 'invoicing' ),
1297
-        'KZN' => __( 'KwaZulu-Natal', 'invoicing' ),
1298
-        'LP'  => __( 'Limpopo', 'invoicing' ),
1299
-        'MP'  => __( 'Mpumalanga', 'invoicing' ),
1300
-        'NC'  => __( 'Northern Cape', 'invoicing' ),
1301
-        'NW'  => __( 'North West', 'invoicing' ),
1302
-        'WC'  => __( 'Western Cape', 'invoicing' )
1294
+        'EC'  => __('Eastern Cape', 'invoicing'),
1295
+        'FS'  => __('Free State', 'invoicing'),
1296
+        'GP'  => __('Gauteng', 'invoicing'),
1297
+        'KZN' => __('KwaZulu-Natal', 'invoicing'),
1298
+        'LP'  => __('Limpopo', 'invoicing'),
1299
+        'MP'  => __('Mpumalanga', 'invoicing'),
1300
+        'NC'  => __('Northern Cape', 'invoicing'),
1301
+        'NW'  => __('North West', 'invoicing'),
1302
+        'WC'  => __('Western Cape', 'invoicing')
1303 1303
     );
1304 1304
 
1305
-    return apply_filters( 'wpinv_south_africa_states', $states );
1305
+    return apply_filters('wpinv_south_africa_states', $states);
1306 1306
 }
1307 1307
 
1308 1308
 function wpinv_get_thailand_states_list() {
1309 1309
     $states = array(
1310
-        'TH-37' => __( 'Amnat Charoen (&#3629;&#3635;&#3609;&#3634;&#3592;&#3648;&#3592;&#3619;&#3636;&#3597;)', 'invoicing' ),
1311
-        'TH-15' => __( 'Ang Thong (&#3629;&#3656;&#3634;&#3591;&#3607;&#3629;&#3591;)', 'invoicing' ),
1312
-        'TH-14' => __( 'Ayutthaya (&#3614;&#3619;&#3632;&#3609;&#3588;&#3619;&#3624;&#3619;&#3637;&#3629;&#3618;&#3640;&#3608;&#3618;&#3634;)', 'invoicing' ),
1313
-        'TH-10' => __( 'Bangkok (&#3585;&#3619;&#3640;&#3591;&#3648;&#3607;&#3614;&#3617;&#3627;&#3634;&#3609;&#3588;&#3619;)', 'invoicing' ),
1314
-        'TH-38' => __( 'Bueng Kan (&#3610;&#3638;&#3591;&#3585;&#3634;&#3628;)', 'invoicing' ),
1315
-        'TH-31' => __( 'Buri Ram (&#3610;&#3640;&#3619;&#3637;&#3619;&#3633;&#3617;&#3618;&#3660;)', 'invoicing' ),
1316
-        'TH-24' => __( 'Chachoengsao (&#3593;&#3632;&#3648;&#3594;&#3636;&#3591;&#3648;&#3607;&#3619;&#3634;)', 'invoicing' ),
1317
-        'TH-18' => __( 'Chai Nat (&#3594;&#3633;&#3618;&#3609;&#3634;&#3607;)', 'invoicing' ),
1318
-        'TH-36' => __( 'Chaiyaphum (&#3594;&#3633;&#3618;&#3616;&#3641;&#3617;&#3636;)', 'invoicing' ),
1319
-        'TH-22' => __( 'Chanthaburi (&#3592;&#3633;&#3609;&#3607;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1320
-        'TH-50' => __( 'Chiang Mai (&#3648;&#3594;&#3637;&#3618;&#3591;&#3651;&#3627;&#3617;&#3656;)', 'invoicing' ),
1321
-        'TH-57' => __( 'Chiang Rai (&#3648;&#3594;&#3637;&#3618;&#3591;&#3619;&#3634;&#3618;)', 'invoicing' ),
1322
-        'TH-20' => __( 'Chonburi (&#3594;&#3621;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1323
-        'TH-86' => __( 'Chumphon (&#3594;&#3640;&#3617;&#3614;&#3619;)', 'invoicing' ),
1324
-        'TH-46' => __( 'Kalasin (&#3585;&#3634;&#3628;&#3626;&#3636;&#3609;&#3608;&#3640;&#3660;)', 'invoicing' ),
1325
-        'TH-62' => __( 'Kamphaeng Phet (&#3585;&#3635;&#3649;&#3614;&#3591;&#3648;&#3614;&#3594;&#3619;)', 'invoicing' ),
1326
-        'TH-71' => __( 'Kanchanaburi (&#3585;&#3634;&#3597;&#3592;&#3609;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1327
-        'TH-40' => __( 'Khon Kaen (&#3586;&#3629;&#3609;&#3649;&#3585;&#3656;&#3609;)', 'invoicing' ),
1328
-        'TH-81' => __( 'Krabi (&#3585;&#3619;&#3632;&#3610;&#3637;&#3656;)', 'invoicing' ),
1329
-        'TH-52' => __( 'Lampang (&#3621;&#3635;&#3611;&#3634;&#3591;)', 'invoicing' ),
1330
-        'TH-51' => __( 'Lamphun (&#3621;&#3635;&#3614;&#3641;&#3609;)', 'invoicing' ),
1331
-        'TH-42' => __( 'Loei (&#3648;&#3621;&#3618;)', 'invoicing' ),
1332
-        'TH-16' => __( 'Lopburi (&#3621;&#3614;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1333
-        'TH-58' => __( 'Mae Hong Son (&#3649;&#3617;&#3656;&#3630;&#3656;&#3629;&#3591;&#3626;&#3629;&#3609;)', 'invoicing' ),
1334
-        'TH-44' => __( 'Maha Sarakham (&#3617;&#3627;&#3634;&#3626;&#3634;&#3619;&#3588;&#3634;&#3617;)', 'invoicing' ),
1335
-        'TH-49' => __( 'Mukdahan (&#3617;&#3640;&#3585;&#3604;&#3634;&#3627;&#3634;&#3619;)', 'invoicing' ),
1336
-        'TH-26' => __( 'Nakhon Nayok (&#3609;&#3588;&#3619;&#3609;&#3634;&#3618;&#3585;)', 'invoicing' ),
1337
-        'TH-73' => __( 'Nakhon Pathom (&#3609;&#3588;&#3619;&#3611;&#3600;&#3617;)', 'invoicing' ),
1338
-        'TH-48' => __( 'Nakhon Phanom (&#3609;&#3588;&#3619;&#3614;&#3609;&#3617;)', 'invoicing' ),
1339
-        'TH-30' => __( 'Nakhon Ratchasima (&#3609;&#3588;&#3619;&#3619;&#3634;&#3594;&#3626;&#3637;&#3617;&#3634;)', 'invoicing' ),
1340
-        'TH-60' => __( 'Nakhon Sawan (&#3609;&#3588;&#3619;&#3626;&#3623;&#3619;&#3619;&#3588;&#3660;)', 'invoicing' ),
1341
-        'TH-80' => __( 'Nakhon Si Thammarat (&#3609;&#3588;&#3619;&#3624;&#3619;&#3637;&#3608;&#3619;&#3619;&#3617;&#3619;&#3634;&#3594;)', 'invoicing' ),
1342
-        'TH-55' => __( 'Nan (&#3609;&#3656;&#3634;&#3609;)', 'invoicing' ),
1343
-        'TH-96' => __( 'Narathiwat (&#3609;&#3619;&#3634;&#3608;&#3636;&#3623;&#3634;&#3626;)', 'invoicing' ),
1344
-        'TH-39' => __( 'Nong Bua Lam Phu (&#3627;&#3609;&#3629;&#3591;&#3610;&#3633;&#3623;&#3621;&#3635;&#3616;&#3641;)', 'invoicing' ),
1345
-        'TH-43' => __( 'Nong Khai (&#3627;&#3609;&#3629;&#3591;&#3588;&#3634;&#3618;)', 'invoicing' ),
1346
-        'TH-12' => __( 'Nonthaburi (&#3609;&#3609;&#3607;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1347
-        'TH-13' => __( 'Pathum Thani (&#3611;&#3607;&#3640;&#3617;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1348
-        'TH-94' => __( 'Pattani (&#3611;&#3633;&#3605;&#3605;&#3634;&#3609;&#3637;)', 'invoicing' ),
1349
-        'TH-82' => __( 'Phang Nga (&#3614;&#3633;&#3591;&#3591;&#3634;)', 'invoicing' ),
1350
-        'TH-93' => __( 'Phatthalung (&#3614;&#3633;&#3607;&#3621;&#3640;&#3591;)', 'invoicing' ),
1351
-        'TH-56' => __( 'Phayao (&#3614;&#3632;&#3648;&#3618;&#3634;)', 'invoicing' ),
1352
-        'TH-67' => __( 'Phetchabun (&#3648;&#3614;&#3594;&#3619;&#3610;&#3641;&#3619;&#3603;&#3660;)', 'invoicing' ),
1353
-        'TH-76' => __( 'Phetchaburi (&#3648;&#3614;&#3594;&#3619;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1354
-        'TH-66' => __( 'Phichit (&#3614;&#3636;&#3592;&#3636;&#3605;&#3619;)', 'invoicing' ),
1355
-        'TH-65' => __( 'Phitsanulok (&#3614;&#3636;&#3625;&#3603;&#3640;&#3650;&#3621;&#3585;)', 'invoicing' ),
1356
-        'TH-54' => __( 'Phrae (&#3649;&#3614;&#3619;&#3656;)', 'invoicing' ),
1357
-        'TH-83' => __( 'Phuket (&#3616;&#3641;&#3648;&#3585;&#3655;&#3605;)', 'invoicing' ),
1358
-        'TH-25' => __( 'Prachin Buri (&#3611;&#3619;&#3634;&#3592;&#3637;&#3609;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1359
-        'TH-77' => __( 'Prachuap Khiri Khan (&#3611;&#3619;&#3632;&#3592;&#3623;&#3610;&#3588;&#3637;&#3619;&#3637;&#3586;&#3633;&#3609;&#3608;&#3660;)', 'invoicing' ),
1360
-        'TH-85' => __( 'Ranong (&#3619;&#3632;&#3609;&#3629;&#3591;)', 'invoicing' ),
1361
-        'TH-70' => __( 'Ratchaburi (&#3619;&#3634;&#3594;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1362
-        'TH-21' => __( 'Rayong (&#3619;&#3632;&#3618;&#3629;&#3591;)', 'invoicing' ),
1363
-        'TH-45' => __( 'Roi Et (&#3619;&#3657;&#3629;&#3618;&#3648;&#3629;&#3655;&#3604;)', 'invoicing' ),
1364
-        'TH-27' => __( 'Sa Kaeo (&#3626;&#3619;&#3632;&#3649;&#3585;&#3657;&#3623;)', 'invoicing' ),
1365
-        'TH-47' => __( 'Sakon Nakhon (&#3626;&#3585;&#3621;&#3609;&#3588;&#3619;)', 'invoicing' ),
1366
-        'TH-11' => __( 'Samut Prakan (&#3626;&#3617;&#3640;&#3607;&#3619;&#3611;&#3619;&#3634;&#3585;&#3634;&#3619;)', 'invoicing' ),
1367
-        'TH-74' => __( 'Samut Sakhon (&#3626;&#3617;&#3640;&#3607;&#3619;&#3626;&#3634;&#3588;&#3619;)', 'invoicing' ),
1368
-        'TH-75' => __( 'Samut Songkhram (&#3626;&#3617;&#3640;&#3607;&#3619;&#3626;&#3591;&#3588;&#3619;&#3634;&#3617;)', 'invoicing' ),
1369
-        'TH-19' => __( 'Saraburi (&#3626;&#3619;&#3632;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1370
-        'TH-91' => __( 'Satun (&#3626;&#3605;&#3641;&#3621;)', 'invoicing' ),
1371
-        'TH-17' => __( 'Sing Buri (&#3626;&#3636;&#3591;&#3627;&#3660;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1372
-        'TH-33' => __( 'Sisaket (&#3624;&#3619;&#3637;&#3626;&#3632;&#3648;&#3585;&#3625;)', 'invoicing' ),
1373
-        'TH-90' => __( 'Songkhla (&#3626;&#3591;&#3586;&#3621;&#3634;)', 'invoicing' ),
1374
-        'TH-64' => __( 'Sukhothai (&#3626;&#3640;&#3650;&#3586;&#3607;&#3633;&#3618;)', 'invoicing' ),
1375
-        'TH-72' => __( 'Suphan Buri (&#3626;&#3640;&#3614;&#3619;&#3619;&#3603;&#3610;&#3640;&#3619;&#3637;)', 'invoicing' ),
1376
-        'TH-84' => __( 'Surat Thani (&#3626;&#3640;&#3619;&#3634;&#3625;&#3598;&#3619;&#3660;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1377
-        'TH-32' => __( 'Surin (&#3626;&#3640;&#3619;&#3636;&#3609;&#3607;&#3619;&#3660;)', 'invoicing' ),
1378
-        'TH-63' => __( 'Tak (&#3605;&#3634;&#3585;)', 'invoicing' ),
1379
-        'TH-92' => __( 'Trang (&#3605;&#3619;&#3633;&#3591;)', 'invoicing' ),
1380
-        'TH-23' => __( 'Trat (&#3605;&#3619;&#3634;&#3604;)', 'invoicing' ),
1381
-        'TH-34' => __( 'Ubon Ratchathani (&#3629;&#3640;&#3610;&#3621;&#3619;&#3634;&#3594;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1382
-        'TH-41' => __( 'Udon Thani (&#3629;&#3640;&#3604;&#3619;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1383
-        'TH-61' => __( 'Uthai Thani (&#3629;&#3640;&#3607;&#3633;&#3618;&#3608;&#3634;&#3609;&#3637;)', 'invoicing' ),
1384
-        'TH-53' => __( 'Uttaradit (&#3629;&#3640;&#3605;&#3619;&#3604;&#3636;&#3605;&#3606;&#3660;)', 'invoicing' ),
1385
-        'TH-95' => __( 'Yala (&#3618;&#3632;&#3621;&#3634;)', 'invoicing' ),
1386
-        'TH-35' => __( 'Yasothon (&#3618;&#3650;&#3626;&#3608;&#3619;)', 'invoicing' )
1310
+        'TH-37' => __('Amnat Charoen (&#3629;&#3635;&#3609;&#3634;&#3592;&#3648;&#3592;&#3619;&#3636;&#3597;)', 'invoicing'),
1311
+        'TH-15' => __('Ang Thong (&#3629;&#3656;&#3634;&#3591;&#3607;&#3629;&#3591;)', 'invoicing'),
1312
+        'TH-14' => __('Ayutthaya (&#3614;&#3619;&#3632;&#3609;&#3588;&#3619;&#3624;&#3619;&#3637;&#3629;&#3618;&#3640;&#3608;&#3618;&#3634;)', 'invoicing'),
1313
+        'TH-10' => __('Bangkok (&#3585;&#3619;&#3640;&#3591;&#3648;&#3607;&#3614;&#3617;&#3627;&#3634;&#3609;&#3588;&#3619;)', 'invoicing'),
1314
+        'TH-38' => __('Bueng Kan (&#3610;&#3638;&#3591;&#3585;&#3634;&#3628;)', 'invoicing'),
1315
+        'TH-31' => __('Buri Ram (&#3610;&#3640;&#3619;&#3637;&#3619;&#3633;&#3617;&#3618;&#3660;)', 'invoicing'),
1316
+        'TH-24' => __('Chachoengsao (&#3593;&#3632;&#3648;&#3594;&#3636;&#3591;&#3648;&#3607;&#3619;&#3634;)', 'invoicing'),
1317
+        'TH-18' => __('Chai Nat (&#3594;&#3633;&#3618;&#3609;&#3634;&#3607;)', 'invoicing'),
1318
+        'TH-36' => __('Chaiyaphum (&#3594;&#3633;&#3618;&#3616;&#3641;&#3617;&#3636;)', 'invoicing'),
1319
+        'TH-22' => __('Chanthaburi (&#3592;&#3633;&#3609;&#3607;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1320
+        'TH-50' => __('Chiang Mai (&#3648;&#3594;&#3637;&#3618;&#3591;&#3651;&#3627;&#3617;&#3656;)', 'invoicing'),
1321
+        'TH-57' => __('Chiang Rai (&#3648;&#3594;&#3637;&#3618;&#3591;&#3619;&#3634;&#3618;)', 'invoicing'),
1322
+        'TH-20' => __('Chonburi (&#3594;&#3621;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1323
+        'TH-86' => __('Chumphon (&#3594;&#3640;&#3617;&#3614;&#3619;)', 'invoicing'),
1324
+        'TH-46' => __('Kalasin (&#3585;&#3634;&#3628;&#3626;&#3636;&#3609;&#3608;&#3640;&#3660;)', 'invoicing'),
1325
+        'TH-62' => __('Kamphaeng Phet (&#3585;&#3635;&#3649;&#3614;&#3591;&#3648;&#3614;&#3594;&#3619;)', 'invoicing'),
1326
+        'TH-71' => __('Kanchanaburi (&#3585;&#3634;&#3597;&#3592;&#3609;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1327
+        'TH-40' => __('Khon Kaen (&#3586;&#3629;&#3609;&#3649;&#3585;&#3656;&#3609;)', 'invoicing'),
1328
+        'TH-81' => __('Krabi (&#3585;&#3619;&#3632;&#3610;&#3637;&#3656;)', 'invoicing'),
1329
+        'TH-52' => __('Lampang (&#3621;&#3635;&#3611;&#3634;&#3591;)', 'invoicing'),
1330
+        'TH-51' => __('Lamphun (&#3621;&#3635;&#3614;&#3641;&#3609;)', 'invoicing'),
1331
+        'TH-42' => __('Loei (&#3648;&#3621;&#3618;)', 'invoicing'),
1332
+        'TH-16' => __('Lopburi (&#3621;&#3614;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1333
+        'TH-58' => __('Mae Hong Son (&#3649;&#3617;&#3656;&#3630;&#3656;&#3629;&#3591;&#3626;&#3629;&#3609;)', 'invoicing'),
1334
+        'TH-44' => __('Maha Sarakham (&#3617;&#3627;&#3634;&#3626;&#3634;&#3619;&#3588;&#3634;&#3617;)', 'invoicing'),
1335
+        'TH-49' => __('Mukdahan (&#3617;&#3640;&#3585;&#3604;&#3634;&#3627;&#3634;&#3619;)', 'invoicing'),
1336
+        'TH-26' => __('Nakhon Nayok (&#3609;&#3588;&#3619;&#3609;&#3634;&#3618;&#3585;)', 'invoicing'),
1337
+        'TH-73' => __('Nakhon Pathom (&#3609;&#3588;&#3619;&#3611;&#3600;&#3617;)', 'invoicing'),
1338
+        'TH-48' => __('Nakhon Phanom (&#3609;&#3588;&#3619;&#3614;&#3609;&#3617;)', 'invoicing'),
1339
+        'TH-30' => __('Nakhon Ratchasima (&#3609;&#3588;&#3619;&#3619;&#3634;&#3594;&#3626;&#3637;&#3617;&#3634;)', 'invoicing'),
1340
+        'TH-60' => __('Nakhon Sawan (&#3609;&#3588;&#3619;&#3626;&#3623;&#3619;&#3619;&#3588;&#3660;)', 'invoicing'),
1341
+        'TH-80' => __('Nakhon Si Thammarat (&#3609;&#3588;&#3619;&#3624;&#3619;&#3637;&#3608;&#3619;&#3619;&#3617;&#3619;&#3634;&#3594;)', 'invoicing'),
1342
+        'TH-55' => __('Nan (&#3609;&#3656;&#3634;&#3609;)', 'invoicing'),
1343
+        'TH-96' => __('Narathiwat (&#3609;&#3619;&#3634;&#3608;&#3636;&#3623;&#3634;&#3626;)', 'invoicing'),
1344
+        'TH-39' => __('Nong Bua Lam Phu (&#3627;&#3609;&#3629;&#3591;&#3610;&#3633;&#3623;&#3621;&#3635;&#3616;&#3641;)', 'invoicing'),
1345
+        'TH-43' => __('Nong Khai (&#3627;&#3609;&#3629;&#3591;&#3588;&#3634;&#3618;)', 'invoicing'),
1346
+        'TH-12' => __('Nonthaburi (&#3609;&#3609;&#3607;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1347
+        'TH-13' => __('Pathum Thani (&#3611;&#3607;&#3640;&#3617;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1348
+        'TH-94' => __('Pattani (&#3611;&#3633;&#3605;&#3605;&#3634;&#3609;&#3637;)', 'invoicing'),
1349
+        'TH-82' => __('Phang Nga (&#3614;&#3633;&#3591;&#3591;&#3634;)', 'invoicing'),
1350
+        'TH-93' => __('Phatthalung (&#3614;&#3633;&#3607;&#3621;&#3640;&#3591;)', 'invoicing'),
1351
+        'TH-56' => __('Phayao (&#3614;&#3632;&#3648;&#3618;&#3634;)', 'invoicing'),
1352
+        'TH-67' => __('Phetchabun (&#3648;&#3614;&#3594;&#3619;&#3610;&#3641;&#3619;&#3603;&#3660;)', 'invoicing'),
1353
+        'TH-76' => __('Phetchaburi (&#3648;&#3614;&#3594;&#3619;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1354
+        'TH-66' => __('Phichit (&#3614;&#3636;&#3592;&#3636;&#3605;&#3619;)', 'invoicing'),
1355
+        'TH-65' => __('Phitsanulok (&#3614;&#3636;&#3625;&#3603;&#3640;&#3650;&#3621;&#3585;)', 'invoicing'),
1356
+        'TH-54' => __('Phrae (&#3649;&#3614;&#3619;&#3656;)', 'invoicing'),
1357
+        'TH-83' => __('Phuket (&#3616;&#3641;&#3648;&#3585;&#3655;&#3605;)', 'invoicing'),
1358
+        'TH-25' => __('Prachin Buri (&#3611;&#3619;&#3634;&#3592;&#3637;&#3609;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1359
+        'TH-77' => __('Prachuap Khiri Khan (&#3611;&#3619;&#3632;&#3592;&#3623;&#3610;&#3588;&#3637;&#3619;&#3637;&#3586;&#3633;&#3609;&#3608;&#3660;)', 'invoicing'),
1360
+        'TH-85' => __('Ranong (&#3619;&#3632;&#3609;&#3629;&#3591;)', 'invoicing'),
1361
+        'TH-70' => __('Ratchaburi (&#3619;&#3634;&#3594;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1362
+        'TH-21' => __('Rayong (&#3619;&#3632;&#3618;&#3629;&#3591;)', 'invoicing'),
1363
+        'TH-45' => __('Roi Et (&#3619;&#3657;&#3629;&#3618;&#3648;&#3629;&#3655;&#3604;)', 'invoicing'),
1364
+        'TH-27' => __('Sa Kaeo (&#3626;&#3619;&#3632;&#3649;&#3585;&#3657;&#3623;)', 'invoicing'),
1365
+        'TH-47' => __('Sakon Nakhon (&#3626;&#3585;&#3621;&#3609;&#3588;&#3619;)', 'invoicing'),
1366
+        'TH-11' => __('Samut Prakan (&#3626;&#3617;&#3640;&#3607;&#3619;&#3611;&#3619;&#3634;&#3585;&#3634;&#3619;)', 'invoicing'),
1367
+        'TH-74' => __('Samut Sakhon (&#3626;&#3617;&#3640;&#3607;&#3619;&#3626;&#3634;&#3588;&#3619;)', 'invoicing'),
1368
+        'TH-75' => __('Samut Songkhram (&#3626;&#3617;&#3640;&#3607;&#3619;&#3626;&#3591;&#3588;&#3619;&#3634;&#3617;)', 'invoicing'),
1369
+        'TH-19' => __('Saraburi (&#3626;&#3619;&#3632;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1370
+        'TH-91' => __('Satun (&#3626;&#3605;&#3641;&#3621;)', 'invoicing'),
1371
+        'TH-17' => __('Sing Buri (&#3626;&#3636;&#3591;&#3627;&#3660;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1372
+        'TH-33' => __('Sisaket (&#3624;&#3619;&#3637;&#3626;&#3632;&#3648;&#3585;&#3625;)', 'invoicing'),
1373
+        'TH-90' => __('Songkhla (&#3626;&#3591;&#3586;&#3621;&#3634;)', 'invoicing'),
1374
+        'TH-64' => __('Sukhothai (&#3626;&#3640;&#3650;&#3586;&#3607;&#3633;&#3618;)', 'invoicing'),
1375
+        'TH-72' => __('Suphan Buri (&#3626;&#3640;&#3614;&#3619;&#3619;&#3603;&#3610;&#3640;&#3619;&#3637;)', 'invoicing'),
1376
+        'TH-84' => __('Surat Thani (&#3626;&#3640;&#3619;&#3634;&#3625;&#3598;&#3619;&#3660;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1377
+        'TH-32' => __('Surin (&#3626;&#3640;&#3619;&#3636;&#3609;&#3607;&#3619;&#3660;)', 'invoicing'),
1378
+        'TH-63' => __('Tak (&#3605;&#3634;&#3585;)', 'invoicing'),
1379
+        'TH-92' => __('Trang (&#3605;&#3619;&#3633;&#3591;)', 'invoicing'),
1380
+        'TH-23' => __('Trat (&#3605;&#3619;&#3634;&#3604;)', 'invoicing'),
1381
+        'TH-34' => __('Ubon Ratchathani (&#3629;&#3640;&#3610;&#3621;&#3619;&#3634;&#3594;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1382
+        'TH-41' => __('Udon Thani (&#3629;&#3640;&#3604;&#3619;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1383
+        'TH-61' => __('Uthai Thani (&#3629;&#3640;&#3607;&#3633;&#3618;&#3608;&#3634;&#3609;&#3637;)', 'invoicing'),
1384
+        'TH-53' => __('Uttaradit (&#3629;&#3640;&#3605;&#3619;&#3604;&#3636;&#3605;&#3606;&#3660;)', 'invoicing'),
1385
+        'TH-95' => __('Yala (&#3618;&#3632;&#3621;&#3634;)', 'invoicing'),
1386
+        'TH-35' => __('Yasothon (&#3618;&#3650;&#3626;&#3608;&#3619;)', 'invoicing')
1387 1387
     );
1388 1388
 
1389
-    return apply_filters( 'wpinv_thailand_states', $states );
1389
+    return apply_filters('wpinv_thailand_states', $states);
1390 1390
 }
1391 1391
 
1392 1392
 function wpinv_get_turkey_states_list() {
1393 1393
     $states = array(
1394
-        'TR01' => __( 'Adana', 'invoicing' ),
1395
-        'TR02' => __( 'Ad&#305;yaman', 'invoicing' ),
1396
-        'TR03' => __( 'Afyon', 'invoicing' ),
1397
-        'TR04' => __( 'A&#287;r&#305;', 'invoicing' ),
1398
-        'TR05' => __( 'Amasya', 'invoicing' ),
1399
-        'TR06' => __( 'Ankara', 'invoicing' ),
1400
-        'TR07' => __( 'Antalya', 'invoicing' ),
1401
-        'TR08' => __( 'Artvin', 'invoicing' ),
1402
-        'TR09' => __( 'Ayd&#305;n', 'invoicing' ),
1403
-        'TR10' => __( 'Bal&#305;kesir', 'invoicing' ),
1404
-        'TR11' => __( 'Bilecik', 'invoicing' ),
1405
-        'TR12' => __( 'Bing&#246;l', 'invoicing' ),
1406
-        'TR13' => __( 'Bitlis', 'invoicing' ),
1407
-        'TR14' => __( 'Bolu', 'invoicing' ),
1408
-        'TR15' => __( 'Burdur', 'invoicing' ),
1409
-        'TR16' => __( 'Bursa', 'invoicing' ),
1410
-        'TR17' => __( '&#199;anakkale', 'invoicing' ),
1411
-        'TR18' => __( '&#199;ank&#305;kesir', 'invoicing' ),
1412
-        'TR19' => __( '&#199;orum', 'invoicing' ),
1413
-        'TR20' => __( 'Denizli', 'invoicing' ),
1414
-        'TR21' => __( 'Diyarbak&#305;r', 'invoicing' ),
1415
-        'TR22' => __( 'Edirne', 'invoicing' ),
1416
-        'TR23' => __( 'Elaz&#305;&#287;', 'invoicing' ),
1417
-        'TR24' => __( 'Erzincan', 'invoicing' ),
1418
-        'TR25' => __( 'Erzurum', 'invoicing' ),
1419
-        'TR26' => __( 'Eski&#351;ehir', 'invoicing' ),
1420
-        'TR27' => __( 'Gaziantep', 'invoicing' ),
1421
-        'TR28' => __( 'Giresun', 'invoicing' ),
1422
-        'TR29' => __( 'G&#252;m&#252;&#351;hane', 'invoicing' ),
1423
-        'TR30' => __( 'Hakkari', 'invoicing' ),
1424
-        'TR31' => __( 'Hatay', 'invoicing' ),
1425
-        'TR32' => __( 'Isparta', 'invoicing' ),
1426
-        'TR33' => __( '&#304;&#231;el', 'invoicing' ),
1427
-        'TR34' => __( '&#304;stanbul', 'invoicing' ),
1428
-        'TR35' => __( '&#304;zmir', 'invoicing' ),
1429
-        'TR36' => __( 'Kars', 'invoicing' ),
1430
-        'TR37' => __( 'Kastamonu', 'invoicing' ),
1431
-        'TR38' => __( 'Kayseri', 'invoicing' ),
1432
-        'TR39' => __( 'K&#305;rklareli', 'invoicing' ),
1433
-        'TR40' => __( 'K&#305;r&#351;ehir', 'invoicing' ),
1434
-        'TR41' => __( 'Kocaeli', 'invoicing' ),
1435
-        'TR42' => __( 'Konya', 'invoicing' ),
1436
-        'TR43' => __( 'K&#252;tahya', 'invoicing' ),
1437
-        'TR44' => __( 'Malatya', 'invoicing' ),
1438
-        'TR45' => __( 'Manisa', 'invoicing' ),
1439
-        'TR46' => __( 'Kahramanmara&#351;', 'invoicing' ),
1440
-        'TR47' => __( 'Mardin', 'invoicing' ),
1441
-        'TR48' => __( 'Mu&#287;la', 'invoicing' ),
1442
-        'TR49' => __( 'Mu&#351;', 'invoicing' ),
1443
-        'TR50' => __( 'Nev&#351;ehir', 'invoicing' ),
1444
-        'TR51' => __( 'Ni&#287;de', 'invoicing' ),
1445
-        'TR52' => __( 'Ordu', 'invoicing' ),
1446
-        'TR53' => __( 'Rize', 'invoicing' ),
1447
-        'TR54' => __( 'Sakarya', 'invoicing' ),
1448
-        'TR55' => __( 'Samsun', 'invoicing' ),
1449
-        'TR56' => __( 'Siirt', 'invoicing' ),
1450
-        'TR57' => __( 'Sinop', 'invoicing' ),
1451
-        'TR58' => __( 'Sivas', 'invoicing' ),
1452
-        'TR59' => __( 'Tekirda&#287;', 'invoicing' ),
1453
-        'TR60' => __( 'Tokat', 'invoicing' ),
1454
-        'TR61' => __( 'Trabzon', 'invoicing' ),
1455
-        'TR62' => __( 'Tunceli', 'invoicing' ),
1456
-        'TR63' => __( '&#350;anl&#305;urfa', 'invoicing' ),
1457
-        'TR64' => __( 'U&#351;ak', 'invoicing' ),
1458
-        'TR65' => __( 'Van', 'invoicing' ),
1459
-        'TR66' => __( 'Yozgat', 'invoicing' ),
1460
-        'TR67' => __( 'Zonguldak', 'invoicing' ),
1461
-        'TR68' => __( 'Aksaray', 'invoicing' ),
1462
-        'TR69' => __( 'Bayburt', 'invoicing' ),
1463
-        'TR70' => __( 'Karaman', 'invoicing' ),
1464
-        'TR71' => __( 'K&#305;r&#305;kkale', 'invoicing' ),
1465
-        'TR72' => __( 'Batman', 'invoicing' ),
1466
-        'TR73' => __( '&#350;&#305;rnak', 'invoicing' ),
1467
-        'TR74' => __( 'Bart&#305;n', 'invoicing' ),
1468
-        'TR75' => __( 'Ardahan', 'invoicing' ),
1469
-        'TR76' => __( 'I&#287;d&#305;r', 'invoicing' ),
1470
-        'TR77' => __( 'Yalova', 'invoicing' ),
1471
-        'TR78' => __( 'Karab&#252;k', 'invoicing' ),
1472
-        'TR79' => __( 'Kilis', 'invoicing' ),
1473
-        'TR80' => __( 'Osmaniye', 'invoicing' ),
1474
-        'TR81' => __( 'D&#252;zce', 'invoicing' )
1394
+        'TR01' => __('Adana', 'invoicing'),
1395
+        'TR02' => __('Ad&#305;yaman', 'invoicing'),
1396
+        'TR03' => __('Afyon', 'invoicing'),
1397
+        'TR04' => __('A&#287;r&#305;', 'invoicing'),
1398
+        'TR05' => __('Amasya', 'invoicing'),
1399
+        'TR06' => __('Ankara', 'invoicing'),
1400
+        'TR07' => __('Antalya', 'invoicing'),
1401
+        'TR08' => __('Artvin', 'invoicing'),
1402
+        'TR09' => __('Ayd&#305;n', 'invoicing'),
1403
+        'TR10' => __('Bal&#305;kesir', 'invoicing'),
1404
+        'TR11' => __('Bilecik', 'invoicing'),
1405
+        'TR12' => __('Bing&#246;l', 'invoicing'),
1406
+        'TR13' => __('Bitlis', 'invoicing'),
1407
+        'TR14' => __('Bolu', 'invoicing'),
1408
+        'TR15' => __('Burdur', 'invoicing'),
1409
+        'TR16' => __('Bursa', 'invoicing'),
1410
+        'TR17' => __('&#199;anakkale', 'invoicing'),
1411
+        'TR18' => __('&#199;ank&#305;kesir', 'invoicing'),
1412
+        'TR19' => __('&#199;orum', 'invoicing'),
1413
+        'TR20' => __('Denizli', 'invoicing'),
1414
+        'TR21' => __('Diyarbak&#305;r', 'invoicing'),
1415
+        'TR22' => __('Edirne', 'invoicing'),
1416
+        'TR23' => __('Elaz&#305;&#287;', 'invoicing'),
1417
+        'TR24' => __('Erzincan', 'invoicing'),
1418
+        'TR25' => __('Erzurum', 'invoicing'),
1419
+        'TR26' => __('Eski&#351;ehir', 'invoicing'),
1420
+        'TR27' => __('Gaziantep', 'invoicing'),
1421
+        'TR28' => __('Giresun', 'invoicing'),
1422
+        'TR29' => __('G&#252;m&#252;&#351;hane', 'invoicing'),
1423
+        'TR30' => __('Hakkari', 'invoicing'),
1424
+        'TR31' => __('Hatay', 'invoicing'),
1425
+        'TR32' => __('Isparta', 'invoicing'),
1426
+        'TR33' => __('&#304;&#231;el', 'invoicing'),
1427
+        'TR34' => __('&#304;stanbul', 'invoicing'),
1428
+        'TR35' => __('&#304;zmir', 'invoicing'),
1429
+        'TR36' => __('Kars', 'invoicing'),
1430
+        'TR37' => __('Kastamonu', 'invoicing'),
1431
+        'TR38' => __('Kayseri', 'invoicing'),
1432
+        'TR39' => __('K&#305;rklareli', 'invoicing'),
1433
+        'TR40' => __('K&#305;r&#351;ehir', 'invoicing'),
1434
+        'TR41' => __('Kocaeli', 'invoicing'),
1435
+        'TR42' => __('Konya', 'invoicing'),
1436
+        'TR43' => __('K&#252;tahya', 'invoicing'),
1437
+        'TR44' => __('Malatya', 'invoicing'),
1438
+        'TR45' => __('Manisa', 'invoicing'),
1439
+        'TR46' => __('Kahramanmara&#351;', 'invoicing'),
1440
+        'TR47' => __('Mardin', 'invoicing'),
1441
+        'TR48' => __('Mu&#287;la', 'invoicing'),
1442
+        'TR49' => __('Mu&#351;', 'invoicing'),
1443
+        'TR50' => __('Nev&#351;ehir', 'invoicing'),
1444
+        'TR51' => __('Ni&#287;de', 'invoicing'),
1445
+        'TR52' => __('Ordu', 'invoicing'),
1446
+        'TR53' => __('Rize', 'invoicing'),
1447
+        'TR54' => __('Sakarya', 'invoicing'),
1448
+        'TR55' => __('Samsun', 'invoicing'),
1449
+        'TR56' => __('Siirt', 'invoicing'),
1450
+        'TR57' => __('Sinop', 'invoicing'),
1451
+        'TR58' => __('Sivas', 'invoicing'),
1452
+        'TR59' => __('Tekirda&#287;', 'invoicing'),
1453
+        'TR60' => __('Tokat', 'invoicing'),
1454
+        'TR61' => __('Trabzon', 'invoicing'),
1455
+        'TR62' => __('Tunceli', 'invoicing'),
1456
+        'TR63' => __('&#350;anl&#305;urfa', 'invoicing'),
1457
+        'TR64' => __('U&#351;ak', 'invoicing'),
1458
+        'TR65' => __('Van', 'invoicing'),
1459
+        'TR66' => __('Yozgat', 'invoicing'),
1460
+        'TR67' => __('Zonguldak', 'invoicing'),
1461
+        'TR68' => __('Aksaray', 'invoicing'),
1462
+        'TR69' => __('Bayburt', 'invoicing'),
1463
+        'TR70' => __('Karaman', 'invoicing'),
1464
+        'TR71' => __('K&#305;r&#305;kkale', 'invoicing'),
1465
+        'TR72' => __('Batman', 'invoicing'),
1466
+        'TR73' => __('&#350;&#305;rnak', 'invoicing'),
1467
+        'TR74' => __('Bart&#305;n', 'invoicing'),
1468
+        'TR75' => __('Ardahan', 'invoicing'),
1469
+        'TR76' => __('I&#287;d&#305;r', 'invoicing'),
1470
+        'TR77' => __('Yalova', 'invoicing'),
1471
+        'TR78' => __('Karab&#252;k', 'invoicing'),
1472
+        'TR79' => __('Kilis', 'invoicing'),
1473
+        'TR80' => __('Osmaniye', 'invoicing'),
1474
+        'TR81' => __('D&#252;zce', 'invoicing')
1475 1475
     );
1476 1476
 
1477
-    return apply_filters( 'wpinv_turkey_states', $states );
1477
+    return apply_filters('wpinv_turkey_states', $states);
1478 1478
 }
1479 1479
 
1480 1480
 function wpinv_get_spain_states_list() {
1481 1481
     $states = array(
1482
-        'C'  => __( 'A Coru&ntilde;a', 'invoicing' ),
1483
-        'VI' => __( 'Araba', 'invoicing' ),
1484
-        'AB' => __( 'Albacete', 'invoicing' ),
1485
-        'A'  => __( 'Alicante', 'invoicing' ),
1486
-        'AL' => __( 'Almer&iacute;a', 'invoicing' ),
1487
-        'O'  => __( 'Asturias', 'invoicing' ),
1488
-        'AV' => __( '&Aacute;vila', 'invoicing' ),
1489
-        'BA' => __( 'Badajoz', 'invoicing' ),
1490
-        'PM' => __( 'Baleares', 'invoicing' ),
1491
-        'B'  => __( 'Barcelona', 'invoicing' ),
1492
-        'BU' => __( 'Burgos', 'invoicing' ),
1493
-        'CC' => __( 'C&aacute;ceres', 'invoicing' ),
1494
-        'CA' => __( 'C&aacute;diz', 'invoicing' ),
1495
-        'S'  => __( 'Cantabria', 'invoicing' ),
1496
-        'CS' => __( 'Castell&oacute;n', 'invoicing' ),
1497
-        'CE' => __( 'Ceuta', 'invoicing' ),
1498
-        'CR' => __( 'Ciudad Real', 'invoicing' ),
1499
-        'CO' => __( 'C&oacute;rdoba', 'invoicing' ),
1500
-        'CU' => __( 'Cuenca', 'invoicing' ),
1501
-        'GI' => __( 'Girona', 'invoicing' ),
1502
-        'GR' => __( 'Granada', 'invoicing' ),
1503
-        'GU' => __( 'Guadalajara', 'invoicing' ),
1504
-        'SS' => __( 'Gipuzkoa', 'invoicing' ),
1505
-        'H'  => __( 'Huelva', 'invoicing' ),
1506
-        'HU' => __( 'Huesca', 'invoicing' ),
1507
-        'J'  => __( 'Ja&eacute;n', 'invoicing' ),
1508
-        'LO' => __( 'La Rioja', 'invoicing' ),
1509
-        'GC' => __( 'Las Palmas', 'invoicing' ),
1510
-        'LE' => __( 'Le&oacute;n', 'invoicing' ),
1511
-        'L'  => __( 'Lleida', 'invoicing' ),
1512
-        'LU' => __( 'Lugo', 'invoicing' ),
1513
-        'M'  => __( 'Madrid', 'invoicing' ),
1514
-        'MA' => __( 'M&aacute;laga', 'invoicing' ),
1515
-        'ML' => __( 'Melilla', 'invoicing' ),
1516
-        'MU' => __( 'Murcia', 'invoicing' ),
1517
-        'NA' => __( 'Navarra', 'invoicing' ),
1518
-        'OR' => __( 'Ourense', 'invoicing' ),
1519
-        'P'  => __( 'Palencia', 'invoicing' ),
1520
-        'PO' => __( 'Pontevedra', 'invoicing' ),
1521
-        'SA' => __( 'Salamanca', 'invoicing' ),
1522
-        'TF' => __( 'Santa Cruz de Tenerife', 'invoicing' ),
1523
-        'SG' => __( 'Segovia', 'invoicing' ),
1524
-        'SE' => __( 'Sevilla', 'invoicing' ),
1525
-        'SO' => __( 'Soria', 'invoicing' ),
1526
-        'T'  => __( 'Tarragona', 'invoicing' ),
1527
-        'TE' => __( 'Teruel', 'invoicing' ),
1528
-        'TO' => __( 'Toledo', 'invoicing' ),
1529
-        'V'  => __( 'Valencia', 'invoicing' ),
1530
-        'VA' => __( 'Valladolid', 'invoicing' ),
1531
-        'BI' => __( 'Bizkaia', 'invoicing' ),
1532
-        'ZA' => __( 'Zamora', 'invoicing' ),
1533
-        'Z'  => __( 'Zaragoza', 'invoicing' )
1482
+        'C'  => __('A Coru&ntilde;a', 'invoicing'),
1483
+        'VI' => __('Araba', 'invoicing'),
1484
+        'AB' => __('Albacete', 'invoicing'),
1485
+        'A'  => __('Alicante', 'invoicing'),
1486
+        'AL' => __('Almer&iacute;a', 'invoicing'),
1487
+        'O'  => __('Asturias', 'invoicing'),
1488
+        'AV' => __('&Aacute;vila', 'invoicing'),
1489
+        'BA' => __('Badajoz', 'invoicing'),
1490
+        'PM' => __('Baleares', 'invoicing'),
1491
+        'B'  => __('Barcelona', 'invoicing'),
1492
+        'BU' => __('Burgos', 'invoicing'),
1493
+        'CC' => __('C&aacute;ceres', 'invoicing'),
1494
+        'CA' => __('C&aacute;diz', 'invoicing'),
1495
+        'S'  => __('Cantabria', 'invoicing'),
1496
+        'CS' => __('Castell&oacute;n', 'invoicing'),
1497
+        'CE' => __('Ceuta', 'invoicing'),
1498
+        'CR' => __('Ciudad Real', 'invoicing'),
1499
+        'CO' => __('C&oacute;rdoba', 'invoicing'),
1500
+        'CU' => __('Cuenca', 'invoicing'),
1501
+        'GI' => __('Girona', 'invoicing'),
1502
+        'GR' => __('Granada', 'invoicing'),
1503
+        'GU' => __('Guadalajara', 'invoicing'),
1504
+        'SS' => __('Gipuzkoa', 'invoicing'),
1505
+        'H'  => __('Huelva', 'invoicing'),
1506
+        'HU' => __('Huesca', 'invoicing'),
1507
+        'J'  => __('Ja&eacute;n', 'invoicing'),
1508
+        'LO' => __('La Rioja', 'invoicing'),
1509
+        'GC' => __('Las Palmas', 'invoicing'),
1510
+        'LE' => __('Le&oacute;n', 'invoicing'),
1511
+        'L'  => __('Lleida', 'invoicing'),
1512
+        'LU' => __('Lugo', 'invoicing'),
1513
+        'M'  => __('Madrid', 'invoicing'),
1514
+        'MA' => __('M&aacute;laga', 'invoicing'),
1515
+        'ML' => __('Melilla', 'invoicing'),
1516
+        'MU' => __('Murcia', 'invoicing'),
1517
+        'NA' => __('Navarra', 'invoicing'),
1518
+        'OR' => __('Ourense', 'invoicing'),
1519
+        'P'  => __('Palencia', 'invoicing'),
1520
+        'PO' => __('Pontevedra', 'invoicing'),
1521
+        'SA' => __('Salamanca', 'invoicing'),
1522
+        'TF' => __('Santa Cruz de Tenerife', 'invoicing'),
1523
+        'SG' => __('Segovia', 'invoicing'),
1524
+        'SE' => __('Sevilla', 'invoicing'),
1525
+        'SO' => __('Soria', 'invoicing'),
1526
+        'T'  => __('Tarragona', 'invoicing'),
1527
+        'TE' => __('Teruel', 'invoicing'),
1528
+        'TO' => __('Toledo', 'invoicing'),
1529
+        'V'  => __('Valencia', 'invoicing'),
1530
+        'VA' => __('Valladolid', 'invoicing'),
1531
+        'BI' => __('Bizkaia', 'invoicing'),
1532
+        'ZA' => __('Zamora', 'invoicing'),
1533
+        'Z'  => __('Zaragoza', 'invoicing')
1534 1534
     );
1535 1535
 
1536
-    return apply_filters( 'wpinv_spain_states', $states );
1536
+    return apply_filters('wpinv_spain_states', $states);
1537 1537
 }
1538 1538
 
1539 1539
 function wpinv_get_states_field() {
1540
-	if( empty( $_POST['country'] ) ) {
1540
+	if (empty($_POST['country'])) {
1541 1541
 		$_POST['country'] = wpinv_get_default_country();
1542 1542
 	}
1543
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
1543
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
1544 1544
 
1545
-	if( !empty( $states ) ) {
1546
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
1545
+	if (!empty($states)) {
1546
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
1547 1547
         
1548 1548
         $args = array(
1549 1549
 			'name'    => $sanitized_field_name,
1550 1550
 			'id'      => $sanitized_field_name,
1551 1551
 			'class'   => $sanitized_field_name . ' wpinv-select wpi_select2',
1552
-			'options' => array_merge( array( '' => '' ), $states ),
1552
+			'options' => array_merge(array('' => ''), $states),
1553 1553
 			'show_option_all'  => false,
1554 1554
 			'show_option_none' => false
1555 1555
 		);
1556 1556
 
1557
-		$response = wpinv_html_select( $args );
1557
+		$response = wpinv_html_select($args);
1558 1558
 
1559 1559
 	} else {
1560 1560
 		$response = 'nostates';
@@ -1563,8 +1563,8 @@  discard block
 block discarded – undo
1563 1563
 	return $response;
1564 1564
 }
1565 1565
 
1566
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
1567
-    $country = !empty( $country ) ? $country : wpinv_get_default_country();
1566
+function wpinv_default_billing_country($country = '', $user_id = 0) {
1567
+    $country = !empty($country) ? $country : wpinv_get_default_country();
1568 1568
     
1569
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
1569
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
1570 1570
 }
1571 1571
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-item-functions.php 3 patches
Braces   +9 added lines, -5 removed lines patch added patch discarded remove patch
@@ -1,6 +1,8 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if ( ! defined( 'ABSPATH' ) ) {
4
+    exit;
5
+}
4 6
 
5 7
 function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6 8
     if( empty( $field ) || empty( $value ) ) {
@@ -118,8 +120,9 @@  discard block
 block discarded – undo
118 120
 function wpinv_get_item( $item = 0 ) {
119 121
     if ( is_numeric( $item ) ) {
120 122
         $item = get_post( $item );
121
-        if ( ! $item || 'wpi_item' !== $item->post_type )
122
-            return null;
123
+        if ( ! $item || 'wpi_item' !== $item->post_type ) {
124
+                    return null;
125
+        }
123 126
         return $item;
124 127
     }
125 128
 
@@ -283,8 +286,9 @@  discard block
 block discarded – undo
283 286
 }
284 287
 
285 288
 function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
286
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
287
-        return;
289
+    if ( 'wpi_item' !== get_post_type( $item_id ) ) {
290
+            return;
291
+    }
288 292
 
289 293
     global $wpinv_logs;
290 294
     
Please login to merge, or discard this patch.
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -799,7 +799,7 @@
 block discarded – undo
799 799
                 case 'trial_interval':
800 800
                     $value = absint( $value );
801 801
                 break;
802
-				case 'editable':
802
+                case 'editable':
803 803
                     $value = (int) $value;
804 804
                 break;
805 805
             }
Please login to merge, or discard this patch.
Spacing   +281 added lines, -281 removed lines patch added patch discarded remove patch
@@ -1,19 +1,19 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 // Exit if accessed directly
3
-if ( ! defined( 'ABSPATH' ) ) exit;
3
+if (!defined('ABSPATH')) exit;
4 4
 
5
-function wpinv_get_item_by( $field = '', $value = '', $type = '' ) {
6
-    if( empty( $field ) || empty( $value ) ) {
5
+function wpinv_get_item_by($field = '', $value = '', $type = '') {
6
+    if (empty($field) || empty($value)) {
7 7
         return false;
8 8
     }
9 9
     
10 10
     $posts = array();
11 11
 
12
-    switch( strtolower( $field ) ) {
12
+    switch (strtolower($field)) {
13 13
         case 'id':
14
-            $item = new WPInv_Item( $value );
14
+            $item = new WPInv_Item($value);
15 15
 
16
-            if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
16
+            if (!empty($item) && $item->post_type == 'wpi_item') {
17 17
                 return $item;
18 18
             }
19 19
             return false;
@@ -22,16 +22,16 @@  discard block
 block discarded – undo
22 22
 
23 23
         case 'slug':
24 24
         case 'name':
25
-            $posts = get_posts( array(
25
+            $posts = get_posts(array(
26 26
                 'post_type'      => 'wpi_item',
27 27
                 'name'           => $value,
28 28
                 'posts_per_page' => 1,
29 29
                 'post_status'    => 'any'
30
-            ) );
30
+            ));
31 31
 
32 32
             break;
33 33
         case 'custom_id':
34
-            if ( empty( $value ) || empty( $type ) ) {
34
+            if (empty($value) || empty($type)) {
35 35
                 return false;
36 36
             }
37 37
             
@@ -51,10 +51,10 @@  discard block
 block discarded – undo
51 51
                 'post_status'    => 'any',
52 52
                 'orderby'        => 'ID',
53 53
                 'order'          => 'ASC',
54
-                'meta_query'     => array( $meta_query )
54
+                'meta_query'     => array($meta_query)
55 55
             );
56 56
             
57
-            $posts = get_posts( $args );
57
+            $posts = get_posts($args);
58 58
 
59 59
             break;
60 60
 
@@ -62,10 +62,10 @@  discard block
 block discarded – undo
62 62
             return false;
63 63
     }
64 64
     
65
-    if ( !empty( $posts[0] ) ) {
66
-        $item = new WPInv_Item( $posts[0]->ID );
65
+    if (!empty($posts[0])) {
66
+        $item = new WPInv_Item($posts[0]->ID);
67 67
 
68
-        if ( !empty( $item ) && $item->post_type == 'wpi_item' ) {
68
+        if (!empty($item) && $item->post_type == 'wpi_item') {
69 69
             return $item;
70 70
         }
71 71
     }
@@ -73,10 +73,10 @@  discard block
 block discarded – undo
73 73
     return false;
74 74
 }
75 75
 
76
-function wpinv_get_item( $item = 0 ) {
77
-    if ( is_numeric( $item ) ) {
78
-        $item = get_post( $item );
79
-        if ( ! $item || 'wpi_item' !== $item->post_type )
76
+function wpinv_get_item($item = 0) {
77
+    if (is_numeric($item)) {
78
+        $item = get_post($item);
79
+        if (!$item || 'wpi_item' !== $item->post_type)
80 80
             return null;
81 81
         return $item;
82 82
     }
@@ -89,150 +89,150 @@  discard block
 block discarded – undo
89 89
 
90 90
     $item = get_posts($args);
91 91
 
92
-    if ( $item ) {
92
+    if ($item) {
93 93
         return $item[0];
94 94
     }
95 95
 
96 96
     return null;
97 97
 }
98 98
 
99
-function wpinv_is_free_item( $item_id = 0 ) {
100
-    if( empty( $item_id ) ) {
99
+function wpinv_is_free_item($item_id = 0) {
100
+    if (empty($item_id)) {
101 101
         return false;
102 102
     }
103 103
 
104
-    $item = new WPInv_Item( $item_id );
104
+    $item = new WPInv_Item($item_id);
105 105
     
106 106
     return $item->is_free();
107 107
 }
108 108
 
109
-function wpinv_item_is_editable( $item = 0 ) {
110
-    if ( !empty( $item ) && is_a( $item, 'WP_Post' ) ) {
109
+function wpinv_item_is_editable($item = 0) {
110
+    if (!empty($item) && is_a($item, 'WP_Post')) {
111 111
         $item = $item->ID;
112 112
     }
113 113
         
114
-    if ( empty( $item ) ) {
114
+    if (empty($item)) {
115 115
         return true;
116 116
     }
117 117
 
118
-    $item = new WPInv_Item( $item );
118
+    $item = new WPInv_Item($item);
119 119
     
120
-    return (bool) $item->is_editable();
120
+    return (bool)$item->is_editable();
121 121
 }
122 122
 
123
-function wpinv_get_item_price( $item_id = 0 ) {
124
-    if( empty( $item_id ) ) {
123
+function wpinv_get_item_price($item_id = 0) {
124
+    if (empty($item_id)) {
125 125
         return false;
126 126
     }
127 127
 
128
-    $item = new WPInv_Item( $item_id );
128
+    $item = new WPInv_Item($item_id);
129 129
     
130 130
     return $item->get_price();
131 131
 }
132 132
 
133
-function wpinv_is_recurring_item( $item_id = 0 ) {
134
-    if( empty( $item_id ) ) {
133
+function wpinv_is_recurring_item($item_id = 0) {
134
+    if (empty($item_id)) {
135 135
         return false;
136 136
     }
137 137
 
138
-    $item = new WPInv_Item( $item_id );
138
+    $item = new WPInv_Item($item_id);
139 139
     
140 140
     return $item->is_recurring();
141 141
 }
142 142
 
143
-function wpinv_item_price( $item_id = 0 ) {
144
-    if( empty( $item_id ) ) {
143
+function wpinv_item_price($item_id = 0) {
144
+    if (empty($item_id)) {
145 145
         return false;
146 146
     }
147 147
 
148
-    $price = wpinv_get_item_price( $item_id );
149
-    $price = wpinv_price( wpinv_format_amount( $price ) );
148
+    $price = wpinv_get_item_price($item_id);
149
+    $price = wpinv_price(wpinv_format_amount($price));
150 150
     
151
-    return apply_filters( 'wpinv_item_price', $price, $item_id );
151
+    return apply_filters('wpinv_item_price', $price, $item_id);
152 152
 }
153 153
 
154
-function wpinv_item_show_price( $item_id = 0, $echo = true ) {
155
-    if ( empty( $item_id ) ) {
154
+function wpinv_item_show_price($item_id = 0, $echo = true) {
155
+    if (empty($item_id)) {
156 156
         $item_id = get_the_ID();
157 157
     }
158 158
 
159
-    $price = wpinv_item_price( $item_id );
159
+    $price = wpinv_item_price($item_id);
160 160
 
161
-    $price           = apply_filters( 'wpinv_item_price', wpinv_sanitize_amount( $price ), $item_id );
161
+    $price           = apply_filters('wpinv_item_price', wpinv_sanitize_amount($price), $item_id);
162 162
     $formatted_price = '<span class="wpinv_price" id="wpinv_item_' . $item_id . '">' . $price . '</span>';
163
-    $formatted_price = apply_filters( 'wpinv_item_price_after_html', $formatted_price, $item_id, $price );
163
+    $formatted_price = apply_filters('wpinv_item_price_after_html', $formatted_price, $item_id, $price);
164 164
 
165
-    if ( $echo ) {
165
+    if ($echo) {
166 166
         echo $formatted_price;
167 167
     } else {
168 168
         return $formatted_price;
169 169
     }
170 170
 }
171 171
 
172
-function wpinv_get_item_final_price( $item_id = 0, $amount_override = null ) {
173
-    if ( is_null( $amount_override ) ) {
174
-        $original_price = get_post_meta( $item_id, '_wpinv_price', true );
172
+function wpinv_get_item_final_price($item_id = 0, $amount_override = null) {
173
+    if (is_null($amount_override)) {
174
+        $original_price = get_post_meta($item_id, '_wpinv_price', true);
175 175
     } else {
176 176
         $original_price = $amount_override;
177 177
     }
178 178
     
179 179
     $price = $original_price;
180 180
 
181
-    return apply_filters( 'wpinv_get_item_final_price', $price, $item_id );
181
+    return apply_filters('wpinv_get_item_final_price', $price, $item_id);
182 182
 }
183 183
 
184
-function wpinv_item_custom_singular_name( $item_id ) {
185
-    if( empty( $item_id ) ) {
184
+function wpinv_item_custom_singular_name($item_id) {
185
+    if (empty($item_id)) {
186 186
         return false;
187 187
     }
188 188
 
189
-    $item = new WPInv_Item( $item_id );
189
+    $item = new WPInv_Item($item_id);
190 190
     
191 191
     return $item->get_custom_singular_name();
192 192
 }
193 193
 
194 194
 function wpinv_get_item_types() {
195 195
     $item_types = array(
196
-            'custom'    => __( 'Standard', 'invoicing' ),
197
-            'fee'       => __( 'Fee', 'invoicing' ),
196
+            'custom'    => __('Standard', 'invoicing'),
197
+            'fee'       => __('Fee', 'invoicing'),
198 198
         );
199
-    return apply_filters( 'wpinv_get_item_types', $item_types );
199
+    return apply_filters('wpinv_get_item_types', $item_types);
200 200
 }
201 201
 
202 202
 function wpinv_item_types() {
203 203
     $item_types = wpinv_get_item_types();
204 204
     
205
-    return ( !empty( $item_types ) ? array_keys( $item_types ) : array() );
205
+    return (!empty($item_types) ? array_keys($item_types) : array());
206 206
 }
207 207
 
208
-function wpinv_get_item_type( $item_id ) {
209
-    if( empty( $item_id ) ) {
208
+function wpinv_get_item_type($item_id) {
209
+    if (empty($item_id)) {
210 210
         return false;
211 211
     }
212 212
 
213
-    $item = new WPInv_Item( $item_id );
213
+    $item = new WPInv_Item($item_id);
214 214
     
215 215
     return $item->get_type();
216 216
 }
217 217
 
218
-function wpinv_item_type( $item_id ) {
218
+function wpinv_item_type($item_id) {
219 219
     $item_types = wpinv_get_item_types();
220 220
     
221
-    $item_type = wpinv_get_item_type( $item_id );
221
+    $item_type = wpinv_get_item_type($item_id);
222 222
     
223
-    if ( empty( $item_type ) ) {
223
+    if (empty($item_type)) {
224 224
         $item_type = '-';
225 225
     }
226 226
     
227
-    $item_type = isset( $item_types[$item_type] ) ? $item_types[$item_type] : __( $item_type, 'invoicing' );
227
+    $item_type = isset($item_types[$item_type]) ? $item_types[$item_type] : __($item_type, 'invoicing');
228 228
 
229
-    return apply_filters( 'wpinv_item_type', $item_type, $item_id );
229
+    return apply_filters('wpinv_item_type', $item_type, $item_id);
230 230
 }
231 231
 
232
-function wpinv_record_item_in_log( $item_id = 0, $file_id, $user_info, $ip, $invoice_id ) {
232
+function wpinv_record_item_in_log($item_id = 0, $file_id, $user_info, $ip, $invoice_id) {
233 233
     global $wpinv_logs;
234 234
     
235
-    if ( empty( $wpinv_logs ) ) {
235
+    if (empty($wpinv_logs)) {
236 236
         return false;
237 237
     }
238 238
 
@@ -241,7 +241,7 @@  discard block
 block discarded – undo
241 241
         'log_type'		=> 'wpi_item'
242 242
     );
243 243
 
244
-    $user_id = isset( $user_info['user_id'] ) ? $user_info['user_id'] : (int) -1;
244
+    $user_id = isset($user_info['user_id']) ? $user_info['user_id'] : (int) -1;
245 245
 
246 246
     $log_meta = array(
247 247
         'user_info'	=> $user_info,
@@ -251,254 +251,254 @@  discard block
 block discarded – undo
251 251
         'invoice_id'=> $invoice_id,
252 252
     );
253 253
 
254
-    $wpinv_logs->insert_log( $log_data, $log_meta );
254
+    $wpinv_logs->insert_log($log_data, $log_meta);
255 255
 }
256 256
 
257
-function wpinv_remove_item_logs_on_delete( $item_id = 0 ) {
258
-    if ( 'wpi_item' !== get_post_type( $item_id ) )
257
+function wpinv_remove_item_logs_on_delete($item_id = 0) {
258
+    if ('wpi_item' !== get_post_type($item_id))
259 259
         return;
260 260
 
261 261
     global $wpinv_logs;
262 262
     
263
-    if ( empty( $wpinv_logs ) ) {
263
+    if (empty($wpinv_logs)) {
264 264
         return false;
265 265
     }
266 266
 
267 267
     // Remove all log entries related to this item
268
-    $wpinv_logs->delete_logs( $item_id );
268
+    $wpinv_logs->delete_logs($item_id);
269 269
 }
270
-add_action( 'delete_post', 'wpinv_remove_item_logs_on_delete' );
270
+add_action('delete_post', 'wpinv_remove_item_logs_on_delete');
271 271
 
272
-function wpinv_get_random_item( $post_ids = true ) {
273
-    wpinv_get_random_items( 1, $post_ids );
272
+function wpinv_get_random_item($post_ids = true) {
273
+    wpinv_get_random_items(1, $post_ids);
274 274
 }
275 275
 
276
-function wpinv_get_random_items( $num = 3, $post_ids = true ) {
277
-    if ( $post_ids ) {
278
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids' );
276
+function wpinv_get_random_items($num = 3, $post_ids = true) {
277
+    if ($post_ids) {
278
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num, 'fields' => 'ids');
279 279
     } else {
280
-        $args = array( 'post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num );
280
+        $args = array('post_type' => 'wpi_item', 'orderby' => 'rand', 'post_count' => $num);
281 281
     }
282 282
     
283
-    $args  = apply_filters( 'wpinv_get_random_items', $args );
283
+    $args = apply_filters('wpinv_get_random_items', $args);
284 284
     
285
-    return get_posts( $args );
285
+    return get_posts($args);
286 286
 }
287 287
 
288
-function wpinv_get_item_token( $url = '' ) {
288
+function wpinv_get_item_token($url = '') {
289 289
     $args    = array();
290
-    $hash    = apply_filters( 'wpinv_get_url_token_algorithm', 'sha256' );
291
-    $secret  = apply_filters( 'wpinv_get_url_token_secret', hash( $hash, wp_salt() ) );
290
+    $hash    = apply_filters('wpinv_get_url_token_algorithm', 'sha256');
291
+    $secret  = apply_filters('wpinv_get_url_token_secret', hash($hash, wp_salt()));
292 292
 
293
-    $parts   = parse_url( $url );
293
+    $parts   = parse_url($url);
294 294
     $options = array();
295 295
 
296
-    if ( isset( $parts['query'] ) ) {
297
-        wp_parse_str( $parts['query'], $query_args );
296
+    if (isset($parts['query'])) {
297
+        wp_parse_str($parts['query'], $query_args);
298 298
 
299
-        if ( ! empty( $query_args['o'] ) ) {
300
-            $options = explode( ':', rawurldecode( $query_args['o'] ) );
299
+        if (!empty($query_args['o'])) {
300
+            $options = explode(':', rawurldecode($query_args['o']));
301 301
 
302
-            if ( in_array( 'ip', $options ) ) {
302
+            if (in_array('ip', $options)) {
303 303
                 $args['ip'] = wpinv_get_ip();
304 304
             }
305 305
 
306
-            if ( in_array( 'ua', $options ) ) {
306
+            if (in_array('ua', $options)) {
307 307
                 $ua = wpinv_get_user_agent();
308
-                $args['user_agent'] = rawurlencode( $ua );
308
+                $args['user_agent'] = rawurlencode($ua);
309 309
             }
310 310
         }
311 311
     }
312 312
 
313
-    $args = apply_filters( 'wpinv_get_url_token_args', $args, $url, $options );
313
+    $args = apply_filters('wpinv_get_url_token_args', $args, $url, $options);
314 314
 
315 315
     $args['secret'] = $secret;
316 316
     $args['token']  = false;
317 317
 
318
-    $url   = add_query_arg( $args, $url );
319
-    $parts = parse_url( $url );
318
+    $url   = add_query_arg($args, $url);
319
+    $parts = parse_url($url);
320 320
 
321
-    if ( ! isset( $parts['path'] ) ) {
321
+    if (!isset($parts['path'])) {
322 322
         $parts['path'] = '';
323 323
     }
324 324
 
325
-    $token = md5( $parts['path'] . '?' . $parts['query'] );
325
+    $token = md5($parts['path'] . '?' . $parts['query']);
326 326
 
327 327
     return $token;
328 328
 }
329 329
 
330
-function wpinv_validate_url_token( $url = '' ) {
330
+function wpinv_validate_url_token($url = '') {
331 331
     $ret   = false;
332
-    $parts = parse_url( $url );
332
+    $parts = parse_url($url);
333 333
 
334
-    if ( isset( $parts['query'] ) ) {
335
-        wp_parse_str( $parts['query'], $query_args );
334
+    if (isset($parts['query'])) {
335
+        wp_parse_str($parts['query'], $query_args);
336 336
 
337
-        $allowed = apply_filters( 'wpinv_url_token_allowed_params', array(
337
+        $allowed = apply_filters('wpinv_url_token_allowed_params', array(
338 338
             'item',
339 339
             'ttl',
340 340
             'token'
341
-        ) );
341
+        ));
342 342
 
343 343
         $remove = array();
344 344
 
345
-        foreach( $query_args as $key => $value ) {
346
-            if( false === in_array( $key, $allowed ) ) {
345
+        foreach ($query_args as $key => $value) {
346
+            if (false === in_array($key, $allowed)) {
347 347
                 $remove[] = $key;
348 348
             }
349 349
         }
350 350
 
351
-        if( ! empty( $remove ) ) {
352
-            $url = remove_query_arg( $remove, $url );
351
+        if (!empty($remove)) {
352
+            $url = remove_query_arg($remove, $url);
353 353
         }
354 354
 
355
-        if ( isset( $query_args['ttl'] ) && current_time( 'timestamp' ) > $query_args['ttl'] ) {
356
-            wp_die( apply_filters( 'wpinv_item_link_expired_text', __( 'Sorry but your item link has expired.', 'invoicing' ) ), __( 'Error', 'invoicing' ), array( 'response' => 403 ) );
355
+        if (isset($query_args['ttl']) && current_time('timestamp') > $query_args['ttl']) {
356
+            wp_die(apply_filters('wpinv_item_link_expired_text', __('Sorry but your item link has expired.', 'invoicing')), __('Error', 'invoicing'), array('response' => 403));
357 357
         }
358 358
 
359
-        if ( isset( $query_args['token'] ) && $query_args['token'] == wpinv_get_item_token( $url ) ) {
359
+        if (isset($query_args['token']) && $query_args['token'] == wpinv_get_item_token($url)) {
360 360
             $ret = true;
361 361
         }
362 362
 
363 363
     }
364 364
 
365
-    return apply_filters( 'wpinv_validate_url_token', $ret, $url, $query_args );
365
+    return apply_filters('wpinv_validate_url_token', $ret, $url, $query_args);
366 366
 }
367 367
 
368
-function wpinv_item_in_cart( $item_id = 0, $options = array() ) {
368
+function wpinv_item_in_cart($item_id = 0, $options = array()) {
369 369
     $cart_items = wpinv_get_cart_contents();
370 370
 
371 371
     $ret = false;
372 372
 
373
-    if ( is_array( $cart_items ) ) {
374
-        foreach ( $cart_items as $item ) {
375
-            if ( $item['id'] == $item_id ) {
373
+    if (is_array($cart_items)) {
374
+        foreach ($cart_items as $item) {
375
+            if ($item['id'] == $item_id) {
376 376
                 $ret = true;
377 377
                 break;
378 378
             }
379 379
         }
380 380
     }
381 381
 
382
-    return (bool) apply_filters( 'wpinv_item_in_cart', $ret, $item_id, $options );
382
+    return (bool)apply_filters('wpinv_item_in_cart', $ret, $item_id, $options);
383 383
 }
384 384
 
385
-function wpinv_get_cart_item_tax( $item_id = 0, $subtotal = '', $options = array() ) {
385
+function wpinv_get_cart_item_tax($item_id = 0, $subtotal = '', $options = array()) {
386 386
     $tax = 0;
387
-    if ( ! wpinv_item_is_tax_exclusive( $item_id ) ) {
388
-        $country = !empty( $_POST['country'] ) ? $_POST['country'] : false;
389
-        $state   = isset( $_POST['state'] ) ? $_POST['state'] : '';
387
+    if (!wpinv_item_is_tax_exclusive($item_id)) {
388
+        $country = !empty($_POST['country']) ? $_POST['country'] : false;
389
+        $state   = isset($_POST['state']) ? $_POST['state'] : '';
390 390
 
391
-        $tax = wpinv_calculate_tax( $subtotal, $country, $state, $item_id );
391
+        $tax = wpinv_calculate_tax($subtotal, $country, $state, $item_id);
392 392
     }
393 393
 
394
-    return apply_filters( 'wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options );
394
+    return apply_filters('wpinv_get_cart_item_tax', $tax, $item_id, $subtotal, $options);
395 395
 }
396 396
 
397
-function wpinv_cart_item_price( $item ) {
398
-    $item_id    = isset( $item['id'] ) ? $item['id'] : 0;
399
-    $price      = isset( $item['item_price'] ) ? wpinv_round_amount( $item['item_price'] ) : 0;
400
-    $tax        = wpinv_price( wpinv_format_amount( $item['tax'] ) );
397
+function wpinv_cart_item_price($item) {
398
+    $item_id    = isset($item['id']) ? $item['id'] : 0;
399
+    $price      = isset($item['item_price']) ? wpinv_round_amount($item['item_price']) : 0;
400
+    $tax        = wpinv_price(wpinv_format_amount($item['tax']));
401 401
     
402
-    if ( !wpinv_is_free_item( $item_id ) && !wpinv_item_is_tax_exclusive( $item_id ) ) {
403
-        if ( wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax() ) {
402
+    if (!wpinv_is_free_item($item_id) && !wpinv_item_is_tax_exclusive($item_id)) {
403
+        if (wpinv_prices_show_tax_on_checkout() && !wpinv_prices_include_tax()) {
404 404
             $price += $tax;
405 405
         }
406 406
         
407
-        if( !wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax() ) {
407
+        if (!wpinv_prices_show_tax_on_checkout() && wpinv_prices_include_tax()) {
408 408
             $price -= $tax;
409 409
         }        
410 410
     }
411 411
 
412
-    $price = wpinv_price( wpinv_format_amount( $price ) );
412
+    $price = wpinv_price(wpinv_format_amount($price));
413 413
 
414
-    return apply_filters( 'wpinv_cart_item_price_label', $price, $item );
414
+    return apply_filters('wpinv_cart_item_price_label', $price, $item);
415 415
 }
416 416
 
417
-function wpinv_cart_item_subtotal( $item ) {
418
-    $subtotal   = isset( $item['subtotal'] ) ? $item['subtotal'] : 0;
419
-    $subtotal   = wpinv_price( wpinv_format_amount( $subtotal ) );
417
+function wpinv_cart_item_subtotal($item) {
418
+    $subtotal   = isset($item['subtotal']) ? $item['subtotal'] : 0;
419
+    $subtotal   = wpinv_price(wpinv_format_amount($subtotal));
420 420
 
421
-    return apply_filters( 'wpinv_cart_item_subtotal_label', $subtotal, $item );
421
+    return apply_filters('wpinv_cart_item_subtotal_label', $subtotal, $item);
422 422
 }
423 423
 
424
-function wpinv_cart_item_tax( $item ) {
424
+function wpinv_cart_item_tax($item) {
425 425
     $tax        = '';
426 426
     $tax_rate   = '';
427 427
     
428
-    if ( isset( $item['tax'] ) && $item['tax'] > 0 && $item['subtotal'] > 0 ) {
429
-        $tax      = wpinv_price( wpinv_format_amount( $item['tax'] ) );
430
-        $tax_rate = !empty( $item['vat_rate'] ) ? $item['vat_rate'] : ( $item['tax'] / $item['subtotal'] ) * 100;
431
-        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount( $tax_rate, 4 ) : '';
428
+    if (isset($item['tax']) && $item['tax'] > 0 && $item['subtotal'] > 0) {
429
+        $tax      = wpinv_price(wpinv_format_amount($item['tax']));
430
+        $tax_rate = !empty($item['vat_rate']) ? $item['vat_rate'] : ($item['tax'] / $item['subtotal']) * 100;
431
+        $tax_rate = $tax_rate > 0 ? (float)wpinv_round_amount($tax_rate, 4) : '';
432 432
         $tax_rate = $tax_rate != '' ? ' <small class="tax-rate normal small">(' . $tax_rate . '%)</small>' : '';
433 433
     }
434 434
     
435
-    $tax        = $tax . $tax_rate;
435
+    $tax = $tax . $tax_rate;
436 436
     
437
-    if ( $tax === '' ) {
437
+    if ($tax === '') {
438 438
         $tax = 0; // Zero tax
439 439
     }
440 440
 
441
-    return apply_filters( 'wpinv_cart_item_tax_label', $tax, $item );
441
+    return apply_filters('wpinv_cart_item_tax_label', $tax, $item);
442 442
 }
443 443
 
444
-function wpinv_get_cart_item_price( $item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false ) {
444
+function wpinv_get_cart_item_price($item_id = 0, $cart_item = array(), $options = array(), $remove_tax_from_inclusive = false) {
445 445
     $price = 0;
446 446
     
447 447
     // Set custom price
448
-    if ( isset( $cart_item['custom_price'] ) && $cart_item['custom_price'] !== '' ) {
448
+    if (isset($cart_item['custom_price']) && $cart_item['custom_price'] !== '') {
449 449
         $price = $cart_item['custom_price'];
450 450
     } else {
451
-        $variable_prices = wpinv_has_variable_prices( $item_id );
451
+        $variable_prices = wpinv_has_variable_prices($item_id);
452 452
 
453
-        if ( $variable_prices ) {
454
-            $prices = wpinv_get_variable_prices( $item_id );
453
+        if ($variable_prices) {
454
+            $prices = wpinv_get_variable_prices($item_id);
455 455
 
456
-            if ( $prices ) {
457
-                if( ! empty( $options ) ) {
458
-                    $price = isset( $prices[ $options['price_id'] ] ) ? $prices[ $options['price_id'] ]['amount'] : false;
456
+            if ($prices) {
457
+                if (!empty($options)) {
458
+                    $price = isset($prices[$options['price_id']]) ? $prices[$options['price_id']]['amount'] : false;
459 459
                 } else {
460 460
                     $price = false;
461 461
                 }
462 462
             }
463 463
         }
464 464
 
465
-        if( ! $variable_prices || false === $price ) {
466
-            if($cart_item['item_price'] > 0){
465
+        if (!$variable_prices || false === $price) {
466
+            if ($cart_item['item_price'] > 0) {
467 467
                 $price = $cart_item['item_price'];
468 468
             } else {
469 469
                 // Get the standard Item price if not using variable prices
470
-                $price = wpinv_get_item_price( $item_id );
470
+                $price = wpinv_get_item_price($item_id);
471 471
             }
472 472
         }
473 473
     }
474 474
 
475
-    if ( $remove_tax_from_inclusive && wpinv_prices_include_tax() ) {
476
-        $price -= wpinv_get_cart_item_tax( $item_id, $price, $options );
475
+    if ($remove_tax_from_inclusive && wpinv_prices_include_tax()) {
476
+        $price -= wpinv_get_cart_item_tax($item_id, $price, $options);
477 477
     }
478 478
 
479
-    return apply_filters( 'wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive );
479
+    return apply_filters('wpinv_cart_item_price', $price, $item_id, $cart_item, $options, $remove_tax_from_inclusive);
480 480
 }
481 481
 
482
-function wpinv_get_cart_item_price_id( $item = array() ) {
483
-    if( isset( $item['item_number'] ) ) {
484
-        $price_id = isset( $item['item_number']['options']['price_id'] ) ? $item['item_number']['options']['price_id'] : null;
482
+function wpinv_get_cart_item_price_id($item = array()) {
483
+    if (isset($item['item_number'])) {
484
+        $price_id = isset($item['item_number']['options']['price_id']) ? $item['item_number']['options']['price_id'] : null;
485 485
     } else {
486
-        $price_id = isset( $item['options']['price_id'] ) ? $item['options']['price_id'] : null;
486
+        $price_id = isset($item['options']['price_id']) ? $item['options']['price_id'] : null;
487 487
     }
488 488
     return $price_id;
489 489
 }
490 490
 
491
-function wpinv_get_cart_item_price_name( $item = array() ) {
492
-    $price_id = (int)wpinv_get_cart_item_price_id( $item );
493
-    $prices   = wpinv_get_variable_prices( $item['id'] );
494
-    $name     = ! empty( $prices[ $price_id ] ) ? $prices[ $price_id ]['name'] : '';
495
-    return apply_filters( 'wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item );
491
+function wpinv_get_cart_item_price_name($item = array()) {
492
+    $price_id = (int)wpinv_get_cart_item_price_id($item);
493
+    $prices   = wpinv_get_variable_prices($item['id']);
494
+    $name     = !empty($prices[$price_id]) ? $prices[$price_id]['name'] : '';
495
+    return apply_filters('wpinv_get_cart_item_price_name', $name, $item['id'], $price_id, $item);
496 496
 }
497 497
 
498
-function wpinv_get_cart_item_name( $item = array() ) {
499
-    $item_title = !empty( $item['name'] ) ? $item['name'] : get_the_title( $item['id'] );
498
+function wpinv_get_cart_item_name($item = array()) {
499
+    $item_title = !empty($item['name']) ? $item['name'] : get_the_title($item['id']);
500 500
 
501
-    if ( empty( $item_title ) ) {
501
+    if (empty($item_title)) {
502 502
         $item_title = $item['id'];
503 503
     }
504 504
 
@@ -508,23 +508,23 @@  discard block
 block discarded – undo
508 508
     }
509 509
     */
510 510
 
511
-    return apply_filters( 'wpinv_get_cart_item_name', $item_title, $item['id'], $item );
511
+    return apply_filters('wpinv_get_cart_item_name', $item_title, $item['id'], $item);
512 512
 }
513 513
 
514
-function wpinv_has_variable_prices( $item_id = 0 ) {
514
+function wpinv_has_variable_prices($item_id = 0) {
515 515
     return false;
516 516
 }
517 517
 
518
-function wpinv_get_item_position_in_cart( $item_id = 0, $options = array() ) {
518
+function wpinv_get_item_position_in_cart($item_id = 0, $options = array()) {
519 519
     $cart_items = wpinv_get_cart_contents();
520 520
 
521
-    if ( !is_array( $cart_items ) ) {
521
+    if (!is_array($cart_items)) {
522 522
         return false; // Empty cart
523 523
     } else {
524
-        foreach ( $cart_items as $position => $item ) {
525
-            if ( $item['id'] == $item_id ) {
526
-                if ( isset( $options['price_id'] ) && isset( $item['options']['price_id'] ) ) {
527
-                    if ( (int) $options['price_id'] == (int) $item['options']['price_id'] ) {
524
+        foreach ($cart_items as $position => $item) {
525
+            if ($item['id'] == $item_id) {
526
+                if (isset($options['price_id']) && isset($item['options']['price_id'])) {
527
+                    if ((int)$options['price_id'] == (int)$item['options']['price_id']) {
528 528
                         return $position;
529 529
                     }
530 530
                 } else {
@@ -537,80 +537,80 @@  discard block
 block discarded – undo
537 537
     return false; // Not found
538 538
 }
539 539
 
540
-function wpinv_get_cart_item_quantity( $item ) {
541
-    if ( wpinv_item_quantities_enabled() ) {
542
-        $quantity = !empty( $item['quantity'] ) && (int)$item['quantity'] > 0 ? absint( $item['quantity'] ) : 1;
540
+function wpinv_get_cart_item_quantity($item) {
541
+    if (wpinv_item_quantities_enabled()) {
542
+        $quantity = !empty($item['quantity']) && (int)$item['quantity'] > 0 ? absint($item['quantity']) : 1;
543 543
     } else {
544 544
         $quantity = 1;
545 545
     }
546 546
     
547
-    if ( $quantity < 1 ) {
547
+    if ($quantity < 1) {
548 548
         $quantity = 1;
549 549
     }
550 550
     
551
-    return apply_filters( 'wpinv_get_cart_item_quantity', $quantity, $item );
551
+    return apply_filters('wpinv_get_cart_item_quantity', $quantity, $item);
552 552
 }
553 553
 
554
-function wpinv_get_item_suffix( $item, $html = true ) {
555
-    if ( empty( $item ) ) {
554
+function wpinv_get_item_suffix($item, $html = true) {
555
+    if (empty($item)) {
556 556
         return NULL;
557 557
     }
558 558
     
559
-    if ( is_int( $item ) ) {
560
-        $item = new WPInv_Item( $item );
559
+    if (is_int($item)) {
560
+        $item = new WPInv_Item($item);
561 561
     }
562 562
     
563
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
563
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
564 564
         return NULL;
565 565
     }
566 566
     
567
-    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __( '(r)', 'invoicing' ) . '</span>' : '';
567
+    $suffix = $item->is_recurring() ? ' <span class="wpi-suffix">' . __('(r)', 'invoicing') . '</span>' : '';
568 568
     
569
-    if ( !$html && $suffix ) {
570
-        $suffix = strip_tags( $suffix );
569
+    if (!$html && $suffix) {
570
+        $suffix = strip_tags($suffix);
571 571
     }
572 572
     
573
-    return apply_filters( 'wpinv_get_item_suffix', $suffix, $item, $html );
573
+    return apply_filters('wpinv_get_item_suffix', $suffix, $item, $html);
574 574
 }
575 575
 
576
-function wpinv_remove_item( $item = 0, $force_delete = false ) {
577
-    if ( empty( $item ) ) {
576
+function wpinv_remove_item($item = 0, $force_delete = false) {
577
+    if (empty($item)) {
578 578
         return NULL;
579 579
     }
580 580
     
581
-    if ( is_int( $item ) ) {
582
-        $item = new WPInv_Item( $item );
581
+    if (is_int($item)) {
582
+        $item = new WPInv_Item($item);
583 583
     }
584 584
     
585
-    if ( !( is_object( $item ) && is_a( $item, 'WPInv_Item' ) ) ) {
585
+    if (!(is_object($item) && is_a($item, 'WPInv_Item'))) {
586 586
         return NULL;
587 587
     }
588 588
     
589
-    do_action( 'wpinv_pre_delete_item', $item );
589
+    do_action('wpinv_pre_delete_item', $item);
590 590
 
591
-    wp_delete_post( $item->ID, $force_delete );
591
+    wp_delete_post($item->ID, $force_delete);
592 592
 
593
-    do_action( 'wpinv_post_delete_item', $item );
593
+    do_action('wpinv_post_delete_item', $item);
594 594
 }
595 595
 
596
-function wpinv_can_delete_item( $post_id ) {
597
-    $return = current_user_can( 'manage_options' ) ? true : false;
596
+function wpinv_can_delete_item($post_id) {
597
+    $return = current_user_can('manage_options') ? true : false;
598 598
     
599
-    if ( $return && wpinv_item_in_use( $post_id ) ) {
599
+    if ($return && wpinv_item_in_use($post_id)) {
600 600
         $return = false; // Don't delete item already use in invoices.
601 601
     }
602 602
     
603
-    return apply_filters( 'wpinv_can_delete_item', $return, $post_id );
603
+    return apply_filters('wpinv_can_delete_item', $return, $post_id);
604 604
 }
605 605
 
606 606
 function wpinv_admin_action_delete() {
607 607
     $screen = get_current_screen();
608 608
     
609
-    if ( !empty( $screen->post_type ) && $screen->post_type == 'wpi_item' && !empty( $_REQUEST['post'] ) && is_array( $_REQUEST['post'] ) ) {
609
+    if (!empty($screen->post_type) && $screen->post_type == 'wpi_item' && !empty($_REQUEST['post']) && is_array($_REQUEST['post'])) {
610 610
         $post_ids = array();
611 611
         
612
-        foreach ( $_REQUEST['post'] as $post_id ) {
613
-            if ( !wpinv_can_delete_item( $post_id ) ) {
612
+        foreach ($_REQUEST['post'] as $post_id) {
613
+            if (!wpinv_can_delete_item($post_id)) {
614 614
                 continue;
615 615
             }
616 616
             
@@ -620,86 +620,86 @@  discard block
 block discarded – undo
620 620
         $_REQUEST['post'] = $post_ids;
621 621
     }
622 622
 }
623
-add_action( 'admin_action_trash', 'wpinv_admin_action_delete', -10 );
624
-add_action( 'admin_action_delete', 'wpinv_admin_action_delete', -10 );
623
+add_action('admin_action_trash', 'wpinv_admin_action_delete', -10);
624
+add_action('admin_action_delete', 'wpinv_admin_action_delete', -10);
625 625
 
626
-function wpinv_check_delete_item( $check, $post, $force_delete ) {
627
-    if ( $post->post_type == 'wpi_item' ) {
628
-        if ( $force_delete && !wpinv_can_delete_item( $post->ID ) ) {
626
+function wpinv_check_delete_item($check, $post, $force_delete) {
627
+    if ($post->post_type == 'wpi_item') {
628
+        if ($force_delete && !wpinv_can_delete_item($post->ID)) {
629 629
             return true;
630 630
         }
631 631
     }
632 632
     
633 633
     return $check;
634 634
 }
635
-add_filter( 'pre_delete_post', 'wpinv_check_delete_item', 10, 3 );
635
+add_filter('pre_delete_post', 'wpinv_check_delete_item', 10, 3);
636 636
 
637
-function wpinv_item_in_use( $item_id ) {
637
+function wpinv_item_in_use($item_id) {
638 638
     global $wpdb, $wpi_items_in_use;
639 639
     
640
-    if ( !$item_id > 0 ) {
640
+    if (!$item_id > 0) {
641 641
         return false;
642 642
     }
643 643
     
644
-    if ( !empty( $wpi_items_in_use ) ) {
645
-        if ( isset( $wpi_items_in_use[$item_id] ) ) {
644
+    if (!empty($wpi_items_in_use)) {
645
+        if (isset($wpi_items_in_use[$item_id])) {
646 646
             return $wpi_items_in_use[$item_id];
647 647
         }
648 648
     } else {
649 649
         $wpi_items_in_use = array();
650 650
     }
651 651
     
652
-    $statuses   = array_keys( wpinv_get_invoice_statuses( true, true ) );
652
+    $statuses = array_keys(wpinv_get_invoice_statuses(true, true));
653 653
     
654
-    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode( "','", $statuses ) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
655
-    $in_use = $wpdb->get_var( $query ) > 0 ? true : false;
654
+    $query  = "SELECT p.ID FROM " . $wpdb->posts . " AS p INNER JOIN " . $wpdb->postmeta . " AS pm ON p.ID = pm.post_id WHERE p.post_type = 'wpi_invoice' AND p.post_status IN( '" . implode("','", $statuses) . "' ) AND pm.meta_key = '_wpinv_item_ids' AND FIND_IN_SET( '" . (int)$item_id . "', pm.meta_value )";
655
+    $in_use = $wpdb->get_var($query) > 0 ? true : false;
656 656
     
657 657
     $wpi_items_in_use[$item_id] = $in_use;
658 658
     
659 659
     return $in_use;
660 660
 }
661 661
 
662
-function wpinv_create_item( $args = array(), $wp_error = false, $force_update = false ) {
662
+function wpinv_create_item($args = array(), $wp_error = false, $force_update = false) {
663 663
     // Set some defaults
664 664
     $defaults = array(
665
-        'type'                 => 'custom',                                                // Optional. Item type. Default 'custom'.
666
-        'title'                => '',                                                      // Required. Item title.
667
-        'custom_id'            => 0,                                                       // Optional. Any integer or non numeric id. Must be unique within item type.
668
-        'price'                => '0.00',                                                  // Optional. Item price. Default '0.00'.
669
-        'status'               => 'pending',                                               // Optional. pending, publish
670
-        'custom_name'          => '',                                                      // Optional. Plural sub title for item.
671
-        'custom_singular_name' => '',                                                      // Optional. Singular sub title for item.
672
-        'vat_rule'             => 'digital',                                               // Optional. digital => Digital item, physical => Physical item
673
-        'editable'             => true,                                                    // Optional. Item editable from Items list page? Default true.
674
-        'excerpt'              => '',                                                      // Optional. Item short description
665
+        'type'                 => 'custom', // Optional. Item type. Default 'custom'.
666
+        'title'                => '', // Required. Item title.
667
+        'custom_id'            => 0, // Optional. Any integer or non numeric id. Must be unique within item type.
668
+        'price'                => '0.00', // Optional. Item price. Default '0.00'.
669
+        'status'               => 'pending', // Optional. pending, publish
670
+        'custom_name'          => '', // Optional. Plural sub title for item.
671
+        'custom_singular_name' => '', // Optional. Singular sub title for item.
672
+        'vat_rule'             => 'digital', // Optional. digital => Digital item, physical => Physical item
673
+        'editable'             => true, // Optional. Item editable from Items list page? Default true.
674
+        'excerpt'              => '', // Optional. Item short description
675 675
         /* Recurring item fields */
676
-        'is_recurring'         => 0,                                                       // Optional. 1 => Allow recurring or 0 => Don't allow recurring
677
-        'recurring_period'     => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
678
-        'recurring_interval'   => 0,                                                       // Optional. Integer value between 1 - 90.
679
-        'recurring_limit'      => 0,                                                       // Optional. Any integer number. 0 for recurring forever until cancelled.
680
-        'free_trial'           => 0,                                                       // Optional. 1 => Allow free trial or 0 => Don't free trial
681
-        'trial_period'         => 'M',                                                     // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
682
-        'trial_interval'       => 0,                                                       // Optional. Any integer number.
676
+        'is_recurring'         => 0, // Optional. 1 => Allow recurring or 0 => Don't allow recurring
677
+        'recurring_period'     => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
678
+        'recurring_interval'   => 0, // Optional. Integer value between 1 - 90.
679
+        'recurring_limit'      => 0, // Optional. Any integer number. 0 for recurring forever until cancelled.
680
+        'free_trial'           => 0, // Optional. 1 => Allow free trial or 0 => Don't free trial
681
+        'trial_period'         => 'M', // Optional. D => Daily, W => Weekly, M => Monthly, Y => Yearly
682
+        'trial_interval'       => 0, // Optional. Any integer number.
683 683
     );
684 684
 
685
-    $data = wp_parse_args( $args, $defaults );
685
+    $data = wp_parse_args($args, $defaults);
686 686
 
687
-    if ( empty( $data['type'] ) ) {
687
+    if (empty($data['type'])) {
688 688
         $data['type'] = 'custom';
689 689
     }
690 690
 
691
-    if ( !empty( $data['custom_id'] ) ) {
692
-        $item = wpinv_get_item_by( 'custom_id', $data['custom_id'], $data['type'] );
691
+    if (!empty($data['custom_id'])) {
692
+        $item = wpinv_get_item_by('custom_id', $data['custom_id'], $data['type']);
693 693
     } else {
694 694
         $item = NULL;
695 695
     }
696 696
 
697
-    if ( !empty( $item ) ) {
698
-        if ( $force_update ) {
699
-            if ( empty( $args['ID'] ) ) {
697
+    if (!empty($item)) {
698
+        if ($force_update) {
699
+            if (empty($args['ID'])) {
700 700
                 $args['ID'] = $item->ID;
701 701
             }
702
-            return wpinv_update_item( $args, $wp_error );
702
+            return wpinv_update_item($args, $wp_error);
703 703
         }
704 704
 
705 705
         return $item;
@@ -710,19 +710,19 @@  discard block
 block discarded – undo
710 710
     $meta['custom_id']              = $data['custom_id'];
711 711
     $meta['custom_singular_name']   = $data['custom_singular_name'];
712 712
     $meta['custom_name']            = $data['custom_name'];
713
-    $meta['price']                  = wpinv_round_amount( $data['price'] );
713
+    $meta['price']                  = wpinv_round_amount($data['price']);
714 714
     $meta['editable']               = (int)$data['editable'];
715 715
     $meta['vat_rule']               = $data['vat_rule'];
716 716
     $meta['vat_class']              = '_standard';
717 717
     
718
-    if ( !empty( $data['is_recurring'] ) ) {
718
+    if (!empty($data['is_recurring'])) {
719 719
         $meta['is_recurring']       = $data['is_recurring'];
720 720
         $meta['recurring_period']   = $data['recurring_period'];
721
-        $meta['recurring_interval'] = absint( $data['recurring_interval'] );
722
-        $meta['recurring_limit']    = absint( $data['recurring_limit'] );
721
+        $meta['recurring_interval'] = absint($data['recurring_interval']);
722
+        $meta['recurring_limit']    = absint($data['recurring_limit']);
723 723
         $meta['free_trial']         = $data['free_trial'];
724 724
         $meta['trial_period']       = $data['trial_period'];
725
-        $meta['trial_interval']     = absint( $data['trial_interval'] );
725
+        $meta['trial_interval']     = absint($data['trial_interval']);
726 726
     } else {
727 727
         $meta['is_recurring']       = 0;
728 728
         $meta['recurring_period']   = '';
@@ -733,7 +733,7 @@  discard block
 block discarded – undo
733 733
         $meta['trial_interval']     = '';
734 734
     }
735 735
     
736
-    $post_data  = array( 
736
+    $post_data = array( 
737 737
         'post_title'    => $data['title'],
738 738
         'post_excerpt'  => $data['excerpt'],
739 739
         'post_status'   => $data['status'],
@@ -741,89 +741,89 @@  discard block
 block discarded – undo
741 741
     );
742 742
 
743 743
     $item = new WPInv_Item();
744
-    $return = $item->create( $post_data, $wp_error );
744
+    $return = $item->create($post_data, $wp_error);
745 745
 
746
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
746
+    if ($return && !empty($item) && !is_wp_error($return)) {
747 747
         return $item;
748 748
     }
749 749
 
750
-    if ( $wp_error && is_wp_error( $return ) ) {
750
+    if ($wp_error && is_wp_error($return)) {
751 751
         return $return;
752 752
     }
753 753
     return 0;
754 754
 }
755 755
 
756
-function wpinv_update_item( $args = array(), $wp_error = false ) {
757
-    $item = !empty( $args['ID'] ) ? new WPInv_Item( $args['ID'] ) : NULL;
756
+function wpinv_update_item($args = array(), $wp_error = false) {
757
+    $item = !empty($args['ID']) ? new WPInv_Item($args['ID']) : NULL;
758 758
 
759
-    if ( empty( $item ) || !( !empty( $item->post_type ) && $item->post_type == 'wpi_item' ) ) {
760
-        if ( $wp_error ) {
761
-            return new WP_Error( 'wpinv_invalid_item', __( 'Invalid item.', 'invoicing' ) );
759
+    if (empty($item) || !(!empty($item->post_type) && $item->post_type == 'wpi_item')) {
760
+        if ($wp_error) {
761
+            return new WP_Error('wpinv_invalid_item', __('Invalid item.', 'invoicing'));
762 762
         }
763 763
         return 0;
764 764
     }
765 765
     
766
-    if ( !empty( $args['custom_id'] ) ) {
767
-        $item_exists = wpinv_get_item_by( 'custom_id', $args['custom_id'], ( !empty( $args['type'] ) ? $args['type'] : $item->type ) );
766
+    if (!empty($args['custom_id'])) {
767
+        $item_exists = wpinv_get_item_by('custom_id', $args['custom_id'], (!empty($args['type']) ? $args['type'] : $item->type));
768 768
         
769
-        if ( !empty( $item_exists ) && $item_exists->ID != $args['ID'] ) {
770
-            if ( $wp_error ) {
771
-                return new WP_Error( 'wpinv_invalid_custom_id', __( 'Item with custom id already exists.', 'invoicing' ) );
769
+        if (!empty($item_exists) && $item_exists->ID != $args['ID']) {
770
+            if ($wp_error) {
771
+                return new WP_Error('wpinv_invalid_custom_id', __('Item with custom id already exists.', 'invoicing'));
772 772
             }
773 773
             return 0;
774 774
         }
775 775
     }
776 776
 
777
-    $meta_fields = array( 'type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval' );
777
+    $meta_fields = array('type', 'custom_id', 'custom_singular_name', 'custom_name', 'price', 'editable', 'vat_rule', 'vat_class', 'is_recurring', 'recurring_period', 'recurring_interval', 'recurring_limit', 'free_trial', 'trial_period', 'trial_interval');
778 778
 
779 779
     $post_data = array();
780
-    if ( isset( $args['title'] ) ) { 
780
+    if (isset($args['title'])) { 
781 781
         $post_data['post_title'] = $args['title'];
782 782
     }
783
-    if ( isset( $args['excerpt'] ) ) { 
783
+    if (isset($args['excerpt'])) { 
784 784
         $post_data['post_excerpt'] = $args['excerpt'];
785 785
     }
786
-    if ( isset( $args['status'] ) ) { 
786
+    if (isset($args['status'])) { 
787 787
         $post_data['post_status'] = $args['status'];
788 788
     }
789 789
     
790
-    foreach ( $meta_fields as $meta_field ) {
791
-        if ( isset( $args[ $meta_field ] ) ) { 
792
-            $value = $args[ $meta_field ];
790
+    foreach ($meta_fields as $meta_field) {
791
+        if (isset($args[$meta_field])) { 
792
+            $value = $args[$meta_field];
793 793
 
794
-            switch ( $meta_field ) {
794
+            switch ($meta_field) {
795 795
                 case 'price':
796
-                    $value = wpinv_round_amount( $value );
796
+                    $value = wpinv_round_amount($value);
797 797
                 break;
798 798
                 case 'recurring_interval':
799 799
                 case 'recurring_limit':
800 800
                 case 'trial_interval':
801
-                    $value = absint( $value );
801
+                    $value = absint($value);
802 802
                 break;
803 803
 				case 'editable':
804
-                    $value = (int) $value;
804
+                    $value = (int)$value;
805 805
                 break;
806 806
             }
807 807
 
808
-            $post_data['meta'][ $meta_field ] = $value;
808
+            $post_data['meta'][$meta_field] = $value;
809 809
         };
810 810
     }
811 811
 
812
-    if ( empty( $post_data ) ) {
813
-        if ( $wp_error ) {
814
-            return new WP_Error( 'wpinv_invalid_item_data', __( 'Invalid item data.', 'invoicing' ) );
812
+    if (empty($post_data)) {
813
+        if ($wp_error) {
814
+            return new WP_Error('wpinv_invalid_item_data', __('Invalid item data.', 'invoicing'));
815 815
         }
816 816
         return 0;
817 817
     }
818 818
     $post_data['ID'] = $args['ID'];
819 819
 
820
-    $return = $item->update( $post_data, $wp_error );
820
+    $return = $item->update($post_data, $wp_error);
821 821
 
822
-    if ( $return && !empty( $item ) && !is_wp_error( $return ) ) {
822
+    if ($return && !empty($item) && !is_wp_error($return)) {
823 823
         return $item;
824 824
     }
825 825
 
826
-    if ( $wp_error && is_wp_error( $return ) ) {
826
+    if ($wp_error && is_wp_error($return)) {
827 827
         return $return;
828 828
     }
829 829
     return 0;
Please login to merge, or discard this patch.
includes/wpinv-invoice-functions.php 4 patches
Braces   +21 added lines, -16 removed lines patch added patch discarded remove patch
@@ -83,8 +83,9 @@  discard block
 block discarded – undo
83 83
 
84 84
     $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
85 85
 
86
-    if ( $invoice_id != NULL )
87
-        return $invoice_id;
86
+    if ( $invoice_id != NULL ) {
87
+            return $invoice_id;
88
+    }
88 89
 
89 90
     return 0;
90 91
 }
@@ -750,8 +751,9 @@  discard block
 block discarded – undo
750 751
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
751 752
     $ret = false;
752 753
 
753
-    if ( empty( $zip ) || empty( $country_code ) )
754
-        return $ret;
754
+    if ( empty( $zip ) || empty( $country_code ) ) {
755
+            return $ret;
756
+    }
755 757
 
756 758
     $country_code = strtoupper( $country_code );
757 759
 
@@ -913,8 +915,9 @@  discard block
 block discarded – undo
913 915
         "ZM" => "\d{5}"
914 916
     );
915 917
 
916
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
917
-        $ret = true;
918
+    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) ) {
919
+            $ret = true;
920
+    }
918 921
 
919 922
     return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
920 923
 }
@@ -1238,14 +1241,15 @@  discard block
 block discarded – undo
1238 1241
         }
1239 1242
     }
1240 1243
     
1241
-    if ( get_query_var( 'paged' ) )
1242
-        $args['page'] = get_query_var('paged');
1243
-    else if ( get_query_var( 'page' ) )
1244
-        $args['page'] = get_query_var( 'page' );
1245
-    else if ( !empty( $args[ 'page' ] ) )
1246
-        $args['page'] = $args[ 'page' ];
1247
-    else
1248
-        $args['page'] = 1;
1244
+    if ( get_query_var( 'paged' ) ) {
1245
+            $args['page'] = get_query_var('paged');
1246
+    } else if ( get_query_var( 'page' ) ) {
1247
+            $args['page'] = get_query_var( 'page' );
1248
+    } else if ( !empty( $args[ 'page' ] ) ) {
1249
+            $args['page'] = $args[ 'page' ];
1250
+    } else {
1251
+            $args['page'] = 1;
1252
+    }
1249 1253
 
1250 1254
     /**
1251 1255
      * Generate WP_Query args. This logic will change if orders are moved to
@@ -1380,8 +1384,9 @@  discard block
 block discarded – undo
1380 1384
 
1381 1385
 	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1382 1386
 
1383
-	if ( $invoice_id != NULL )
1384
-		return $invoice_id;
1387
+	if ( $invoice_id != NULL ) {
1388
+			return $invoice_id;
1389
+	}
1385 1390
 
1386 1391
 	return 0;
1387 1392
 }
Please login to merge, or discard this patch.
Doc Comments   +12 added lines patch added patch discarded remove patch
@@ -488,6 +488,9 @@  discard block
 block discarded – undo
488 488
     return $invoice->get_description();
489 489
 }
490 490
 
491
+/**
492
+ * @return string
493
+ */
491 494
 function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
492 495
     $invoice = new WPInv_Invoice( $invoice_id );
493 496
     return $invoice->get_currency();
@@ -521,6 +524,9 @@  discard block
 block discarded – undo
521 524
     return $invoice->get_gateway_title();
522 525
 }
523 526
 
527
+/**
528
+ * @return string
529
+ */
524 530
 function wpinv_get_payment_transaction_id( $invoice_id ) {
525 531
     $invoice = new WPInv_Invoice( $invoice_id );
526 532
     
@@ -616,6 +622,9 @@  discard block
 block discarded – undo
616 622
     return $invoice->get_total( $currency );
617 623
 }
618 624
 
625
+/**
626
+ * @return string
627
+ */
619 628
 function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
620 629
     $invoice = new WPInv_Invoice( $invoice_id );
621 630
 
@@ -626,6 +635,9 @@  discard block
 block discarded – undo
626 635
     return $date_created;
627 636
 }
628 637
 
638
+/**
639
+ * @return string
640
+ */
629 641
 function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
630 642
     $invoice = new WPInv_Invoice( $invoice_id );
631 643
     
Please login to merge, or discard this patch.
Indentation   +70 added lines, -70 removed lines patch added patch discarded remove patch
@@ -669,7 +669,7 @@  discard block
 block discarded – undo
669 669
 }
670 670
 
671 671
 function wpinv_get_payment_key( $invoice_id = 0 ) {
672
-	$invoice = new WPInv_Invoice( $invoice_id );
672
+    $invoice = new WPInv_Invoice( $invoice_id );
673 673
     return $invoice->get_key();
674 674
 }
675 675
 
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
         return false;
920 920
     }
921 921
     $invoice = wpinv_get_invoice_cart();
922
-	if ( empty( $invoice ) ) {
922
+    if ( empty( $invoice ) ) {
923 923
         return false;
924 924
     }
925 925
 
@@ -1216,20 +1216,20 @@  discard block
 block discarded – undo
1216 1216
 }
1217 1217
 
1218 1218
 function wpinv_checkout_get_cc_info() {
1219
-	$cc_info = array();
1220
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1221
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1222
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1223
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1224
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1225
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1226
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1227
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1228
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1229
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1230
-
1231
-	// Return cc info
1232
-	return $cc_info;
1219
+    $cc_info = array();
1220
+    $cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1221
+    $cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1222
+    $cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1223
+    $cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1224
+    $cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1225
+    $cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1226
+    $cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1227
+    $cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1228
+    $cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1229
+    $cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1230
+
1231
+    // Return cc info
1232
+    return $cc_info;
1233 1233
 }
1234 1234
 
1235 1235
 function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
@@ -1436,7 +1436,7 @@  discard block
 block discarded – undo
1436 1436
         $required_fields  = wpinv_checkout_required_fields();
1437 1437
 
1438 1438
         // Loop through required fields and show error messages
1439
-         if ( !empty( $required_fields ) ) {
1439
+            if ( !empty( $required_fields ) ) {
1440 1440
             foreach ( $required_fields as $field_name => $value ) {
1441 1441
                 if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1442 1442
                     wpinv_set_error( $value['error_id'], $value['error_message'] );
@@ -1539,7 +1539,7 @@  discard block
 block discarded – undo
1539 1539
 }
1540 1540
 
1541 1541
 function wpinv_get_checkout_session() {
1542
-	global $wpi_session;
1542
+    global $wpi_session;
1543 1543
     
1544 1544
     return $wpi_session->get( 'wpinv_checkout' );
1545 1545
 }
@@ -1620,7 +1620,7 @@  discard block
 block discarded – undo
1620 1620
         $response['data']['taxf']       = $invoice->get_tax( true );
1621 1621
         $response['data']['total']      = $invoice->get_total();
1622 1622
         $response['data']['totalf']     = $invoice->get_total( true );
1623
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1623
+        $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1624 1624
 
1625 1625
         wp_send_json( $response );
1626 1626
     }
@@ -1905,57 +1905,57 @@  discard block
 block discarded – undo
1905 1905
 }
1906 1906
 
1907 1907
 function wpinv_get_invoice_id_by_key( $key ) {
1908
-	global $wpdb;
1908
+    global $wpdb;
1909 1909
 
1910
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1910
+    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1911 1911
 
1912
-	if ( $invoice_id != NULL )
1913
-		return $invoice_id;
1912
+    if ( $invoice_id != NULL )
1913
+        return $invoice_id;
1914 1914
 
1915
-	return 0;
1915
+    return 0;
1916 1916
 }
1917 1917
 
1918 1918
 function wpinv_can_view_receipt( $invoice_key = '' ) {
1919
-	$return = false;
1919
+    $return = false;
1920 1920
 
1921
-	if ( empty( $invoice_key ) ) {
1922
-		return $return;
1923
-	}
1921
+    if ( empty( $invoice_key ) ) {
1922
+        return $return;
1923
+    }
1924 1924
 
1925
-	global $wpinv_receipt_args;
1925
+    global $wpinv_receipt_args;
1926 1926
 
1927
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1928
-	if ( isset( $_GET['invoice-id'] ) ) {
1929
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1930
-	}
1927
+    $wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1928
+    if ( isset( $_GET['invoice-id'] ) ) {
1929
+        $wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1930
+    }
1931 1931
 
1932
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1933
-		return $return;
1934
-	}
1932
+    if ( empty( $wpinv_receipt_args['id'] ) ) {
1933
+        return $return;
1934
+    }
1935 1935
 
1936
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1937
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1938
-		return $return;
1939
-	}
1936
+    $invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1937
+    if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1938
+        return $return;
1939
+    }
1940 1940
 
1941
-	if ( is_user_logged_in() ) {
1942
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1943
-			$return = true;
1944
-		}
1945
-	}
1941
+    if ( is_user_logged_in() ) {
1942
+        if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1943
+            $return = true;
1944
+        }
1945
+    }
1946 1946
 
1947
-	$session = wpinv_get_checkout_session();
1948
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1949
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1947
+    $session = wpinv_get_checkout_session();
1948
+    if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1949
+        $check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1950 1950
 
1951
-		if ( wpinv_require_login_to_checkout() ) {
1952
-			$return = $return && $check_key === $invoice_key;
1953
-		} else {
1954
-			$return = $check_key === $invoice_key;
1955
-		}
1956
-	}
1951
+        if ( wpinv_require_login_to_checkout() ) {
1952
+            $return = $return && $check_key === $invoice_key;
1953
+        } else {
1954
+            $return = $check_key === $invoice_key;
1955
+        }
1956
+    }
1957 1957
 
1958
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1958
+    return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1959 1959
 }
1960 1960
 
1961 1961
 function wpinv_pay_for_invoice() {
@@ -2263,14 +2263,14 @@  discard block
 block discarded – undo
2263 2263
 
2264 2264
     if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2265 2265
         $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2266
-	    global $post;
2266
+        global $post;
2267 2267
 
2268 2268
         if(!empty($invoice_key)){
2269
-	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2269
+            $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2270 2270
         } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2271
-			$invoice_id = $post->ID;
2271
+            $invoice_id = $post->ID;
2272 2272
         } else {
2273
-        	return;
2273
+            return;
2274 2274
         }
2275 2275
 
2276 2276
         $invoice = new WPInv_Invoice($invoice_id);
@@ -2279,17 +2279,17 @@  discard block
 block discarded – undo
2279 2279
             return;
2280 2280
         }
2281 2281
 
2282
-	    if ( is_user_logged_in() ) {
2283
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2284
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2285
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2286
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2287
-		    }
2288
-	    } else {
2289
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2290
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2291
-		    }
2292
-	    }
2282
+        if ( is_user_logged_in() ) {
2283
+            if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2284
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2285
+            } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2286
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2287
+            }
2288
+        } else {
2289
+            if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2290
+                update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2291
+            }
2292
+        }
2293 2293
     }
2294 2294
 
2295 2295
 }
Please login to merge, or discard this patch.
Spacing   +758 added lines, -758 removed lines patch added patch discarded remove patch
@@ -7,40 +7,40 @@  discard block
 block discarded – undo
7 7
  */
8 8
  
9 9
 // MUST have WordPress.
10
-if ( !defined( 'WPINC' ) ) {
11
-    exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) );
10
+if (!defined('WPINC')) {
11
+    exit('Do NOT access this file directly: ' . basename(__FILE__));
12 12
 }
13 13
 
14 14
 function wpinv_get_invoice_cart_id() {
15 15
     $wpinv_checkout = wpinv_get_checkout_session();
16 16
     
17
-    if ( !empty( $wpinv_checkout['invoice_id'] ) ) {
17
+    if (!empty($wpinv_checkout['invoice_id'])) {
18 18
         return $wpinv_checkout['invoice_id'];
19 19
     }
20 20
     
21 21
     return NULL;
22 22
 }
23 23
 
24
-function wpinv_insert_invoice( $invoice_data = array(), $wp_error = false ) {
25
-    if ( empty( $invoice_data ) ) {
24
+function wpinv_insert_invoice($invoice_data = array(), $wp_error = false) {
25
+    if (empty($invoice_data)) {
26 26
         return false;
27 27
     }
28 28
     
29
-    if ( !( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) ) {
30
-        return $wp_error ? new WP_Error( 'wpinv_invalid_items', __( 'Invoice must have atleast on item.', 'invoicing' ) ) : 0;
29
+    if (!(!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']))) {
30
+        return $wp_error ? new WP_Error('wpinv_invalid_items', __('Invoice must have atleast on item.', 'invoicing')) : 0;
31 31
     }
32 32
     
33
-    if ( empty( $invoice_data['user_id'] ) ) {
33
+    if (empty($invoice_data['user_id'])) {
34 34
         $invoice_data['user_id'] = get_current_user_id();
35 35
     }
36 36
     
37
-    $invoice_data['invoice_id'] = !empty( $invoice_data['invoice_id'] ) ? (int)$invoice_data['invoice_id'] : 0;
37
+    $invoice_data['invoice_id'] = !empty($invoice_data['invoice_id']) ? (int)$invoice_data['invoice_id'] : 0;
38 38
     
39
-    if ( empty( $invoice_data['status'] ) ) {
39
+    if (empty($invoice_data['status'])) {
40 40
         $invoice_data['status'] = 'wpi-pending';
41 41
     }
42 42
     
43
-    if ( empty( $invoice_data['ip'] ) ) {
43
+    if (empty($invoice_data['ip'])) {
44 44
         $invoice_data['ip'] = wpinv_get_ip();
45 45
     }
46 46
 
@@ -51,12 +51,12 @@  discard block
 block discarded – undo
51 51
         'status'        => $invoice_data['status'],
52 52
     );
53 53
 
54
-    $invoice = wpinv_create_invoice( $default_args, $invoice_data, true );
55
-    if ( is_wp_error( $invoice ) ) {
54
+    $invoice = wpinv_create_invoice($default_args, $invoice_data, true);
55
+    if (is_wp_error($invoice)) {
56 56
         return $wp_error ? $invoice : 0;
57 57
     }
58 58
     
59
-    if ( empty( $invoice_data['invoice_id'] ) ) {
59
+    if (empty($invoice_data['invoice_id'])) {
60 60
         //$invoice->add_note( wp_sprintf( __( 'Invoice is created with status %s.', 'invoicing' ), wpinv_status_nicename( $invoice->status ) ) );
61 61
     }
62 62
     
@@ -79,24 +79,24 @@  discard block
 block discarded – undo
79 79
         'discount'              => array(),
80 80
     );
81 81
 
82
-    if ( $user_id = (int)$invoice->get_user_id() ) {
83
-        if ( $user_address = wpinv_get_user_address( $user_id ) ) {
84
-            $default_user_info = wp_parse_args( $user_address, $default_user_info );
82
+    if ($user_id = (int)$invoice->get_user_id()) {
83
+        if ($user_address = wpinv_get_user_address($user_id)) {
84
+            $default_user_info = wp_parse_args($user_address, $default_user_info);
85 85
         }
86 86
     }
87 87
     
88
-    if ( empty( $invoice_data['user_info'] ) ) {
88
+    if (empty($invoice_data['user_info'])) {
89 89
         $invoice_data['user_info'] = array();
90 90
     }
91 91
     
92
-    $user_info = wp_parse_args( $invoice_data['user_info'], $default_user_info );
92
+    $user_info = wp_parse_args($invoice_data['user_info'], $default_user_info);
93 93
     
94
-    if ( empty( $user_info['first_name'] ) ) {
94
+    if (empty($user_info['first_name'])) {
95 95
         $user_info['first_name'] = $default_user_info['first_name'];
96 96
         $user_info['last_name'] = $default_user_info['last_name'];
97 97
     }
98 98
     
99
-    if ( empty( $user_info['country'] ) ) {
99
+    if (empty($user_info['country'])) {
100 100
         $user_info['country'] = $default_user_info['country'];
101 101
         $user_info['state'] = $default_user_info['state'];
102 102
         $user_info['city'] = $default_user_info['city'];
@@ -105,13 +105,13 @@  discard block
 block discarded – undo
105 105
         $user_info['phone'] = $default_user_info['phone'];
106 106
     }
107 107
     
108
-    if ( !empty( $user_info['discount'] ) && !is_array( $user_info['discount'] ) ) {
108
+    if (!empty($user_info['discount']) && !is_array($user_info['discount'])) {
109 109
         $user_info['discount'] = (array)$user_info['discount'];
110 110
     }
111 111
 
112 112
     // Payment details
113 113
     $payment_details = array();
114
-    if ( !empty( $invoice_data['payment_details'] ) ) {
114
+    if (!empty($invoice_data['payment_details'])) {
115 115
         $default_payment_details = array(
116 116
             'gateway'           => 'manual',
117 117
             'gateway_title'     => '',
@@ -119,56 +119,56 @@  discard block
 block discarded – undo
119 119
             'transaction_id'    => '',
120 120
         );
121 121
         
122
-        $payment_details = wp_parse_args( $invoice_data['payment_details'], $default_payment_details );
122
+        $payment_details = wp_parse_args($invoice_data['payment_details'], $default_payment_details);
123 123
         
124
-        if ( empty( $payment_details['gateway'] ) ) {
124
+        if (empty($payment_details['gateway'])) {
125 125
             $payment_details['gateway'] = 'manual';
126 126
         }
127 127
         
128
-        if ( empty( $payment_details['currency'] ) ) {
128
+        if (empty($payment_details['currency'])) {
129 129
             $payment_details['currency'] = wpinv_get_default_country();
130 130
         }
131 131
         
132
-        if ( empty( $payment_details['gateway_title'] ) ) {
133
-            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label( $payment_details['gateway'] );
132
+        if (empty($payment_details['gateway_title'])) {
133
+            $payment_details['gateway_title'] = wpinv_get_gateway_checkout_label($payment_details['gateway']);
134 134
         }
135 135
     }
136 136
     
137
-    $invoice->set( 'status', ( !empty( $invoice_data['status'] ) ? $invoice_data['status'] : 'wpi-pending' ) );
138
-    
139
-    if ( !empty( $payment_details ) ) {
140
-        $invoice->set( 'currency', $payment_details['currency'] );
141
-        $invoice->set( 'gateway', $payment_details['gateway'] );
142
-        $invoice->set( 'gateway_title', $payment_details['gateway_title'] );
143
-        $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
144
-    }
145
-    
146
-    $invoice->set( 'user_info', $user_info );
147
-    $invoice->set( 'first_name', $user_info['first_name'] );
148
-    $invoice->set( 'last_name', $user_info['last_name'] );
149
-    $invoice->set( 'address', $user_info['address'] );
150
-    $invoice->set( 'company', $user_info['company'] );
151
-    $invoice->set( 'vat_number', $user_info['vat_number'] );
152
-    $invoice->set( 'phone', $user_info['phone'] );
153
-    $invoice->set( 'city', $user_info['city'] );
154
-    $invoice->set( 'country', $user_info['country'] );
155
-    $invoice->set( 'state', $user_info['state'] );
156
-    $invoice->set( 'zip', $user_info['zip'] );
157
-    $invoice->set( 'discounts', $user_info['discount'] );
158
-    $invoice->set( 'ip', ( !empty( $invoice_data['ip'] ) ? $invoice_data['ip'] : wpinv_get_ip() ) );
159
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
160
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
161
-    
162
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
163
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
164
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
165
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
166
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
167
-            $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : '';
137
+    $invoice->set('status', (!empty($invoice_data['status']) ? $invoice_data['status'] : 'wpi-pending'));
138
+    
139
+    if (!empty($payment_details)) {
140
+        $invoice->set('currency', $payment_details['currency']);
141
+        $invoice->set('gateway', $payment_details['gateway']);
142
+        $invoice->set('gateway_title', $payment_details['gateway_title']);
143
+        $invoice->set('transaction_id', $payment_details['transaction_id']);
144
+    }
145
+    
146
+    $invoice->set('user_info', $user_info);
147
+    $invoice->set('first_name', $user_info['first_name']);
148
+    $invoice->set('last_name', $user_info['last_name']);
149
+    $invoice->set('address', $user_info['address']);
150
+    $invoice->set('company', $user_info['company']);
151
+    $invoice->set('vat_number', $user_info['vat_number']);
152
+    $invoice->set('phone', $user_info['phone']);
153
+    $invoice->set('city', $user_info['city']);
154
+    $invoice->set('country', $user_info['country']);
155
+    $invoice->set('state', $user_info['state']);
156
+    $invoice->set('zip', $user_info['zip']);
157
+    $invoice->set('discounts', $user_info['discount']);
158
+    $invoice->set('ip', (!empty($invoice_data['ip']) ? $invoice_data['ip'] : wpinv_get_ip()));
159
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
160
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
161
+    
162
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
163
+        foreach ($invoice_data['cart_details'] as $key => $item) {
164
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
165
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
166
+            $name           = !empty($item['name']) ? $item['name'] : '';
167
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
168 168
             
169
-            $post_item  = new WPInv_Item( $item_id );
170
-            if ( !empty( $post_item ) ) {
171
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
169
+            $post_item = new WPInv_Item($item_id);
170
+            if (!empty($post_item)) {
171
+                $name       = !empty($name) ? $name : $post_item->get_name();
172 172
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
173 173
             } else {
174 174
                 continue;
@@ -178,253 +178,253 @@  discard block
 block discarded – undo
178 178
                 'name'          => $name,
179 179
                 'quantity'      => $quantity,
180 180
                 'item_price'    => $item_price,
181
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
182
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
183
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
184
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
185
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
181
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
182
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
183
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
184
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
185
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
186 186
             );
187 187
 
188
-            $invoice->add_item( $item_id, $args );
188
+            $invoice->add_item($item_id, $args);
189 189
         }
190 190
     }
191 191
 
192
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
192
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
193 193
 
194
-    if ( isset( $invoice_data['post_date'] ) ) {
195
-        $invoice->set( 'date', $invoice_data['post_date'] );
194
+    if (isset($invoice_data['post_date'])) {
195
+        $invoice->set('date', $invoice_data['post_date']);
196 196
     }
197 197
     
198 198
     // Invoice due date
199
-    if ( isset( $invoice_data['due_date'] ) ) {
200
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
199
+    if (isset($invoice_data['due_date'])) {
200
+        $invoice->set('due_date', $invoice_data['due_date']);
201 201
     }
202 202
     
203 203
     $invoice->save();
204 204
     
205 205
     // Add notes
206
-    if ( !empty( $invoice_data['private_note'] ) ) {
207
-        $invoice->add_note( $invoice_data['private_note'] );
206
+    if (!empty($invoice_data['private_note'])) {
207
+        $invoice->add_note($invoice_data['private_note']);
208 208
     }
209
-    if ( !empty( $invoice_data['user_note'] ) ) {
210
-        $invoice->add_note( $invoice_data['user_note'], true );
209
+    if (!empty($invoice_data['user_note'])) {
210
+        $invoice->add_note($invoice_data['user_note'], true);
211 211
     }
212 212
     
213
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
213
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
214 214
 
215
-    if ( ! empty( $invoice->ID ) ) {
215
+    if (!empty($invoice->ID)) {
216 216
         global $wpi_userID, $wpinv_ip_address_country;
217 217
         
218 218
         $checkout_session = wpinv_get_checkout_session();
219 219
         
220 220
         $data_session                   = array();
221 221
         $data_session['invoice_id']     = $invoice->ID;
222
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
222
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
223 223
         
224
-        wpinv_set_checkout_session( $data_session );
224
+        wpinv_set_checkout_session($data_session);
225 225
         
226 226
         $wpi_userID         = (int)$invoice->get_user_id();
227 227
         
228
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
228
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
229 229
         $_POST['state']     = $invoice->state;
230 230
 
231
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
232
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
231
+        $invoice->set('country', sanitize_text_field($_POST['country']));
232
+        $invoice->set('state', sanitize_text_field($_POST['state']));
233 233
         
234 234
         $wpinv_ip_address_country = $invoice->country;
235 235
         
236
-        $invoice = $invoice->recalculate_totals( true );
236
+        $invoice = $invoice->recalculate_totals(true);
237 237
         
238
-        wpinv_set_checkout_session( $checkout_session );
238
+        wpinv_set_checkout_session($checkout_session);
239 239
                     
240 240
         return $invoice;
241 241
     }
242 242
     
243
-    if ( $wp_error ) {
244
-        if ( is_wp_error( $invoice ) ) {
243
+    if ($wp_error) {
244
+        if (is_wp_error($invoice)) {
245 245
             return $invoice;
246 246
         } else {
247
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
247
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
248 248
         }
249 249
     } else {
250 250
         return 0;
251 251
     }
252 252
 }
253 253
 
254
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
255
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
254
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
255
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
256 256
 
257
-    if ( !$invoice_ID ) {
258
-        if ( $wp_error ) {
259
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
257
+    if (!$invoice_ID) {
258
+        if ($wp_error) {
259
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
260 260
         }
261 261
         return 0;
262 262
     }
263 263
 
264
-    $invoice = wpinv_get_invoice( $invoice_ID );
264
+    $invoice = wpinv_get_invoice($invoice_ID);
265 265
 
266
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
266
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
267 267
 
268
-    if ( empty( $invoice->ID ) ) {
269
-        if ( $wp_error ) {
270
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
268
+    if (empty($invoice->ID)) {
269
+        if ($wp_error) {
270
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
271 271
         }
272 272
         return 0;
273 273
     }
274 274
 
275
-    if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) {
276
-        if ( $wp_error ) {
277
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
275
+    if (!$invoice->has_status(array('wpi-pending'))) {
276
+        if ($wp_error) {
277
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
278 278
         }
279 279
         return 0;
280 280
     }
281 281
 
282 282
     // Invoice status
283
-    if ( !empty( $invoice_data['status'] ) ) {
284
-        $invoice->set( 'status', $invoice_data['status'] );
283
+    if (!empty($invoice_data['status'])) {
284
+        $invoice->set('status', $invoice_data['status']);
285 285
     }
286 286
 
287 287
     // Invoice date
288
-    if ( !empty( $invoice_data['post_date'] ) ) {
289
-        $invoice->set( 'date', $invoice_data['post_date'] );
288
+    if (!empty($invoice_data['post_date'])) {
289
+        $invoice->set('date', $invoice_data['post_date']);
290 290
     }
291 291
 
292 292
     // Invoice due date
293
-    if ( isset( $invoice_data['due_date'] ) ) {
294
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
293
+    if (isset($invoice_data['due_date'])) {
294
+        $invoice->set('due_date', $invoice_data['due_date']);
295 295
     }
296 296
 
297 297
     // Invoice IP address
298
-    if ( !empty( $invoice_data['ip'] ) ) {
299
-        $invoice->set( 'ip', $invoice_data['ip'] );
298
+    if (!empty($invoice_data['ip'])) {
299
+        $invoice->set('ip', $invoice_data['ip']);
300 300
     }
301 301
     
302 302
     // User info
303
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
304
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
303
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
304
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
305 305
 
306
-        if ( $discounts = $invoice->get_discounts() ) {
306
+        if ($discounts = $invoice->get_discounts()) {
307 307
             $set_discount = $discounts;
308 308
         } else {
309 309
             $set_discount = '';
310 310
         }
311 311
 
312 312
         // Manage discount
313
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
313
+        if (!empty($invoice_data['user_info']['discount'])) {
314 314
             // Remove discount
315
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
315
+            if ($invoice_data['user_info']['discount'] == 'none') {
316 316
                 $set_discount = '';
317 317
             } else {
318 318
                 $set_discount = $invoice_data['user_info']['discount'];
319 319
             }
320 320
 
321
-            $invoice->set( 'discounts', $set_discount );
321
+            $invoice->set('discounts', $set_discount);
322 322
         }
323 323
 
324 324
         $user_info['discount'] = $set_discount;
325 325
 
326
-        $invoice->set( 'user_info', $user_info );
326
+        $invoice->set('user_info', $user_info);
327 327
     }
328 328
 
329
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
330
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
329
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
330
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
331 331
 
332
-        if ( !empty( $remove_items[0]['id'] ) ) {
333
-            foreach ( $remove_items as $item ) {
334
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
335
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
336
-                if ( empty( $item_id ) ) {
332
+        if (!empty($remove_items[0]['id'])) {
333
+            foreach ($remove_items as $item) {
334
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
335
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
336
+                if (empty($item_id)) {
337 337
                     continue;
338 338
                 }
339 339
 
340
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
341
-                    if ( $item_id == $cart_item['id'] ) {
340
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
341
+                    if ($item_id == $cart_item['id']) {
342 342
                         $args = array(
343 343
                             'id'         => $item_id,
344 344
                             'quantity'   => $quantity,
345 345
                             'cart_index' => $cart_index
346 346
                         );
347 347
 
348
-                        $invoice->remove_item( $item_id, $args );
348
+                        $invoice->remove_item($item_id, $args);
349 349
                         break;
350 350
                     }
351 351
                 }
352 352
             }
353 353
         }
354 354
 
355
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
355
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
356 356
 
357
-        if ( !empty( $add_items[0]['id'] ) ) {
358
-            foreach ( $add_items as $item ) {
359
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
360
-                $post_item      = new WPInv_Item( $item_id );
361
-                if ( empty( $post_item ) ) {
357
+        if (!empty($add_items[0]['id'])) {
358
+            foreach ($add_items as $item) {
359
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
360
+                $post_item      = new WPInv_Item($item_id);
361
+                if (empty($post_item)) {
362 362
                     continue;
363 363
                 }
364 364
 
365 365
                 $valid_item = true;
366
-                if ( !empty( $recurring_item ) ) {
367
-                    if ( $recurring_item->ID != $item_id ) {
366
+                if (!empty($recurring_item)) {
367
+                    if ($recurring_item->ID != $item_id) {
368 368
                         $valid_item = false;
369 369
                     }
370
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
370
+                } else if (wpinv_is_recurring_item($item_id)) {
371 371
                     $valid_item = false;
372 372
                 }
373 373
                 
374
-                if ( !$valid_item ) {
375
-                    if ( $wp_error ) {
376
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item because recurring item must be paid individually!', 'invoicing' ) );
374
+                if (!$valid_item) {
375
+                    if ($wp_error) {
376
+                        return new WP_Error('invalid_invoice_item', __('You can not add item because recurring item must be paid individually!', 'invoicing'));
377 377
                     }
378 378
                     return 0;
379 379
                 }
380 380
 
381
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
382
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
383
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
381
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
382
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
383
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
384 384
 
385 385
                 $args = array(
386 386
                     'name'          => $name,
387 387
                     'quantity'      => $quantity,
388 388
                     'item_price'    => $item_price,
389
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
390
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
391
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
392
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
393
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
389
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
390
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
391
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
392
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
393
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
394 394
                 );
395 395
 
396
-                $invoice->add_item( $item_id, $args );
396
+                $invoice->add_item($item_id, $args);
397 397
             }
398 398
         }
399 399
     }
400 400
     
401 401
     // Payment details
402
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
403
-        if ( !empty( $payment_details['gateway'] ) ) {
404
-            $invoice->set( 'gateway', $payment_details['gateway'] );
402
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
403
+        if (!empty($payment_details['gateway'])) {
404
+            $invoice->set('gateway', $payment_details['gateway']);
405 405
         }
406 406
 
407
-        if ( !empty( $payment_details['transaction_id'] ) ) {
408
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
407
+        if (!empty($payment_details['transaction_id'])) {
408
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
409 409
         }
410 410
     }
411 411
 
412
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
412
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
413 413
 
414 414
     // Parent invoice
415
-    if ( !empty( $invoice_data['parent'] ) ) {
416
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
415
+    if (!empty($invoice_data['parent'])) {
416
+        $invoice->set('parent_invoice', $invoice_data['parent']);
417 417
     }
418 418
 
419 419
     // Save invoice data.
420 420
     $invoice->save();
421 421
     
422
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
423
-        if ( $wp_error ) {
424
-            if ( is_wp_error( $invoice ) ) {
422
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
423
+        if ($wp_error) {
424
+            if (is_wp_error($invoice)) {
425 425
                 return $invoice;
426 426
             } else {
427
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
427
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
428 428
             }
429 429
         } else {
430 430
             return 0;
@@ -432,13 +432,13 @@  discard block
 block discarded – undo
432 432
     }
433 433
 
434 434
     // Add private note
435
-    if ( !empty( $invoice_data['private_note'] ) ) {
436
-        $invoice->add_note( $invoice_data['private_note'] );
435
+    if (!empty($invoice_data['private_note'])) {
436
+        $invoice->add_note($invoice_data['private_note']);
437 437
     }
438 438
 
439 439
     // Add user note
440
-    if ( !empty( $invoice_data['user_note'] ) ) {
441
-        $invoice->add_note( $invoice_data['user_note'], true );
440
+    if (!empty($invoice_data['user_note'])) {
441
+        $invoice->add_note($invoice_data['user_note'], true);
442 442
     }
443 443
 
444 444
     global $wpi_userID, $wpinv_ip_address_country;
@@ -447,450 +447,450 @@  discard block
 block discarded – undo
447 447
 
448 448
     $data_session                   = array();
449 449
     $data_session['invoice_id']     = $invoice->ID;
450
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
450
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
451 451
 
452
-    wpinv_set_checkout_session( $data_session );
452
+    wpinv_set_checkout_session($data_session);
453 453
 
454 454
     $wpi_userID         = (int)$invoice->get_user_id();
455 455
 
456
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
456
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
457 457
     $_POST['state']     = $invoice->state;
458 458
 
459
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
460
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
459
+    $invoice->set('country', sanitize_text_field($_POST['country']));
460
+    $invoice->set('state', sanitize_text_field($_POST['state']));
461 461
 
462 462
     $wpinv_ip_address_country = $invoice->country;
463 463
 
464
-    $invoice = $invoice->recalculate_totals( true );
464
+    $invoice = $invoice->recalculate_totals(true);
465 465
 
466
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
466
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
467 467
 
468
-    wpinv_set_checkout_session( $checkout_session );
468
+    wpinv_set_checkout_session($checkout_session);
469 469
 
470 470
     return $invoice;
471 471
 }
472 472
 
473
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
474
-    if ( $cart && empty( $invoice_id ) ) {
473
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
474
+    if ($cart && empty($invoice_id)) {
475 475
         $invoice_id = (int)wpinv_get_invoice_cart_id();
476 476
     }
477 477
 
478
-    $invoice = new WPInv_Invoice( $invoice_id );
478
+    $invoice = new WPInv_Invoice($invoice_id);
479 479
 
480
-    if ( ! empty( $invoice ) && ! empty( $invoice->ID ) ) {
480
+    if (!empty($invoice) && !empty($invoice->ID)) {
481 481
         return $invoice;
482 482
     }
483 483
     
484 484
     return NULL;
485 485
 }
486 486
 
487
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
488
-    return wpinv_get_invoice( $invoice_id, true );
487
+function wpinv_get_invoice_cart($invoice_id = 0) {
488
+    return wpinv_get_invoice($invoice_id, true);
489 489
 }
490 490
 
491
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
492
-    $invoice = new WPInv_Invoice( $invoice_id );
491
+function wpinv_get_invoice_description($invoice_id = 0) {
492
+    $invoice = new WPInv_Invoice($invoice_id);
493 493
     return $invoice->get_description();
494 494
 }
495 495
 
496
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
497
-    $invoice = new WPInv_Invoice( $invoice_id );
496
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
497
+    $invoice = new WPInv_Invoice($invoice_id);
498 498
     return $invoice->get_currency();
499 499
 }
500 500
 
501
-function wpinv_get_payment_user_email( $invoice_id ) {
502
-    $invoice = new WPInv_Invoice( $invoice_id );
501
+function wpinv_get_payment_user_email($invoice_id) {
502
+    $invoice = new WPInv_Invoice($invoice_id);
503 503
     return $invoice->get_email();
504 504
 }
505 505
 
506
-function wpinv_get_user_id( $invoice_id ) {
507
-    $invoice = new WPInv_Invoice( $invoice_id );
506
+function wpinv_get_user_id($invoice_id) {
507
+    $invoice = new WPInv_Invoice($invoice_id);
508 508
     return $invoice->get_user_id();
509 509
 }
510 510
 
511
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
512
-    $invoice = new WPInv_Invoice( $invoice_id );
511
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
512
+    $invoice = new WPInv_Invoice($invoice_id);
513 513
     
514
-    return $invoice->get_status( $return_label );
514
+    return $invoice->get_status($return_label);
515 515
 }
516 516
 
517
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
518
-    $invoice = new WPInv_Invoice( $invoice_id );
517
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
518
+    $invoice = new WPInv_Invoice($invoice_id);
519 519
     
520
-    return $invoice->get_gateway( $return_label );
520
+    return $invoice->get_gateway($return_label);
521 521
 }
522 522
 
523
-function wpinv_get_payment_gateway_name( $invoice_id ) {
524
-    $invoice = new WPInv_Invoice( $invoice_id );
523
+function wpinv_get_payment_gateway_name($invoice_id) {
524
+    $invoice = new WPInv_Invoice($invoice_id);
525 525
     
526 526
     return $invoice->get_gateway_title();
527 527
 }
528 528
 
529
-function wpinv_get_payment_transaction_id( $invoice_id ) {
530
-    $invoice = new WPInv_Invoice( $invoice_id );
529
+function wpinv_get_payment_transaction_id($invoice_id) {
530
+    $invoice = new WPInv_Invoice($invoice_id);
531 531
     
532 532
     return $invoice->get_transaction_id();
533 533
 }
534 534
 
535
-function wpinv_get_id_by_transaction_id( $key ) {
535
+function wpinv_get_id_by_transaction_id($key) {
536 536
     global $wpdb;
537 537
 
538
-    $invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key ) );
538
+    $invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_transaction_id' AND meta_value = %s LIMIT 1", $key));
539 539
 
540
-    if ( $invoice_id != NULL )
540
+    if ($invoice_id != NULL)
541 541
         return $invoice_id;
542 542
 
543 543
     return 0;
544 544
 }
545 545
 
546
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
547
-    $invoice = new WPInv_Invoice( $invoice_id );
546
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
547
+    $invoice = new WPInv_Invoice($invoice_id);
548 548
 
549
-    return $invoice->get_meta( $meta_key, $single );
549
+    return $invoice->get_meta($meta_key, $single);
550 550
 }
551 551
 
552
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
553
-    $invoice = new WPInv_Invoice( $invoice_id );
552
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
553
+    $invoice = new WPInv_Invoice($invoice_id);
554 554
     
555
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
555
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
556 556
 }
557 557
 
558
-function wpinv_get_items( $invoice_id = 0 ) {
559
-    $invoice            = wpinv_get_invoice( $invoice_id );
558
+function wpinv_get_items($invoice_id = 0) {
559
+    $invoice            = wpinv_get_invoice($invoice_id);
560 560
     
561 561
     $items              = $invoice->get_items();
562 562
     $invoice_currency   = $invoice->get_currency();
563 563
 
564
-    if ( !empty( $items ) && is_array( $items ) ) {
565
-        foreach ( $items as $key => $item ) {
564
+    if (!empty($items) && is_array($items)) {
565
+        foreach ($items as $key => $item) {
566 566
             $items[$key]['currency'] = $invoice_currency;
567 567
 
568
-            if ( !isset( $cart_item['subtotal'] ) ) {
568
+            if (!isset($cart_item['subtotal'])) {
569 569
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
570 570
             }
571 571
         }
572 572
     }
573 573
 
574
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
574
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
575 575
 }
576 576
 
577
-function wpinv_get_fees( $invoice_id = 0 ) {
578
-    $invoice           = wpinv_get_invoice( $invoice_id );
577
+function wpinv_get_fees($invoice_id = 0) {
578
+    $invoice           = wpinv_get_invoice($invoice_id);
579 579
     $fees              = $invoice->get_fees();
580 580
 
581
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
581
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
582 582
 }
583 583
 
584
-function wpinv_get_invoice_ip( $invoice_id ) {
585
-    $invoice = new WPInv_Invoice( $invoice_id );
584
+function wpinv_get_invoice_ip($invoice_id) {
585
+    $invoice = new WPInv_Invoice($invoice_id);
586 586
     return $invoice->get_ip();
587 587
 }
588 588
 
589
-function wpinv_get_invoice_user_info( $invoice_id ) {
590
-    $invoice = new WPInv_Invoice( $invoice_id );
589
+function wpinv_get_invoice_user_info($invoice_id) {
590
+    $invoice = new WPInv_Invoice($invoice_id);
591 591
     return $invoice->get_user_info();
592 592
 }
593 593
 
594
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
595
-    $invoice = new WPInv_Invoice( $invoice_id );
594
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
595
+    $invoice = new WPInv_Invoice($invoice_id);
596 596
 
597
-    return $invoice->get_subtotal( $currency );
597
+    return $invoice->get_subtotal($currency);
598 598
 }
599 599
 
600
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
601
-    $invoice = new WPInv_Invoice( $invoice_id );
600
+function wpinv_tax($invoice_id = 0, $currency = false) {
601
+    $invoice = new WPInv_Invoice($invoice_id);
602 602
 
603
-    return $invoice->get_tax( $currency );
603
+    return $invoice->get_tax($currency);
604 604
 }
605 605
 
606
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
607
-    $invoice = wpinv_get_invoice( $invoice_id );
606
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
607
+    $invoice = wpinv_get_invoice($invoice_id);
608 608
 
609
-    return $invoice->get_discount( $currency, $dash );
609
+    return $invoice->get_discount($currency, $dash);
610 610
 }
611 611
 
612
-function wpinv_discount_code( $invoice_id = 0 ) {
613
-    $invoice = new WPInv_Invoice( $invoice_id );
612
+function wpinv_discount_code($invoice_id = 0) {
613
+    $invoice = new WPInv_Invoice($invoice_id);
614 614
 
615 615
     return $invoice->get_discount_code();
616 616
 }
617 617
 
618
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
619
-    $invoice = new WPInv_Invoice( $invoice_id );
618
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
619
+    $invoice = new WPInv_Invoice($invoice_id);
620 620
 
621
-    return $invoice->get_total( $currency );
621
+    return $invoice->get_total($currency);
622 622
 }
623 623
 
624
-function wpinv_get_date_created( $invoice_id = 0, $format = '' ) {
625
-    $invoice = new WPInv_Invoice( $invoice_id );
624
+function wpinv_get_date_created($invoice_id = 0, $format = '') {
625
+    $invoice = new WPInv_Invoice($invoice_id);
626 626
 
627
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
627
+    $format         = !empty($format) ? $format : get_option('date_format');
628 628
     $date_created   = $invoice->get_created_date();
629
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
629
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
630 630
 
631 631
     return $date_created;
632 632
 }
633 633
 
634
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '', $default = true ) {
635
-    $invoice = new WPInv_Invoice( $invoice_id );
634
+function wpinv_get_invoice_date($invoice_id = 0, $format = '', $default = true) {
635
+    $invoice = new WPInv_Invoice($invoice_id);
636 636
     
637
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
637
+    $format         = !empty($format) ? $format : get_option('date_format');
638 638
     $date_completed = $invoice->get_completed_date();
639
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
640
-    if ( $invoice_date == '' && $default ) {
641
-        $invoice_date   = wpinv_get_date_created( $invoice_id, $format );
639
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
640
+    if ($invoice_date == '' && $default) {
641
+        $invoice_date = wpinv_get_date_created($invoice_id, $format);
642 642
     }
643 643
 
644 644
     return $invoice_date;
645 645
 }
646 646
 
647
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
648
-    $invoice = new WPInv_Invoice( $invoice_id );
647
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
648
+    $invoice = new WPInv_Invoice($invoice_id);
649 649
     
650 650
     return $invoice->vat_number;
651 651
 }
652 652
 
653
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false ) {
654
-    $invoice = new WPInv_Invoice( $invoice_id );
653
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false, $system = false) {
654
+    $invoice = new WPInv_Invoice($invoice_id);
655 655
 
656
-    return $invoice->add_note( $note, $user_type, $added_by_user, $system );
656
+    return $invoice->add_note($note, $user_type, $added_by_user, $system);
657 657
 }
658 658
 
659
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
659
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
660 660
     global $invoicing;
661 661
     
662
-    if ( empty( $invoice_id ) ) {
662
+    if (empty($invoice_id)) {
663 663
         return NULL;
664 664
     }
665 665
     
666
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
666
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
667 667
     
668
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
668
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
669 669
 }
670 670
 
671
-function wpinv_get_payment_key( $invoice_id = 0 ) {
672
-	$invoice = new WPInv_Invoice( $invoice_id );
671
+function wpinv_get_payment_key($invoice_id = 0) {
672
+	$invoice = new WPInv_Invoice($invoice_id);
673 673
     return $invoice->get_key();
674 674
 }
675 675
 
676
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
677
-    $invoice = new WPInv_Invoice( $invoice_id );
676
+function wpinv_get_invoice_number($invoice_id = 0) {
677
+    $invoice = new WPInv_Invoice($invoice_id);
678 678
     return $invoice->get_number();
679 679
 }
680 680
 
681
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
681
+function wpinv_get_cart_discountable_subtotal($code_id) {
682 682
     $cart_items = wpinv_get_cart_content_details();
683 683
     $items      = array();
684 684
 
685
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
685
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
686 686
 
687
-    if( $cart_items ) {
687
+    if ($cart_items) {
688 688
 
689
-        foreach( $cart_items as $item ) {
689
+        foreach ($cart_items as $item) {
690 690
 
691
-            if( ! in_array( $item['id'], $excluded_items ) ) {
692
-                $items[] =  $item;
691
+            if (!in_array($item['id'], $excluded_items)) {
692
+                $items[] = $item;
693 693
             }
694 694
         }
695 695
     }
696 696
 
697
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
697
+    $subtotal = wpinv_get_cart_items_subtotal($items);
698 698
 
699
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
699
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
700 700
 }
701 701
 
702
-function wpinv_get_cart_items_subtotal( $items ) {
702
+function wpinv_get_cart_items_subtotal($items) {
703 703
     $subtotal = 0.00;
704 704
 
705
-    if ( is_array( $items ) && ! empty( $items ) ) {
706
-        $prices = wp_list_pluck( $items, 'subtotal' );
705
+    if (is_array($items) && !empty($items)) {
706
+        $prices = wp_list_pluck($items, 'subtotal');
707 707
 
708
-        if( is_array( $prices ) ) {
709
-            $subtotal = array_sum( $prices );
708
+        if (is_array($prices)) {
709
+            $subtotal = array_sum($prices);
710 710
         } else {
711 711
             $subtotal = 0.00;
712 712
         }
713 713
 
714
-        if( $subtotal < 0 ) {
714
+        if ($subtotal < 0) {
715 715
             $subtotal = 0.00;
716 716
         }
717 717
     }
718 718
 
719
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
719
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
720 720
 }
721 721
 
722
-function wpinv_get_cart_subtotal( $items = array() ) {
723
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
724
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
722
+function wpinv_get_cart_subtotal($items = array()) {
723
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
724
+    $subtotal = wpinv_get_cart_items_subtotal($items);
725 725
 
726
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
726
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
727 727
 }
728 728
 
729
-function wpinv_cart_subtotal( $items = array() ) {
730
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
729
+function wpinv_cart_subtotal($items = array()) {
730
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
731 731
 
732 732
     return $price;
733 733
 }
734 734
 
735
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
736
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
737
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
738
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
735
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
736
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
737
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
738
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
739 739
     $fees      = (float)wpinv_get_cart_fee_total();
740
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
740
+    if (!empty($invoice) && $invoice->is_free_trial()) {
741 741
         $total = 0;
742 742
     } else {
743
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
743
+        $total = $subtotal - $discounts + $cart_tax + $fees;
744 744
     }
745 745
 
746
-    if ( $total < 0 ) {
746
+    if ($total < 0) {
747 747
         $total = 0.00;
748 748
     }
749 749
     
750
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
750
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
751 751
 
752
-    return wpinv_sanitize_amount( $total );
752
+    return wpinv_sanitize_amount($total);
753 753
 }
754 754
 
755
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
755
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
756 756
     global $cart_total;
757
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
758
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
757
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
758
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
759 759
     
760 760
     $cart_total = $total;
761 761
 
762
-    if ( !$echo ) {
762
+    if (!$echo) {
763 763
         return $total;
764 764
     }
765 765
 
766 766
     echo $total;
767 767
 }
768 768
 
769
-function wpinv_get_cart_tax( $items = array() ) {
769
+function wpinv_get_cart_tax($items = array()) {
770 770
     $cart_tax = 0;
771
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
771
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
772 772
 
773
-    if ( $items ) {
774
-        $taxes = wp_list_pluck( $items, 'tax' );
773
+    if ($items) {
774
+        $taxes = wp_list_pluck($items, 'tax');
775 775
 
776
-        if( is_array( $taxes ) ) {
777
-            $cart_tax = array_sum( $taxes );
776
+        if (is_array($taxes)) {
777
+            $cart_tax = array_sum($taxes);
778 778
         }
779 779
     }
780 780
 
781 781
     $cart_tax += wpinv_get_cart_fee_tax();
782 782
 
783
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
783
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
784 784
 }
785 785
 
786
-function wpinv_cart_tax( $items = array(), $echo = false ) {
787
-    $cart_tax = wpinv_get_cart_tax( $items );
788
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
786
+function wpinv_cart_tax($items = array(), $echo = false) {
787
+    $cart_tax = wpinv_get_cart_tax($items);
788
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
789 789
 
790
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
790
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
791 791
 
792
-    if ( !$echo ) {
792
+    if (!$echo) {
793 793
         return $tax;
794 794
     }
795 795
 
796 796
     echo $tax;
797 797
 }
798 798
 
799
-function wpinv_get_cart_discount_code( $items = array() ) {
799
+function wpinv_get_cart_discount_code($items = array()) {
800 800
     $invoice = wpinv_get_invoice_cart();
801
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
801
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
802 802
     
803
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
803
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
804 804
 }
805 805
 
806
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
807
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
806
+function wpinv_cart_discount_code($items = array(), $echo = false) {
807
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
808 808
 
809
-    if ( $cart_discount_code != '' ) {
809
+    if ($cart_discount_code != '') {
810 810
         $cart_discount_code = ' (' . $cart_discount_code . ')';
811 811
     }
812 812
     
813
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
813
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
814 814
 
815
-    if ( !$echo ) {
815
+    if (!$echo) {
816 816
         return $discount_code;
817 817
     }
818 818
 
819 819
     echo $discount_code;
820 820
 }
821 821
 
822
-function wpinv_get_cart_discount( $items = array() ) {
822
+function wpinv_get_cart_discount($items = array()) {
823 823
     $invoice = wpinv_get_invoice_cart();
824
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
824
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
825 825
     
826
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
826
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
827 827
 }
828 828
 
829
-function wpinv_cart_discount( $items = array(), $echo = false ) {
830
-    $cart_discount = wpinv_get_cart_discount( $items );
831
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
829
+function wpinv_cart_discount($items = array(), $echo = false) {
830
+    $cart_discount = wpinv_get_cart_discount($items);
831
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
832 832
 
833
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
833
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
834 834
 
835
-    if ( !$echo ) {
835
+    if (!$echo) {
836 836
         return $discount;
837 837
     }
838 838
 
839 839
     echo $discount;
840 840
 }
841 841
 
842
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
843
-    $item = new WPInv_Item( $item_id );
842
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
843
+    $item = new WPInv_Item($item_id);
844 844
     
845
-    return $item->get_fees( $type, $item_id );
845
+    return $item->get_fees($type, $item_id);
846 846
 }
847 847
 
848 848
 function wpinv_get_cart_fee_total() {
849
-    $total  = 0;
849
+    $total = 0;
850 850
     $fees = wpinv_get_cart_fees();
851 851
     
852
-    if ( $fees ) {
853
-        foreach ( $fees as $fee_id => $fee ) {
852
+    if ($fees) {
853
+        foreach ($fees as $fee_id => $fee) {
854 854
             $total += $fee['amount'];
855 855
         }
856 856
     }
857 857
 
858
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
858
+    return apply_filters('wpinv_get_cart_fee_total', $total);
859 859
 }
860 860
 
861 861
 function wpinv_get_cart_fee_tax() {
862 862
     $tax  = 0;
863 863
     $fees = wpinv_get_cart_fees();
864 864
 
865
-    if ( $fees ) {
866
-        foreach ( $fees as $fee_id => $fee ) {
867
-            if( ! empty( $fee['no_tax'] ) ) {
865
+    if ($fees) {
866
+        foreach ($fees as $fee_id => $fee) {
867
+            if (!empty($fee['no_tax'])) {
868 868
                 continue;
869 869
             }
870 870
 
871
-            $tax += wpinv_calculate_tax( $fee['amount'] );
871
+            $tax += wpinv_calculate_tax($fee['amount']);
872 872
         }
873 873
     }
874 874
 
875
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
875
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
876 876
 }
877 877
 
878 878
 function wpinv_cart_has_recurring_item() {
879 879
     $cart_items = wpinv_get_cart_contents();
880 880
     
881
-    if ( empty( $cart_items ) ) {
881
+    if (empty($cart_items)) {
882 882
         return false;
883 883
     }
884 884
     
885 885
     $has_subscription = false;
886
-    foreach( $cart_items as $cart_item ) {
887
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
886
+    foreach ($cart_items as $cart_item) {
887
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
888 888
             $has_subscription = true;
889 889
             break;
890 890
         }
891 891
     }
892 892
     
893
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
893
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
894 894
 }
895 895
 
896 896
 function wpinv_cart_has_free_trial() {
@@ -898,97 +898,97 @@  discard block
 block discarded – undo
898 898
     
899 899
     $free_trial = false;
900 900
     
901
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
901
+    if (!empty($invoice) && $invoice->is_free_trial()) {
902 902
         $free_trial = true;
903 903
     }
904 904
     
905
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
905
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
906 906
 }
907 907
 
908 908
 function wpinv_get_cart_contents() {
909 909
     $cart_details = wpinv_get_cart_details();
910 910
     
911
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
911
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
912 912
 }
913 913
 
914 914
 function wpinv_get_cart_content_details() {
915 915
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
916 916
     $cart_items = wpinv_get_cart_contents();
917 917
     
918
-    if ( empty( $cart_items ) ) {
918
+    if (empty($cart_items)) {
919 919
         return false;
920 920
     }
921 921
     $invoice = wpinv_get_invoice_cart();
922
-	if ( empty( $invoice ) ) {
922
+	if (empty($invoice)) {
923 923
         return false;
924 924
     }
925 925
 
926 926
     $details = array();
927
-    $length  = count( $cart_items ) - 1;
927
+    $length  = count($cart_items) - 1;
928 928
     
929
-    if ( empty( $_POST['country'] ) ) {
929
+    if (empty($_POST['country'])) {
930 930
         $_POST['country'] = $invoice->country;
931 931
     }
932
-    if ( !isset( $_POST['state'] ) ) {
932
+    if (!isset($_POST['state'])) {
933 933
         $_POST['state'] = $invoice->state;
934 934
     }
935 935
 
936
-    foreach( $cart_items as $key => $item ) {
937
-        $item_id            = isset( $item['id'] ) ? sanitize_text_field( $item['id'] ) : '';
938
-        if ( empty( $item_id ) ) {
936
+    foreach ($cart_items as $key => $item) {
937
+        $item_id = isset($item['id']) ? sanitize_text_field($item['id']) : '';
938
+        if (empty($item_id)) {
939 939
             continue;
940 940
         }
941 941
         
942 942
         $wpi_current_id         = $invoice->ID;
943 943
         $wpi_item_id            = $item_id;
944 944
         
945
-        if ( isset( $item['custom_price'] ) && $item['custom_price'] !== '' ) {
945
+        if (isset($item['custom_price']) && $item['custom_price'] !== '') {
946 946
             $item_price = $item['custom_price'];
947 947
         } else {
948
-            if ( isset( $item['item_price'] ) && $item['item_price'] !== '' && $item['item_price'] !== false ) {
948
+            if (isset($item['item_price']) && $item['item_price'] !== '' && $item['item_price'] !== false) {
949 949
                 $item_price = $item['item_price'];
950 950
             } else {
951
-                $item_price = wpinv_get_item_price( $item_id );
951
+                $item_price = wpinv_get_item_price($item_id);
952 952
             }
953 953
         }
954
-        $discount           = wpinv_get_cart_item_discount_amount( $item );
955
-        $discount           = apply_filters( 'wpinv_get_cart_content_details_item_discount_amount', $discount, $item );
956
-        $quantity           = wpinv_get_cart_item_quantity( $item );
957
-        $fees               = wpinv_get_cart_fees( 'fee', $item_id );
954
+        $discount           = wpinv_get_cart_item_discount_amount($item);
955
+        $discount           = apply_filters('wpinv_get_cart_content_details_item_discount_amount', $discount, $item);
956
+        $quantity           = wpinv_get_cart_item_quantity($item);
957
+        $fees               = wpinv_get_cart_fees('fee', $item_id);
958 958
         
959 959
         $subtotal           = $item_price * $quantity;
960
-        $tax_rate           = wpinv_get_tax_rate( $_POST['country'], $_POST['state'], $wpi_item_id );
961
-        $tax_class          = $wpinv_euvat->get_item_class( $item_id );
962
-        $tax                = wpinv_get_cart_item_tax( $item_id, $subtotal - $discount );
960
+        $tax_rate           = wpinv_get_tax_rate($_POST['country'], $_POST['state'], $wpi_item_id);
961
+        $tax_class          = $wpinv_euvat->get_item_class($item_id);
962
+        $tax                = wpinv_get_cart_item_tax($item_id, $subtotal - $discount);
963 963
         
964
-        if ( wpinv_prices_include_tax() ) {
965
-            $subtotal -= wpinv_round_amount( $tax );
964
+        if (wpinv_prices_include_tax()) {
965
+            $subtotal -= wpinv_round_amount($tax);
966 966
         }
967 967
         
968
-        $total              = $subtotal - $discount + $tax;
968
+        $total = $subtotal - $discount + $tax;
969 969
         
970 970
         // Do not allow totals to go negatve
971
-        if( $total < 0 ) {
971
+        if ($total < 0) {
972 972
             $total = 0;
973 973
         }
974 974
         
975
-        $details[ $key ]  = array(
975
+        $details[$key] = array(
976 976
             'id'                => $item_id,
977
-            'name'              => !empty($item['name']) ? $item['name'] : get_the_title( $item_id ),
978
-            'item_price'        => wpinv_round_amount( $item_price ),
979
-            'custom_price'      => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
977
+            'name'              => !empty($item['name']) ? $item['name'] : get_the_title($item_id),
978
+            'item_price'        => wpinv_round_amount($item_price),
979
+            'custom_price'      => isset($item['custom_price']) ? $item['custom_price'] : '',
980 980
             'quantity'          => $quantity,
981
-            'discount'          => wpinv_round_amount( $discount ),
982
-            'subtotal'          => wpinv_round_amount( $subtotal ),
983
-            'tax'               => wpinv_round_amount( $tax ),
984
-            'price'             => wpinv_round_amount( $total ),
981
+            'discount'          => wpinv_round_amount($discount),
982
+            'subtotal'          => wpinv_round_amount($subtotal),
983
+            'tax'               => wpinv_round_amount($tax),
984
+            'price'             => wpinv_round_amount($total),
985 985
             'vat_rates_class'   => $tax_class,
986 986
             'vat_rate'          => $tax_rate,
987
-            'meta'              => isset( $item['meta'] ) ? $item['meta'] : array(),
987
+            'meta'              => isset($item['meta']) ? $item['meta'] : array(),
988 988
             'fees'              => $fees,
989 989
         );
990 990
         
991
-        if ( $wpinv_is_last_cart_item ) {
991
+        if ($wpinv_is_last_cart_item) {
992 992
             $wpinv_is_last_cart_item   = false;
993 993
             $wpinv_flat_discount_total = 0.00;
994 994
         }
@@ -997,67 +997,67 @@  discard block
 block discarded – undo
997 997
     return $details;
998 998
 }
999 999
 
1000
-function wpinv_get_cart_details( $invoice_id = 0 ) {
1000
+function wpinv_get_cart_details($invoice_id = 0) {
1001 1001
     global $ajax_cart_details;
1002 1002
 
1003
-    $invoice      = wpinv_get_invoice_cart( $invoice_id );
1003
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1004 1004
     $cart_details = $ajax_cart_details;
1005
-    if ( empty( $cart_details ) && ! empty( $invoice->cart_details ) ) {
1005
+    if (empty($cart_details) && !empty($invoice->cart_details)) {
1006 1006
         $cart_details = $invoice->cart_details;
1007 1007
     }
1008 1008
 
1009
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1010
-        $invoice_currency = ! empty( $invoice->currency ) ? $invoice->currency : wpinv_get_default_country();
1009
+    if (!empty($cart_details) && is_array($cart_details)) {
1010
+        $invoice_currency = !empty($invoice->currency) ? $invoice->currency : wpinv_get_default_country();
1011 1011
 
1012
-        foreach ( $cart_details as $key => $cart_item ) {
1013
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1012
+        foreach ($cart_details as $key => $cart_item) {
1013
+            $cart_details[$key]['currency'] = $invoice_currency;
1014 1014
 
1015
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1016
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1015
+            if (!isset($cart_item['subtotal'])) {
1016
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1017 1017
             }
1018 1018
         }
1019 1019
     }
1020 1020
 
1021
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1021
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1022 1022
 }
1023 1023
 
1024
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1025
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1024
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1025
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1026 1026
         return;
1027 1027
     }
1028 1028
 
1029
-    if ( ( $old_status == 'wpi-pending' && $new_status == 'draft' ) || ( $old_status == 'draft' && $new_status == 'wpi-pending' ) ) {
1029
+    if (($old_status == 'wpi-pending' && $new_status == 'draft') || ($old_status == 'draft' && $new_status == 'wpi-pending')) {
1030 1030
         return;
1031 1031
     }
1032 1032
 
1033
-    $invoice    = wpinv_get_invoice( $invoice_id );
1033
+    $invoice    = wpinv_get_invoice($invoice_id);
1034 1034
     
1035
-    $old_status = wpinv_status_nicename( $old_status );
1036
-    $new_status = wpinv_status_nicename( $new_status );
1035
+    $old_status = wpinv_status_nicename($old_status);
1036
+    $new_status = wpinv_status_nicename($new_status);
1037 1037
 
1038
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1038
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1039 1039
     
1040 1040
     // Add note
1041
-    return $invoice->add_note( $status_change, false, false, true );
1041
+    return $invoice->add_note($status_change, false, false, true);
1042 1042
 }
1043
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1043
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1044 1044
 
1045
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1045
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1046 1046
     global $wpi_has_free_trial;
1047 1047
     
1048 1048
     $wpi_has_free_trial = false;
1049 1049
     
1050
-    if ( $old_status == 'publish' ) {
1050
+    if ($old_status == 'publish') {
1051 1051
         return; // Make sure that payments are only paid once
1052 1052
     }
1053 1053
 
1054 1054
     // Make sure the payment completion is only processed when new status is paid
1055
-    if ( $new_status != 'publish' ) {
1055
+    if ($new_status != 'publish') {
1056 1056
         return;
1057 1057
     }
1058 1058
 
1059
-    $invoice = new WPInv_Invoice( $invoice_id );
1060
-    if ( empty( $invoice ) ) {
1059
+    $invoice = new WPInv_Invoice($invoice_id);
1060
+    if (empty($invoice)) {
1061 1061
         return;
1062 1062
     }
1063 1063
 
@@ -1065,58 +1065,58 @@  discard block
 block discarded – undo
1065 1065
     $completed_date = $invoice->completed_date;
1066 1066
     $cart_details   = $invoice->cart_details;
1067 1067
 
1068
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1068
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1069 1069
 
1070
-    if ( is_array( $cart_details ) ) {
1070
+    if (is_array($cart_details)) {
1071 1071
         // Increase purchase count and earnings
1072
-        foreach ( $cart_details as $cart_index => $item ) {
1072
+        foreach ($cart_details as $cart_index => $item) {
1073 1073
             // Ensure these actions only run once, ever
1074
-            if ( empty( $completed_date ) ) {
1075
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1074
+            if (empty($completed_date)) {
1075
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1076 1076
             }
1077 1077
         }
1078 1078
     }
1079 1079
     
1080 1080
     // Check for discount codes and increment their use counts
1081
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1082
-        if( ! empty( $discounts ) ) {
1083
-            foreach( $discounts as $code ) {
1084
-                wpinv_increase_discount_usage( $code );
1081
+    if ($discounts = $invoice->get_discounts(true)) {
1082
+        if (!empty($discounts)) {
1083
+            foreach ($discounts as $code) {
1084
+                wpinv_increase_discount_usage($code);
1085 1085
             }
1086 1086
         }
1087 1087
     }
1088 1088
     
1089 1089
     // Ensure this action only runs once ever
1090
-    if( empty( $completed_date ) ) {
1090
+    if (empty($completed_date)) {
1091 1091
         // Save the completed date
1092
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1092
+        $invoice->set('completed_date', current_time('mysql', 0));
1093 1093
         $invoice->save();
1094 1094
 
1095
-        do_action( 'wpinv_complete_payment', $invoice_id );
1095
+        do_action('wpinv_complete_payment', $invoice_id);
1096 1096
     }
1097 1097
 
1098 1098
     // Empty the shopping cart
1099 1099
     wpinv_empty_cart();
1100 1100
 }
1101
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1101
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1102 1102
 
1103
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1104
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1103
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1104
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
1105 1105
     
1106
-    if ( empty( $invoice ) ) {
1106
+    if (empty($invoice)) {
1107 1107
         return false;
1108 1108
     }
1109 1109
     
1110
-    return $invoice->update_status( $new_status );
1110
+    return $invoice->update_status($new_status);
1111 1111
 }
1112 1112
 
1113
-function wpinv_cart_has_fees( $type = 'all' ) {
1113
+function wpinv_cart_has_fees($type = 'all') {
1114 1114
     return false;
1115 1115
 }
1116 1116
 
1117 1117
 function wpinv_validate_checkout_fields() {    
1118 1118
     // Check if there is $_POST
1119
-    if ( empty( $_POST ) ) {
1119
+    if (empty($_POST)) {
1120 1120
         return false;
1121 1121
     }
1122 1122
     
@@ -1128,11 +1128,11 @@  discard block
 block discarded – undo
1128 1128
     );
1129 1129
     
1130 1130
     // Validate agree to terms
1131
-    $page = wpinv_get_option( 'tandc_page' );
1132
-    if(isset($page) && (int)$page > 0 && apply_filters( 'wpinv_checkout_show_terms', true )){
1131
+    $page = wpinv_get_option('tandc_page');
1132
+    if (isset($page) && (int)$page > 0 && apply_filters('wpinv_checkout_show_terms', true)) {
1133 1133
         // Validate agree to terms
1134
-        if ( ! isset( $_POST['wpi_terms'] ) || !$_POST['wpi_terms'] ) {
1135
-            wpinv_set_error( 'accept_terms', apply_filters( 'wpinv_accept_terms_error_text', __( 'You must accept terms and conditions', 'invoicing' ) ) );
1134
+        if (!isset($_POST['wpi_terms']) || !$_POST['wpi_terms']) {
1135
+            wpinv_set_error('accept_terms', apply_filters('wpinv_accept_terms_error_text', __('You must accept terms and conditions', 'invoicing')));
1136 1136
         }
1137 1137
     }
1138 1138
     
@@ -1148,26 +1148,26 @@  discard block
 block discarded – undo
1148 1148
     
1149 1149
     $invoice = wpinv_get_invoice_cart();
1150 1150
     $has_subscription = $invoice->is_recurring();
1151
-    if ( empty( $invoice ) ) {
1152
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1151
+    if (empty($invoice)) {
1152
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1153 1153
         return $gateway;
1154 1154
     }
1155 1155
 
1156 1156
     // Check if a gateway value is present
1157
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1158
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1157
+    if (!empty($_REQUEST['wpi-gateway'])) {
1158
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1159 1159
 
1160
-        if ( $invoice->is_free() ) {
1160
+        if ($invoice->is_free()) {
1161 1161
             $gateway = 'manual';
1162
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1163
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1164
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1165
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
1162
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1163
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1164
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1165
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
1166 1166
         }
1167 1167
     }
1168 1168
 
1169
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1170
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1169
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1170
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1171 1171
     }
1172 1172
 
1173 1173
     return $gateway;
@@ -1181,10 +1181,10 @@  discard block
 block discarded – undo
1181 1181
     
1182 1182
     $error = false;
1183 1183
     // If we have discounts, loop through them
1184
-    if ( ! empty( $discounts ) ) {
1185
-        foreach ( $discounts as $discount ) {
1184
+    if (!empty($discounts)) {
1185
+        foreach ($discounts as $discount) {
1186 1186
             // Check if valid
1187
-            if (  !wpinv_is_discount_valid( $discount, (int)$wpi_cart->get_user_id() ) ) {
1187
+            if (!wpinv_is_discount_valid($discount, (int)$wpi_cart->get_user_id())) {
1188 1188
                 // Discount is not valid
1189 1189
                 $error = true;
1190 1190
             }
@@ -1194,20 +1194,20 @@  discard block
 block discarded – undo
1194 1194
         return NULL;
1195 1195
     }
1196 1196
 
1197
-    if ( $error && !wpinv_get_errors() ) {
1198
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1197
+    if ($error && !wpinv_get_errors()) {
1198
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1199 1199
     }
1200 1200
 
1201
-    return implode( ',', $discounts );
1201
+    return implode(',', $discounts);
1202 1202
 }
1203 1203
 
1204 1204
 function wpinv_checkout_validate_cc() {
1205 1205
     $card_data = wpinv_checkout_get_cc_info();
1206 1206
 
1207 1207
     // Validate the card zip
1208
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1209
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1210
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1208
+    if (!empty($card_data['wpinv_zip'])) {
1209
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1210
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1211 1211
         }
1212 1212
     }
1213 1213
 
@@ -1217,28 +1217,28 @@  discard block
 block discarded – undo
1217 1217
 
1218 1218
 function wpinv_checkout_get_cc_info() {
1219 1219
 	$cc_info = array();
1220
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1221
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1222
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1223
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1224
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1225
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1226
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1227
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1228
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1229
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1220
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1221
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1222
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1223
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1224
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1225
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1226
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1227
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1228
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1229
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1230 1230
 
1231 1231
 	// Return cc info
1232 1232
 	return $cc_info;
1233 1233
 }
1234 1234
 
1235
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1235
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1236 1236
     $ret = false;
1237 1237
 
1238
-    if ( empty( $zip ) || empty( $country_code ) )
1238
+    if (empty($zip) || empty($country_code))
1239 1239
         return $ret;
1240 1240
 
1241
-    $country_code = strtoupper( $country_code );
1241
+    $country_code = strtoupper($country_code);
1242 1242
 
1243 1243
     $zip_regex = array(
1244 1244
         "AD" => "AD\d{3}",
@@ -1398,24 +1398,24 @@  discard block
 block discarded – undo
1398 1398
         "ZM" => "\d{5}"
1399 1399
     );
1400 1400
 
1401
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1401
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1402 1402
         $ret = true;
1403 1403
 
1404
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1404
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1405 1405
 }
1406 1406
 
1407 1407
 function wpinv_checkout_validate_agree_to_terms() {
1408 1408
     // Validate agree to terms
1409
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1409
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1410 1410
         // User did not agree
1411
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1411
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1412 1412
     }
1413 1413
 }
1414 1414
 
1415 1415
 function wpinv_checkout_validate_invoice_user() {
1416 1416
     global $wpi_cart, $user_ID;
1417 1417
 
1418
-    if(empty($wpi_cart)){
1418
+    if (empty($wpi_cart)) {
1419 1419
         $wpi_cart = wpinv_get_invoice_cart();
1420 1420
     }
1421 1421
 
@@ -1425,45 +1425,45 @@  discard block
 block discarded – undo
1425 1425
     );
1426 1426
 
1427 1427
     // If guest checkout allowed
1428
-    if ( !wpinv_require_login_to_checkout() ) {
1428
+    if (!wpinv_require_login_to_checkout()) {
1429 1429
         return $valid_user_data;
1430 1430
     }
1431 1431
     
1432 1432
     // Verify there is a user_ID
1433
-    if ( $user_ID == $invoice_user ) {
1433
+    if ($user_ID == $invoice_user) {
1434 1434
         // Get the logged in user data
1435
-        $user_data = get_userdata( $user_ID );
1436
-        $required_fields  = wpinv_checkout_required_fields();
1435
+        $user_data = get_userdata($user_ID);
1436
+        $required_fields = wpinv_checkout_required_fields();
1437 1437
 
1438 1438
         // Loop through required fields and show error messages
1439
-         if ( !empty( $required_fields ) ) {
1440
-            foreach ( $required_fields as $field_name => $value ) {
1441
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1442
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1439
+         if (!empty($required_fields)) {
1440
+            foreach ($required_fields as $field_name => $value) {
1441
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1442
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1443 1443
                 }
1444 1444
             }
1445 1445
         }
1446 1446
 
1447 1447
         // Verify data
1448
-        if ( $user_data ) {
1448
+        if ($user_data) {
1449 1449
             // Collected logged in user data
1450 1450
             $valid_user_data = array(
1451 1451
                 'user_id'     => $user_ID,
1452
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1453
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1454
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1452
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1453
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1454
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1455 1455
             );
1456 1456
 
1457
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1458
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1457
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1458
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1459 1459
             }
1460 1460
         } else {
1461 1461
             // Set invalid user error
1462
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1462
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1463 1463
         }
1464 1464
     } else {
1465 1465
         // Set invalid user error
1466
-        wpinv_set_error( 'invalid_user_id', __( 'The invalid invoice user id', 'invoicing' ) );
1466
+        wpinv_set_error('invalid_user_id', __('The invalid invoice user id', 'invoicing'));
1467 1467
     }
1468 1468
 
1469 1469
     // Return user data
@@ -1475,27 +1475,27 @@  discard block
 block discarded – undo
1475 1475
 
1476 1476
     $data = array();
1477 1477
     
1478
-    if ( is_user_logged_in() ) {
1479
-        if ( !wpinv_require_login_to_checkout() || ( wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id() ) ) {
1478
+    if (is_user_logged_in()) {
1479
+        if (!wpinv_require_login_to_checkout() || (wpinv_require_login_to_checkout() && (int)$wpi_cart->get_user_id() === (int)get_current_user_id())) {
1480 1480
             $data['user_id'] = (int)get_current_user_id();
1481 1481
         } else {
1482
-            wpinv_set_error( 'logged_in_only', __( 'You are not allowed to pay for this invoice', 'invoicing' ) );
1482
+            wpinv_set_error('logged_in_only', __('You are not allowed to pay for this invoice', 'invoicing'));
1483 1483
         }
1484 1484
     } else {
1485 1485
         // If guest checkout allowed
1486
-        if ( !wpinv_require_login_to_checkout() ) {
1486
+        if (!wpinv_require_login_to_checkout()) {
1487 1487
             $data['user_id'] = 0;
1488 1488
         } else {
1489
-            wpinv_set_error( 'logged_in_only', __( 'You must be logged in to pay for this invoice', 'invoicing' ) );
1489
+            wpinv_set_error('logged_in_only', __('You must be logged in to pay for this invoice', 'invoicing'));
1490 1490
         }
1491 1491
     }
1492 1492
 
1493 1493
     return $data;
1494 1494
 }
1495 1495
 
1496
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1496
+function wpinv_checkout_form_get_user($valid_data = array()) {
1497 1497
 
1498
-    if ( !empty( $valid_data['current_user']['user_id'] ) ) {
1498
+    if (!empty($valid_data['current_user']['user_id'])) {
1499 1499
         $user = $valid_data['current_user'];
1500 1500
     } else {
1501 1501
         // Set the valid invoice user
@@ -1503,7 +1503,7 @@  discard block
 block discarded – undo
1503 1503
     }
1504 1504
 
1505 1505
     // Verify invoice have an user
1506
-    if ( false === $user || empty( $user ) ) {
1506
+    if (false === $user || empty($user)) {
1507 1507
         return false;
1508 1508
     }
1509 1509
 
@@ -1520,11 +1520,11 @@  discard block
 block discarded – undo
1520 1520
         'zip',
1521 1521
     );
1522 1522
     
1523
-    foreach ( $address_fields as $field ) {
1524
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1523
+    foreach ($address_fields as $field) {
1524
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1525 1525
         
1526
-        if ( !empty( $user['user_id'] ) && !empty( $valid_data['current_user']['user_id'] ) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id'] ) {
1527
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1526
+        if (!empty($user['user_id']) && !empty($valid_data['current_user']['user_id']) && $valid_data['current_user']['user_id'] == $valid_data['invoice_user']['user_id']) {
1527
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1528 1528
         }
1529 1529
     }
1530 1530
 
@@ -1532,28 +1532,28 @@  discard block
 block discarded – undo
1532 1532
     return $user;
1533 1533
 }
1534 1534
 
1535
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1535
+function wpinv_set_checkout_session($invoice_data = array()) {
1536 1536
     global $wpi_session;
1537 1537
     
1538
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1538
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1539 1539
 }
1540 1540
 
1541 1541
 function wpinv_get_checkout_session() {
1542 1542
 	global $wpi_session;
1543 1543
     
1544
-    return $wpi_session->get( 'wpinv_checkout' );
1544
+    return $wpi_session->get('wpinv_checkout');
1545 1545
 }
1546 1546
 
1547 1547
 function wpinv_empty_cart() {
1548 1548
     global $wpi_session;
1549 1549
 
1550 1550
     // Remove cart contents
1551
-    $wpi_session->set( 'wpinv_checkout', NULL );
1551
+    $wpi_session->set('wpinv_checkout', NULL);
1552 1552
 
1553 1553
     // Remove all cart fees
1554
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1554
+    $wpi_session->set('wpi_cart_fees', NULL);
1555 1555
 
1556
-    do_action( 'wpinv_empty_cart' );
1556
+    do_action('wpinv_empty_cart');
1557 1557
 }
1558 1558
 
1559 1559
 function wpinv_process_checkout() {
@@ -1562,7 +1562,7 @@  discard block
 block discarded – undo
1562 1562
     wpinv_clear_errors();
1563 1563
     
1564 1564
     $invoice = wpinv_get_invoice_cart();
1565
-    if ( empty( $invoice ) ) {
1565
+    if (empty($invoice)) {
1566 1566
         return false;
1567 1567
     }
1568 1568
     
@@ -1570,42 +1570,42 @@  discard block
 block discarded – undo
1570 1570
     
1571 1571
     $wpi_checkout_id = $invoice->ID;
1572 1572
     
1573
-    do_action( 'wpinv_pre_process_checkout' );
1573
+    do_action('wpinv_pre_process_checkout');
1574 1574
     
1575
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1575
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1576 1576
         $valid_data = false;
1577
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1577
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1578 1578
     } else {
1579 1579
         // Validate the form $_POST data
1580 1580
         $valid_data = wpinv_validate_checkout_fields();
1581 1581
         
1582 1582
         // Allow themes and plugins to hook to errors
1583
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1583
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1584 1584
     }
1585 1585
     
1586
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1586
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1587 1587
     
1588 1588
     // Validate the user
1589
-    $user = wpinv_checkout_form_get_user( $valid_data );
1589
+    $user = wpinv_checkout_form_get_user($valid_data);
1590 1590
 
1591 1591
     // Let extensions validate fields after user is logged in if user has used login/registration form
1592
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1592
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1593 1593
     
1594
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1595
-        if ( $is_ajax ) {
1596
-            do_action( 'wpinv_ajax_checkout_errors' );
1594
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1595
+        if ($is_ajax) {
1596
+            do_action('wpinv_ajax_checkout_errors');
1597 1597
             die();
1598 1598
         } else {
1599 1599
             return false;
1600 1600
         }
1601 1601
     }
1602 1602
 
1603
-    if ( $is_ajax ) {
1603
+    if ($is_ajax) {
1604 1604
         // Save address fields.
1605
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1606
-        foreach ( $address_fields as $field ) {
1607
-            if ( isset( $user[$field] ) ) {
1608
-                $invoice->set( $field, $user[$field] );
1605
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1606
+        foreach ($address_fields as $field) {
1607
+            if (isset($user[$field])) {
1608
+                $invoice->set($field, $user[$field]);
1609 1609
             }
1610 1610
 
1611 1611
             $invoice->save();
@@ -1613,16 +1613,16 @@  discard block
 block discarded – undo
1613 1613
 
1614 1614
         $response['success']            = true;
1615 1615
         $response['data']['subtotal']   = $invoice->get_subtotal();
1616
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1616
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1617 1617
         $response['data']['discount']   = $invoice->get_discount();
1618
-        $response['data']['discountf']  = $invoice->get_discount( true );
1618
+        $response['data']['discountf']  = $invoice->get_discount(true);
1619 1619
         $response['data']['tax']        = $invoice->get_tax();
1620
-        $response['data']['taxf']       = $invoice->get_tax( true );
1620
+        $response['data']['taxf']       = $invoice->get_tax(true);
1621 1621
         $response['data']['total']      = $invoice->get_total();
1622
-        $response['data']['totalf']     = $invoice->get_total( true );
1623
-	    $response['data']['free']       = $invoice->is_free() && ( ! ( (float) $response['data']['total'] > 0 ) || $invoice->is_free_trial() ) ? true : false;
1622
+        $response['data']['totalf']     = $invoice->get_total(true);
1623
+	    $response['data']['free'] = $invoice->is_free() && (!((float)$response['data']['total'] > 0) || $invoice->is_free_trial()) ? true : false;
1624 1624
 
1625
-        wp_send_json( $response );
1625
+        wp_send_json($response);
1626 1626
     }
1627 1627
     
1628 1628
     $user_info = array(
@@ -1644,42 +1644,42 @@  discard block
 block discarded – undo
1644 1644
     
1645 1645
     // Setup invoice information
1646 1646
     $invoice_data = array(
1647
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1647
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1648 1648
         'items'             => $cart_items,
1649 1649
         'cart_discounts'    => $discounts,
1650
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1651
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1652
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1653
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1654
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1650
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1651
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1652
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1653
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1654
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1655 1655
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1656 1656
         'user_email'        => $invoice->get_email(),
1657
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1658
-        'user_info'         => stripslashes_deep( $user_info ),
1657
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1658
+        'user_info'         => stripslashes_deep($user_info),
1659 1659
         'post_data'         => $_POST,
1660 1660
         'cart_details'      => $cart_items,
1661 1661
         'gateway'           => $valid_data['gateway'],
1662 1662
         'card_info'         => $valid_data['cc_info']
1663 1663
     );
1664 1664
     
1665
-    $vat_info   = $wpinv_euvat->current_vat_data();
1666
-    if ( is_array( $vat_info ) ) {
1665
+    $vat_info = $wpinv_euvat->current_vat_data();
1666
+    if (is_array($vat_info)) {
1667 1667
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1668 1668
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1669
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1669
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1670 1670
 
1671 1671
         // Add the VAT rate to each item in the cart
1672
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1672
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1673 1673
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1674
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1674
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1675 1675
         }
1676 1676
     }
1677 1677
     
1678 1678
     // Save vat fields.
1679
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1680
-    foreach ( $address_fields as $field ) {
1681
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1682
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1679
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1680
+    foreach ($address_fields as $field) {
1681
+        if (isset($invoice_data['user_info'][$field])) {
1682
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1683 1683
         }
1684 1684
 
1685 1685
         $invoice->save();
@@ -1689,55 +1689,55 @@  discard block
 block discarded – undo
1689 1689
     $valid_data['user'] = $user;
1690 1690
     
1691 1691
     // Allow themes and plugins to hook before the gateway
1692
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1692
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1693 1693
     
1694 1694
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1695
-    if ( !$invoice_data['price'] ) {
1695
+    if (!$invoice_data['price']) {
1696 1696
         // Revert to manual
1697 1697
         $invoice_data['gateway'] = 'manual';
1698 1698
         $_POST['wpi-gateway'] = 'manual';
1699 1699
     }
1700 1700
     
1701 1701
     // Allow the invoice data to be modified before it is sent to the gateway
1702
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1702
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1703 1703
     
1704
-    if ( $invoice_data['price'] && $invoice_data['gateway'] == 'manual' ) {
1704
+    if ($invoice_data['price'] && $invoice_data['gateway'] == 'manual') {
1705 1705
         $mode = 'test';
1706 1706
     } else {
1707
-        $mode = wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live';
1707
+        $mode = wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live';
1708 1708
     }
1709 1709
     
1710 1710
     // Setup the data we're storing in the purchase session
1711 1711
     $session_data = $invoice_data;
1712 1712
     // Make sure credit card numbers are never stored in sessions
1713
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1714
-        unset( $session_data['card_info']['card_number'] );
1713
+    if (!empty($session_data['card_info']['card_number'])) {
1714
+        unset($session_data['card_info']['card_number']);
1715 1715
     }
1716 1716
     
1717 1717
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1718
-    wpinv_set_checkout_session( $invoice_data );
1718
+    wpinv_set_checkout_session($invoice_data);
1719 1719
     
1720 1720
     // Set gateway
1721
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1722
-    $invoice->update_meta( '_wpinv_mode', $mode );
1723
-    $invoice->update_meta( '_wpinv_checkout', date_i18n( 'Y-m-d H:i:s', current_time( 'timestamp' ) ) );
1721
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1722
+    $invoice->update_meta('_wpinv_mode', $mode);
1723
+    $invoice->update_meta('_wpinv_checkout', date_i18n('Y-m-d H:i:s', current_time('timestamp')));
1724 1724
     
1725
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1725
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1726 1726
 
1727 1727
     // Send info to the gateway for payment processing
1728
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1728
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1729 1729
     die();
1730 1730
 }
1731
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1731
+add_action('wpinv_payment', 'wpinv_process_checkout');
1732 1732
 
1733
-function wpinv_get_invoices( $args ) {
1734
-    $args = wp_parse_args( $args, array(
1735
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1733
+function wpinv_get_invoices($args) {
1734
+    $args = wp_parse_args($args, array(
1735
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1736 1736
         'type'     => 'wpi_invoice',
1737 1737
         'parent'   => null,
1738 1738
         'user'     => null,
1739 1739
         'email'    => '',
1740
-        'limit'    => get_option( 'posts_per_page' ),
1740
+        'limit'    => get_option('posts_per_page'),
1741 1741
         'offset'   => null,
1742 1742
         'page'     => 1,
1743 1743
         'exclude'  => array(),
@@ -1745,7 +1745,7 @@  discard block
 block discarded – undo
1745 1745
         'order'    => 'DESC',
1746 1746
         'return'   => 'objects',
1747 1747
         'paginate' => false,
1748
-    ) );
1748
+    ));
1749 1749
     
1750 1750
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1751 1751
     $map_legacy = array(
@@ -1758,18 +1758,18 @@  discard block
 block discarded – undo
1758 1758
         'paged'          => 'page',
1759 1759
     );
1760 1760
 
1761
-    foreach ( $map_legacy as $from => $to ) {
1762
-        if ( isset( $args[ $from ] ) ) {
1763
-            $args[ $to ] = $args[ $from ];
1761
+    foreach ($map_legacy as $from => $to) {
1762
+        if (isset($args[$from])) {
1763
+            $args[$to] = $args[$from];
1764 1764
         }
1765 1765
     }
1766 1766
 
1767
-    if ( get_query_var( 'paged' ) )
1767
+    if (get_query_var('paged'))
1768 1768
         $args['page'] = get_query_var('paged');
1769
-    else if ( get_query_var( 'page' ) )
1770
-        $args['page'] = get_query_var( 'page' );
1771
-    else if ( !empty( $args[ 'page' ] ) )
1772
-        $args['page'] = $args[ 'page' ];
1769
+    else if (get_query_var('page'))
1770
+        $args['page'] = get_query_var('page');
1771
+    else if (!empty($args['page']))
1772
+        $args['page'] = $args['page'];
1773 1773
     else
1774 1774
         $args['page'] = 1;
1775 1775
 
@@ -1782,49 +1782,49 @@  discard block
 block discarded – undo
1782 1782
         'post_status'    => $args['status'],
1783 1783
         'posts_per_page' => $args['limit'],
1784 1784
         'meta_query'     => array(),
1785
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1785
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1786 1786
         'fields'         => 'ids',
1787 1787
         'orderby'        => $args['orderby'],
1788 1788
         'order'          => $args['order'],
1789 1789
     );
1790 1790
     
1791
-    if ( !empty( $args['user'] ) ) {
1792
-        $wp_query_args['author'] = absint( $args['user'] );
1791
+    if (!empty($args['user'])) {
1792
+        $wp_query_args['author'] = absint($args['user']);
1793 1793
     }
1794 1794
 
1795
-    if ( ! is_null( $args['parent'] ) ) {
1796
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1795
+    if (!is_null($args['parent'])) {
1796
+        $wp_query_args['post_parent'] = absint($args['parent']);
1797 1797
     }
1798 1798
 
1799
-    if ( ! is_null( $args['offset'] ) ) {
1800
-        $wp_query_args['offset'] = absint( $args['offset'] );
1799
+    if (!is_null($args['offset'])) {
1800
+        $wp_query_args['offset'] = absint($args['offset']);
1801 1801
     } else {
1802
-        $wp_query_args['paged'] = absint( $args['page'] );
1802
+        $wp_query_args['paged'] = absint($args['page']);
1803 1803
     }
1804 1804
 
1805
-    if ( ! empty( $args['exclude'] ) ) {
1806
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1805
+    if (!empty($args['exclude'])) {
1806
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1807 1807
     }
1808 1808
 
1809
-    if ( ! $args['paginate' ] ) {
1809
+    if (!$args['paginate']) {
1810 1810
         $wp_query_args['no_found_rows'] = true;
1811 1811
     }
1812 1812
 
1813 1813
     $wp_query_args = apply_filters('wpinv_get_invoices_args', $wp_query_args, $args);
1814 1814
 
1815 1815
     // Get results.
1816
-    $invoices = new WP_Query( $wp_query_args );
1816
+    $invoices = new WP_Query($wp_query_args);
1817 1817
 
1818
-    if ( 'objects' === $args['return'] ) {
1819
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1820
-    } elseif ( 'self' === $args['return'] ) {
1818
+    if ('objects' === $args['return']) {
1819
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1820
+    } elseif ('self' === $args['return']) {
1821 1821
         return $invoices;
1822 1822
     } else {
1823 1823
         $return = $invoices->posts;
1824 1824
     }
1825 1825
 
1826
-    if ( $args['paginate' ] ) {
1827
-        return (object) array(
1826
+    if ($args['paginate']) {
1827
+        return (object)array(
1828 1828
             'invoices'      => $return,
1829 1829
             'total'         => $invoices->found_posts,
1830 1830
             'max_num_pages' => $invoices->max_num_pages,
@@ -1836,22 +1836,22 @@  discard block
 block discarded – undo
1836 1836
 
1837 1837
 function wpinv_get_user_invoices_columns() {
1838 1838
     $columns = array(
1839
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1840
-            'created-date'    => array( 'title' => __( 'Created Date', 'invoicing' ), 'class' => 'text-left' ),
1841
-            'payment-date'    => array( 'title' => __( 'Payment Date', 'invoicing' ), 'class' => 'text-left' ),
1842
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1843
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1844
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1839
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1840
+            'created-date'    => array('title' => __('Created Date', 'invoicing'), 'class' => 'text-left'),
1841
+            'payment-date'    => array('title' => __('Payment Date', 'invoicing'), 'class' => 'text-left'),
1842
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1843
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1844
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1845 1845
         );
1846 1846
 
1847
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1847
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1848 1848
 }
1849 1849
 
1850
-function wpinv_payment_receipt( $atts, $content = null ) {
1850
+function wpinv_payment_receipt($atts, $content = null) {
1851 1851
     global $wpinv_receipt_args;
1852 1852
 
1853
-    $wpinv_receipt_args = shortcode_atts( array(
1854
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1853
+    $wpinv_receipt_args = shortcode_atts(array(
1854
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1855 1855
         'price'           => true,
1856 1856
         'discount'        => true,
1857 1857
         'items'           => true,
@@ -1860,197 +1860,197 @@  discard block
 block discarded – undo
1860 1860
         'invoice_key'     => false,
1861 1861
         'payment_method'  => true,
1862 1862
         'invoice_id'      => true
1863
-    ), $atts, 'wpinv_receipt' );
1863
+    ), $atts, 'wpinv_receipt');
1864 1864
 
1865 1865
     $session = wpinv_get_checkout_session();
1866
-    if ( isset( $_GET['invoice_key'] ) ) {
1867
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1868
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1866
+    if (isset($_GET['invoice_key'])) {
1867
+        $invoice_key = urldecode($_GET['invoice_key']);
1868
+    } else if ($session && isset($session['invoice_key'])) {
1869 1869
         $invoice_key = $session['invoice_key'];
1870
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1870
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1871 1871
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1872
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1873
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1872
+    } else if (isset($_GET['invoice-id'])) {
1873
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1874 1874
     }
1875 1875
 
1876 1876
     // No key found
1877
-    if ( ! isset( $invoice_key ) ) {
1877
+    if (!isset($invoice_key)) {
1878 1878
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1879 1879
     }
1880 1880
 
1881
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1882
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1883
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1881
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1882
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1883
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1884 1884
         $invoice_id     = (int)$_GET['invoice-id'];
1885
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1885
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1886 1886
     }
1887 1887
 
1888 1888
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1889
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1889
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1890 1890
         // login redirect
1891
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1891
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1892 1892
     }
1893 1893
 
1894
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1894
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1895 1895
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1896 1896
     }
1897 1897
 
1898 1898
     ob_start();
1899 1899
 
1900
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1900
+    wpinv_get_template_part('wpinv-invoice-receipt');
1901 1901
 
1902 1902
     $display = ob_get_clean();
1903 1903
 
1904 1904
     return $display;
1905 1905
 }
1906 1906
 
1907
-function wpinv_get_invoice_id_by_key( $key ) {
1907
+function wpinv_get_invoice_id_by_key($key) {
1908 1908
 	global $wpdb;
1909 1909
 
1910
-	$invoice_id = $wpdb->get_var( $wpdb->prepare( "SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key ) );
1910
+	$invoice_id = $wpdb->get_var($wpdb->prepare("SELECT post_id FROM $wpdb->postmeta WHERE meta_key = '_wpinv_key' AND meta_value = %s LIMIT 1", $key));
1911 1911
 
1912
-	if ( $invoice_id != NULL )
1912
+	if ($invoice_id != NULL)
1913 1913
 		return $invoice_id;
1914 1914
 
1915 1915
 	return 0;
1916 1916
 }
1917 1917
 
1918
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1918
+function wpinv_can_view_receipt($invoice_key = '') {
1919 1919
 	$return = false;
1920 1920
 
1921
-	if ( empty( $invoice_key ) ) {
1921
+	if (empty($invoice_key)) {
1922 1922
 		return $return;
1923 1923
 	}
1924 1924
 
1925 1925
 	global $wpinv_receipt_args;
1926 1926
 
1927
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1928
-	if ( isset( $_GET['invoice-id'] ) ) {
1929
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1927
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1928
+	if (isset($_GET['invoice-id'])) {
1929
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1930 1930
 	}
1931 1931
 
1932
-	if ( empty( $wpinv_receipt_args['id'] ) ) {
1932
+	if (empty($wpinv_receipt_args['id'])) {
1933 1933
 		return $return;
1934 1934
 	}
1935 1935
 
1936
-	$invoice = wpinv_get_invoice( $wpinv_receipt_args['id'] );
1937
-	if ( !( !empty( $invoice->ID ) && $invoice->get_key() === $invoice_key ) ) {
1936
+	$invoice = wpinv_get_invoice($wpinv_receipt_args['id']);
1937
+	if (!(!empty($invoice->ID) && $invoice->get_key() === $invoice_key)) {
1938 1938
 		return $return;
1939 1939
 	}
1940 1940
 
1941
-	if ( is_user_logged_in() ) {
1942
-		if ( (int)$invoice->get_user_id() === (int) get_current_user_id() ) {
1941
+	if (is_user_logged_in()) {
1942
+		if ((int)$invoice->get_user_id() === (int)get_current_user_id()) {
1943 1943
 			$return = true;
1944 1944
 		}
1945 1945
 	}
1946 1946
 
1947 1947
 	$session = wpinv_get_checkout_session();
1948
-	if ( isset( $_GET['invoice_key'] ) || ( $session && isset( $session['invoice_key'] ) ) ) {
1949
-		$check_key = isset( $_GET['invoice_key'] ) ? $_GET['invoice_key'] : $session['invoice_key'];
1948
+	if (isset($_GET['invoice_key']) || ($session && isset($session['invoice_key']))) {
1949
+		$check_key = isset($_GET['invoice_key']) ? $_GET['invoice_key'] : $session['invoice_key'];
1950 1950
 
1951
-		if ( wpinv_require_login_to_checkout() ) {
1951
+		if (wpinv_require_login_to_checkout()) {
1952 1952
 			$return = $return && $check_key === $invoice_key;
1953 1953
 		} else {
1954 1954
 			$return = $check_key === $invoice_key;
1955 1955
 		}
1956 1956
 	}
1957 1957
 
1958
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1958
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1959 1959
 }
1960 1960
 
1961 1961
 function wpinv_pay_for_invoice() {
1962 1962
     global $wpinv_euvat;
1963 1963
     
1964
-    if ( isset( $_GET['invoice_key'] ) ) {
1964
+    if (isset($_GET['invoice_key'])) {
1965 1965
         $checkout_uri   = wpinv_get_checkout_uri();
1966
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1966
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1967 1967
         
1968
-        if ( empty( $invoice_key ) ) {
1969
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1970
-            wp_redirect( $checkout_uri );
1968
+        if (empty($invoice_key)) {
1969
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1970
+            wp_redirect($checkout_uri);
1971 1971
             exit();
1972 1972
         }
1973 1973
         
1974
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1974
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1975 1975
 
1976
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1977
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1978
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1976
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1977
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1978
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1979 1979
             $invoice_id     = (int)$_GET['invoice-id'];
1980
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1980
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1981 1981
         }
1982 1982
         
1983
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1984
-            if ( $invoice->needs_payment() ) {
1983
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1984
+            if ($invoice->needs_payment()) {
1985 1985
                 $data                   = array();
1986 1986
                 $data['invoice_id']     = $invoice_id;
1987
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1987
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1988 1988
                 
1989
-                wpinv_set_checkout_session( $data );
1989
+                wpinv_set_checkout_session($data);
1990 1990
                 
1991
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1991
+                if (wpinv_get_option('vat_ip_country_default')) {
1992 1992
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1993 1993
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1994 1994
                     
1995
-                    wpinv_recalculate_tax( true );
1995
+                    wpinv_recalculate_tax(true);
1996 1996
                 }
1997 1997
                 
1998 1998
             } else {
1999 1999
                 $checkout_uri = $invoice->get_view_url();
2000 2000
             }
2001 2001
         } else {
2002
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
2002
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
2003 2003
             
2004
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
2004
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
2005 2005
         }
2006 2006
         
2007
-        if(wp_redirect( $checkout_uri )){
2007
+        if (wp_redirect($checkout_uri)) {
2008 2008
             exit;
2009 2009
         };
2010 2010
         wpinv_die();
2011 2011
     }
2012 2012
 }
2013
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
2013
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
2014 2014
 
2015
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
2016
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
2017
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
2015
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
2016
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
2017
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
2018 2018
             $user_id = $invoice->get_user_id();
2019
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
2019
+            $secret = sanitize_text_field($_GET['_wpipay']);
2020 2020
             
2021
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
2022
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
2021
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
2022
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
2023 2023
                 
2024
-                wpinv_guest_redirect( $redirect_to, $user_id );
2024
+                wpinv_guest_redirect($redirect_to, $user_id);
2025 2025
                 exit();
2026 2026
             }
2027 2027
         }
2028 2028
     }
2029 2029
 }
2030
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
2030
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
2031 2031
 
2032
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
2033
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
2032
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
2033
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
2034 2034
     
2035
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
2035
+    if (empty($invoice_id) && $invoice_id > 0) {
2036 2036
         return false;
2037 2037
     }
2038 2038
     
2039
-    if ( empty( $transaction_id ) ) {
2039
+    if (empty($transaction_id)) {
2040 2040
         $transaction_id = $invoice_id;
2041 2041
     }
2042 2042
 
2043
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
2043
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
2044 2044
     
2045
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
2045
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
2046 2046
 }
2047 2047
 
2048
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
2049
-    if ( empty( $status_display ) ) {
2050
-        $status_display = wpinv_status_nicename( $status );
2048
+function wpinv_invoice_status_label($status, $status_display = '') {
2049
+    if (empty($status_display)) {
2050
+        $status_display = wpinv_status_nicename($status);
2051 2051
     }
2052 2052
     
2053
-    switch ( $status ) {
2053
+    switch ($status) {
2054 2054
         case 'publish' :
2055 2055
         case 'wpi-renewal' :
2056 2056
             $class = 'label-success';
@@ -2075,201 +2075,201 @@  discard block
 block discarded – undo
2075 2075
     
2076 2076
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2077 2077
     
2078
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2078
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2079 2079
 }
2080 2080
 
2081
-function wpinv_format_invoice_number( $number, $type = '' ) {
2082
-    $check = apply_filters( 'wpinv_pre_format_invoice_number', null, $number, $type );
2083
-    if ( null !== $check ) {
2081
+function wpinv_format_invoice_number($number, $type = '') {
2082
+    $check = apply_filters('wpinv_pre_format_invoice_number', null, $number, $type);
2083
+    if (null !== $check) {
2084 2084
         return $check;
2085 2085
     }
2086 2086
 
2087
-    if ( !empty( $number ) && !is_numeric( $number ) ) {
2087
+    if (!empty($number) && !is_numeric($number)) {
2088 2088
         return $number;
2089 2089
     }
2090 2090
 
2091
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2092
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2093
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2091
+    $padd = wpinv_get_option('invoice_number_padd');
2092
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2093
+    $postfix = wpinv_get_option('invoice_number_postfix');
2094 2094
     
2095
-    $padd = absint( $padd );
2096
-    $formatted_number = absint( $number );
2095
+    $padd = absint($padd);
2096
+    $formatted_number = absint($number);
2097 2097
     
2098
-    if ( $padd > 0 ) {
2099
-        $formatted_number = zeroise( $formatted_number, $padd );
2098
+    if ($padd > 0) {
2099
+        $formatted_number = zeroise($formatted_number, $padd);
2100 2100
     }    
2101 2101
 
2102 2102
     $formatted_number = $prefix . $formatted_number . $postfix;
2103 2103
 
2104
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2104
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2105 2105
 }
2106 2106
 
2107
-function wpinv_get_next_invoice_number( $type = '' ) {
2108
-    $check = apply_filters( 'wpinv_get_pre_next_invoice_number', null, $type );
2109
-    if ( null !== $check ) {
2107
+function wpinv_get_next_invoice_number($type = '') {
2108
+    $check = apply_filters('wpinv_get_pre_next_invoice_number', null, $type);
2109
+    if (null !== $check) {
2110 2110
         return $check;
2111 2111
     }
2112 2112
     
2113
-    if ( !wpinv_sequential_number_active() ) {
2113
+    if (!wpinv_sequential_number_active()) {
2114 2114
         return false;
2115 2115
     }
2116 2116
 
2117
-    $number = $last_number = get_option( 'wpinv_last_invoice_number', 0 );
2118
-    $start  = wpinv_get_option( 'invoice_sequence_start', 1 );
2119
-    if ( !absint( $start ) > 0 ) {
2117
+    $number = $last_number = get_option('wpinv_last_invoice_number', 0);
2118
+    $start  = wpinv_get_option('invoice_sequence_start', 1);
2119
+    if (!absint($start) > 0) {
2120 2120
         $start = 1;
2121 2121
     }
2122 2122
     $increment_number = true;
2123 2123
     $save_number = false;
2124 2124
 
2125
-    if ( !empty( $number ) && !is_numeric( $number ) && $number == wpinv_format_invoice_number( $number ) ) {
2126
-        $number = wpinv_clean_invoice_number( $number );
2125
+    if (!empty($number) && !is_numeric($number) && $number == wpinv_format_invoice_number($number)) {
2126
+        $number = wpinv_clean_invoice_number($number);
2127 2127
     }
2128 2128
 
2129
-    if ( empty( $number ) ) {
2130
-        if ( !( $last_number === 0 || $last_number === '0' ) ) {
2131
-            $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys( wpinv_get_invoice_statuses( true, true ) ) ) );
2129
+    if (empty($number)) {
2130
+        if (!($last_number === 0 || $last_number === '0')) {
2131
+            $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => array_keys(wpinv_get_invoice_statuses(true, true))));
2132 2132
 
2133
-            if ( !empty( $last_invoice[0] ) && $invoice_number = wpinv_get_invoice_number( $last_invoice[0] ) ) {
2134
-                if ( is_numeric( $invoice_number ) ) {
2133
+            if (!empty($last_invoice[0]) && $invoice_number = wpinv_get_invoice_number($last_invoice[0])) {
2134
+                if (is_numeric($invoice_number)) {
2135 2135
                     $number = $invoice_number;
2136 2136
                 } else {
2137
-                    $number = wpinv_clean_invoice_number( $invoice_number );
2137
+                    $number = wpinv_clean_invoice_number($invoice_number);
2138 2138
                 }
2139 2139
             }
2140 2140
 
2141
-            if ( empty( $number ) ) {
2141
+            if (empty($number)) {
2142 2142
                 $increment_number = false;
2143 2143
                 $number = $start;
2144
-                $save_number = ( $number - 1 );
2144
+                $save_number = ($number - 1);
2145 2145
             } else {
2146 2146
                 $save_number = $number;
2147 2147
             }
2148 2148
         }
2149 2149
     }
2150 2150
 
2151
-    if ( $start > $number ) {
2151
+    if ($start > $number) {
2152 2152
         $increment_number = false;
2153 2153
         $number = $start;
2154
-        $save_number = ( $number - 1 );
2154
+        $save_number = ($number - 1);
2155 2155
     }
2156 2156
 
2157
-    if ( $save_number !== false ) {
2158
-        update_option( 'wpinv_last_invoice_number', $save_number );
2157
+    if ($save_number !== false) {
2158
+        update_option('wpinv_last_invoice_number', $save_number);
2159 2159
     }
2160 2160
     
2161
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2161
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2162 2162
 
2163
-    if ( $increment_number ) {
2163
+    if ($increment_number) {
2164 2164
         $number++;
2165 2165
     }
2166 2166
 
2167
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2167
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2168 2168
 }
2169 2169
 
2170
-function wpinv_clean_invoice_number( $number, $type = '' ) {
2171
-    $check = apply_filters( 'wpinv_pre_clean_invoice_number', null, $number, $type );
2172
-    if ( null !== $check ) {
2170
+function wpinv_clean_invoice_number($number, $type = '') {
2171
+    $check = apply_filters('wpinv_pre_clean_invoice_number', null, $number, $type);
2172
+    if (null !== $check) {
2173 2173
         return $check;
2174 2174
     }
2175 2175
     
2176
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2177
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2176
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2177
+    $postfix = wpinv_get_option('invoice_number_postfix');
2178 2178
 
2179
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2179
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2180 2180
 
2181
-    $length      = strlen( $number );
2182
-    $postfix_pos = strrpos( $number, $postfix );
2181
+    $length      = strlen($number);
2182
+    $postfix_pos = strrpos($number, $postfix);
2183 2183
     
2184
-    if ( false !== $postfix_pos ) {
2185
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2184
+    if (false !== $postfix_pos) {
2185
+        $number = substr_replace($number, '', $postfix_pos, $length);
2186 2186
     }
2187 2187
 
2188
-    $number = intval( $number );
2188
+    $number = intval($number);
2189 2189
 
2190
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2190
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2191 2191
 }
2192 2192
 
2193
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2193
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2194 2194
     global $wpdb;
2195 2195
 
2196
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2197
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft', $post->post_type );
2196
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2197
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft', $post->post_type);
2198 2198
     }
2199 2199
 
2200
-    if ( !$update ) {
2201
-        $wpdb->update( $wpdb->posts, array( 'post_name' => wpinv_generate_post_name( $post_ID ) ), array( 'ID' => $post_ID ) );
2202
-        clean_post_cache( $post_ID );
2200
+    if (!$update) {
2201
+        $wpdb->update($wpdb->posts, array('post_name' => wpinv_generate_post_name($post_ID)), array('ID' => $post_ID));
2202
+        clean_post_cache($post_ID);
2203 2203
     }
2204 2204
 }
2205
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2205
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2206 2206
 
2207
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2208
-    if ( !empty( $post_after->post_type ) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status ) {
2209
-        wpinv_update_invoice_number( $post_ID, true, $post_after->post_type );
2207
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2208
+    if (!empty($post_after->post_type) && $post_after->post_type == 'wpi_invoice' && $post_before->post_status == 'auto-draft' && $post_after->post_status != $post_before->post_status) {
2209
+        wpinv_update_invoice_number($post_ID, true, $post_after->post_type);
2210 2210
     }
2211 2211
 }
2212
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2212
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2213 2213
 
2214
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false, $type = '' ) {
2214
+function wpinv_update_invoice_number($post_ID, $save_sequential = false, $type = '') {
2215 2215
     global $wpdb;
2216 2216
     
2217
-    $check = apply_filters( 'wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type );
2218
-    if ( null !== $check ) {
2217
+    $check = apply_filters('wpinv_pre_update_invoice_number', null, $post_ID, $save_sequential, $type);
2218
+    if (null !== $check) {
2219 2219
         return $check;
2220 2220
     }
2221 2221
 
2222
-    if ( wpinv_sequential_number_active() ) {
2222
+    if (wpinv_sequential_number_active()) {
2223 2223
         $number = wpinv_get_next_invoice_number();
2224 2224
 
2225
-        if ( $save_sequential ) {
2226
-            update_option( 'wpinv_last_invoice_number', $number );
2225
+        if ($save_sequential) {
2226
+            update_option('wpinv_last_invoice_number', $number);
2227 2227
         }
2228 2228
     } else {
2229 2229
         $number = $post_ID;
2230 2230
     }
2231 2231
 
2232
-    $number = wpinv_format_invoice_number( $number );
2232
+    $number = wpinv_format_invoice_number($number);
2233 2233
 
2234
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2234
+    update_post_meta($post_ID, '_wpinv_number', $number);
2235 2235
 
2236
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2236
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2237 2237
 
2238
-    clean_post_cache( $post_ID );
2238
+    clean_post_cache($post_ID);
2239 2239
 
2240 2240
     return $number;
2241 2241
 }
2242 2242
 
2243
-function wpinv_post_name_prefix( $post_type = 'wpi_invoice' ) {
2244
-    return apply_filters( 'wpinv_post_name_prefix', 'inv-', $post_type );
2243
+function wpinv_post_name_prefix($post_type = 'wpi_invoice') {
2244
+    return apply_filters('wpinv_post_name_prefix', 'inv-', $post_type);
2245 2245
 }
2246 2246
 
2247
-function wpinv_generate_post_name( $post_ID ) {
2248
-    $prefix = wpinv_post_name_prefix( get_post_type( $post_ID ) );
2249
-    $post_name = sanitize_title( $prefix . $post_ID );
2247
+function wpinv_generate_post_name($post_ID) {
2248
+    $prefix = wpinv_post_name_prefix(get_post_type($post_ID));
2249
+    $post_name = sanitize_title($prefix . $post_ID);
2250 2250
 
2251
-    return apply_filters( 'wpinv_generate_post_name', $post_name, $post_ID, $prefix );
2251
+    return apply_filters('wpinv_generate_post_name', $post_name, $post_ID, $prefix);
2252 2252
 }
2253 2253
 
2254
-function wpinv_is_invoice_viewed( $invoice_id ) {
2255
-    if ( empty( $invoice_id ) ) {
2254
+function wpinv_is_invoice_viewed($invoice_id) {
2255
+    if (empty($invoice_id)) {
2256 2256
         return false;
2257 2257
     }
2258 2258
 
2259
-    $viewed_meta = get_post_meta( $invoice_id, '_wpinv_is_viewed', true );
2259
+    $viewed_meta = get_post_meta($invoice_id, '_wpinv_is_viewed', true);
2260 2260
 
2261
-    return apply_filters( 'wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id );
2261
+    return apply_filters('wpinv_is_invoice_viewed', 1 === (int)$viewed_meta, $invoice_id);
2262 2262
 }
2263 2263
 
2264 2264
 function wpinv_mark_invoice_viewed() {
2265 2265
 
2266
-    if ( isset( $_GET['invoice_key'] ) || is_singular( 'wpi_invoice' ) || is_singular( 'wpi_quote' ) ) {
2267
-        $invoice_key = isset( $_GET['invoice_key'] ) ? urldecode($_GET['invoice_key']) : '';
2266
+    if (isset($_GET['invoice_key']) || is_singular('wpi_invoice') || is_singular('wpi_quote')) {
2267
+        $invoice_key = isset($_GET['invoice_key']) ? urldecode($_GET['invoice_key']) : '';
2268 2268
 	    global $post;
2269 2269
 
2270
-        if(!empty($invoice_key)){
2270
+        if (!empty($invoice_key)) {
2271 2271
 	        $invoice_id = wpinv_get_invoice_id_by_key($invoice_key);
2272
-        } else if(!empty( $post ) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2272
+        } else if (!empty($post) && ($post->post_type == 'wpi_invoice' || $post->post_type == 'wpi_quote')) {
2273 2273
 			$invoice_id = $post->ID;
2274 2274
         } else {
2275 2275
         	return;
@@ -2277,60 +2277,60 @@  discard block
 block discarded – undo
2277 2277
 
2278 2278
         $invoice = new WPInv_Invoice($invoice_id);
2279 2279
 
2280
-        if(!$invoice_id){
2280
+        if (!$invoice_id) {
2281 2281
             return;
2282 2282
         }
2283 2283
 
2284
-	    if ( is_user_logged_in() ) {
2285
-		    if ( (int)$invoice->get_user_id() === get_current_user_id() ) {
2286
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2287
-		    } else if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2288
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2284
+	    if (is_user_logged_in()) {
2285
+		    if ((int)$invoice->get_user_id() === get_current_user_id()) {
2286
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2287
+		    } else if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2288
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2289 2289
 		    }
2290 2290
 	    } else {
2291
-		    if ( !wpinv_require_login_to_checkout() && isset( $_GET['invoice_key'] ) && $_GET['invoice_key'] === $invoice->get_key() ) {
2292
-			    update_post_meta($invoice_id,'_wpinv_is_viewed', 1);
2291
+		    if (!wpinv_require_login_to_checkout() && isset($_GET['invoice_key']) && $_GET['invoice_key'] === $invoice->get_key()) {
2292
+			    update_post_meta($invoice_id, '_wpinv_is_viewed', 1);
2293 2293
 		    }
2294 2294
 	    }
2295 2295
     }
2296 2296
 
2297 2297
 }
2298
-add_action( 'template_redirect', 'wpinv_mark_invoice_viewed' );
2298
+add_action('template_redirect', 'wpinv_mark_invoice_viewed');
2299 2299
 
2300
-function wpinv_get_subscription( $invoice, $by_parent = false ) {
2301
-    if ( empty( $invoice ) ) {
2300
+function wpinv_get_subscription($invoice, $by_parent = false) {
2301
+    if (empty($invoice)) {
2302 2302
         return false;
2303 2303
     }
2304 2304
     
2305
-    if ( ! is_object( $invoice ) && is_scalar( $invoice ) ) {
2306
-        $invoice = wpinv_get_invoice( $invoice );
2305
+    if (!is_object($invoice) && is_scalar($invoice)) {
2306
+        $invoice = wpinv_get_invoice($invoice);
2307 2307
     }
2308 2308
     
2309
-    if ( !( is_object( $invoice ) && ! empty( $invoice->ID ) && $invoice->is_recurring() ) ) {
2309
+    if (!(is_object($invoice) && !empty($invoice->ID) && $invoice->is_recurring())) {
2310 2310
         return false;
2311 2311
     }
2312 2312
     
2313
-    $invoice_id = ! $by_parent && ! empty( $invoice->parent_invoice ) ? $invoice->parent_invoice : $invoice->ID;
2313
+    $invoice_id = !$by_parent && !empty($invoice->parent_invoice) ? $invoice->parent_invoice : $invoice->ID;
2314 2314
     
2315 2315
     $subs_db    = new WPInv_Subscriptions_DB;
2316
-    $subs       = $subs_db->get_subscriptions( array( 'parent_payment_id' => $invoice_id, 'number' => 1 ) );
2316
+    $subs       = $subs_db->get_subscriptions(array('parent_payment_id' => $invoice_id, 'number' => 1));
2317 2317
     
2318
-    if ( ! empty( $subs ) ) {
2319
-        return reset( $subs );
2318
+    if (!empty($subs)) {
2319
+        return reset($subs);
2320 2320
     }
2321 2321
     
2322 2322
     return false;
2323 2323
 }
2324 2324
 
2325
-function wpinv_filter_posts_clauses( $clauses, $wp_query ) {
2325
+function wpinv_filter_posts_clauses($clauses, $wp_query) {
2326 2326
     global $wpdb;
2327 2327
 
2328
-    if ( ! empty( $wp_query->query_vars['orderby'] ) && $wp_query->query_vars['orderby'] == 'invoice_date' ) {
2329
-        if ( !empty( $clauses['join'] ) ) {
2328
+    if (!empty($wp_query->query_vars['orderby']) && $wp_query->query_vars['orderby'] == 'invoice_date') {
2329
+        if (!empty($clauses['join'])) {
2330 2330
             $clauses['join'] .= " ";
2331 2331
         }
2332 2332
 
2333
-        if ( !empty( $clauses['fields'] ) ) {
2333
+        if (!empty($clauses['fields'])) {
2334 2334
             $clauses['fields'] .= ", ";
2335 2335
         }
2336 2336
 
@@ -2341,4 +2341,4 @@  discard block
 block discarded – undo
2341 2341
 
2342 2342
     return $clauses;
2343 2343
 }
2344
-add_filter( 'posts_clauses', 'wpinv_filter_posts_clauses', 10, 2 );
2345 2344
\ No newline at end of file
2345
+add_filter('posts_clauses', 'wpinv_filter_posts_clauses', 10, 2);
2346 2346
\ No newline at end of file
Please login to merge, or discard this patch.