Passed
Push — master ( 9df976...f7b81c )
by Stiofan
03:33
created
includes/wpinv-invoice-functions.php 1 patch
Spacing   +689 added lines, -689 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'] = '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,59 +119,59 @@  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'] = geodir_get_currency_type();
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
-    if ( !empty( $invoice_data['invoice_key'] ) ) {
160
-        $invoice->set( 'key', $invoice_data['invoice_key'] );
161
-    }
162
-    $invoice->set( 'mode', ( wpinv_is_test_mode() ? 'test' : 'live' ) );
163
-    $invoice->set( 'parent_invoice', ( !empty( $invoice_data['parent'] ) ? absint( $invoice_data['parent'] ) : '' ) );
164
-    
165
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) ) {
166
-        foreach ( $invoice_data['cart_details'] as $key => $item ) {
167
-            $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
168
-            $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
169
-            $name           = !empty( $item['name'] ) ? $item['name'] : '';
170
-            $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
+    if (!empty($invoice_data['invoice_key'])) {
160
+        $invoice->set('key', $invoice_data['invoice_key']);
161
+    }
162
+    $invoice->set('mode', (wpinv_is_test_mode() ? 'test' : 'live'));
163
+    $invoice->set('parent_invoice', (!empty($invoice_data['parent']) ? absint($invoice_data['parent']) : ''));
164
+    
165
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details'])) {
166
+        foreach ($invoice_data['cart_details'] as $key => $item) {
167
+            $item_id        = !empty($item['id']) ? $item['id'] : 0;
168
+            $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
169
+            $name           = !empty($item['name']) ? $item['name'] : '';
170
+            $item_price     = isset($item['item_price']) ? $item['item_price'] : '';
171 171
             
172
-            $post_item  = new WPInv_Item( $item_id );
173
-            if ( !empty( $post_item ) ) {
174
-                $name       = !empty( $name ) ? $name : $post_item->get_name();
172
+            $post_item = new WPInv_Item($item_id);
173
+            if (!empty($post_item)) {
174
+                $name       = !empty($name) ? $name : $post_item->get_name();
175 175
                 $item_price = $item_price !== '' ? $item_price : $post_item->get_price();
176 176
             } else {
177 177
                 continue;
@@ -181,258 +181,258 @@  discard block
 block discarded – undo
181 181
                 'name'          => $name,
182 182
                 'quantity'      => $quantity,
183 183
                 'item_price'    => $item_price,
184
-                'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
185
-                'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0.00,
186
-                'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
187
-                'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
188
-                'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
184
+                'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
185
+                'tax'           => !empty($item['tax']) ? $item['tax'] : 0.00,
186
+                'discount'      => isset($item['discount']) ? $item['discount'] : 0,
187
+                'meta'          => isset($item['meta']) ? $item['meta'] : array(),
188
+                'fees'          => isset($item['fees']) ? $item['fees'] : array(),
189 189
             );
190 190
 
191
-            $invoice->add_item( $item_id, $args );
191
+            $invoice->add_item($item_id, $args);
192 192
         }
193 193
     }
194 194
 
195
-    $invoice->increase_tax( wpinv_get_cart_fee_tax() );
195
+    $invoice->increase_tax(wpinv_get_cart_fee_tax());
196 196
 
197
-    if ( isset( $invoice_data['post_date'] ) ) {
198
-        $invoice->set( 'date', $invoice_data['post_date'] );
197
+    if (isset($invoice_data['post_date'])) {
198
+        $invoice->set('date', $invoice_data['post_date']);
199 199
     }
200 200
     
201 201
     // Invoice due date
202
-    if ( isset( $invoice_data['due_date'] ) ) {
203
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
202
+    if (isset($invoice_data['due_date'])) {
203
+        $invoice->set('due_date', $invoice_data['due_date']);
204 204
     }
205 205
     
206 206
     $invoice->save();
207 207
     
208 208
     // Add notes
209
-    if ( !empty( $invoice_data['private_note'] ) ) {
210
-        $invoice->add_note( $invoice_data['private_note'] );
209
+    if (!empty($invoice_data['private_note'])) {
210
+        $invoice->add_note($invoice_data['private_note']);
211 211
     }
212
-    if ( !empty( $invoice_data['user_note'] ) ) {
213
-        $invoice->add_note( $invoice_data['user_note'], true );
212
+    if (!empty($invoice_data['user_note'])) {
213
+        $invoice->add_note($invoice_data['user_note'], true);
214 214
     }
215 215
     
216
-    do_action( 'wpinv_insert_invoice', $invoice->ID, $invoice_data );
216
+    do_action('wpinv_insert_invoice', $invoice->ID, $invoice_data);
217 217
 
218
-    if ( ! empty( $invoice->ID ) ) {
218
+    if (!empty($invoice->ID)) {
219 219
         global $wpi_userID, $wpinv_ip_address_country;
220 220
         
221 221
         $checkout_session = wpinv_get_checkout_session();
222 222
         
223 223
         $data_session                   = array();
224 224
         $data_session['invoice_id']     = $invoice->ID;
225
-        $data_session['cart_discounts'] = $invoice->get_discounts( true );
225
+        $data_session['cart_discounts'] = $invoice->get_discounts(true);
226 226
         
227
-        wpinv_set_checkout_session( $data_session );
227
+        wpinv_set_checkout_session($data_session);
228 228
         
229 229
         $wpi_userID         = (int)$invoice->get_user_id();
230 230
         
231
-        $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
231
+        $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
232 232
         $_POST['state']     = $invoice->state;
233 233
 
234
-        $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
235
-        $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
234
+        $invoice->set('country', sanitize_text_field($_POST['country']));
235
+        $invoice->set('state', sanitize_text_field($_POST['state']));
236 236
         
237 237
         $wpinv_ip_address_country = $invoice->country;
238 238
         
239
-        $invoice = $invoice->recalculate_totals( true );
239
+        $invoice = $invoice->recalculate_totals(true);
240 240
         
241
-        wpinv_set_checkout_session( $checkout_session );
241
+        wpinv_set_checkout_session($checkout_session);
242 242
                     
243 243
         return $invoice;
244 244
     }
245 245
     
246
-    if ( $wp_error ) {
247
-        if ( is_wp_error( $invoice ) ) {
246
+    if ($wp_error) {
247
+        if (is_wp_error($invoice)) {
248 248
             return $invoice;
249 249
         } else {
250
-            return new WP_Error( 'wpinv_insert_invoice_error', __( 'Error in insert invoice.', 'invoicing' ) );
250
+            return new WP_Error('wpinv_insert_invoice_error', __('Error in insert invoice.', 'invoicing'));
251 251
         }
252 252
     } else {
253 253
         return 0;
254 254
     }
255 255
 }
256 256
 
257
-function wpinv_update_invoice( $invoice_data = array(), $wp_error = false ) {
258
-    $invoice_ID = !empty( $invoice_data['ID'] ) ? absint( $invoice_data['ID'] ) : NULL;
257
+function wpinv_update_invoice($invoice_data = array(), $wp_error = false) {
258
+    $invoice_ID = !empty($invoice_data['ID']) ? absint($invoice_data['ID']) : NULL;
259 259
 
260
-    if ( !$invoice_ID ) {
261
-        if ( $wp_error ) {
262
-            return new WP_Error( 'invalid_invoice_id', __( 'Invalid invoice ID.', 'invoicing' ) );
260
+    if (!$invoice_ID) {
261
+        if ($wp_error) {
262
+            return new WP_Error('invalid_invoice_id', __('Invalid invoice ID.', 'invoicing'));
263 263
         }
264 264
         return 0;
265 265
     }
266 266
 
267
-    $invoice = wpinv_get_invoice( $invoice_ID );
267
+    $invoice = wpinv_get_invoice($invoice_ID);
268 268
 
269
-    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring( true ) : NULL;
269
+    $recurring_item = $invoice->is_recurring() ? $invoice->get_recurring(true) : NULL;
270 270
 
271
-    if ( empty( $invoice->ID ) ) {
272
-        if ( $wp_error ) {
273
-            return new WP_Error( 'invalid_invoice', __( 'Invalid invoice.', 'invoicing' ) );
271
+    if (empty($invoice->ID)) {
272
+        if ($wp_error) {
273
+            return new WP_Error('invalid_invoice', __('Invalid invoice.', 'invoicing'));
274 274
         }
275 275
         return 0;
276 276
     }
277 277
 
278
-    if ( !$invoice->has_status( array( 'wpi-pending' ) ) ) {
279
-        if ( $wp_error ) {
280
-            return new WP_Error( 'invalid_invoice_status', __( 'Only invoice with pending payment is allowed to update.', 'invoicing' ) );
278
+    if (!$invoice->has_status(array('wpi-pending'))) {
279
+        if ($wp_error) {
280
+            return new WP_Error('invalid_invoice_status', __('Only invoice with pending payment is allowed to update.', 'invoicing'));
281 281
         }
282 282
         return 0;
283 283
     }
284 284
 
285 285
     // Invoice status
286
-    if ( !empty( $invoice_data['status'] ) ) {
287
-        $invoice->set( 'status', $invoice_data['status'] );
286
+    if (!empty($invoice_data['status'])) {
287
+        $invoice->set('status', $invoice_data['status']);
288 288
     }
289 289
 
290 290
     // Invoice date
291
-    if ( !empty( $invoice_data['post_date'] ) ) {
292
-        $invoice->set( 'date', $invoice_data['post_date'] );
291
+    if (!empty($invoice_data['post_date'])) {
292
+        $invoice->set('date', $invoice_data['post_date']);
293 293
     }
294 294
 
295 295
     // Invoice due date
296
-    if ( isset( $invoice_data['due_date'] ) ) {
297
-        $invoice->set( 'due_date', $invoice_data['due_date'] );
296
+    if (isset($invoice_data['due_date'])) {
297
+        $invoice->set('due_date', $invoice_data['due_date']);
298 298
     }
299 299
 
300 300
     // Invoice IP address
301
-    if ( !empty( $invoice_data['ip'] ) ) {
302
-        $invoice->set( 'ip', $invoice_data['ip'] );
301
+    if (!empty($invoice_data['ip'])) {
302
+        $invoice->set('ip', $invoice_data['ip']);
303 303
     }
304 304
 
305 305
     // Invoice key
306
-    if ( !empty( $invoice_data['invoice_key'] ) ) {
307
-        $invoice->set( 'key', $invoice_data['invoice_key'] );
306
+    if (!empty($invoice_data['invoice_key'])) {
307
+        $invoice->set('key', $invoice_data['invoice_key']);
308 308
     }
309 309
     
310 310
     // User info
311
-    if ( !empty( $invoice_data['user_info'] ) && is_array( $invoice_data['user_info'] ) ) {
312
-        $user_info = wp_parse_args( $invoice_data['user_info'], $invoice->user_info );
311
+    if (!empty($invoice_data['user_info']) && is_array($invoice_data['user_info'])) {
312
+        $user_info = wp_parse_args($invoice_data['user_info'], $invoice->user_info);
313 313
 
314
-        if ( $discounts = $invoice->get_discounts() ) {
314
+        if ($discounts = $invoice->get_discounts()) {
315 315
             $set_discount = $discounts;
316 316
         } else {
317 317
             $set_discount = '';
318 318
         }
319 319
 
320 320
         // Manage discount
321
-        if ( !empty( $invoice_data['user_info']['discount'] ) ) {
321
+        if (!empty($invoice_data['user_info']['discount'])) {
322 322
             // Remove discount
323
-            if ( $invoice_data['user_info']['discount'] == 'none' ) {
323
+            if ($invoice_data['user_info']['discount'] == 'none') {
324 324
                 $set_discount = '';
325 325
             } else {
326 326
                 $set_discount = $invoice_data['user_info']['discount'];
327 327
             }
328 328
 
329
-            $invoice->set( 'discounts', $set_discount );
329
+            $invoice->set('discounts', $set_discount);
330 330
         }
331 331
 
332 332
         $user_info['discount'] = $set_discount;
333 333
 
334
-        $invoice->set( 'user_info', $user_info );
334
+        $invoice->set('user_info', $user_info);
335 335
     }
336 336
 
337
-    if ( !empty( $invoice_data['cart_details'] ) && is_array( $invoice_data['cart_details'] ) && $cart_details = $invoice_data['cart_details'] ) {
338
-        $remove_items = !empty( $cart_details['remove_items'] ) && is_array( $cart_details['remove_items'] ) ? $cart_details['remove_items'] : array();
337
+    if (!empty($invoice_data['cart_details']) && is_array($invoice_data['cart_details']) && $cart_details = $invoice_data['cart_details']) {
338
+        $remove_items = !empty($cart_details['remove_items']) && is_array($cart_details['remove_items']) ? $cart_details['remove_items'] : array();
339 339
 
340
-        if ( !empty( $remove_items[0]['id'] ) ) {
341
-            foreach ( $remove_items as $item ) {
342
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
343
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
344
-                if ( empty( $item_id ) ) {
340
+        if (!empty($remove_items[0]['id'])) {
341
+            foreach ($remove_items as $item) {
342
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
343
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
344
+                if (empty($item_id)) {
345 345
                     continue;
346 346
                 }
347 347
 
348
-                foreach ( $invoice->cart_details as $cart_index => $cart_item ) {
349
-                    if ( $item_id == $cart_item['id'] ) {
348
+                foreach ($invoice->cart_details as $cart_index => $cart_item) {
349
+                    if ($item_id == $cart_item['id']) {
350 350
                         $args = array(
351 351
                             'id'         => $item_id,
352 352
                             'quantity'   => $quantity,
353 353
                             'cart_index' => $cart_index
354 354
                         );
355 355
 
356
-                        $invoice->remove_item( $item_id, $args );
356
+                        $invoice->remove_item($item_id, $args);
357 357
                         break;
358 358
                     }
359 359
                 }
360 360
             }
361 361
         }
362 362
 
363
-        $add_items = !empty( $cart_details['add_items'] ) && is_array( $cart_details['add_items'] ) ? $cart_details['add_items'] : array();
363
+        $add_items = !empty($cart_details['add_items']) && is_array($cart_details['add_items']) ? $cart_details['add_items'] : array();
364 364
 
365
-        if ( !empty( $add_items[0]['id'] ) ) {
366
-            foreach ( $add_items as $item ) {
367
-                $item_id        = !empty( $item['id'] ) ? $item['id'] : 0;
368
-                $post_item      = new WPInv_Item( $item_id );
369
-                if ( empty( $post_item ) ) {
365
+        if (!empty($add_items[0]['id'])) {
366
+            foreach ($add_items as $item) {
367
+                $item_id        = !empty($item['id']) ? $item['id'] : 0;
368
+                $post_item      = new WPInv_Item($item_id);
369
+                if (empty($post_item)) {
370 370
                     continue;
371 371
                 }
372 372
 
373 373
                 $valid_item = true;
374
-                if ( !empty( $recurring_item ) ) {
375
-                    if ( $recurring_item->ID != $item_id ) {
374
+                if (!empty($recurring_item)) {
375
+                    if ($recurring_item->ID != $item_id) {
376 376
                         $valid_item = false;
377 377
                     }
378
-                } else if ( wpinv_is_recurring_item( $item_id ) ) {
378
+                } else if (wpinv_is_recurring_item($item_id)) {
379 379
                     $valid_item = false;
380 380
                 }
381 381
                 
382
-                if ( !$valid_item ) {
383
-                    if ( $wp_error ) {
384
-                        return new WP_Error( 'invalid_invoice_item', __( 'You can not add item to invoice because recurring item must be paid individually!', 'invoicing' ) );
382
+                if (!$valid_item) {
383
+                    if ($wp_error) {
384
+                        return new WP_Error('invalid_invoice_item', __('You can not add item to invoice because recurring item must be paid individually!', 'invoicing'));
385 385
                     }
386 386
                     return 0;
387 387
                 }
388 388
 
389
-                $quantity       = !empty( $item['quantity'] ) ? $item['quantity'] : 1;
390
-                $name           = !empty( $item['name'] ) ? $item['name'] : $post_item->get_name();
391
-                $item_price     = isset( $item['item_price'] ) ? $item['item_price'] : $post_item->get_price();
389
+                $quantity       = !empty($item['quantity']) ? $item['quantity'] : 1;
390
+                $name           = !empty($item['name']) ? $item['name'] : $post_item->get_name();
391
+                $item_price     = isset($item['item_price']) ? $item['item_price'] : $post_item->get_price();
392 392
 
393 393
                 $args = array(
394 394
                     'name'          => $name,
395 395
                     'quantity'      => $quantity,
396 396
                     'item_price'    => $item_price,
397
-                    'custom_price'  => isset( $item['custom_price'] ) ? $item['custom_price'] : '',
398
-                    'tax'           => !empty( $item['tax'] ) ? $item['tax'] : 0,
399
-                    'discount'      => isset( $item['discount'] ) ? $item['discount'] : 0,
400
-                    'meta'          => isset( $item['meta'] ) ? $item['meta'] : array(),
401
-                    'fees'          => isset( $item['fees'] ) ? $item['fees'] : array(),
397
+                    'custom_price'  => isset($item['custom_price']) ? $item['custom_price'] : '',
398
+                    'tax'           => !empty($item['tax']) ? $item['tax'] : 0,
399
+                    'discount'      => isset($item['discount']) ? $item['discount'] : 0,
400
+                    'meta'          => isset($item['meta']) ? $item['meta'] : array(),
401
+                    'fees'          => isset($item['fees']) ? $item['fees'] : array(),
402 402
                 );
403 403
 
404
-                $invoice->add_item( $item_id, $args );
404
+                $invoice->add_item($item_id, $args);
405 405
             }
406 406
         }
407 407
     }
408 408
     
409 409
     // Payment details
410
-    if ( !empty( $invoice_data['payment_details'] ) && $payment_details = $invoice_data['payment_details'] ) {
411
-        if ( !empty( $payment_details['gateway'] ) ) {
412
-            $invoice->set( 'gateway', $payment_details['gateway'] );
410
+    if (!empty($invoice_data['payment_details']) && $payment_details = $invoice_data['payment_details']) {
411
+        if (!empty($payment_details['gateway'])) {
412
+            $invoice->set('gateway', $payment_details['gateway']);
413 413
         }
414 414
 
415
-        if ( !empty( $payment_details['transaction_id'] ) ) {
416
-            $invoice->set( 'transaction_id', $payment_details['transaction_id'] );
415
+        if (!empty($payment_details['transaction_id'])) {
416
+            $invoice->set('transaction_id', $payment_details['transaction_id']);
417 417
         }
418 418
     }
419 419
 
420
-    do_action( 'wpinv_pre_update_invoice', $invoice->ID, $invoice_data );
420
+    do_action('wpinv_pre_update_invoice', $invoice->ID, $invoice_data);
421 421
 
422 422
     // Parent invoice
423
-    if ( !empty( $invoice_data['parent'] ) ) {
424
-        $invoice->set( 'parent_invoice', $invoice_data['parent'] );
423
+    if (!empty($invoice_data['parent'])) {
424
+        $invoice->set('parent_invoice', $invoice_data['parent']);
425 425
     }
426 426
 
427 427
     // Save invoice data.
428 428
     $invoice->save();
429 429
     
430
-    if ( empty( $invoice->ID ) || is_wp_error( $invoice ) ) {
431
-        if ( $wp_error ) {
432
-            if ( is_wp_error( $invoice ) ) {
430
+    if (empty($invoice->ID) || is_wp_error($invoice)) {
431
+        if ($wp_error) {
432
+            if (is_wp_error($invoice)) {
433 433
                 return $invoice;
434 434
             } else {
435
-                return new WP_Error( 'wpinv_update_invoice_error', __( 'Error in update invoice.', 'invoicing' ) );
435
+                return new WP_Error('wpinv_update_invoice_error', __('Error in update invoice.', 'invoicing'));
436 436
             }
437 437
         } else {
438 438
             return 0;
@@ -440,13 +440,13 @@  discard block
 block discarded – undo
440 440
     }
441 441
 
442 442
     // Add private note
443
-    if ( !empty( $invoice_data['private_note'] ) ) {
444
-        $invoice->add_note( $invoice_data['private_note'] );
443
+    if (!empty($invoice_data['private_note'])) {
444
+        $invoice->add_note($invoice_data['private_note']);
445 445
     }
446 446
 
447 447
     // Add user note
448
-    if ( !empty( $invoice_data['user_note'] ) ) {
449
-        $invoice->add_note( $invoice_data['user_note'], true );
448
+    if (!empty($invoice_data['user_note'])) {
449
+        $invoice->add_note($invoice_data['user_note'], true);
450 450
     }
451 451
 
452 452
     global $wpi_userID, $wpinv_ip_address_country;
@@ -455,445 +455,445 @@  discard block
 block discarded – undo
455 455
 
456 456
     $data_session                   = array();
457 457
     $data_session['invoice_id']     = $invoice->ID;
458
-    $data_session['cart_discounts'] = $invoice->get_discounts( true );
458
+    $data_session['cart_discounts'] = $invoice->get_discounts(true);
459 459
 
460
-    wpinv_set_checkout_session( $data_session );
460
+    wpinv_set_checkout_session($data_session);
461 461
 
462 462
     $wpi_userID         = (int)$invoice->get_user_id();
463 463
 
464
-    $_POST['country']   = !empty( $invoice->country ) ? $invoice->country : wpinv_get_default_country();
464
+    $_POST['country']   = !empty($invoice->country) ? $invoice->country : wpinv_get_default_country();
465 465
     $_POST['state']     = $invoice->state;
466 466
 
467
-    $invoice->set( 'country', sanitize_text_field( $_POST['country'] ) );
468
-    $invoice->set( 'state', sanitize_text_field( $_POST['state'] ) );
467
+    $invoice->set('country', sanitize_text_field($_POST['country']));
468
+    $invoice->set('state', sanitize_text_field($_POST['state']));
469 469
 
470 470
     $wpinv_ip_address_country = $invoice->country;
471 471
 
472
-    $invoice = $invoice->recalculate_totals( true );
472
+    $invoice = $invoice->recalculate_totals(true);
473 473
 
474
-    do_action( 'wpinv_post_update_invoice', $invoice->ID, $invoice_data );
474
+    do_action('wpinv_post_update_invoice', $invoice->ID, $invoice_data);
475 475
 
476
-    wpinv_set_checkout_session( $checkout_session );
476
+    wpinv_set_checkout_session($checkout_session);
477 477
 
478 478
     return $invoice;
479 479
 }
480 480
 
481
-function wpinv_get_invoice( $invoice_id = 0, $cart = false ) {
482
-    if ( $cart && empty( $invoice_id ) ) {
481
+function wpinv_get_invoice($invoice_id = 0, $cart = false) {
482
+    if ($cart && empty($invoice_id)) {
483 483
         $invoice_id = (int)wpinv_get_invoice_cart_id();
484 484
     }
485 485
 
486
-    $invoice = new WPInv_Invoice( $invoice_id );
486
+    $invoice = new WPInv_Invoice($invoice_id);
487 487
     return $invoice;
488 488
 }
489 489
 
490
-function wpinv_get_invoice_cart( $invoice_id = 0 ) {
491
-    return wpinv_get_invoice( $invoice_id, true );
490
+function wpinv_get_invoice_cart($invoice_id = 0) {
491
+    return wpinv_get_invoice($invoice_id, true);
492 492
 }
493 493
 
494
-function wpinv_get_invoice_description( $invoice_id = 0 ) {
495
-    $invoice = new WPInv_Invoice( $invoice_id );
494
+function wpinv_get_invoice_description($invoice_id = 0) {
495
+    $invoice = new WPInv_Invoice($invoice_id);
496 496
     return $invoice->get_description();
497 497
 }
498 498
 
499
-function wpinv_get_invoice_currency_code( $invoice_id = 0 ) {
500
-    $invoice = new WPInv_Invoice( $invoice_id );
499
+function wpinv_get_invoice_currency_code($invoice_id = 0) {
500
+    $invoice = new WPInv_Invoice($invoice_id);
501 501
     return $invoice->get_currency();
502 502
 }
503 503
 
504
-function wpinv_get_payment_user_email( $invoice_id ) {
505
-    $invoice = new WPInv_Invoice( $invoice_id );
504
+function wpinv_get_payment_user_email($invoice_id) {
505
+    $invoice = new WPInv_Invoice($invoice_id);
506 506
     return $invoice->get_email();
507 507
 }
508 508
 
509
-function wpinv_get_user_id( $invoice_id ) {
510
-    $invoice = new WPInv_Invoice( $invoice_id );
509
+function wpinv_get_user_id($invoice_id) {
510
+    $invoice = new WPInv_Invoice($invoice_id);
511 511
     return $invoice->get_user_id();
512 512
 }
513 513
 
514
-function wpinv_get_invoice_status( $invoice_id, $return_label = false ) {
515
-    $invoice = new WPInv_Invoice( $invoice_id );
514
+function wpinv_get_invoice_status($invoice_id, $return_label = false) {
515
+    $invoice = new WPInv_Invoice($invoice_id);
516 516
     
517
-    return $invoice->get_status( $return_label );
517
+    return $invoice->get_status($return_label);
518 518
 }
519 519
 
520
-function wpinv_get_payment_gateway( $invoice_id, $return_label = false ) {
521
-    $invoice = new WPInv_Invoice( $invoice_id );
520
+function wpinv_get_payment_gateway($invoice_id, $return_label = false) {
521
+    $invoice = new WPInv_Invoice($invoice_id);
522 522
     
523
-    return $invoice->get_gateway( $return_label );
523
+    return $invoice->get_gateway($return_label);
524 524
 }
525 525
 
526
-function wpinv_get_payment_gateway_name( $invoice_id ) {
527
-    $invoice = new WPInv_Invoice( $invoice_id );
526
+function wpinv_get_payment_gateway_name($invoice_id) {
527
+    $invoice = new WPInv_Invoice($invoice_id);
528 528
     
529 529
     return $invoice->get_gateway_title();
530 530
 }
531 531
 
532
-function wpinv_get_payment_transaction_id( $invoice_id ) {
533
-    $invoice = new WPInv_Invoice( $invoice_id );
532
+function wpinv_get_payment_transaction_id($invoice_id) {
533
+    $invoice = new WPInv_Invoice($invoice_id);
534 534
     
535 535
     return $invoice->get_transaction_id();
536 536
 }
537 537
 
538
-function wpinv_get_id_by_transaction_id( $key ) {
538
+function wpinv_get_id_by_transaction_id($key) {
539 539
     global $wpdb;
540 540
 
541
-    $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 ) );
541
+    $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));
542 542
 
543
-    if ( $invoice_id != NULL )
543
+    if ($invoice_id != NULL)
544 544
         return $invoice_id;
545 545
 
546 546
     return 0;
547 547
 }
548 548
 
549
-function wpinv_get_invoice_meta( $invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true ) {
550
-    $invoice = new WPInv_Invoice( $invoice_id );
549
+function wpinv_get_invoice_meta($invoice_id = 0, $meta_key = '_wpinv_payment_meta', $single = true) {
550
+    $invoice = new WPInv_Invoice($invoice_id);
551 551
 
552
-    return $invoice->get_meta( $meta_key, $single );
552
+    return $invoice->get_meta($meta_key, $single);
553 553
 }
554 554
 
555
-function wpinv_update_invoice_meta( $invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '' ) {
556
-    $invoice = new WPInv_Invoice( $invoice_id );
555
+function wpinv_update_invoice_meta($invoice_id = 0, $meta_key = '', $meta_value = '', $prev_value = '') {
556
+    $invoice = new WPInv_Invoice($invoice_id);
557 557
     
558
-    return $invoice->update_meta( $meta_key, $meta_value, $prev_value );
558
+    return $invoice->update_meta($meta_key, $meta_value, $prev_value);
559 559
 }
560 560
 
561
-function wpinv_get_items( $invoice_id = 0 ) {
562
-    $invoice            = wpinv_get_invoice( $invoice_id );
561
+function wpinv_get_items($invoice_id = 0) {
562
+    $invoice            = wpinv_get_invoice($invoice_id);
563 563
     
564 564
     $items              = $invoice->get_items();
565 565
     $invoice_currency   = $invoice->get_currency();
566 566
 
567
-    if ( !empty( $items ) && is_array( $items ) ) {
568
-        foreach ( $items as $key => $item ) {
567
+    if (!empty($items) && is_array($items)) {
568
+        foreach ($items as $key => $item) {
569 569
             $items[$key]['currency'] = $invoice_currency;
570 570
 
571
-            if ( !isset( $cart_item['subtotal'] ) ) {
571
+            if (!isset($cart_item['subtotal'])) {
572 572
                 $items[$key]['subtotal'] = $items[$key]['amount'] * 1;
573 573
             }
574 574
         }
575 575
     }
576 576
 
577
-    return apply_filters( 'wpinv_get_items', $items, $invoice_id );
577
+    return apply_filters('wpinv_get_items', $items, $invoice_id);
578 578
 }
579 579
 
580
-function wpinv_get_fees( $invoice_id = 0 ) {
581
-    $invoice           = wpinv_get_invoice( $invoice_id );
580
+function wpinv_get_fees($invoice_id = 0) {
581
+    $invoice           = wpinv_get_invoice($invoice_id);
582 582
     $fees              = $invoice->get_fees();
583 583
 
584
-    return apply_filters( 'wpinv_get_fees', $fees, $invoice_id );
584
+    return apply_filters('wpinv_get_fees', $fees, $invoice_id);
585 585
 }
586 586
 
587
-function wpinv_get_invoice_ip( $invoice_id ) {
588
-    $invoice = new WPInv_Invoice( $invoice_id );
587
+function wpinv_get_invoice_ip($invoice_id) {
588
+    $invoice = new WPInv_Invoice($invoice_id);
589 589
     return $invoice->get_ip();
590 590
 }
591 591
 
592
-function wpinv_get_invoice_user_info( $invoice_id ) {
593
-    $invoice = new WPInv_Invoice( $invoice_id );
592
+function wpinv_get_invoice_user_info($invoice_id) {
593
+    $invoice = new WPInv_Invoice($invoice_id);
594 594
     return $invoice->get_user_info();
595 595
 }
596 596
 
597
-function wpinv_subtotal( $invoice_id = 0, $currency = false ) {
598
-    $invoice = new WPInv_Invoice( $invoice_id );
597
+function wpinv_subtotal($invoice_id = 0, $currency = false) {
598
+    $invoice = new WPInv_Invoice($invoice_id);
599 599
 
600
-    return $invoice->get_subtotal( $currency );
600
+    return $invoice->get_subtotal($currency);
601 601
 }
602 602
 
603
-function wpinv_tax( $invoice_id = 0, $currency = false ) {
604
-    $invoice = new WPInv_Invoice( $invoice_id );
603
+function wpinv_tax($invoice_id = 0, $currency = false) {
604
+    $invoice = new WPInv_Invoice($invoice_id);
605 605
 
606
-    return $invoice->get_tax( $currency );
606
+    return $invoice->get_tax($currency);
607 607
 }
608 608
 
609
-function wpinv_discount( $invoice_id = 0, $currency = false, $dash = false ) {
610
-    $invoice = wpinv_get_invoice( $invoice_id );
609
+function wpinv_discount($invoice_id = 0, $currency = false, $dash = false) {
610
+    $invoice = wpinv_get_invoice($invoice_id);
611 611
 
612
-    return $invoice->get_discount( $currency, $dash );
612
+    return $invoice->get_discount($currency, $dash);
613 613
 }
614 614
 
615
-function wpinv_discount_code( $invoice_id = 0 ) {
616
-    $invoice = new WPInv_Invoice( $invoice_id );
615
+function wpinv_discount_code($invoice_id = 0) {
616
+    $invoice = new WPInv_Invoice($invoice_id);
617 617
 
618 618
     return $invoice->get_discount_code();
619 619
 }
620 620
 
621
-function wpinv_payment_total( $invoice_id = 0, $currency = false ) {
622
-    $invoice = new WPInv_Invoice( $invoice_id );
621
+function wpinv_payment_total($invoice_id = 0, $currency = false) {
622
+    $invoice = new WPInv_Invoice($invoice_id);
623 623
 
624
-    return $invoice->get_total( $currency );
624
+    return $invoice->get_total($currency);
625 625
 }
626 626
 
627
-function wpinv_get_date_created( $invoice_id = 0 ) {
628
-    $invoice = new WPInv_Invoice( $invoice_id );
627
+function wpinv_get_date_created($invoice_id = 0) {
628
+    $invoice = new WPInv_Invoice($invoice_id);
629 629
     
630 630
     $date_created   = $invoice->get_created_date();
631
-    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( get_option( 'date_format' ), strtotime( $date_created ) ) : '';
631
+    $date_created   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n(get_option('date_format'), strtotime($date_created)) : '';
632 632
 
633 633
     return $date_created;
634 634
 }
635 635
 
636
-function wpinv_get_invoice_date( $invoice_id = 0, $format = '' ) {
637
-    $invoice = new WPInv_Invoice( $invoice_id );
636
+function wpinv_get_invoice_date($invoice_id = 0, $format = '') {
637
+    $invoice = new WPInv_Invoice($invoice_id);
638 638
     
639
-    $format         = !empty( $format ) ? $format : get_option( 'date_format' );
639
+    $format         = !empty($format) ? $format : get_option('date_format');
640 640
     $date_completed = $invoice->get_completed_date();
641
-    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_completed ) ) : '';
642
-    if ( $invoice_date == '' ) {
641
+    $invoice_date   = $date_completed != '' && $date_completed != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_completed)) : '';
642
+    if ($invoice_date == '') {
643 643
         $date_created   = $invoice->get_created_date();
644
-        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n( $format, strtotime( $date_created ) ) : '';
644
+        $invoice_date   = $date_created != '' && $date_created != '0000-00-00 00:00:00' ? date_i18n($format, strtotime($date_created)) : '';
645 645
     }
646 646
 
647 647
     return $invoice_date;
648 648
 }
649 649
 
650
-function wpinv_get_invoice_vat_number( $invoice_id = 0 ) {
651
-    $invoice = new WPInv_Invoice( $invoice_id );
650
+function wpinv_get_invoice_vat_number($invoice_id = 0) {
651
+    $invoice = new WPInv_Invoice($invoice_id);
652 652
     
653 653
     return $invoice->vat_number;
654 654
 }
655 655
 
656
-function wpinv_insert_payment_note( $invoice_id = 0, $note = '', $user_type = false, $added_by_user = false ) {
657
-    $invoice = new WPInv_Invoice( $invoice_id );
656
+function wpinv_insert_payment_note($invoice_id = 0, $note = '', $user_type = false, $added_by_user = false) {
657
+    $invoice = new WPInv_Invoice($invoice_id);
658 658
 
659
-    return $invoice->add_note( $note, $user_type, $added_by_user );
659
+    return $invoice->add_note($note, $user_type, $added_by_user);
660 660
 }
661 661
 
662
-function wpinv_get_invoice_notes( $invoice_id = 0, $type = '' ) {
662
+function wpinv_get_invoice_notes($invoice_id = 0, $type = '') {
663 663
     global $invoicing;
664 664
     
665
-    if ( empty( $invoice_id ) ) {
665
+    if (empty($invoice_id)) {
666 666
         return NULL;
667 667
     }
668 668
     
669
-    $notes = $invoicing->notes->get_invoice_notes( $invoice_id, $type );
669
+    $notes = $invoicing->notes->get_invoice_notes($invoice_id, $type);
670 670
     
671
-    return apply_filters( 'wpinv_invoice_notes', $notes, $invoice_id, $type );
671
+    return apply_filters('wpinv_invoice_notes', $notes, $invoice_id, $type);
672 672
 }
673 673
 
674
-function wpinv_get_payment_key( $invoice_id = 0 ) {
675
-	$invoice = new WPInv_Invoice( $invoice_id );
674
+function wpinv_get_payment_key($invoice_id = 0) {
675
+	$invoice = new WPInv_Invoice($invoice_id);
676 676
     return $invoice->get_key();
677 677
 }
678 678
 
679
-function wpinv_get_invoice_number( $invoice_id = 0 ) {
680
-    $invoice = new WPInv_Invoice( $invoice_id );
679
+function wpinv_get_invoice_number($invoice_id = 0) {
680
+    $invoice = new WPInv_Invoice($invoice_id);
681 681
     return $invoice->get_number();
682 682
 }
683 683
 
684
-function wpinv_get_cart_discountable_subtotal( $code_id ) {
684
+function wpinv_get_cart_discountable_subtotal($code_id) {
685 685
     $cart_items = wpinv_get_cart_content_details();
686 686
     $items      = array();
687 687
 
688
-    $excluded_items = wpinv_get_discount_excluded_items( $code_id );
688
+    $excluded_items = wpinv_get_discount_excluded_items($code_id);
689 689
 
690
-    if( $cart_items ) {
690
+    if ($cart_items) {
691 691
 
692
-        foreach( $cart_items as $item ) {
692
+        foreach ($cart_items as $item) {
693 693
 
694
-            if( ! in_array( $item['id'], $excluded_items ) ) {
695
-                $items[] =  $item;
694
+            if (!in_array($item['id'], $excluded_items)) {
695
+                $items[] = $item;
696 696
             }
697 697
         }
698 698
     }
699 699
 
700
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
700
+    $subtotal = wpinv_get_cart_items_subtotal($items);
701 701
 
702
-    return apply_filters( 'wpinv_get_cart_discountable_subtotal', $subtotal );
702
+    return apply_filters('wpinv_get_cart_discountable_subtotal', $subtotal);
703 703
 }
704 704
 
705
-function wpinv_get_cart_items_subtotal( $items ) {
705
+function wpinv_get_cart_items_subtotal($items) {
706 706
     $subtotal = 0.00;
707 707
 
708
-    if ( is_array( $items ) && ! empty( $items ) ) {
709
-        $prices = wp_list_pluck( $items, 'subtotal' );
708
+    if (is_array($items) && !empty($items)) {
709
+        $prices = wp_list_pluck($items, 'subtotal');
710 710
 
711
-        if( is_array( $prices ) ) {
712
-            $subtotal = array_sum( $prices );
711
+        if (is_array($prices)) {
712
+            $subtotal = array_sum($prices);
713 713
         } else {
714 714
             $subtotal = 0.00;
715 715
         }
716 716
 
717
-        if( $subtotal < 0 ) {
717
+        if ($subtotal < 0) {
718 718
             $subtotal = 0.00;
719 719
         }
720 720
     }
721 721
 
722
-    return apply_filters( 'wpinv_get_cart_items_subtotal', $subtotal );
722
+    return apply_filters('wpinv_get_cart_items_subtotal', $subtotal);
723 723
 }
724 724
 
725
-function wpinv_get_cart_subtotal( $items = array() ) {
726
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
727
-    $subtotal = wpinv_get_cart_items_subtotal( $items );
725
+function wpinv_get_cart_subtotal($items = array()) {
726
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
727
+    $subtotal = wpinv_get_cart_items_subtotal($items);
728 728
 
729
-    return apply_filters( 'wpinv_get_cart_subtotal', $subtotal );
729
+    return apply_filters('wpinv_get_cart_subtotal', $subtotal);
730 730
 }
731 731
 
732
-function wpinv_cart_subtotal( $items = array() ) {
733
-    $price = wpinv_price( wpinv_format_amount( wpinv_get_cart_subtotal( $items ) ) );
732
+function wpinv_cart_subtotal($items = array()) {
733
+    $price = wpinv_price(wpinv_format_amount(wpinv_get_cart_subtotal($items)));
734 734
 
735 735
     return $price;
736 736
 }
737 737
 
738
-function wpinv_get_cart_total( $items = array(), $discounts = false, $invoice = array() ) {
739
-    $subtotal  = (float)wpinv_get_cart_subtotal( $items );
740
-    $discounts = (float)wpinv_get_cart_discounted_amount( $items );
741
-    $cart_tax  = (float)wpinv_get_cart_tax( $items );
738
+function wpinv_get_cart_total($items = array(), $discounts = false, $invoice = array()) {
739
+    $subtotal  = (float)wpinv_get_cart_subtotal($items);
740
+    $discounts = (float)wpinv_get_cart_discounted_amount($items);
741
+    $cart_tax  = (float)wpinv_get_cart_tax($items);
742 742
     $fees      = (float)wpinv_get_cart_fee_total();
743
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
743
+    if (!empty($invoice) && $invoice->is_free_trial()) {
744 744
         $total = 0;
745 745
     } else {
746
-        $total     = $subtotal - $discounts + $cart_tax + $fees;
746
+        $total = $subtotal - $discounts + $cart_tax + $fees;
747 747
     }
748 748
 
749
-    if ( $total < 0 ) {
749
+    if ($total < 0) {
750 750
         $total = 0.00;
751 751
     }
752 752
     
753
-    $total = (float)apply_filters( 'wpinv_get_cart_total', $total, $items );
753
+    $total = (float)apply_filters('wpinv_get_cart_total', $total, $items);
754 754
 
755
-    return wpinv_sanitize_amount( $total );
755
+    return wpinv_sanitize_amount($total);
756 756
 }
757 757
 
758
-function wpinv_cart_total( $cart_items = array(), $echo = true, $invoice = array() ) {
758
+function wpinv_cart_total($cart_items = array(), $echo = true, $invoice = array()) {
759 759
     global $cart_total;
760
-    $total = wpinv_price( wpinv_format_amount( wpinv_get_cart_total( $cart_items, NULL, $invoice ) ) );
761
-    $total = apply_filters( 'wpinv_cart_total', $total, $cart_items, $invoice );
760
+    $total = wpinv_price(wpinv_format_amount(wpinv_get_cart_total($cart_items, NULL, $invoice)));
761
+    $total = apply_filters('wpinv_cart_total', $total, $cart_items, $invoice);
762 762
     
763 763
     $cart_total = $total;
764 764
 
765
-    if ( !$echo ) {
765
+    if (!$echo) {
766 766
         return $total;
767 767
     }
768 768
 
769 769
     echo $total;
770 770
 }
771 771
 
772
-function wpinv_get_cart_tax( $items = array() ) {
772
+function wpinv_get_cart_tax($items = array()) {
773 773
     $cart_tax = 0;
774
-    $items    = !empty( $items ) ? $items : wpinv_get_cart_content_details();
774
+    $items    = !empty($items) ? $items : wpinv_get_cart_content_details();
775 775
 
776
-    if ( $items ) {
777
-        $taxes = wp_list_pluck( $items, 'tax' );
776
+    if ($items) {
777
+        $taxes = wp_list_pluck($items, 'tax');
778 778
 
779
-        if( is_array( $taxes ) ) {
780
-            $cart_tax = array_sum( $taxes );
779
+        if (is_array($taxes)) {
780
+            $cart_tax = array_sum($taxes);
781 781
         }
782 782
     }
783 783
 
784 784
     $cart_tax += wpinv_get_cart_fee_tax();
785 785
 
786
-    return apply_filters( 'wpinv_get_cart_tax', wpinv_sanitize_amount( $cart_tax ) );
786
+    return apply_filters('wpinv_get_cart_tax', wpinv_sanitize_amount($cart_tax));
787 787
 }
788 788
 
789
-function wpinv_cart_tax( $items = array(), $echo = false ) {
790
-    $cart_tax = wpinv_get_cart_tax( $items );
791
-    $cart_tax = wpinv_price( wpinv_format_amount( $cart_tax ) );
789
+function wpinv_cart_tax($items = array(), $echo = false) {
790
+    $cart_tax = wpinv_get_cart_tax($items);
791
+    $cart_tax = wpinv_price(wpinv_format_amount($cart_tax));
792 792
 
793
-    $tax = apply_filters( 'wpinv_cart_tax', $cart_tax, $items );
793
+    $tax = apply_filters('wpinv_cart_tax', $cart_tax, $items);
794 794
 
795
-    if ( !$echo ) {
795
+    if (!$echo) {
796 796
         return $tax;
797 797
     }
798 798
 
799 799
     echo $tax;
800 800
 }
801 801
 
802
-function wpinv_get_cart_discount_code( $items = array() ) {
802
+function wpinv_get_cart_discount_code($items = array()) {
803 803
     $invoice = wpinv_get_invoice_cart();
804
-    $cart_discount_code = !empty( $invoice ) ? $invoice->get_discount_code() : '';
804
+    $cart_discount_code = !empty($invoice) ? $invoice->get_discount_code() : '';
805 805
     
806
-    return apply_filters( 'wpinv_get_cart_discount_code', $cart_discount_code );
806
+    return apply_filters('wpinv_get_cart_discount_code', $cart_discount_code);
807 807
 }
808 808
 
809
-function wpinv_cart_discount_code( $items = array(), $echo = false ) {
810
-    $cart_discount_code = wpinv_get_cart_discount_code( $items );
809
+function wpinv_cart_discount_code($items = array(), $echo = false) {
810
+    $cart_discount_code = wpinv_get_cart_discount_code($items);
811 811
 
812
-    if ( $cart_discount_code != '' ) {
812
+    if ($cart_discount_code != '') {
813 813
         $cart_discount_code = ' (' . $cart_discount_code . ')';
814 814
     }
815 815
     
816
-    $discount_code = apply_filters( 'wpinv_cart_discount_code', $cart_discount_code, $items );
816
+    $discount_code = apply_filters('wpinv_cart_discount_code', $cart_discount_code, $items);
817 817
 
818
-    if ( !$echo ) {
818
+    if (!$echo) {
819 819
         return $discount_code;
820 820
     }
821 821
 
822 822
     echo $discount_code;
823 823
 }
824 824
 
825
-function wpinv_get_cart_discount( $items = array() ) {
825
+function wpinv_get_cart_discount($items = array()) {
826 826
     $invoice = wpinv_get_invoice_cart();
827
-    $cart_discount = !empty( $invoice ) ? $invoice->get_discount() : 0;
827
+    $cart_discount = !empty($invoice) ? $invoice->get_discount() : 0;
828 828
     
829
-    return apply_filters( 'wpinv_get_cart_discount', wpinv_sanitize_amount( $cart_discount ), $items );
829
+    return apply_filters('wpinv_get_cart_discount', wpinv_sanitize_amount($cart_discount), $items);
830 830
 }
831 831
 
832
-function wpinv_cart_discount( $items = array(), $echo = false ) {
833
-    $cart_discount = wpinv_get_cart_discount( $items );
834
-    $cart_discount = wpinv_price( wpinv_format_amount( $cart_discount ) );
832
+function wpinv_cart_discount($items = array(), $echo = false) {
833
+    $cart_discount = wpinv_get_cart_discount($items);
834
+    $cart_discount = wpinv_price(wpinv_format_amount($cart_discount));
835 835
 
836
-    $discount = apply_filters( 'wpinv_cart_discount', $cart_discount, $items );
836
+    $discount = apply_filters('wpinv_cart_discount', $cart_discount, $items);
837 837
 
838
-    if ( !$echo ) {
838
+    if (!$echo) {
839 839
         return $discount;
840 840
     }
841 841
 
842 842
     echo $discount;
843 843
 }
844 844
 
845
-function wpinv_get_cart_fees( $type = 'all', $item_id = 0 ) {
846
-    $item = new WPInv_Item( $item_id );
845
+function wpinv_get_cart_fees($type = 'all', $item_id = 0) {
846
+    $item = new WPInv_Item($item_id);
847 847
     
848
-    return $item->get_fees( $type, $item_id );
848
+    return $item->get_fees($type, $item_id);
849 849
 }
850 850
 
851 851
 function wpinv_get_cart_fee_total() {
852
-    $total  = 0;
852
+    $total = 0;
853 853
     $fees = wpinv_get_cart_fees();
854 854
     
855
-    if ( $fees ) {
856
-        foreach ( $fees as $fee_id => $fee ) {
855
+    if ($fees) {
856
+        foreach ($fees as $fee_id => $fee) {
857 857
             $total += $fee['amount'];
858 858
         }
859 859
     }
860 860
 
861
-    return apply_filters( 'wpinv_get_cart_fee_total', $total );
861
+    return apply_filters('wpinv_get_cart_fee_total', $total);
862 862
 }
863 863
 
864 864
 function wpinv_get_cart_fee_tax() {
865 865
     $tax  = 0;
866 866
     $fees = wpinv_get_cart_fees();
867 867
 
868
-    if ( $fees ) {
869
-        foreach ( $fees as $fee_id => $fee ) {
870
-            if( ! empty( $fee['no_tax'] ) ) {
868
+    if ($fees) {
869
+        foreach ($fees as $fee_id => $fee) {
870
+            if (!empty($fee['no_tax'])) {
871 871
                 continue;
872 872
             }
873 873
 
874
-            $tax += wpinv_calculate_tax( $fee['amount'] );
874
+            $tax += wpinv_calculate_tax($fee['amount']);
875 875
         }
876 876
     }
877 877
 
878
-    return apply_filters( 'wpinv_get_cart_fee_tax', $tax );
878
+    return apply_filters('wpinv_get_cart_fee_tax', $tax);
879 879
 }
880 880
 
881 881
 function wpinv_cart_has_recurring_item() {
882 882
     $cart_items = wpinv_get_cart_contents();
883 883
     
884
-    if ( empty( $cart_items ) ) {
884
+    if (empty($cart_items)) {
885 885
         return false;
886 886
     }
887 887
     
888 888
     $has_subscription = false;
889
-    foreach( $cart_items as $cart_item ) {
890
-        if ( !empty( $cart_item['id'] ) && wpinv_is_recurring_item( $cart_item['id'] )  ) {
889
+    foreach ($cart_items as $cart_item) {
890
+        if (!empty($cart_item['id']) && wpinv_is_recurring_item($cart_item['id'])) {
891 891
             $has_subscription = true;
892 892
             break;
893 893
         }
894 894
     }
895 895
     
896
-    return apply_filters( 'wpinv_cart_has_recurring_item', $has_subscription, $cart_items );
896
+    return apply_filters('wpinv_cart_has_recurring_item', $has_subscription, $cart_items);
897 897
 }
898 898
 
899 899
 function wpinv_cart_has_free_trial() {
@@ -901,94 +901,94 @@  discard block
 block discarded – undo
901 901
     
902 902
     $free_trial = false;
903 903
     
904
-    if ( !empty( $invoice ) && $invoice->is_free_trial() ) {
904
+    if (!empty($invoice) && $invoice->is_free_trial()) {
905 905
         $free_trial = true;
906 906
     }
907 907
     
908
-    return apply_filters( 'wpinv_cart_has_free_trial', $free_trial, $invoice );
908
+    return apply_filters('wpinv_cart_has_free_trial', $free_trial, $invoice);
909 909
 }
910 910
 
911 911
 function wpinv_get_cart_contents() {
912 912
     $cart_details = wpinv_get_cart_details();
913 913
     
914
-    return apply_filters( 'wpinv_get_cart_contents', $cart_details );
914
+    return apply_filters('wpinv_get_cart_contents', $cart_details);
915 915
 }
916 916
 
917 917
 function wpinv_get_cart_content_details() {
918 918
     global $wpinv_euvat, $wpi_current_id, $wpi_item_id, $wpinv_is_last_cart_item, $wpinv_flat_discount_total;
919 919
     $cart_items = wpinv_get_cart_contents();
920 920
     
921
-    if ( empty( $cart_items ) ) {
921
+    if (empty($cart_items)) {
922 922
         return false;
923 923
     }
924 924
     $invoice = wpinv_get_invoice_cart();
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,60 +997,60 @@  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 );
1004
-    $cart_details = !empty( $ajax_cart_details ) ? $ajax_cart_details : $invoice->cart_details;
1003
+    $invoice      = wpinv_get_invoice_cart($invoice_id);
1004
+    $cart_details = !empty($ajax_cart_details) ? $ajax_cart_details : $invoice->cart_details;
1005 1005
 
1006 1006
     $invoice_currency = $invoice->currency;
1007 1007
 
1008
-    if ( ! empty( $cart_details ) && is_array( $cart_details ) ) {
1009
-        foreach ( $cart_details as $key => $cart_item ) {
1010
-            $cart_details[ $key ]['currency'] = $invoice_currency;
1008
+    if (!empty($cart_details) && is_array($cart_details)) {
1009
+        foreach ($cart_details as $key => $cart_item) {
1010
+            $cart_details[$key]['currency'] = $invoice_currency;
1011 1011
 
1012
-            if ( ! isset( $cart_item['subtotal'] ) ) {
1013
-                $cart_details[ $key ]['subtotal'] = $cart_item['price'];
1012
+            if (!isset($cart_item['subtotal'])) {
1013
+                $cart_details[$key]['subtotal'] = $cart_item['price'];
1014 1014
             }
1015 1015
         }
1016 1016
     }
1017 1017
 
1018
-    return apply_filters( 'wpinv_get_cart_details', $cart_details, $invoice_id );
1018
+    return apply_filters('wpinv_get_cart_details', $cart_details, $invoice_id);
1019 1019
 }
1020 1020
 
1021
-function wpinv_record_status_change( $invoice_id, $new_status, $old_status ) {
1022
-    if ( 'wpi_invoice' != get_post_type( $invoice_id ) ) {
1021
+function wpinv_record_status_change($invoice_id, $new_status, $old_status) {
1022
+    if ('wpi_invoice' != get_post_type($invoice_id)) {
1023 1023
         return;
1024 1024
     }
1025 1025
 
1026
-    $invoice    = wpinv_get_invoice( $invoice_id );
1026
+    $invoice    = wpinv_get_invoice($invoice_id);
1027 1027
     
1028
-    $old_status = wpinv_status_nicename( $old_status );
1029
-    $new_status = wpinv_status_nicename( $new_status );
1028
+    $old_status = wpinv_status_nicename($old_status);
1029
+    $new_status = wpinv_status_nicename($new_status);
1030 1030
 
1031
-    $status_change = sprintf( __( 'Invoice status changed from %s to %s', 'invoicing' ), $old_status, $new_status );
1031
+    $status_change = sprintf(__('Invoice status changed from %s to %s', 'invoicing'), $old_status, $new_status);
1032 1032
     
1033 1033
     // Add note
1034
-    return $invoice->add_note( $status_change, false, false, true );
1034
+    return $invoice->add_note($status_change, false, false, true);
1035 1035
 }
1036
-add_action( 'wpinv_update_status', 'wpinv_record_status_change', 100, 3 );
1036
+add_action('wpinv_update_status', 'wpinv_record_status_change', 100, 3);
1037 1037
 
1038
-function wpinv_complete_payment( $invoice_id, $new_status, $old_status ) {
1038
+function wpinv_complete_payment($invoice_id, $new_status, $old_status) {
1039 1039
     global $wpi_has_free_trial;
1040 1040
     
1041 1041
     $wpi_has_free_trial = false;
1042 1042
     
1043
-    if ( $old_status == 'publish' ) {
1043
+    if ($old_status == 'publish') {
1044 1044
         return; // Make sure that payments are only paid once
1045 1045
     }
1046 1046
 
1047 1047
     // Make sure the payment completion is only processed when new status is paid
1048
-    if ( $new_status != 'publish' ) {
1048
+    if ($new_status != 'publish') {
1049 1049
         return;
1050 1050
     }
1051 1051
 
1052
-    $invoice = new WPInv_Invoice( $invoice_id );
1053
-    if ( empty( $invoice ) ) {
1052
+    $invoice = new WPInv_Invoice($invoice_id);
1053
+    if (empty($invoice)) {
1054 1054
         return;
1055 1055
     }
1056 1056
 
@@ -1058,58 +1058,58 @@  discard block
 block discarded – undo
1058 1058
     $completed_date = $invoice->completed_date;
1059 1059
     $cart_details   = $invoice->cart_details;
1060 1060
 
1061
-    do_action( 'wpinv_pre_complete_payment', $invoice_id );
1061
+    do_action('wpinv_pre_complete_payment', $invoice_id);
1062 1062
 
1063
-    if ( is_array( $cart_details ) ) {
1063
+    if (is_array($cart_details)) {
1064 1064
         // Increase purchase count and earnings
1065
-        foreach ( $cart_details as $cart_index => $item ) {
1065
+        foreach ($cart_details as $cart_index => $item) {
1066 1066
             // Ensure these actions only run once, ever
1067
-            if ( empty( $completed_date ) ) {
1068
-                do_action( 'wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index );
1067
+            if (empty($completed_date)) {
1068
+                do_action('wpinv_complete_item_payment', $item['id'], $invoice_id, $item, $cart_index);
1069 1069
             }
1070 1070
         }
1071 1071
     }
1072 1072
     
1073 1073
     // Check for discount codes and increment their use counts
1074
-    if ( $discounts = $invoice->get_discounts( true ) ) {
1075
-        if( ! empty( $discounts ) ) {
1076
-            foreach( $discounts as $code ) {
1077
-                wpinv_increase_discount_usage( $code );
1074
+    if ($discounts = $invoice->get_discounts(true)) {
1075
+        if (!empty($discounts)) {
1076
+            foreach ($discounts as $code) {
1077
+                wpinv_increase_discount_usage($code);
1078 1078
             }
1079 1079
         }
1080 1080
     }
1081 1081
     
1082 1082
     // Ensure this action only runs once ever
1083
-    if( empty( $completed_date ) ) {
1083
+    if (empty($completed_date)) {
1084 1084
         // Save the completed date
1085
-        $invoice->set( 'completed_date', current_time( 'mysql', 0 ) );
1085
+        $invoice->set('completed_date', current_time('mysql', 0));
1086 1086
         $invoice->save();
1087 1087
 
1088
-        do_action( 'wpinv_complete_payment', $invoice_id );
1088
+        do_action('wpinv_complete_payment', $invoice_id);
1089 1089
     }
1090 1090
 
1091 1091
     // Empty the shopping cart
1092 1092
     wpinv_empty_cart();
1093 1093
 }
1094
-add_action( 'wpinv_update_status', 'wpinv_complete_payment', 100, 3 );
1094
+add_action('wpinv_update_status', 'wpinv_complete_payment', 100, 3);
1095 1095
 
1096
-function wpinv_update_payment_status( $invoice_id, $new_status = 'publish' ) {    
1097
-    $invoice = !empty( $invoice_id ) && is_object( $invoice_id ) ? $invoice_id : wpinv_get_invoice( (int)$invoice_id );
1096
+function wpinv_update_payment_status($invoice_id, $new_status = 'publish') {    
1097
+    $invoice = !empty($invoice_id) && is_object($invoice_id) ? $invoice_id : wpinv_get_invoice((int)$invoice_id);
1098 1098
     
1099
-    if ( empty( $invoice ) ) {
1099
+    if (empty($invoice)) {
1100 1100
         return false;
1101 1101
     }
1102 1102
     
1103
-    return $invoice->update_status( $new_status );
1103
+    return $invoice->update_status($new_status);
1104 1104
 }
1105 1105
 
1106
-function wpinv_cart_has_fees( $type = 'all' ) {
1106
+function wpinv_cart_has_fees($type = 'all') {
1107 1107
     return false;
1108 1108
 }
1109 1109
 
1110 1110
 function wpinv_validate_checkout_fields() {    
1111 1111
     // Check if there is $_POST
1112
-    if ( empty( $_POST ) ) {
1112
+    if (empty($_POST)) {
1113 1113
         return false;
1114 1114
     }
1115 1115
     
@@ -1121,11 +1121,11 @@  discard block
 block discarded – undo
1121 1121
     );
1122 1122
     
1123 1123
     // Validate agree to terms
1124
-    if ( wpinv_get_option( 'show_agree_to_terms', false ) ) {
1124
+    if (wpinv_get_option('show_agree_to_terms', false)) {
1125 1125
         wpinv_checkout_validate_agree_to_terms();
1126 1126
     }
1127 1127
     
1128
-    $valid_data['logged_in_user']   = wpinv_checkout_validate_logged_in_user();
1128
+    $valid_data['logged_in_user'] = wpinv_checkout_validate_logged_in_user();
1129 1129
     
1130 1130
     // Return collected data
1131 1131
     return $valid_data;
@@ -1136,26 +1136,26 @@  discard block
 block discarded – undo
1136 1136
     
1137 1137
     $invoice = wpinv_get_invoice_cart();
1138 1138
     $has_subscription = $invoice->is_recurring();
1139
-    if ( empty( $invoice ) ) {
1140
-        wpinv_set_error( 'invalid_invoice', __( 'Your cart is empty.', 'invoicing' ) );
1139
+    if (empty($invoice)) {
1140
+        wpinv_set_error('invalid_invoice', __('Your cart is empty.', 'invoicing'));
1141 1141
         return $gateway;
1142 1142
     }
1143 1143
 
1144 1144
     // Check if a gateway value is present
1145
-    if ( !empty( $_REQUEST['wpi-gateway'] ) ) {
1146
-        $gateway = sanitize_text_field( $_REQUEST['wpi-gateway'] );
1145
+    if (!empty($_REQUEST['wpi-gateway'])) {
1146
+        $gateway = sanitize_text_field($_REQUEST['wpi-gateway']);
1147 1147
 
1148
-        if ( $invoice->is_free() ) {
1148
+        if ($invoice->is_free()) {
1149 1149
             $gateway = 'manual';
1150
-        } elseif ( !wpinv_is_gateway_active( $gateway ) ) {
1151
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway is not enabled', 'invoicing' ) );
1152
-        } elseif ( $has_subscription && !wpinv_gateway_support_subscription( $gateway ) ) {
1153
-            wpinv_set_error( 'invalid_gateway', __( 'The selected payment gateway doesnot support subscription payment', 'invoicing' ) );
1150
+        } elseif (!wpinv_is_gateway_active($gateway)) {
1151
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway is not enabled', 'invoicing'));
1152
+        } elseif ($has_subscription && !wpinv_gateway_support_subscription($gateway)) {
1153
+            wpinv_set_error('invalid_gateway', __('The selected payment gateway doesnot support subscription payment', 'invoicing'));
1154 1154
         }
1155 1155
     }
1156 1156
 
1157
-    if ( $has_subscription && count( wpinv_get_cart_contents() ) > 1 ) {
1158
-        wpinv_set_error( 'subscription_invalid', __( 'Only one subscription may be purchased through payment per checkout.', 'invoicing' ) );
1157
+    if ($has_subscription && count(wpinv_get_cart_contents()) > 1) {
1158
+        wpinv_set_error('subscription_invalid', __('Only one subscription may be purchased through payment per checkout.', 'invoicing'));
1159 1159
     }
1160 1160
 
1161 1161
     return $gateway;
@@ -1167,10 +1167,10 @@  discard block
 block discarded – undo
1167 1167
     
1168 1168
     $error = false;
1169 1169
     // If we have discounts, loop through them
1170
-    if ( ! empty( $discounts ) ) {
1171
-        foreach ( $discounts as $discount ) {
1170
+    if (!empty($discounts)) {
1171
+        foreach ($discounts as $discount) {
1172 1172
             // Check if valid
1173
-            if (  !wpinv_is_discount_valid( $discount, get_current_user_id() ) ) {
1173
+            if (!wpinv_is_discount_valid($discount, get_current_user_id())) {
1174 1174
                 // Discount is not valid
1175 1175
                 $error = true;
1176 1176
             }
@@ -1180,20 +1180,20 @@  discard block
 block discarded – undo
1180 1180
         return NULL;
1181 1181
     }
1182 1182
 
1183
-    if ( $error && !wpinv_get_errors() ) {
1184
-        wpinv_set_error( 'invalid_discount', __( 'Discount code you entered is invalid', 'invoicing' ) );
1183
+    if ($error && !wpinv_get_errors()) {
1184
+        wpinv_set_error('invalid_discount', __('Discount code you entered is invalid', 'invoicing'));
1185 1185
     }
1186 1186
 
1187
-    return implode( ',', $discounts );
1187
+    return implode(',', $discounts);
1188 1188
 }
1189 1189
 
1190 1190
 function wpinv_checkout_validate_cc() {
1191 1191
     $card_data = wpinv_checkout_get_cc_info();
1192 1192
 
1193 1193
     // Validate the card zip
1194
-    if ( !empty( $card_data['wpinv_zip'] ) ) {
1195
-        if ( !wpinv_checkout_validate_cc_zip( $card_data['wpinv_zip'], $card_data['wpinv_country'] ) ) {
1196
-            wpinv_set_error( 'invalid_cc_zip', __( 'The zip / postcode you entered for your billing address is invalid', 'invoicing' ) );
1194
+    if (!empty($card_data['wpinv_zip'])) {
1195
+        if (!wpinv_checkout_validate_cc_zip($card_data['wpinv_zip'], $card_data['wpinv_country'])) {
1196
+            wpinv_set_error('invalid_cc_zip', __('The zip / postcode you entered for your billing address is invalid', 'invoicing'));
1197 1197
         }
1198 1198
     }
1199 1199
 
@@ -1203,28 +1203,28 @@  discard block
 block discarded – undo
1203 1203
 
1204 1204
 function wpinv_checkout_get_cc_info() {
1205 1205
 	$cc_info = array();
1206
-	$cc_info['card_name']      = isset( $_POST['card_name'] )       ? sanitize_text_field( $_POST['card_name'] )       : '';
1207
-	$cc_info['card_number']    = isset( $_POST['card_number'] )     ? sanitize_text_field( $_POST['card_number'] )     : '';
1208
-	$cc_info['card_cvc']       = isset( $_POST['card_cvc'] )        ? sanitize_text_field( $_POST['card_cvc'] )        : '';
1209
-	$cc_info['card_exp_month'] = isset( $_POST['card_exp_month'] )  ? sanitize_text_field( $_POST['card_exp_month'] )  : '';
1210
-	$cc_info['card_exp_year']  = isset( $_POST['card_exp_year'] )   ? sanitize_text_field( $_POST['card_exp_year'] )   : '';
1211
-	$cc_info['card_address']   = isset( $_POST['wpinv_address'] )  ? sanitize_text_field( $_POST['wpinv_address'] ) : '';
1212
-	$cc_info['card_city']      = isset( $_POST['wpinv_city'] )     ? sanitize_text_field( $_POST['wpinv_city'] )    : '';
1213
-	$cc_info['card_state']     = isset( $_POST['wpinv_state'] )    ? sanitize_text_field( $_POST['wpinv_state'] )   : '';
1214
-	$cc_info['card_country']   = isset( $_POST['wpinv_country'] )  ? sanitize_text_field( $_POST['wpinv_country'] ) : '';
1215
-	$cc_info['card_zip']       = isset( $_POST['wpinv_zip'] )      ? sanitize_text_field( $_POST['wpinv_zip'] )     : '';
1206
+	$cc_info['card_name']      = isset($_POST['card_name']) ? sanitize_text_field($_POST['card_name']) : '';
1207
+	$cc_info['card_number']    = isset($_POST['card_number']) ? sanitize_text_field($_POST['card_number']) : '';
1208
+	$cc_info['card_cvc']       = isset($_POST['card_cvc']) ? sanitize_text_field($_POST['card_cvc']) : '';
1209
+	$cc_info['card_exp_month'] = isset($_POST['card_exp_month']) ? sanitize_text_field($_POST['card_exp_month']) : '';
1210
+	$cc_info['card_exp_year']  = isset($_POST['card_exp_year']) ? sanitize_text_field($_POST['card_exp_year']) : '';
1211
+	$cc_info['card_address']   = isset($_POST['wpinv_address']) ? sanitize_text_field($_POST['wpinv_address']) : '';
1212
+	$cc_info['card_city']      = isset($_POST['wpinv_city']) ? sanitize_text_field($_POST['wpinv_city']) : '';
1213
+	$cc_info['card_state']     = isset($_POST['wpinv_state']) ? sanitize_text_field($_POST['wpinv_state']) : '';
1214
+	$cc_info['card_country']   = isset($_POST['wpinv_country']) ? sanitize_text_field($_POST['wpinv_country']) : '';
1215
+	$cc_info['card_zip']       = isset($_POST['wpinv_zip']) ? sanitize_text_field($_POST['wpinv_zip']) : '';
1216 1216
 
1217 1217
 	// Return cc info
1218 1218
 	return $cc_info;
1219 1219
 }
1220 1220
 
1221
-function wpinv_checkout_validate_cc_zip( $zip = 0, $country_code = '' ) {
1221
+function wpinv_checkout_validate_cc_zip($zip = 0, $country_code = '') {
1222 1222
     $ret = false;
1223 1223
 
1224
-    if ( empty( $zip ) || empty( $country_code ) )
1224
+    if (empty($zip) || empty($country_code))
1225 1225
         return $ret;
1226 1226
 
1227
-    $country_code = strtoupper( $country_code );
1227
+    $country_code = strtoupper($country_code);
1228 1228
 
1229 1229
     $zip_regex = array(
1230 1230
         "AD" => "AD\d{3}",
@@ -1384,17 +1384,17 @@  discard block
 block discarded – undo
1384 1384
         "ZM" => "\d{5}"
1385 1385
     );
1386 1386
 
1387
-    if ( ! isset ( $zip_regex[ $country_code ] ) || preg_match( "/" . $zip_regex[ $country_code ] . "/i", $zip ) )
1387
+    if (!isset ($zip_regex[$country_code]) || preg_match("/" . $zip_regex[$country_code] . "/i", $zip))
1388 1388
         $ret = true;
1389 1389
 
1390
-    return apply_filters( 'wpinv_is_zip_valid', $ret, $zip, $country_code );
1390
+    return apply_filters('wpinv_is_zip_valid', $ret, $zip, $country_code);
1391 1391
 }
1392 1392
 
1393 1393
 function wpinv_checkout_validate_agree_to_terms() {
1394 1394
     // Validate agree to terms
1395
-    if ( ! isset( $_POST['wpi_agree_to_terms'] ) || $_POST['wpi_agree_to_terms'] != 1 ) {
1395
+    if (!isset($_POST['wpi_agree_to_terms']) || $_POST['wpi_agree_to_terms'] != 1) {
1396 1396
         // User did not agree
1397
-        wpinv_set_error( 'agree_to_terms', apply_filters( 'wpinv_agree_to_terms_text', __( 'You must agree to the terms of use', 'invoicing' ) ) );
1397
+        wpinv_set_error('agree_to_terms', apply_filters('wpinv_agree_to_terms_text', __('You must agree to the terms of use', 'invoicing')));
1398 1398
     }
1399 1399
 }
1400 1400
 
@@ -1407,36 +1407,36 @@  discard block
 block discarded – undo
1407 1407
     );
1408 1408
     
1409 1409
     // Verify there is a user_ID
1410
-    if ( $user_ID > 0 ) {
1410
+    if ($user_ID > 0) {
1411 1411
         // Get the logged in user data
1412
-        $user_data = get_userdata( $user_ID );
1413
-        $required_fields  = wpinv_checkout_required_fields();
1412
+        $user_data = get_userdata($user_ID);
1413
+        $required_fields = wpinv_checkout_required_fields();
1414 1414
 
1415 1415
         // Loop through required fields and show error messages
1416
-         if ( !empty( $required_fields ) ) {
1417
-            foreach ( $required_fields as $field_name => $value ) {
1418
-                if ( in_array( $value, $required_fields ) && empty( $_POST[ 'wpinv_' . $field_name ] ) ) {
1419
-                    wpinv_set_error( $value['error_id'], $value['error_message'] );
1416
+         if (!empty($required_fields)) {
1417
+            foreach ($required_fields as $field_name => $value) {
1418
+                if (in_array($value, $required_fields) && empty($_POST['wpinv_' . $field_name])) {
1419
+                    wpinv_set_error($value['error_id'], $value['error_message']);
1420 1420
                 }
1421 1421
             }
1422 1422
         }
1423 1423
 
1424 1424
         // Verify data
1425
-        if ( $user_data ) {
1425
+        if ($user_data) {
1426 1426
             // Collected logged in user data
1427 1427
             $valid_user_data = array(
1428 1428
                 'user_id'     => $user_ID,
1429
-                'email'       => isset( $_POST['wpinv_email'] ) ? sanitize_email( $_POST['wpinv_email'] ) : $user_data->user_email,
1430
-                'first_name'  => isset( $_POST['wpinv_first_name'] ) && ! empty( $_POST['wpinv_first_name'] ) ? sanitize_text_field( $_POST['wpinv_first_name'] ) : $user_data->first_name,
1431
-                'last_name'   => isset( $_POST['wpinv_last_name'] ) && ! empty( $_POST['wpinv_last_name']  ) ? sanitize_text_field( $_POST['wpinv_last_name']  ) : $user_data->last_name,
1429
+                'email'       => isset($_POST['wpinv_email']) ? sanitize_email($_POST['wpinv_email']) : $user_data->user_email,
1430
+                'first_name'  => isset($_POST['wpinv_first_name']) && !empty($_POST['wpinv_first_name']) ? sanitize_text_field($_POST['wpinv_first_name']) : $user_data->first_name,
1431
+                'last_name'   => isset($_POST['wpinv_last_name']) && !empty($_POST['wpinv_last_name']) ? sanitize_text_field($_POST['wpinv_last_name']) : $user_data->last_name,
1432 1432
             );
1433 1433
 
1434
-            if ( !empty( $_POST[ 'wpinv_email' ] ) && !is_email( $_POST[ 'wpinv_email' ] ) ) {
1435
-                wpinv_set_error( 'invalid_email', __( 'Please enter a valid email address', 'invoicing' ) );
1434
+            if (!empty($_POST['wpinv_email']) && !is_email($_POST['wpinv_email'])) {
1435
+                wpinv_set_error('invalid_email', __('Please enter a valid email address', 'invoicing'));
1436 1436
             }
1437 1437
         } else {
1438 1438
             // Set invalid user error
1439
-            wpinv_set_error( 'invalid_user', __( 'The user billing information is invalid', 'invoicing' ) );
1439
+            wpinv_set_error('invalid_user', __('The user billing information is invalid', 'invoicing'));
1440 1440
         }
1441 1441
     }
1442 1442
 
@@ -1444,21 +1444,21 @@  discard block
 block discarded – undo
1444 1444
     return $valid_user_data;
1445 1445
 }
1446 1446
 
1447
-function wpinv_checkout_form_get_user( $valid_data = array() ) {
1447
+function wpinv_checkout_form_get_user($valid_data = array()) {
1448 1448
     // Initialize user
1449 1449
     $user    = false;
1450
-    $is_ajax = defined( 'DOING_AJAX' ) && DOING_AJAX;
1450
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1451 1451
 
1452 1452
     /*if ( $is_ajax ) {
1453 1453
         // Do not create or login the user during the ajax submission (check for errors only)
1454 1454
         return true;
1455
-    } else */if ( is_user_logged_in() ) {
1455
+    } else */if (is_user_logged_in()) {
1456 1456
         // Set the valid user as the logged in collected data
1457 1457
         $user = $valid_data['logged_in_user'];
1458 1458
     }
1459 1459
 
1460 1460
     // Verify we have an user
1461
-    if ( false === $user || empty( $user ) ) {
1461
+    if (false === $user || empty($user)) {
1462 1462
         // Return false
1463 1463
         return false;
1464 1464
     }
@@ -1477,11 +1477,11 @@  discard block
 block discarded – undo
1477 1477
         'zip',
1478 1478
     );
1479 1479
     
1480
-    foreach ( $address_fields as $field ) {
1481
-        $user[$field]  = !empty( $_POST['wpinv_' . $field] ) ? sanitize_text_field( $_POST['wpinv_' . $field] ) : false;
1480
+    foreach ($address_fields as $field) {
1481
+        $user[$field] = !empty($_POST['wpinv_' . $field]) ? sanitize_text_field($_POST['wpinv_' . $field]) : false;
1482 1482
         
1483
-        if ( !empty( $user['user_id'] ) ) {
1484
-            update_user_meta( $user['user_id'], '_wpinv_' . $field, $user[$field] );
1483
+        if (!empty($user['user_id'])) {
1484
+            update_user_meta($user['user_id'], '_wpinv_' . $field, $user[$field]);
1485 1485
         }
1486 1486
     }
1487 1487
 
@@ -1489,28 +1489,28 @@  discard block
 block discarded – undo
1489 1489
     return $user;
1490 1490
 }
1491 1491
 
1492
-function wpinv_set_checkout_session( $invoice_data = array() ) {
1492
+function wpinv_set_checkout_session($invoice_data = array()) {
1493 1493
     global $wpi_session;
1494 1494
     
1495
-    return $wpi_session->set( 'wpinv_checkout', $invoice_data );
1495
+    return $wpi_session->set('wpinv_checkout', $invoice_data);
1496 1496
 }
1497 1497
 
1498 1498
 function wpinv_get_checkout_session() {
1499 1499
 	global $wpi_session;
1500 1500
     
1501
-    return $wpi_session->get( 'wpinv_checkout' );
1501
+    return $wpi_session->get('wpinv_checkout');
1502 1502
 }
1503 1503
 
1504 1504
 function wpinv_empty_cart() {
1505 1505
     global $wpi_session;
1506 1506
 
1507 1507
     // Remove cart contents
1508
-    $wpi_session->set( 'wpinv_checkout', NULL );
1508
+    $wpi_session->set('wpinv_checkout', NULL);
1509 1509
 
1510 1510
     // Remove all cart fees
1511
-    $wpi_session->set( 'wpi_cart_fees', NULL );
1511
+    $wpi_session->set('wpi_cart_fees', NULL);
1512 1512
 
1513
-    do_action( 'wpinv_empty_cart' );
1513
+    do_action('wpinv_empty_cart');
1514 1514
 }
1515 1515
 
1516 1516
 function wpinv_process_checkout() {
@@ -1522,42 +1522,42 @@  discard block
 block discarded – undo
1522 1522
     
1523 1523
     $wpi_checkout_id = $invoice->ID;
1524 1524
     
1525
-    do_action( 'wpinv_pre_process_checkout' );
1525
+    do_action('wpinv_pre_process_checkout');
1526 1526
     
1527
-    if ( !wpinv_get_cart_contents() ) { // Make sure the cart isn't empty
1527
+    if (!wpinv_get_cart_contents()) { // Make sure the cart isn't empty
1528 1528
         $valid_data = false;
1529
-        wpinv_set_error( 'empty_cart', __( 'Your cart is empty', 'invoicing' ) );
1529
+        wpinv_set_error('empty_cart', __('Your cart is empty', 'invoicing'));
1530 1530
     } else {
1531 1531
         // Validate the form $_POST data
1532 1532
         $valid_data = wpinv_validate_checkout_fields();
1533 1533
         
1534 1534
         // Allow themes and plugins to hook to errors
1535
-        do_action( 'wpinv_checkout_error_checks', $valid_data, $_POST );
1535
+        do_action('wpinv_checkout_error_checks', $valid_data, $_POST);
1536 1536
     }
1537 1537
     
1538
-    $is_ajax    = defined( 'DOING_AJAX' ) && DOING_AJAX;
1538
+    $is_ajax = defined('DOING_AJAX') && DOING_AJAX;
1539 1539
     
1540 1540
     // Validate the user
1541
-    $user = wpinv_checkout_form_get_user( $valid_data );
1541
+    $user = wpinv_checkout_form_get_user($valid_data);
1542 1542
 
1543 1543
     // Let extensions validate fields after user is logged in if user has used login/registration form
1544
-    do_action( 'wpinv_checkout_user_error_checks', $user, $valid_data, $_POST );
1544
+    do_action('wpinv_checkout_user_error_checks', $user, $valid_data, $_POST);
1545 1545
     
1546
-    if ( false === $valid_data || wpinv_get_errors() || ! $user ) {
1547
-        if ( $is_ajax ) {
1548
-            do_action( 'wpinv_ajax_checkout_errors' );
1546
+    if (false === $valid_data || wpinv_get_errors() || !$user) {
1547
+        if ($is_ajax) {
1548
+            do_action('wpinv_ajax_checkout_errors');
1549 1549
             die();
1550 1550
         } else {
1551 1551
             return false;
1552 1552
         }
1553 1553
     }
1554 1554
 
1555
-    if ( $is_ajax ) {
1555
+    if ($is_ajax) {
1556 1556
         // Save address fields.
1557
-        $address_fields = array( 'first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company' );
1558
-        foreach ( $address_fields as $field ) {
1559
-            if ( isset( $user[$field] ) ) {
1560
-                $invoice->set( $field, $user[$field] );
1557
+        $address_fields = array('first_name', 'last_name', 'phone', 'address', 'city', 'country', 'state', 'zip', 'company');
1558
+        foreach ($address_fields as $field) {
1559
+            if (isset($user[$field])) {
1560
+                $invoice->set($field, $user[$field]);
1561 1561
             }
1562 1562
             
1563 1563
             $invoice->save();
@@ -1565,15 +1565,15 @@  discard block
 block discarded – undo
1565 1565
 
1566 1566
         $response['success']            = true;
1567 1567
         $response['data']['subtotal']   = $invoice->get_subtotal();
1568
-        $response['data']['subtotalf']  = $invoice->get_subtotal( true );
1568
+        $response['data']['subtotalf']  = $invoice->get_subtotal(true);
1569 1569
         $response['data']['discount']   = $invoice->get_discount();
1570
-        $response['data']['discountf']  = $invoice->get_discount( true );
1570
+        $response['data']['discountf']  = $invoice->get_discount(true);
1571 1571
         $response['data']['tax']        = $invoice->get_tax();
1572
-        $response['data']['taxf']       = $invoice->get_tax( true );
1572
+        $response['data']['taxf']       = $invoice->get_tax(true);
1573 1573
         $response['data']['total']      = $invoice->get_total();
1574
-        $response['data']['totalf']     = $invoice->get_total( true );
1574
+        $response['data']['totalf']     = $invoice->get_total(true);
1575 1575
         
1576
-        wp_send_json( $response );
1576
+        wp_send_json($response);
1577 1577
     }
1578 1578
     
1579 1579
     $user_info = array(
@@ -1595,42 +1595,42 @@  discard block
 block discarded – undo
1595 1595
     
1596 1596
     // Setup invoice information
1597 1597
     $invoice_data = array(
1598
-        'invoice_id'        => !empty( $invoice ) ? $invoice->ID : 0,
1598
+        'invoice_id'        => !empty($invoice) ? $invoice->ID : 0,
1599 1599
         'items'             => $cart_items,
1600 1600
         'cart_discounts'    => $discounts,
1601
-        'fees'              => wpinv_get_cart_fees(),        // Any arbitrary fees that have been added to the cart
1602
-        'subtotal'          => wpinv_get_cart_subtotal( $cart_items ),    // Amount before taxes and discounts
1603
-        'discount'          => wpinv_get_cart_items_discount_amount( $cart_items, $discounts ), // Discounted amount
1604
-        'tax'               => wpinv_get_cart_tax( $cart_items ),               // Taxed amount
1605
-        'price'             => wpinv_get_cart_total( $cart_items, $discounts ),    // Amount after taxes
1601
+        'fees'              => wpinv_get_cart_fees(), // Any arbitrary fees that have been added to the cart
1602
+        'subtotal'          => wpinv_get_cart_subtotal($cart_items), // Amount before taxes and discounts
1603
+        'discount'          => wpinv_get_cart_items_discount_amount($cart_items, $discounts), // Discounted amount
1604
+        'tax'               => wpinv_get_cart_tax($cart_items), // Taxed amount
1605
+        'price'             => wpinv_get_cart_total($cart_items, $discounts), // Amount after taxes
1606 1606
         'invoice_key'       => $invoice->get_key() ? $invoice->get_key() : $invoice->generate_key(),
1607 1607
         'user_email'        => $user['email'],
1608
-        'date'              => date( 'Y-m-d H:i:s', current_time( 'timestamp' ) ),
1609
-        'user_info'         => stripslashes_deep( $user_info ),
1608
+        'date'              => date('Y-m-d H:i:s', current_time('timestamp')),
1609
+        'user_info'         => stripslashes_deep($user_info),
1610 1610
         'post_data'         => $_POST,
1611 1611
         'cart_details'      => $cart_items,
1612 1612
         'gateway'           => $valid_data['gateway'],
1613 1613
         'card_info'         => $valid_data['cc_info']
1614 1614
     );
1615 1615
     
1616
-    $vat_info   = $wpinv_euvat->current_vat_data();
1617
-    if ( is_array( $vat_info ) ) {
1616
+    $vat_info = $wpinv_euvat->current_vat_data();
1617
+    if (is_array($vat_info)) {
1618 1618
         $invoice_data['user_info']['vat_number']        = $vat_info['number'];
1619 1619
         $invoice_data['user_info']['vat_rate']          = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state']);
1620
-        $invoice_data['user_info']['adddress_confirmed']    = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1620
+        $invoice_data['user_info']['adddress_confirmed'] = isset($vat_info['adddress_confirmed']) ? $vat_info['adddress_confirmed'] : false;
1621 1621
 
1622 1622
         // Add the VAT rate to each item in the cart
1623
-        foreach( $invoice_data['cart_details'] as $key => $item_data) {
1623
+        foreach ($invoice_data['cart_details'] as $key => $item_data) {
1624 1624
             $rate = wpinv_get_tax_rate($invoice_data['user_info']['country'], $invoice_data['user_info']['state'], $item_data['id']);
1625
-            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount( $rate, 4 );
1625
+            $invoice_data['cart_details'][$key]['vat_rate'] = wpinv_round_amount($rate, 4);
1626 1626
         }
1627 1627
     }
1628 1628
     
1629 1629
     // Save vat fields.
1630
-    $address_fields = array( 'vat_number', 'vat_rate', 'adddress_confirmed' );
1631
-    foreach ( $address_fields as $field ) {
1632
-        if ( isset( $invoice_data['user_info'][$field] ) ) {
1633
-            $invoice->set( $field, $invoice_data['user_info'][$field] );
1630
+    $address_fields = array('vat_number', 'vat_rate', 'adddress_confirmed');
1631
+    foreach ($address_fields as $field) {
1632
+        if (isset($invoice_data['user_info'][$field])) {
1633
+            $invoice->set($field, $invoice_data['user_info'][$field]);
1634 1634
         }
1635 1635
         
1636 1636
         $invoice->save();
@@ -1640,49 +1640,49 @@  discard block
 block discarded – undo
1640 1640
     $valid_data['user'] = $user;
1641 1641
     
1642 1642
     // Allow themes and plugins to hook before the gateway
1643
-    do_action( 'wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data );
1643
+    do_action('wpinv_checkout_before_gateway', $_POST, $user_info, $valid_data);
1644 1644
     
1645 1645
     // If the total amount in the cart is 0, send to the manual gateway. This emulates a free invoice
1646
-    if ( !$invoice_data['price'] ) {
1646
+    if (!$invoice_data['price']) {
1647 1647
         // Revert to manual
1648 1648
         $invoice_data['gateway'] = 'manual';
1649 1649
         $_POST['wpi-gateway'] = 'manual';
1650 1650
     }
1651 1651
     
1652 1652
     // Allow the invoice data to be modified before it is sent to the gateway
1653
-    $invoice_data = apply_filters( 'wpinv_data_before_gateway', $invoice_data, $valid_data );
1653
+    $invoice_data = apply_filters('wpinv_data_before_gateway', $invoice_data, $valid_data);
1654 1654
     
1655 1655
     // Setup the data we're storing in the purchase session
1656 1656
     $session_data = $invoice_data;
1657 1657
     // Make sure credit card numbers are never stored in sessions
1658
-    if ( !empty( $session_data['card_info']['card_number'] ) ) {
1659
-        unset( $session_data['card_info']['card_number'] );
1658
+    if (!empty($session_data['card_info']['card_number'])) {
1659
+        unset($session_data['card_info']['card_number']);
1660 1660
     }
1661 1661
     
1662 1662
     // Used for showing item links to non logged-in users after purchase, and for other plugins needing purchase data.
1663
-    wpinv_set_checkout_session( $invoice_data );
1663
+    wpinv_set_checkout_session($invoice_data);
1664 1664
     
1665 1665
     // Set gateway
1666
-    $invoice->update_meta( '_wpinv_gateway', $invoice_data['gateway'] );
1667
-    $invoice->update_meta( '_wpinv_mode', ( wpinv_is_test_mode( $invoice_data['gateway'] ) ? 'test' : 'live' ) );
1668
-    $invoice->update_meta( '_wpinv_checkout', true );
1666
+    $invoice->update_meta('_wpinv_gateway', $invoice_data['gateway']);
1667
+    $invoice->update_meta('_wpinv_mode', (wpinv_is_test_mode($invoice_data['gateway']) ? 'test' : 'live'));
1668
+    $invoice->update_meta('_wpinv_checkout', true);
1669 1669
     
1670
-    do_action( 'wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data );
1670
+    do_action('wpinv_checkout_before_send_to_gateway', $invoice, $invoice_data);
1671 1671
 
1672 1672
     // Send info to the gateway for payment processing
1673
-    wpinv_send_to_gateway( $invoice_data['gateway'], $invoice_data );
1673
+    wpinv_send_to_gateway($invoice_data['gateway'], $invoice_data);
1674 1674
     die();
1675 1675
 }
1676
-add_action( 'wpinv_payment', 'wpinv_process_checkout' );
1676
+add_action('wpinv_payment', 'wpinv_process_checkout');
1677 1677
 
1678
-function wpinv_get_invoices( $args ) {
1679
-    $args = wp_parse_args( $args, array(
1680
-        'status'   => array_keys( wpinv_get_invoice_statuses() ),
1678
+function wpinv_get_invoices($args) {
1679
+    $args = wp_parse_args($args, array(
1680
+        'status'   => array_keys(wpinv_get_invoice_statuses()),
1681 1681
         'type'     => 'wpi_invoice',
1682 1682
         'parent'   => null,
1683 1683
         'user'     => null,
1684 1684
         'email'    => '',
1685
-        'limit'    => get_option( 'posts_per_page' ),
1685
+        'limit'    => get_option('posts_per_page'),
1686 1686
         'offset'   => null,
1687 1687
         'page'     => 1,
1688 1688
         'exclude'  => array(),
@@ -1690,7 +1690,7 @@  discard block
 block discarded – undo
1690 1690
         'order'    => 'DESC',
1691 1691
         'return'   => 'objects',
1692 1692
         'paginate' => false,
1693
-    ) );
1693
+    ));
1694 1694
     
1695 1695
     // Handle some BW compatibility arg names where wp_query args differ in naming.
1696 1696
     $map_legacy = array(
@@ -1703,18 +1703,18 @@  discard block
 block discarded – undo
1703 1703
         'paged'          => 'page',
1704 1704
     );
1705 1705
 
1706
-    foreach ( $map_legacy as $from => $to ) {
1707
-        if ( isset( $args[ $from ] ) ) {
1708
-            $args[ $to ] = $args[ $from ];
1706
+    foreach ($map_legacy as $from => $to) {
1707
+        if (isset($args[$from])) {
1708
+            $args[$to] = $args[$from];
1709 1709
         }
1710 1710
     }
1711 1711
 
1712
-    if ( get_query_var( 'paged' ) )
1712
+    if (get_query_var('paged'))
1713 1713
         $args['page'] = get_query_var('paged');
1714
-    else if ( get_query_var( 'page' ) )
1715
-        $args['page'] = get_query_var( 'page' );
1716
-    else if ( !empty( $args[ 'page' ] ) )
1717
-        $args['page'] = $args[ 'page' ];
1714
+    else if (get_query_var('page'))
1715
+        $args['page'] = get_query_var('page');
1716
+    else if (!empty($args['page']))
1717
+        $args['page'] = $args['page'];
1718 1718
     else
1719 1719
         $args['page'] = 1;
1720 1720
 
@@ -1727,47 +1727,47 @@  discard block
 block discarded – undo
1727 1727
         'post_status'    => $args['status'],
1728 1728
         'posts_per_page' => $args['limit'],
1729 1729
         'meta_query'     => array(),
1730
-        'date_query'     => !empty( $args['date_query'] ) ? $args['date_query'] : array(),
1730
+        'date_query'     => !empty($args['date_query']) ? $args['date_query'] : array(),
1731 1731
         'fields'         => 'ids',
1732 1732
         'orderby'        => $args['orderby'],
1733 1733
         'order'          => $args['order'],
1734 1734
     );
1735 1735
     
1736
-    if ( !empty( $args['user'] ) ) {
1737
-        $wp_query_args['author'] = absint( $args['user'] );
1736
+    if (!empty($args['user'])) {
1737
+        $wp_query_args['author'] = absint($args['user']);
1738 1738
     }
1739 1739
 
1740
-    if ( ! is_null( $args['parent'] ) ) {
1741
-        $wp_query_args['post_parent'] = absint( $args['parent'] );
1740
+    if (!is_null($args['parent'])) {
1741
+        $wp_query_args['post_parent'] = absint($args['parent']);
1742 1742
     }
1743 1743
 
1744
-    if ( ! is_null( $args['offset'] ) ) {
1745
-        $wp_query_args['offset'] = absint( $args['offset'] );
1744
+    if (!is_null($args['offset'])) {
1745
+        $wp_query_args['offset'] = absint($args['offset']);
1746 1746
     } else {
1747
-        $wp_query_args['paged'] = absint( $args['page'] );
1747
+        $wp_query_args['paged'] = absint($args['page']);
1748 1748
     }
1749 1749
 
1750
-    if ( ! empty( $args['exclude'] ) ) {
1751
-        $wp_query_args['post__not_in'] = array_map( 'absint', $args['exclude'] );
1750
+    if (!empty($args['exclude'])) {
1751
+        $wp_query_args['post__not_in'] = array_map('absint', $args['exclude']);
1752 1752
     }
1753 1753
 
1754
-    if ( ! $args['paginate' ] ) {
1754
+    if (!$args['paginate']) {
1755 1755
         $wp_query_args['no_found_rows'] = true;
1756 1756
     }
1757 1757
 
1758 1758
     // Get results.
1759
-    $invoices = new WP_Query( $wp_query_args );
1759
+    $invoices = new WP_Query($wp_query_args);
1760 1760
 
1761
-    if ( 'objects' === $args['return'] ) {
1762
-        $return = array_map( 'wpinv_get_invoice', $invoices->posts );
1763
-    } elseif ( 'self' === $args['return'] ) {
1761
+    if ('objects' === $args['return']) {
1762
+        $return = array_map('wpinv_get_invoice', $invoices->posts);
1763
+    } elseif ('self' === $args['return']) {
1764 1764
         return $invoices;
1765 1765
     } else {
1766 1766
         $return = $invoices->posts;
1767 1767
     }
1768 1768
 
1769
-    if ( $args['paginate' ] ) {
1770
-        return (object) array(
1769
+    if ($args['paginate']) {
1770
+        return (object)array(
1771 1771
             'invoices'      => $return,
1772 1772
             'total'         => $invoices->found_posts,
1773 1773
             'max_num_pages' => $invoices->max_num_pages,
@@ -1779,21 +1779,21 @@  discard block
 block discarded – undo
1779 1779
 
1780 1780
 function wpinv_get_user_invoices_columns() {
1781 1781
     $columns = array(
1782
-            'invoice-number'  => array( 'title' => __( 'ID', 'invoicing' ), 'class' => 'text-left' ),
1783
-            'invoice-date'    => array( 'title' => __( 'Date', 'invoicing' ), 'class' => 'text-left' ),
1784
-            'invoice-status'  => array( 'title' => __( 'Status', 'invoicing' ), 'class' => 'text-center' ),
1785
-            'invoice-total'   => array( 'title' => __( 'Total', 'invoicing' ), 'class' => 'text-right' ),
1786
-            'invoice-actions' => array( 'title' => '&nbsp;', 'class' => 'text-center' ),
1782
+            'invoice-number'  => array('title' => __('ID', 'invoicing'), 'class' => 'text-left'),
1783
+            'invoice-date'    => array('title' => __('Date', 'invoicing'), 'class' => 'text-left'),
1784
+            'invoice-status'  => array('title' => __('Status', 'invoicing'), 'class' => 'text-center'),
1785
+            'invoice-total'   => array('title' => __('Total', 'invoicing'), 'class' => 'text-right'),
1786
+            'invoice-actions' => array('title' => '&nbsp;', 'class' => 'text-center'),
1787 1787
         );
1788 1788
 
1789
-    return apply_filters( 'wpinv_user_invoices_columns', $columns );
1789
+    return apply_filters('wpinv_user_invoices_columns', $columns);
1790 1790
 }
1791 1791
 
1792
-function wpinv_payment_receipt( $atts, $content = null ) {
1792
+function wpinv_payment_receipt($atts, $content = null) {
1793 1793
     global $wpinv_receipt_args;
1794 1794
 
1795
-    $wpinv_receipt_args = shortcode_atts( array(
1796
-        'error'           => __( 'Sorry, trouble retrieving payment receipt.', 'invoicing' ),
1795
+    $wpinv_receipt_args = shortcode_atts(array(
1796
+        'error'           => __('Sorry, trouble retrieving payment receipt.', 'invoicing'),
1797 1797
         'price'           => true,
1798 1798
         'discount'        => true,
1799 1799
         'items'           => true,
@@ -1802,185 +1802,185 @@  discard block
 block discarded – undo
1802 1802
         'invoice_key'     => false,
1803 1803
         'payment_method'  => true,
1804 1804
         'invoice_id'      => true
1805
-    ), $atts, 'wpinv_receipt' );
1805
+    ), $atts, 'wpinv_receipt');
1806 1806
 
1807 1807
     $session = wpinv_get_checkout_session();
1808
-    if ( isset( $_GET['invoice_key'] ) ) {
1809
-        $invoice_key = urldecode( $_GET['invoice_key'] );
1810
-    } else if ( $session && isset( $session['invoice_key'] ) ) {
1808
+    if (isset($_GET['invoice_key'])) {
1809
+        $invoice_key = urldecode($_GET['invoice_key']);
1810
+    } else if ($session && isset($session['invoice_key'])) {
1811 1811
         $invoice_key = $session['invoice_key'];
1812
-    } elseif ( isset( $wpinv_receipt_args['invoice_key'] ) && $wpinv_receipt_args['invoice_key'] ) {
1812
+    } elseif (isset($wpinv_receipt_args['invoice_key']) && $wpinv_receipt_args['invoice_key']) {
1813 1813
         $invoice_key = $wpinv_receipt_args['invoice_key'];
1814
-    } else if ( isset( $_GET['invoice-id'] ) ) {
1815
-        $invoice_key = wpinv_get_payment_key( (int)$_GET['invoice-id'] );
1814
+    } else if (isset($_GET['invoice-id'])) {
1815
+        $invoice_key = wpinv_get_payment_key((int)$_GET['invoice-id']);
1816 1816
     }
1817 1817
 
1818 1818
     // No key found
1819
-    if ( ! isset( $invoice_key ) ) {
1819
+    if (!isset($invoice_key)) {
1820 1820
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1821 1821
     }
1822 1822
 
1823
-    $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1824
-    $user_can_view = wpinv_can_view_receipt( $invoice_key );
1825
-    if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1823
+    $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1824
+    $user_can_view = wpinv_can_view_receipt($invoice_key);
1825
+    if ($user_can_view && isset($_GET['invoice-id'])) {
1826 1826
         $invoice_id     = (int)$_GET['invoice-id'];
1827
-        $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1827
+        $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1828 1828
     }
1829 1829
 
1830 1830
     // Key was provided, but user is logged out. Offer them the ability to login and view the receipt
1831
-    if ( ! $user_can_view && ! empty( $invoice_key ) && ! is_user_logged_in() ) {
1831
+    if (!$user_can_view && !empty($invoice_key) && !is_user_logged_in()) {
1832 1832
         // login redirect
1833
-        return '<p class="alert alert-error">' . __( 'You are not allowed to access this section', 'invoicing' ) . '</p>';
1833
+        return '<p class="alert alert-error">' . __('You are not allowed to access this section', 'invoicing') . '</p>';
1834 1834
     }
1835 1835
 
1836
-    if ( ! apply_filters( 'wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args ) ) {
1836
+    if (!apply_filters('wpinv_user_can_view_receipt', $user_can_view, $wpinv_receipt_args)) {
1837 1837
         return '<p class="alert alert-error">' . $wpinv_receipt_args['error'] . '</p>';
1838 1838
     }
1839 1839
 
1840 1840
     ob_start();
1841 1841
 
1842
-    wpinv_get_template_part( 'wpinv-invoice-receipt' );
1842
+    wpinv_get_template_part('wpinv-invoice-receipt');
1843 1843
 
1844 1844
     $display = ob_get_clean();
1845 1845
 
1846 1846
     return $display;
1847 1847
 }
1848 1848
 
1849
-function wpinv_get_invoice_id_by_key( $key ) {
1849
+function wpinv_get_invoice_id_by_key($key) {
1850 1850
 	global $wpdb;
1851 1851
 
1852
-	$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 ) );
1852
+	$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));
1853 1853
 
1854
-	if ( $invoice_id != NULL )
1854
+	if ($invoice_id != NULL)
1855 1855
 		return $invoice_id;
1856 1856
 
1857 1857
 	return 0;
1858 1858
 }
1859 1859
 
1860
-function wpinv_can_view_receipt( $invoice_key = '' ) {
1860
+function wpinv_can_view_receipt($invoice_key = '') {
1861 1861
 	$return = false;
1862 1862
 
1863
-	if ( empty( $invoice_key ) ) {
1863
+	if (empty($invoice_key)) {
1864 1864
 		return $return;
1865 1865
 	}
1866 1866
 
1867 1867
 	global $wpinv_receipt_args;
1868 1868
 
1869
-	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key( $invoice_key );
1870
-	if ( isset( $_GET['invoice-id'] ) ) {
1871
-		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? (int)$_GET['invoice-id'] : 0;
1869
+	$wpinv_receipt_args['id'] = wpinv_get_invoice_id_by_key($invoice_key);
1870
+	if (isset($_GET['invoice-id'])) {
1871
+		$wpinv_receipt_args['id'] = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? (int)$_GET['invoice-id'] : 0;
1872 1872
 	}
1873 1873
 
1874
-	$user_id = (int) wpinv_get_user_id( $wpinv_receipt_args['id'] );
1875
-    $invoice_meta = wpinv_get_invoice_meta( $wpinv_receipt_args['id'] );
1874
+	$user_id = (int)wpinv_get_user_id($wpinv_receipt_args['id']);
1875
+    $invoice_meta = wpinv_get_invoice_meta($wpinv_receipt_args['id']);
1876 1876
 
1877
-	if ( is_user_logged_in() ) {
1878
-		if ( $user_id === (int) get_current_user_id() ) {
1877
+	if (is_user_logged_in()) {
1878
+		if ($user_id === (int)get_current_user_id()) {
1879 1879
 			$return = true;
1880 1880
 		}
1881 1881
 	}
1882 1882
 
1883 1883
 	$session = wpinv_get_checkout_session();
1884
-	if ( ! empty( $session ) && ! is_user_logged_in() ) {
1885
-		if ( $session['invoice_key'] === $invoice_meta['key'] ) {
1884
+	if (!empty($session) && !is_user_logged_in()) {
1885
+		if ($session['invoice_key'] === $invoice_meta['key']) {
1886 1886
 			$return = true;
1887 1887
 		}
1888 1888
 	}
1889 1889
 
1890
-	return (bool) apply_filters( 'wpinv_can_view_receipt', $return, $invoice_key );
1890
+	return (bool)apply_filters('wpinv_can_view_receipt', $return, $invoice_key);
1891 1891
 }
1892 1892
 
1893 1893
 function wpinv_pay_for_invoice() {
1894 1894
     global $wpinv_euvat;
1895 1895
     
1896
-    if ( isset( $_GET['invoice_key'] ) ) {
1896
+    if (isset($_GET['invoice_key'])) {
1897 1897
         $checkout_uri   = wpinv_get_checkout_uri();
1898
-        $invoice_key    = sanitize_text_field( $_GET['invoice_key'] );
1898
+        $invoice_key    = sanitize_text_field($_GET['invoice_key']);
1899 1899
         
1900
-        if ( empty( $invoice_key ) ) {
1901
-            wpinv_set_error( 'invalid_invoice', __( 'Invoice not found', 'invoicing' ) );
1902
-            wp_redirect( $checkout_uri );
1900
+        if (empty($invoice_key)) {
1901
+            wpinv_set_error('invalid_invoice', __('Invoice not found', 'invoicing'));
1902
+            wp_redirect($checkout_uri);
1903 1903
             wpinv_die();
1904 1904
         }
1905 1905
         
1906
-        do_action( 'wpinv_check_pay_for_invoice', $invoice_key );
1906
+        do_action('wpinv_check_pay_for_invoice', $invoice_key);
1907 1907
 
1908
-        $invoice_id    = wpinv_get_invoice_id_by_key( $invoice_key );
1909
-        $user_can_view = wpinv_can_view_receipt( $invoice_key );
1910
-        if ( $user_can_view && isset( $_GET['invoice-id'] ) ) {
1908
+        $invoice_id    = wpinv_get_invoice_id_by_key($invoice_key);
1909
+        $user_can_view = wpinv_can_view_receipt($invoice_key);
1910
+        if ($user_can_view && isset($_GET['invoice-id'])) {
1911 1911
             $invoice_id     = (int)$_GET['invoice-id'];
1912
-            $user_can_view  = $invoice_key == wpinv_get_payment_key( (int)$_GET['invoice-id'] ) ? true : false;
1912
+            $user_can_view  = $invoice_key == wpinv_get_payment_key((int)$_GET['invoice-id']) ? true : false;
1913 1913
         }
1914 1914
         
1915
-        if ( $invoice_id && $user_can_view && ( $invoice = wpinv_get_invoice( $invoice_id ) ) ) {
1916
-            if ( $invoice->needs_payment() ) {
1915
+        if ($invoice_id && $user_can_view && ($invoice = wpinv_get_invoice($invoice_id))) {
1916
+            if ($invoice->needs_payment()) {
1917 1917
                 $data                   = array();
1918 1918
                 $data['invoice_id']     = $invoice_id;
1919
-                $data['cart_discounts'] = $invoice->get_discounts( true );
1919
+                $data['cart_discounts'] = $invoice->get_discounts(true);
1920 1920
                 
1921
-                wpinv_set_checkout_session( $data );
1921
+                wpinv_set_checkout_session($data);
1922 1922
                 
1923
-                if ( wpinv_get_option( 'vat_ip_country_default' ) ) {
1923
+                if (wpinv_get_option('vat_ip_country_default')) {
1924 1924
                     $_POST['country']   = $wpinv_euvat->get_country_by_ip();
1925 1925
                     $_POST['state']     = $_POST['country'] == $invoice->country ? $invoice->state : '';
1926 1926
                     
1927
-                    wpinv_recalculate_tax( true );
1927
+                    wpinv_recalculate_tax(true);
1928 1928
                 }
1929 1929
                 
1930 1930
             } else {
1931 1931
                 $checkout_uri = $invoice->get_view_url();
1932 1932
             }
1933 1933
         } else {
1934
-            wpinv_set_error( 'invalid_invoice', __( 'You are not allowed to view this invoice', 'invoicing' ) );
1934
+            wpinv_set_error('invalid_invoice', __('You are not allowed to view this invoice', 'invoicing'));
1935 1935
             
1936
-            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url( get_permalink() );
1936
+            $checkout_uri = is_user_logged_in() ? wpinv_get_history_page_uri() : wp_login_url(get_permalink());
1937 1937
         }
1938 1938
         
1939
-        wp_redirect( $checkout_uri );
1939
+        wp_redirect($checkout_uri);
1940 1940
         wpinv_die();
1941 1941
     }
1942 1942
 }
1943
-add_action( 'wpinv_pay_for_invoice', 'wpinv_pay_for_invoice' );
1943
+add_action('wpinv_pay_for_invoice', 'wpinv_pay_for_invoice');
1944 1944
 
1945
-function wpinv_handle_pay_via_invoice_link( $invoice_key ) {
1946
-    if ( !empty( $invoice_key ) && !empty( $_REQUEST['_wpipay'] ) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key( $invoice_key ) ) {
1947
-        if ( $invoice = wpinv_get_invoice( $invoice_id ) ) {
1945
+function wpinv_handle_pay_via_invoice_link($invoice_key) {
1946
+    if (!empty($invoice_key) && !empty($_REQUEST['_wpipay']) && !is_user_logged_in() && $invoice_id = wpinv_get_invoice_id_by_key($invoice_key)) {
1947
+        if ($invoice = wpinv_get_invoice($invoice_id)) {
1948 1948
             $user_id = $invoice->get_user_id();
1949
-            $secret = sanitize_text_field( $_GET['_wpipay'] );
1949
+            $secret = sanitize_text_field($_GET['_wpipay']);
1950 1950
             
1951
-            if ( $secret === md5( $user_id . '::' . $invoice->get_email() . '::' . $invoice_key ) ) { // valid invoice link
1952
-                $redirect_to = remove_query_arg( '_wpipay', get_permalink() );
1951
+            if ($secret === md5($user_id . '::' . $invoice->get_email() . '::' . $invoice_key)) { // valid invoice link
1952
+                $redirect_to = remove_query_arg('_wpipay', get_permalink());
1953 1953
                 
1954
-                wpinv_guest_redirect( $redirect_to, $user_id );
1954
+                wpinv_guest_redirect($redirect_to, $user_id);
1955 1955
                 wpinv_die();
1956 1956
             }
1957 1957
         }
1958 1958
     }
1959 1959
 }
1960
-add_action( 'wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link' );
1960
+add_action('wpinv_check_pay_for_invoice', 'wpinv_handle_pay_via_invoice_link');
1961 1961
 
1962
-function wpinv_set_payment_transaction_id( $invoice_id = 0, $transaction_id = '' ) {
1963
-    $invoice_id = is_object( $invoice_id ) && !empty( $invoice_id->ID ) ? $invoice_id : $invoice_id;
1962
+function wpinv_set_payment_transaction_id($invoice_id = 0, $transaction_id = '') {
1963
+    $invoice_id = is_object($invoice_id) && !empty($invoice_id->ID) ? $invoice_id : $invoice_id;
1964 1964
     
1965
-    if ( empty( $invoice_id ) && $invoice_id > 0 ) {
1965
+    if (empty($invoice_id) && $invoice_id > 0) {
1966 1966
         return false;
1967 1967
     }
1968 1968
     
1969
-    if ( empty( $transaction_id ) ) {
1969
+    if (empty($transaction_id)) {
1970 1970
         $transaction_id = $invoice_id;
1971 1971
     }
1972 1972
 
1973
-    $transaction_id = apply_filters( 'wpinv_set_payment_transaction_id', $transaction_id, $invoice_id );
1973
+    $transaction_id = apply_filters('wpinv_set_payment_transaction_id', $transaction_id, $invoice_id);
1974 1974
     
1975
-    return wpinv_update_invoice_meta( $invoice_id, '_wpinv_transaction_id', $transaction_id );
1975
+    return wpinv_update_invoice_meta($invoice_id, '_wpinv_transaction_id', $transaction_id);
1976 1976
 }
1977 1977
 
1978
-function wpinv_invoice_status_label( $status, $status_display = '' ) {
1979
-    if ( empty( $status_display ) ) {
1980
-        $status_display = wpinv_status_nicename( $status );
1978
+function wpinv_invoice_status_label($status, $status_display = '') {
1979
+    if (empty($status_display)) {
1980
+        $status_display = wpinv_status_nicename($status);
1981 1981
     }
1982 1982
     
1983
-    switch ( $status ) {
1983
+    switch ($status) {
1984 1984
         case 'publish' :
1985 1985
         case 'wpi-renewal' :
1986 1986
             $class = 'label-success';
@@ -2005,129 +2005,129 @@  discard block
 block discarded – undo
2005 2005
     
2006 2006
     $label = '<span class="label label-inv-' . $status . ' ' . $class . '">' . $status_display . '</span>';
2007 2007
     
2008
-    return apply_filters( 'wpinv_invoice_status_label', $label, $status, $status_display );
2008
+    return apply_filters('wpinv_invoice_status_label', $label, $status, $status_display);
2009 2009
 }
2010 2010
 
2011
-function wpinv_format_invoice_number( $number ) {
2012
-    $padd  = wpinv_get_option( 'invoice_number_padd' );
2011
+function wpinv_format_invoice_number($number) {
2012
+    $padd = wpinv_get_option('invoice_number_padd');
2013 2013
     
2014 2014
     // TODO maintain old invoice numbers if invoice number settings not saved. Should be removed before stable release.
2015
-    if ( $padd === '' || $padd === false || $padd === NULL ) {
2016
-        return wp_sprintf( __( 'WPINV-%d', 'invoicing' ), $number );
2015
+    if ($padd === '' || $padd === false || $padd === NULL) {
2016
+        return wp_sprintf(__('WPINV-%d', 'invoicing'), $number);
2017 2017
     }
2018 2018
     
2019
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2020
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2019
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2020
+    $postfix = wpinv_get_option('invoice_number_postfix');
2021 2021
     
2022
-    $padd = absint( $padd );
2023
-    $formatted_number = absint( $number );
2022
+    $padd = absint($padd);
2023
+    $formatted_number = absint($number);
2024 2024
     
2025
-    if ( $padd > 0 ) {
2026
-        $formatted_number = zeroise( $formatted_number, $padd );
2025
+    if ($padd > 0) {
2026
+        $formatted_number = zeroise($formatted_number, $padd);
2027 2027
     }    
2028 2028
 
2029 2029
     $formatted_number = $prefix . $formatted_number . $postfix;
2030 2030
 
2031
-    return apply_filters( 'wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd );
2031
+    return apply_filters('wpinv_format_invoice_number', $formatted_number, $number, $prefix, $postfix, $padd);
2032 2032
 }
2033 2033
 
2034 2034
 function wpinv_get_next_invoice_number() {
2035
-    if ( ! wpinv_get_option( 'sequential_invoice_number' ) ) {
2035
+    if (!wpinv_get_option('sequential_invoice_number')) {
2036 2036
         return false;
2037 2037
     }
2038 2038
 
2039
-    $number           = get_option( 'wpinv_last_invoice_number' );
2040
-    $start            = wpinv_get_option( 'invoice_sequence_start', 1 );
2039
+    $number           = get_option('wpinv_last_invoice_number');
2040
+    $start            = wpinv_get_option('invoice_sequence_start', 1);
2041 2041
     $increment_number = true;
2042 2042
 
2043
-    if ( false !== $number ) {
2044
-        if ( empty( $number ) ) {
2043
+    if (false !== $number) {
2044
+        if (empty($number)) {
2045 2045
             $number = $start;
2046 2046
             $increment_number = false;
2047 2047
         }
2048 2048
     } else {
2049
-        $last_invoice = wpinv_get_invoices( array( 'limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => 'any' ) );
2049
+        $last_invoice = wpinv_get_invoices(array('limit' => 1, 'order' => 'DESC', 'orderby' => 'ID', 'return' => 'posts', 'fields' => 'ids', 'status' => 'any'));
2050 2050
 
2051
-        if ( ! empty( $last_invoice[0] ) ) {
2052
-            $number = wpinv_get_invoice_number( $last_invoice[0] );
2051
+        if (!empty($last_invoice[0])) {
2052
+            $number = wpinv_get_invoice_number($last_invoice[0]);
2053 2053
         }
2054 2054
 
2055
-        if ( ! empty( $number ) && ! empty( $last_invoice[0] ) && $number !== (int) $last_invoice[0] ) {
2056
-            $number = wpinv_clean_invoice_number( $number );
2055
+        if (!empty($number) && !empty($last_invoice[0]) && $number !== (int)$last_invoice[0]) {
2056
+            $number = wpinv_clean_invoice_number($number);
2057 2057
         } else {
2058 2058
             $number = $start;
2059 2059
             $increment_number = false;
2060 2060
         }
2061 2061
     }
2062 2062
 
2063
-    $increment_number = apply_filters( 'wpinv_increment_payment_number', $increment_number, $number );
2063
+    $increment_number = apply_filters('wpinv_increment_payment_number', $increment_number, $number);
2064 2064
 
2065
-    if ( $increment_number ) {
2065
+    if ($increment_number) {
2066 2066
         $number++;
2067 2067
     }
2068 2068
 
2069
-    return apply_filters( 'wpinv_get_next_invoice_number', $number );
2069
+    return apply_filters('wpinv_get_next_invoice_number', $number);
2070 2070
 }
2071 2071
 
2072
-function wpinv_clean_invoice_number( $number ) {
2073
-    $prefix  = wpinv_get_option( 'invoice_number_prefix' );
2074
-    $postfix = wpinv_get_option( 'invoice_number_postfix' );
2072
+function wpinv_clean_invoice_number($number) {
2073
+    $prefix  = wpinv_get_option('invoice_number_prefix');
2074
+    $postfix = wpinv_get_option('invoice_number_postfix');
2075 2075
 
2076
-    $number = preg_replace( '/' . $prefix . '/', '', $number, 1 );
2076
+    $number = preg_replace('/' . $prefix . '/', '', $number, 1);
2077 2077
 
2078
-    $length      = strlen( $number );
2079
-    $postfix_pos = strrpos( $number, $postfix );
2078
+    $length      = strlen($number);
2079
+    $postfix_pos = strrpos($number, $postfix);
2080 2080
     
2081
-    if ( false !== $postfix_pos ) {
2082
-        $number      = substr_replace( $number, '', $postfix_pos, $length );
2081
+    if (false !== $postfix_pos) {
2082
+        $number = substr_replace($number, '', $postfix_pos, $length);
2083 2083
     }
2084 2084
 
2085
-    $number = intval( $number );
2085
+    $number = intval($number);
2086 2086
 
2087
-    return apply_filters( 'wpinv_clean_invoice_number', $number, $prefix, $postfix );
2087
+    return apply_filters('wpinv_clean_invoice_number', $number, $prefix, $postfix);
2088 2088
 }
2089 2089
 
2090
-function wpinv_save_number_post_saved( $post_ID, $post, $update ) {
2090
+function wpinv_save_number_post_saved($post_ID, $post, $update) {
2091 2091
     global $wpdb;
2092 2092
 
2093
-    if ( !$update && !get_post_meta( $post_ID, '_wpinv_number', true ) ) {
2094
-        wpinv_update_invoice_number( $post_ID, $post->post_status != 'auto-draft' );
2093
+    if (!$update && !get_post_meta($post_ID, '_wpinv_number', true)) {
2094
+        wpinv_update_invoice_number($post_ID, $post->post_status != 'auto-draft');
2095 2095
     }
2096 2096
 
2097
-    if ( !$update ) {
2098
-        $wpdb->update( $wpdb->posts, array( 'post_name' => 'inv-' . $post_ID ), array( 'ID' => $post_ID ) );
2099
-        clean_post_cache( $post_ID );
2097
+    if (!$update) {
2098
+        $wpdb->update($wpdb->posts, array('post_name' => 'inv-' . $post_ID), array('ID' => $post_ID));
2099
+        clean_post_cache($post_ID);
2100 2100
     }
2101 2101
 }
2102
-add_action( 'save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3 );
2102
+add_action('save_post_wpi_invoice', 'wpinv_save_number_post_saved', 1, 3);
2103 2103
 
2104
-function wpinv_save_number_post_updated( $post_ID, $post_after, $post_before ) {
2105
-    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 ) {
2106
-        wpinv_update_invoice_number( $post_ID, true );
2104
+function wpinv_save_number_post_updated($post_ID, $post_after, $post_before) {
2105
+    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) {
2106
+        wpinv_update_invoice_number($post_ID, true);
2107 2107
     }
2108 2108
 }
2109
-add_action( 'post_updated', 'wpinv_save_number_post_updated', 1, 3 );
2109
+add_action('post_updated', 'wpinv_save_number_post_updated', 1, 3);
2110 2110
 
2111
-function wpinv_update_invoice_number( $post_ID, $save_sequential = false ) {
2111
+function wpinv_update_invoice_number($post_ID, $save_sequential = false) {
2112 2112
     global $wpdb;
2113 2113
 
2114
-    if ( wpinv_get_option( 'sequential_invoice_number' ) ) {
2114
+    if (wpinv_get_option('sequential_invoice_number')) {
2115 2115
         $number = wpinv_get_next_invoice_number();
2116 2116
 
2117
-        if ( $save_sequential ) {
2118
-            update_option( 'wpinv_last_invoice_number', $number );
2117
+        if ($save_sequential) {
2118
+            update_option('wpinv_last_invoice_number', $number);
2119 2119
         }
2120 2120
     } else {
2121 2121
         $number = $post_ID;
2122 2122
     }
2123 2123
 
2124
-    $number = wpinv_format_invoice_number( $number );
2124
+    $number = wpinv_format_invoice_number($number);
2125 2125
 
2126
-    update_post_meta( $post_ID, '_wpinv_number', $number );
2126
+    update_post_meta($post_ID, '_wpinv_number', $number);
2127 2127
 
2128
-    $wpdb->update( $wpdb->posts, array( 'post_title' => $number ), array( 'ID' => $post_ID ) );
2128
+    $wpdb->update($wpdb->posts, array('post_title' => $number), array('ID' => $post_ID));
2129 2129
 
2130
-    clean_post_cache( $post_ID );
2130
+    clean_post_cache($post_ID);
2131 2131
 
2132 2132
     return $number;
2133 2133
 }
2134 2134
\ No newline at end of file
Please login to merge, or discard this patch.
includes/wpinv-gateway-functions.php 1 patch
Spacing   +252 added lines, -252 removed lines patch added patch discarded remove patch
@@ -7,206 +7,206 @@  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_payment_gateways() {
15 15
     // Default, built-in gateways
16 16
     $gateways = array(
17 17
         'paypal' => array(
18
-            'admin_label'    => __( 'PayPal Standard', 'invoicing' ),
19
-            'checkout_label' => __( 'PayPal Standard', 'invoicing' ),
18
+            'admin_label'    => __('PayPal Standard', 'invoicing'),
19
+            'checkout_label' => __('PayPal Standard', 'invoicing'),
20 20
             'ordering'       => 1,
21 21
         ),
22 22
         'authorizenet' => array(
23
-            'admin_label'    => __( 'Authorize.Net (AIM)', 'invoicing' ),
24
-            'checkout_label' => __( 'Authorize.Net - Credit Card / Debit Card', 'invoicing' ),
23
+            'admin_label'    => __('Authorize.Net (AIM)', 'invoicing'),
24
+            'checkout_label' => __('Authorize.Net - Credit Card / Debit Card', 'invoicing'),
25 25
             'ordering'       => 4,
26 26
         ),
27 27
         'worldpay' => array(
28
-            'admin_label'    => __( 'Worldpay', 'invoicing' ),
29
-            'checkout_label' => __( 'Worldpay - Credit Card / Debit Card', 'invoicing' ),
28
+            'admin_label'    => __('Worldpay', 'invoicing'),
29
+            'checkout_label' => __('Worldpay - Credit Card / Debit Card', 'invoicing'),
30 30
             'ordering'       => 5,
31 31
         ),
32 32
         'bank_transfer' => array(
33
-            'admin_label'    => __( 'Pre Bank Transfer', 'invoicing' ),
34
-            'checkout_label' => __( 'Pre Bank Transfer', 'invoicing' ),
33
+            'admin_label'    => __('Pre Bank Transfer', 'invoicing'),
34
+            'checkout_label' => __('Pre Bank Transfer', 'invoicing'),
35 35
             'ordering'       => 11,
36 36
         ),
37 37
         'manual' => array(
38
-            'admin_label'    => __( 'Test Payment', 'invoicing' ),
39
-            'checkout_label' => __( 'Test Payment', 'invoicing' ),
38
+            'admin_label'    => __('Test Payment', 'invoicing'),
39
+            'checkout_label' => __('Test Payment', 'invoicing'),
40 40
             'ordering'       => 12,
41 41
         ),
42 42
     );
43 43
 
44
-    return apply_filters( 'wpinv_payment_gateways', $gateways );
44
+    return apply_filters('wpinv_payment_gateways', $gateways);
45 45
 }
46 46
 
47
-function wpinv_payment_gateway_titles( $all_gateways ) {
47
+function wpinv_payment_gateway_titles($all_gateways) {
48 48
     global $wpinv_options;
49 49
     
50 50
     $gateways = array();
51
-    foreach ( $all_gateways as $key => $gateway ) {
52
-        if ( !empty( $wpinv_options[$key . '_title'] ) ) {
53
-            $all_gateways[$key]['checkout_label'] = __( $wpinv_options[$key . '_title'], 'invoicing' );
51
+    foreach ($all_gateways as $key => $gateway) {
52
+        if (!empty($wpinv_options[$key . '_title'])) {
53
+            $all_gateways[$key]['checkout_label'] = __($wpinv_options[$key . '_title'], 'invoicing');
54 54
         }
55 55
         
56
-        $gateways[$key] = isset( $wpinv_options[$key . '_ordering'] ) ? $wpinv_options[$key . '_ordering'] : ( isset( $gateway['ordering'] ) ? $gateway['ordering'] : '' );
56
+        $gateways[$key] = isset($wpinv_options[$key . '_ordering']) ? $wpinv_options[$key . '_ordering'] : (isset($gateway['ordering']) ? $gateway['ordering'] : '');
57 57
     }
58 58
 
59
-    asort( $gateways );
59
+    asort($gateways);
60 60
     
61
-    foreach ( $gateways as $gateway => $key ) {
61
+    foreach ($gateways as $gateway => $key) {
62 62
         $gateways[$gateway] = $all_gateways[$gateway];
63 63
     }
64 64
     
65 65
     return $gateways;
66 66
 }
67
-add_filter( 'wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1 );
67
+add_filter('wpinv_payment_gateways', 'wpinv_payment_gateway_titles', 1000, 1);
68 68
 
69
-function wpinv_get_enabled_payment_gateways( $sort = false ) {
69
+function wpinv_get_enabled_payment_gateways($sort = false) {
70 70
     $gateways = wpinv_get_payment_gateways();
71
-    $enabled  = wpinv_get_option( 'gateways', false );
71
+    $enabled  = wpinv_get_option('gateways', false);
72 72
 
73 73
     $gateway_list = array();
74 74
 
75
-    foreach ( $gateways as $key => $gateway ) {
76
-        if ( isset( $enabled[ $key ] ) && $enabled[ $key ] == 1 ) {
77
-            $gateway_list[ $key ] = $gateway;
75
+    foreach ($gateways as $key => $gateway) {
76
+        if (isset($enabled[$key]) && $enabled[$key] == 1) {
77
+            $gateway_list[$key] = $gateway;
78 78
         }
79 79
     }
80 80
 
81
-    if ( true === $sort ) {
82
-        uasort( $gateway_list, 'wpinv_sort_gateway_order' );
81
+    if (true === $sort) {
82
+        uasort($gateway_list, 'wpinv_sort_gateway_order');
83 83
         
84 84
         // Reorder our gateways so the default is first
85 85
         $default_gateway_id = wpinv_get_default_gateway();
86 86
 
87
-        if ( wpinv_is_gateway_active( $default_gateway_id ) ) {
88
-            $default_gateway    = array( $default_gateway_id => $gateway_list[ $default_gateway_id ] );
89
-            unset( $gateway_list[ $default_gateway_id ] );
87
+        if (wpinv_is_gateway_active($default_gateway_id)) {
88
+            $default_gateway = array($default_gateway_id => $gateway_list[$default_gateway_id]);
89
+            unset($gateway_list[$default_gateway_id]);
90 90
 
91
-            $gateway_list = array_merge( $default_gateway, $gateway_list );
91
+            $gateway_list = array_merge($default_gateway, $gateway_list);
92 92
         }
93 93
     }
94 94
 
95
-    return apply_filters( 'wpinv_enabled_payment_gateways', $gateway_list );
95
+    return apply_filters('wpinv_enabled_payment_gateways', $gateway_list);
96 96
 }
97 97
 
98
-function wpinv_sort_gateway_order( $a, $b ) {
98
+function wpinv_sort_gateway_order($a, $b) {
99 99
     return $a['ordering'] - $b['ordering'];
100 100
 }
101 101
 
102
-function wpinv_is_gateway_active( $gateway ) {
102
+function wpinv_is_gateway_active($gateway) {
103 103
     $gateways = wpinv_get_enabled_payment_gateways();
104 104
 
105
-    $ret = is_array($gateways) && $gateway ?  array_key_exists( $gateway, $gateways ) : false;
105
+    $ret = is_array($gateways) && $gateway ?  array_key_exists($gateway, $gateways) : false;
106 106
 
107
-    return apply_filters( 'wpinv_is_gateway_active', $ret, $gateway, $gateways );
107
+    return apply_filters('wpinv_is_gateway_active', $ret, $gateway, $gateways);
108 108
 }
109 109
 
110 110
 function wpinv_get_default_gateway() {
111
-    $default = wpinv_get_option( 'default_gateway', 'paypal' );
111
+    $default = wpinv_get_option('default_gateway', 'paypal');
112 112
 
113
-    if ( !wpinv_is_gateway_active( $default ) ) {
113
+    if (!wpinv_is_gateway_active($default)) {
114 114
         $gateways = wpinv_get_enabled_payment_gateways();
115
-        $gateways = array_keys( $gateways );
116
-        $default  = reset( $gateways );
115
+        $gateways = array_keys($gateways);
116
+        $default  = reset($gateways);
117 117
     }
118 118
 
119
-    return apply_filters( 'wpinv_default_gateway', $default );
119
+    return apply_filters('wpinv_default_gateway', $default);
120 120
 }
121 121
 
122
-function wpinv_get_gateway_admin_label( $gateway ) {
122
+function wpinv_get_gateway_admin_label($gateway) {
123 123
     $gateways = wpinv_get_payment_gateways();
124
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['admin_label'] : $gateway;
125
-    $payment  = isset( $_GET['id'] ) ? absint( $_GET['id'] ) : false;
124
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['admin_label'] : $gateway;
125
+    $payment  = isset($_GET['id']) ? absint($_GET['id']) : false;
126 126
 
127
-    if( $gateway == 'manual' && $payment ) {
128
-        if( wpinv_get_payment_amount( $payment ) == 0 ) {
129
-            $label = __( 'Manual Payment', 'invoicing' );
127
+    if ($gateway == 'manual' && $payment) {
128
+        if (wpinv_get_payment_amount($payment) == 0) {
129
+            $label = __('Manual Payment', 'invoicing');
130 130
         }
131 131
     }
132 132
 
133
-    return apply_filters( 'wpinv_gateway_admin_label', $label, $gateway );
133
+    return apply_filters('wpinv_gateway_admin_label', $label, $gateway);
134 134
 }
135 135
 
136
-function wpinv_get_gateway_description( $gateway ) {
136
+function wpinv_get_gateway_description($gateway) {
137 137
     global $wpinv_options;
138 138
 
139
-    $description = isset( $wpinv_options[$gateway . '_desc'] ) ? $wpinv_options[$gateway . '_desc'] : '';
139
+    $description = isset($wpinv_options[$gateway . '_desc']) ? $wpinv_options[$gateway . '_desc'] : '';
140 140
 
141
-    return apply_filters( 'wpinv_gateway_description', $description, $gateway );
141
+    return apply_filters('wpinv_gateway_description', $description, $gateway);
142 142
 }
143 143
 
144
-function wpinv_get_gateway_button_label( $gateway ) {
145
-    return apply_filters( 'wpinv_gateway_' . $gateway . '_button_label', '' );
144
+function wpinv_get_gateway_button_label($gateway) {
145
+    return apply_filters('wpinv_gateway_' . $gateway . '_button_label', '');
146 146
 }
147 147
 
148
-function wpinv_get_gateway_checkout_label( $gateway ) {
148
+function wpinv_get_gateway_checkout_label($gateway) {
149 149
     $gateways = wpinv_get_payment_gateways();
150
-    $label    = isset( $gateways[ $gateway ] ) ? $gateways[ $gateway ]['checkout_label'] : $gateway;
150
+    $label    = isset($gateways[$gateway]) ? $gateways[$gateway]['checkout_label'] : $gateway;
151 151
 
152
-    if( $gateway == 'manual' ) {
153
-        $label = __( 'Manual Payment', 'invoicing' );
152
+    if ($gateway == 'manual') {
153
+        $label = __('Manual Payment', 'invoicing');
154 154
     }
155 155
 
156
-    return apply_filters( 'wpinv_gateway_checkout_label', $label, $gateway );
156
+    return apply_filters('wpinv_gateway_checkout_label', $label, $gateway);
157 157
 }
158 158
 
159
-function wpinv_settings_sections_gateways( $settings ) {
159
+function wpinv_settings_sections_gateways($settings) {
160 160
     $gateways = wpinv_get_payment_gateways();
161 161
     
162 162
     if (!empty($gateways)) {
163
-        foreach  ($gateways as $key => $gateway) {
163
+        foreach ($gateways as $key => $gateway) {
164 164
             $settings[$key] = $gateway['admin_label'];
165 165
         }
166 166
     }
167 167
     
168 168
     return $settings;    
169 169
 }
170
-add_filter( 'wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1 );
170
+add_filter('wpinv_settings_sections_gateways', 'wpinv_settings_sections_gateways', 10, 1);
171 171
 
172
-function wpinv_settings_gateways( $settings ) {
172
+function wpinv_settings_gateways($settings) {
173 173
     $gateways = wpinv_get_payment_gateways();
174 174
     
175 175
     if (!empty($gateways)) {
176
-        foreach  ($gateways as $key => $gateway) {
176
+        foreach ($gateways as $key => $gateway) {
177 177
             $setting = array();
178 178
             $setting[$key . '_header'] = array(
179 179
                     'id'   => 'gateway_header',
180
-                    'name' => '<h3>' . wp_sprintf( __( '%s Settings', 'invoicing' ), $gateway['admin_label'] ) . '</h3>',
180
+                    'name' => '<h3>' . wp_sprintf(__('%s Settings', 'invoicing'), $gateway['admin_label']) . '</h3>',
181 181
                     'custom' => $key,
182 182
                     'type' => 'gateway_header',
183 183
                 );
184 184
             $setting[$key . '_active'] = array(
185 185
                     'id'   => $key . '_active',
186
-                    'name' => __( 'Active', 'invoicing' ),
187
-                    'desc' => wp_sprintf( __( 'Enable %s', 'invoicing' ), $gateway['admin_label'] ),
186
+                    'name' => __('Active', 'invoicing'),
187
+                    'desc' => wp_sprintf(__('Enable %s', 'invoicing'), $gateway['admin_label']),
188 188
                     'type' => 'checkbox',
189 189
                 );
190 190
                 
191 191
             $setting[$key . '_title'] = array(
192 192
                     'id'   => $key . '_title',
193
-                    'name' => __( 'Title', 'invoicing' ),
194
-                    'desc' => __( 'This controls the title which the user sees during checkout.', 'invoicing' ),
193
+                    'name' => __('Title', 'invoicing'),
194
+                    'desc' => __('This controls the title which the user sees during checkout.', 'invoicing'),
195 195
                     'type' => 'text',
196 196
                     'std' => isset($gateway['checkout_label']) ? $gateway['checkout_label'] : ''
197 197
                 );
198 198
             
199 199
             $setting[$key . '_desc'] = array(
200 200
                     'id'   => $key . '_desc',
201
-                    'name' => __( 'Description', 'invoicing' ),
202
-                    'desc' => __( 'This controls the description which the user sees during checkout.', 'invoicing' ),
201
+                    'name' => __('Description', 'invoicing'),
202
+                    'desc' => __('This controls the description which the user sees during checkout.', 'invoicing'),
203 203
                     'type' => 'text',
204 204
                     'size' => 'large'
205 205
                 );
206 206
                 
207 207
             $setting[$key . '_ordering'] = array(
208 208
                     'id'   => $key . '_ordering',
209
-                    'name' => __( 'Display Order', 'invoicing' ),
209
+                    'name' => __('Display Order', 'invoicing'),
210 210
                     'type' => 'number',
211 211
                     'size' => 'small',
212 212
                     'std'  => isset($gateway['ordering']) ? $gateway['ordering'] : '10',
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
                     'step' => '1'
216 216
                 );
217 217
                 
218
-            $setting = apply_filters( 'wpinv_gateway_settings', $setting, $key );
219
-            $setting = apply_filters( 'wpinv_gateway_settings_' . $key, $setting );
218
+            $setting = apply_filters('wpinv_gateway_settings', $setting, $key);
219
+            $setting = apply_filters('wpinv_gateway_settings_' . $key, $setting);
220 220
             
221 221
             $settings[$key] = $setting;
222 222
         }
@@ -224,106 +224,106 @@  discard block
 block discarded – undo
224 224
     
225 225
     return $settings;    
226 226
 }
227
-add_filter( 'wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1 );
227
+add_filter('wpinv_settings_gateways', 'wpinv_settings_gateways', 10, 1);
228 228
 
229
-function wpinv_gateway_header_callback( $args ) {
230
-    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr( $args['custom'] ) . '" />';
229
+function wpinv_gateway_header_callback($args) {
230
+    echo '<input type="hidden" id="wpinv_settings[save_gateway]" name="wpinv_settings[save_gateway]" value="' . esc_attr($args['custom']) . '" />';
231 231
 }
232 232
 
233
-function wpinv_get_gateway_supports( $gateway ) {
233
+function wpinv_get_gateway_supports($gateway) {
234 234
     $gateways = wpinv_get_enabled_payment_gateways();
235
-    $supports = isset( $gateways[ $gateway ]['supports'] ) ? $gateways[ $gateway ]['supports'] : array();
236
-    return apply_filters( 'wpinv_gateway_supports', $supports, $gateway );
235
+    $supports = isset($gateways[$gateway]['supports']) ? $gateways[$gateway]['supports'] : array();
236
+    return apply_filters('wpinv_gateway_supports', $supports, $gateway);
237 237
 }
238 238
 
239
-function wpinv_gateway_supports_buy_now( $gateway ) {
240
-    $supports = wpinv_get_gateway_supports( $gateway );
241
-    $ret = in_array( 'buy_now', $supports );
242
-    return apply_filters( 'wpinv_gateway_supports_buy_now', $ret, $gateway );
239
+function wpinv_gateway_supports_buy_now($gateway) {
240
+    $supports = wpinv_get_gateway_supports($gateway);
241
+    $ret = in_array('buy_now', $supports);
242
+    return apply_filters('wpinv_gateway_supports_buy_now', $ret, $gateway);
243 243
 }
244 244
 
245 245
 function wpinv_shop_supports_buy_now() {
246 246
     $gateways = wpinv_get_enabled_payment_gateways();
247 247
     $ret      = false;
248 248
 
249
-    if ( !wpinv_use_taxes()  && $gateways ) {
250
-        foreach ( $gateways as $gateway_id => $gateway ) {
251
-            if ( wpinv_gateway_supports_buy_now( $gateway_id ) ) {
249
+    if (!wpinv_use_taxes() && $gateways) {
250
+        foreach ($gateways as $gateway_id => $gateway) {
251
+            if (wpinv_gateway_supports_buy_now($gateway_id)) {
252 252
                 $ret = true;
253 253
                 break;
254 254
             }
255 255
         }
256 256
     }
257 257
 
258
-    return apply_filters( 'wpinv_shop_supports_buy_now', $ret );
258
+    return apply_filters('wpinv_shop_supports_buy_now', $ret);
259 259
 }
260 260
 
261
-function wpinv_send_to_gateway( $gateway, $payment_data ) {
262
-    $payment_data['gateway_nonce'] = wp_create_nonce( 'wpi-gateway' );
261
+function wpinv_send_to_gateway($gateway, $payment_data) {
262
+    $payment_data['gateway_nonce'] = wp_create_nonce('wpi-gateway');
263 263
 
264 264
     // $gateway must match the ID used when registering the gateway
265
-    do_action( 'wpinv_gateway_' . $gateway, $payment_data );
265
+    do_action('wpinv_gateway_' . $gateway, $payment_data);
266 266
 }
267 267
 
268 268
 function wpinv_show_gateways() {
269 269
     $gateways = wpinv_get_enabled_payment_gateways();
270 270
     $show_gateways = false;
271 271
 
272
-    $chosen_gateway = isset( $_GET['payment-mode'] ) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode'] ) : false;
272
+    $chosen_gateway = isset($_GET['payment-mode']) ? preg_replace('/[^a-zA-Z0-9-_]+/', '', $_GET['payment-mode']) : false;
273 273
 
274
-    if ( count( $gateways ) > 1 && empty( $chosen_gateway ) ) {
274
+    if (count($gateways) > 1 && empty($chosen_gateway)) {
275 275
         $show_gateways = true;
276
-        if ( wpinv_get_cart_total() <= 0 ) {
276
+        if (wpinv_get_cart_total() <= 0) {
277 277
             $show_gateways = false;
278 278
         }
279 279
     }
280 280
     
281
-    if ( !$show_gateways && wpinv_cart_has_recurring_item() ) {
281
+    if (!$show_gateways && wpinv_cart_has_recurring_item()) {
282 282
         $show_gateways = true;
283 283
     }
284 284
 
285
-    return apply_filters( 'wpinv_show_gateways', $show_gateways );
285
+    return apply_filters('wpinv_show_gateways', $show_gateways);
286 286
 }
287 287
 
288
-function wpinv_get_chosen_gateway( $invoice_id = 0 ) {
289
-	$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
288
+function wpinv_get_chosen_gateway($invoice_id = 0) {
289
+	$gateways = array_keys(wpinv_get_enabled_payment_gateways());
290 290
 
291 291
     $chosen = false;
292
-    if ( $invoice_id > 0 && $invoice = wpinv_get_invoice( $invoice_id ) ) {
292
+    if ($invoice_id > 0 && $invoice = wpinv_get_invoice($invoice_id)) {
293 293
         $chosen = $invoice->get_gateway();
294 294
     }
295 295
 
296
-	$chosen   = isset( $_REQUEST['payment-mode'] ) ? sanitize_text_field( $_REQUEST['payment-mode'] ) : $chosen;
296
+	$chosen = isset($_REQUEST['payment-mode']) ? sanitize_text_field($_REQUEST['payment-mode']) : $chosen;
297 297
 
298
-	if ( false !== $chosen ) {
299
-		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen );
298
+	if (false !== $chosen) {
299
+		$chosen = preg_replace('/[^a-zA-Z0-9-_]+/', '', $chosen);
300 300
 	}
301 301
 
302
-	if ( ! empty ( $chosen ) ) {
303
-		$enabled_gateway = urldecode( $chosen );
304
-	} else if (  !empty( $invoice ) && (float)$invoice->get_subtotal() <= 0 ) {
302
+	if (!empty ($chosen)) {
303
+		$enabled_gateway = urldecode($chosen);
304
+	} else if (!empty($invoice) && (float)$invoice->get_subtotal() <= 0) {
305 305
 		$enabled_gateway = 'manual';
306 306
 	} else {
307 307
 		$enabled_gateway = wpinv_get_default_gateway();
308 308
 	}
309 309
     
310
-    if ( !wpinv_is_gateway_active( $enabled_gateway ) && !empty( $gateways ) ) {
311
-        if(wpinv_is_gateway_active( wpinv_get_default_gateway()) ){
310
+    if (!wpinv_is_gateway_active($enabled_gateway) && !empty($gateways)) {
311
+        if (wpinv_is_gateway_active(wpinv_get_default_gateway())) {
312 312
             $enabled_gateway = wpinv_get_default_gateway();
313
-        }else{
313
+        } else {
314 314
             $enabled_gateway = $gateways[0];
315 315
         }
316 316
 
317 317
     }
318 318
 
319
-	return apply_filters( 'wpinv_chosen_gateway', $enabled_gateway );
319
+	return apply_filters('wpinv_chosen_gateway', $enabled_gateway);
320 320
 }
321 321
 
322
-function wpinv_record_gateway_error( $title = '', $message = '', $parent = 0 ) {
323
-    return wpinv_error_log( $message, $title );
322
+function wpinv_record_gateway_error($title = '', $message = '', $parent = 0) {
323
+    return wpinv_error_log($message, $title);
324 324
 }
325 325
 
326
-function wpinv_count_sales_by_gateway( $gateway_id = 'paypal', $status = 'publish' ) {
326
+function wpinv_count_sales_by_gateway($gateway_id = 'paypal', $status = 'publish') {
327 327
 	$ret  = 0;
328 328
 	$args = array(
329 329
 		'meta_key'    => '_wpinv_gateway',
@@ -334,48 +334,48 @@  discard block
 block discarded – undo
334 334
 		'fields'      => 'ids'
335 335
 	);
336 336
 
337
-	$payments = new WP_Query( $args );
337
+	$payments = new WP_Query($args);
338 338
 
339
-	if( $payments )
339
+	if ($payments)
340 340
 		$ret = $payments->post_count;
341 341
 	return $ret;
342 342
 }
343 343
 
344
-function wpinv_settings_update_gateways( $input ) {
344
+function wpinv_settings_update_gateways($input) {
345 345
     global $wpinv_options;
346 346
     
347
-    if ( !empty( $input['save_gateway'] ) ) {
348
-        $gateways = wpinv_get_option( 'gateways', false );
347
+    if (!empty($input['save_gateway'])) {
348
+        $gateways = wpinv_get_option('gateways', false);
349 349
         $gateways = !empty($gateways) ? $gateways : array();
350 350
         $gateway = $input['save_gateway'];
351 351
         
352
-        if ( !empty( $input[$gateway . '_active'] ) ) {
352
+        if (!empty($input[$gateway . '_active'])) {
353 353
             $gateways[$gateway] = 1;
354 354
         } else {
355
-            if ( isset( $gateways[$gateway] ) ) {
356
-                unset( $gateways[$gateway] );
355
+            if (isset($gateways[$gateway])) {
356
+                unset($gateways[$gateway]);
357 357
             }
358 358
         }
359 359
         
360 360
         $input['gateways'] = $gateways;
361 361
     }
362 362
     
363
-    if ( !empty( $input['default_gateway'] ) ) {
363
+    if (!empty($input['default_gateway'])) {
364 364
         $gateways = wpinv_get_payment_gateways();
365 365
         
366
-        foreach ( $gateways as $key => $gateway ) {
367
-            $active   = 0;
368
-            if ( !empty( $input['gateways'] ) && !empty( $input['gateways'][$key] ) ) {
366
+        foreach ($gateways as $key => $gateway) {
367
+            $active = 0;
368
+            if (!empty($input['gateways']) && !empty($input['gateways'][$key])) {
369 369
                 $active = 1;
370 370
             }
371 371
             
372 372
             $input[$key . '_active'] = $active;
373 373
             
374
-            if ( empty( $wpinv_options[$key . '_title'] ) ) {
374
+            if (empty($wpinv_options[$key . '_title'])) {
375 375
                 $input[$key . '_title'] = $gateway['checkout_label'];
376 376
             }
377 377
             
378
-            if ( !isset( $wpinv_options[$key . '_ordering'] ) && isset( $gateway['ordering'] ) ) {
378
+            if (!isset($wpinv_options[$key . '_ordering']) && isset($gateway['ordering'])) {
379 379
                 $input[$key . '_ordering'] = $gateway['ordering'];
380 380
             }
381 381
         }
@@ -383,26 +383,26 @@  discard block
 block discarded – undo
383 383
     
384 384
     return $input;
385 385
 }
386
-add_filter( 'wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1 );
386
+add_filter('wpinv_settings_tab_gateways_sanitize', 'wpinv_settings_update_gateways', 10, 1);
387 387
 
388 388
 // PayPal Standard settings
389
-function wpinv_gateway_settings_paypal( $setting ) {    
390
-    $setting['paypal_desc']['std'] = __( 'Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing' );
389
+function wpinv_gateway_settings_paypal($setting) {    
390
+    $setting['paypal_desc']['std'] = __('Pay via PayPal: you can pay with your credit card if you don\'t have a PayPal account.', 'invoicing');
391 391
     
392 392
     $setting['paypal_sandbox'] = array(
393 393
             'type' => 'checkbox',
394 394
             'id'   => 'paypal_sandbox',
395
-            'name' => __( 'PayPal Sandbox', 'invoicing' ),
396
-            'desc' => __( 'PayPal sandbox can be used to test payments.', 'invoicing' ),
395
+            'name' => __('PayPal Sandbox', 'invoicing'),
396
+            'desc' => __('PayPal sandbox can be used to test payments.', 'invoicing'),
397 397
             'std'  => 1
398 398
         );
399 399
         
400 400
     $setting['paypal_email'] = array(
401 401
             'type' => 'text',
402 402
             'id'   => 'paypal_email',
403
-            'name' => __( 'PayPal Email', 'invoicing' ),
404
-            'desc' => __( 'Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing' ),
405
-            'std' => __( '[email protected]', 'invoicing' ),
403
+            'name' => __('PayPal Email', 'invoicing'),
404
+            'desc' => __('Please enter your PayPal account\'s email address. Ex: [email protected]', 'invoicing'),
405
+            'std' => __('[email protected]', 'invoicing'),
406 406
         );
407 407
     /*
408 408
     $setting['paypal_ipn_url'] = array(
@@ -416,116 +416,116 @@  discard block
 block discarded – undo
416 416
         
417 417
     return $setting;
418 418
 }
419
-add_filter( 'wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1 );
419
+add_filter('wpinv_gateway_settings_paypal', 'wpinv_gateway_settings_paypal', 10, 1);
420 420
 
421 421
 // Pre Bank Transfer settings
422
-function wpinv_gateway_settings_bank_transfer( $setting ) {
423
-    $setting['bank_transfer_desc']['std'] = __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' );
422
+function wpinv_gateway_settings_bank_transfer($setting) {
423
+    $setting['bank_transfer_desc']['std'] = __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing');
424 424
     
425 425
     $setting['bank_transfer_ac_name'] = array(
426 426
             'type' => 'text',
427 427
             'id' => 'bank_transfer_ac_name',
428
-            'name' => __( 'Account Name', 'invoicing' ),
429
-            'desc' => __( 'Enter the bank account name to which you want to transfer payment.', 'invoicing' ),
430
-            'std'  =>  __( 'Mr. John Martin', 'invoicing' ),
428
+            'name' => __('Account Name', 'invoicing'),
429
+            'desc' => __('Enter the bank account name to which you want to transfer payment.', 'invoicing'),
430
+            'std'  =>  __('Mr. John Martin', 'invoicing'),
431 431
         );
432 432
     
433 433
     $setting['bank_transfer_ac_no'] = array(
434 434
             'type' => 'text',
435 435
             'id' => 'bank_transfer_ac_no',
436
-            'name' => __( 'Account Number', 'invoicing' ),
437
-            'desc' => __( 'Enter your bank account number.', 'invoicing' ),
438
-            'std'  =>  __( 'TEST1234567890', 'invoicing' ),
436
+            'name' => __('Account Number', 'invoicing'),
437
+            'desc' => __('Enter your bank account number.', 'invoicing'),
438
+            'std'  =>  __('TEST1234567890', 'invoicing'),
439 439
         );
440 440
     
441 441
     $setting['bank_transfer_bank_name'] = array(
442 442
             'type' => 'text',
443 443
             'id'   => 'bank_transfer_bank_name',
444
-            'name' => __( 'Bank Name', 'invoicing' ),
445
-            'desc' => __( 'Enter the bank name to which you want to transfer payment.', 'invoicing' ),
446
-            'std' => __( 'ICICI Bank', 'invoicing' ),
444
+            'name' => __('Bank Name', 'invoicing'),
445
+            'desc' => __('Enter the bank name to which you want to transfer payment.', 'invoicing'),
446
+            'std' => __('ICICI Bank', 'invoicing'),
447 447
         );
448 448
     
449 449
     $setting['bank_transfer_ifsc'] = array(
450 450
             'type' => 'text',
451 451
             'id'   => 'bank_transfer_ifsc',
452
-            'name' => __( 'IFSC code', 'invoicing' ),
453
-            'desc' => __( 'Enter your bank IFSC code.', 'invoicing' ),
454
-            'std'  =>  __( 'ICIC0001234', 'invoicing' ),
452
+            'name' => __('IFSC code', 'invoicing'),
453
+            'desc' => __('Enter your bank IFSC code.', 'invoicing'),
454
+            'std'  =>  __('ICIC0001234', 'invoicing'),
455 455
         );
456 456
         
457 457
     $setting['bank_transfer_iban'] = array(
458 458
             'type' => 'text',
459 459
             'id'   => 'bank_transfer_iban',
460
-            'name' => __( 'IBAN', 'invoicing' ),
461
-            'desc' => __( 'Enter your International Bank Account Number(IBAN).', 'invoicing' ),
462
-            'std'  =>  __( 'GB29NWBK60161331926819', 'invoicing' ),
460
+            'name' => __('IBAN', 'invoicing'),
461
+            'desc' => __('Enter your International Bank Account Number(IBAN).', 'invoicing'),
462
+            'std'  =>  __('GB29NWBK60161331926819', 'invoicing'),
463 463
         );
464 464
         
465 465
     $setting['bank_transfer_bic'] = array(
466 466
             'type' => 'text',
467 467
             'id'   => 'bank_transfer_bic',
468
-            'name' => __( 'BIC/Swift code', 'invoicing' ),
469
-            'std'  =>  __( 'ICICGB2L129', 'invoicing' ),
468
+            'name' => __('BIC/Swift code', 'invoicing'),
469
+            'std'  =>  __('ICICGB2L129', 'invoicing'),
470 470
         );
471 471
         
472 472
     $setting['bank_transfer_info'] = array(
473 473
             'id'   => 'bank_transfer_info',
474
-            'name' => __( 'Instructions', 'invoicing' ),
475
-            'desc' => __( 'Instructions that will be added to the thank you page and emails.', 'invoicing' ),
474
+            'name' => __('Instructions', 'invoicing'),
475
+            'desc' => __('Instructions that will be added to the thank you page and emails.', 'invoicing'),
476 476
             'type' => 'textarea',
477
-            'std' => __( 'Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing' ),
477
+            'std' => __('Make your payment directly into our bank account. Please use your Invoice ID as the payment reference. Your invoice won\'t be processed until the funds have cleared in our account.', 'invoicing'),
478 478
             'cols' => 37,
479 479
             'rows' => 5
480 480
         );
481 481
         
482 482
     return $setting;
483 483
 }
484
-add_filter( 'wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1 );
484
+add_filter('wpinv_gateway_settings_bank_transfer', 'wpinv_gateway_settings_bank_transfer', 10, 1);
485 485
 
486 486
 // Authorize.Net settings
487
-function wpinv_gateway_settings_authorizenet( $setting ) {
488
-    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __( '( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing' );
489
-    $setting['authorizenet_desc']['std'] = __( 'Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing' );
487
+function wpinv_gateway_settings_authorizenet($setting) {
488
+    $setting['authorizenet_active']['desc'] = $setting['authorizenet_active']['desc'] . ' ' . __('( currencies supported: AUD, CAD, CHF, DKK, EUR, GBP, JPY, NOK, NZD, PLN, SEK, USD, ZAR )', 'invoicing');
489
+    $setting['authorizenet_desc']['std'] = __('Pay using a Authorize.Net to process credit card / debit card transactions.', 'invoicing');
490 490
     
491 491
     $setting['authorizenet_sandbox'] = array(
492 492
             'type' => 'checkbox',
493 493
             'id'   => 'authorizenet_sandbox',
494
-            'name' => __( 'Authorize.Net Test Mode', 'invoicing' ),
495
-            'desc' => __( 'Enable Authorize.Net test mode to test payments.', 'invoicing' ),
494
+            'name' => __('Authorize.Net Test Mode', 'invoicing'),
495
+            'desc' => __('Enable Authorize.Net test mode to test payments.', 'invoicing'),
496 496
             'std'  => 1
497 497
         );
498 498
         
499 499
     $setting['authorizenet_login_id'] = array(
500 500
             'type' => 'text',
501 501
             'id'   => 'authorizenet_login_id',
502
-            'name' => __( 'API Login ID', 'invoicing' ),
503
-            'desc' => __( 'API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing' ),
502
+            'name' => __('API Login ID', 'invoicing'),
503
+            'desc' => __('API Login ID can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 2j4rBekUnD', 'invoicing'),
504 504
             'std' => '2j4rBekUnD',
505 505
         );
506 506
     
507 507
     $setting['authorizenet_transaction_key'] = array(
508 508
             'type' => 'text',
509 509
             'id'   => 'authorizenet_transaction_key',
510
-            'name' => __( 'Transaction Key', 'invoicing' ),
511
-            'desc' => __( 'Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing' ),
510
+            'name' => __('Transaction Key', 'invoicing'),
511
+            'desc' => __('Transaction Key can be obtained from Authorize.Net Account > Settings > Security Settings > General Security Settings > API Credentials & Keys. Example : 4vyBUOJgR74679xa', 'invoicing'),
512 512
             'std' => '4vyBUOJgR74679xa',
513 513
         );
514 514
         
515 515
     $setting['authorizenet_md5_hash'] = array(
516 516
             'type' => 'text',
517 517
             'id'   => 'authorizenet_md5_hash',
518
-            'name' => __( 'MD5-Hash', 'invoicing' ),
519
-            'desc' => __( 'The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing' ),
518
+            'name' => __('MD5-Hash', 'invoicing'),
519
+            'desc' => __('The MD5 Hash security feature allows you to authenticate transaction responses from the Authorize.Net. If you are accepting recurring payments then md5 hash will helps to validate response from Authorize.net. It can be obtained from Authorize.Net Account > Settings > Security Settings > General Settings > MD5 Hash.', 'invoicing'),
520 520
             'std' => '',
521 521
         );
522 522
         
523 523
     $setting['authorizenet_ipn_url'] = array(
524 524
             'type' => 'ipn_url',
525 525
             'id'   => 'authorizenet_ipn_url',
526
-            'name' => __( 'Silent Post URL', 'invoicing' ),
527
-            'std' => wpinv_get_ipn_url( 'authorizenet' ),
528
-            'desc' => __( 'If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing' ),
526
+            'name' => __('Silent Post URL', 'invoicing'),
527
+            'std' => wpinv_get_ipn_url('authorizenet'),
528
+            'desc' => __('If you are accepting recurring payments then you must set this url at Authorize.Net Account > Settings > Transaction Format Settings > Transaction Response Settings > Silent Post URL.', 'invoicing'),
529 529
             'size' => 'large',
530 530
             'custom' => 'authorizenet',
531 531
             'readonly' => true
@@ -533,25 +533,25 @@  discard block
 block discarded – undo
533 533
         
534 534
     return $setting;
535 535
 }
536
-add_filter( 'wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1 );
536
+add_filter('wpinv_gateway_settings_authorizenet', 'wpinv_gateway_settings_authorizenet', 10, 1);
537 537
 
538 538
 // Worldpay settings
539
-function wpinv_gateway_settings_worldpay( $setting ) {
540
-    $setting['worldpay_desc']['std'] = __( 'Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing' );
539
+function wpinv_gateway_settings_worldpay($setting) {
540
+    $setting['worldpay_desc']['std'] = __('Pay using a Worldpay account to process credit card / debit card transactions.', 'invoicing');
541 541
     
542 542
     $setting['worldpay_sandbox'] = array(
543 543
             'type' => 'checkbox',
544 544
             'id'   => 'worldpay_sandbox',
545
-            'name' => __( 'Worldpay Test Mode', 'invoicing' ),
546
-            'desc' => __( 'This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing' ),
545
+            'name' => __('Worldpay Test Mode', 'invoicing'),
546
+            'desc' => __('This provides a special Test Environment to enable you to test your installation and integration to your website before going live.', 'invoicing'),
547 547
             'std'  => 1
548 548
         );
549 549
         
550 550
     $setting['worldpay_instId'] = array(
551 551
             'type' => 'text',
552 552
             'id'   => 'worldpay_instId',
553
-            'name' => __( 'Installation Id', 'invoicing' ),
554
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
553
+            'name' => __('Installation Id', 'invoicing'),
554
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
555 555
             'std' => '211616',
556 556
         );
557 557
     /*
@@ -567,9 +567,9 @@  discard block
 block discarded – undo
567 567
     $setting['worldpay_ipn_url'] = array(
568 568
             'type' => 'ipn_url',
569 569
             'id'   => 'worldpay_ipn_url',
570
-            'name' => __( 'Worldpay Callback Url', 'invoicing' ),
571
-            'std' => wpinv_get_ipn_url( 'worldpay' ),
572
-            'desc' => wp_sprintf( __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing' ), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url( 'worldpay' ) . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>' ),
570
+            'name' => __('Worldpay Callback Url', 'invoicing'),
571
+            'std' => wpinv_get_ipn_url('worldpay'),
572
+            'desc' => wp_sprintf(__('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and type "%s" or "%s" for a dynamic payment response.', 'invoicing'), '<font style="color:#000;font-style:normal">' . wpinv_get_ipn_url('worldpay') . '</font>', '<font style="color:#000;font-style:normal">&lt;wpdisplay item=MC_callback&gt;</font>'),
573 573
             'size' => 'large',
574 574
             'custom' => 'worldpay',
575 575
             'readonly' => true
@@ -577,94 +577,94 @@  discard block
 block discarded – undo
577 577
         
578 578
     return $setting;
579 579
 }
580
-add_filter( 'wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1 );
580
+add_filter('wpinv_gateway_settings_worldpay', 'wpinv_gateway_settings_worldpay', 10, 1);
581 581
 
582
-function wpinv_ipn_url_callback( $args ) {    
583
-    $sanitize_id = wpinv_sanitize_key( $args['id'] );
582
+function wpinv_ipn_url_callback($args) {    
583
+    $sanitize_id = wpinv_sanitize_key($args['id']);
584 584
     
585 585
     $attrs = $args['readonly'] ? ' readonly' : '';
586 586
 
587
-    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr( $args['std'] ) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
588
-    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">'  . $args['desc'] . '</label>';
587
+    $html = '<input style="background-color:#fefefe" type="text" ' . $attrs . ' value="' . esc_attr($args['std']) . '" name="wpinv_settings[' . $sanitize_id . ']" id="wpinv_settings[' . $sanitize_id . ']" class="large-text">';
588
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']">' . $args['desc'] . '</label>';
589 589
 
590 590
     echo $html;
591 591
 }
592 592
 
593
-function wpinv_is_test_mode( $gateway = '' ) {
594
-    if ( empty( $gateway ) ) {
593
+function wpinv_is_test_mode($gateway = '') {
594
+    if (empty($gateway)) {
595 595
         return false;
596 596
     }
597 597
     
598
-    $is_test_mode = wpinv_get_option( $gateway . '_sandbox', false );
598
+    $is_test_mode = wpinv_get_option($gateway . '_sandbox', false);
599 599
     
600
-    return apply_filters( 'wpinv_is_test_mode', $is_test_mode, $gateway );
600
+    return apply_filters('wpinv_is_test_mode', $is_test_mode, $gateway);
601 601
 }
602 602
 
603
-function wpinv_get_ipn_url( $gateway = '', $args = array() ) {
604
-    $data = array( 'wpi-listener' => 'IPN' );
603
+function wpinv_get_ipn_url($gateway = '', $args = array()) {
604
+    $data = array('wpi-listener' => 'IPN');
605 605
     
606
-    if ( !empty( $gateway ) ) {
607
-        $data['wpi-gateway'] = wpinv_sanitize_key( $gateway );
606
+    if (!empty($gateway)) {
607
+        $data['wpi-gateway'] = wpinv_sanitize_key($gateway);
608 608
     }
609 609
     
610
-    $args = !empty( $args ) && is_array( $args ) ? array_merge( $data, $args ) : $data;
610
+    $args = !empty($args) && is_array($args) ? array_merge($data, $args) : $data;
611 611
     
612
-    $ipn_url = add_query_arg( $args,  home_url( 'index.php' ) );
612
+    $ipn_url = add_query_arg($args, home_url('index.php'));
613 613
     
614
-    return apply_filters( 'wpinv_ipn_url', $ipn_url );
614
+    return apply_filters('wpinv_ipn_url', $ipn_url);
615 615
 }
616 616
 
617 617
 function wpinv_listen_for_payment_ipn() {
618 618
     // Regular PayPal IPN
619
-    if ( isset( $_GET['wpi-listener'] ) && $_GET['wpi-listener'] == 'IPN' ) {
620
-        do_action( 'wpinv_verify_payment_ipn' );
619
+    if (isset($_GET['wpi-listener']) && $_GET['wpi-listener'] == 'IPN') {
620
+        do_action('wpinv_verify_payment_ipn');
621 621
         
622
-        if ( !empty( $_GET['wpi-gateway'] ) ) {
623
-            wpinv_error_log( sanitize_text_field( $_GET['wpi-gateway'] ), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__ );
624
-            do_action( 'wpinv_verify_' . sanitize_text_field( $_GET['wpi-gateway'] ) . '_ipn' );
622
+        if (!empty($_GET['wpi-gateway'])) {
623
+            wpinv_error_log(sanitize_text_field($_GET['wpi-gateway']), 'wpinv_listen_for_payment_ipn()', __FILE__, __LINE__);
624
+            do_action('wpinv_verify_' . sanitize_text_field($_GET['wpi-gateway']) . '_ipn');
625 625
         }
626 626
     }
627 627
 }
628
-add_action( 'init', 'wpinv_listen_for_payment_ipn' );
628
+add_action('init', 'wpinv_listen_for_payment_ipn');
629 629
 
630 630
 function wpinv_get_bank_instructions() {
631
-    $bank_instructions = wpinv_get_option( 'bank_transfer_info' );
631
+    $bank_instructions = wpinv_get_option('bank_transfer_info');
632 632
     
633
-    return apply_filters( 'wpinv_bank_instructions', $bank_instructions );
633
+    return apply_filters('wpinv_bank_instructions', $bank_instructions);
634 634
 }
635 635
 
636
-function wpinv_get_bank_info( $filtered = false ) {
636
+function wpinv_get_bank_info($filtered = false) {
637 637
     $bank_fields = array(
638
-        'bank_transfer_ac_name' => __( 'Account Name', 'invoicing' ),
639
-        'bank_transfer_ac_no' => __( 'Account Number', 'invoicing' ),
640
-        'bank_transfer_bank_name' => __( 'Bank Name', 'invoicing' ),
641
-        'bank_transfer_ifsc' => __( 'IFSC code', 'invoicing' ),
642
-        'bank_transfer_iban' => __( 'IBAN', 'invoicing' ),
643
-        'bank_transfer_bic' => __( 'BIC/Swift code', 'invoicing' )
638
+        'bank_transfer_ac_name' => __('Account Name', 'invoicing'),
639
+        'bank_transfer_ac_no' => __('Account Number', 'invoicing'),
640
+        'bank_transfer_bank_name' => __('Bank Name', 'invoicing'),
641
+        'bank_transfer_ifsc' => __('IFSC code', 'invoicing'),
642
+        'bank_transfer_iban' => __('IBAN', 'invoicing'),
643
+        'bank_transfer_bic' => __('BIC/Swift code', 'invoicing')
644 644
     );
645 645
     
646 646
     $bank_info = array();
647
-    foreach ( $bank_fields as $field => $label ) {
648
-        if ( $filtered && !( $value = wpinv_get_option( $field ) ) ) {
647
+    foreach ($bank_fields as $field => $label) {
648
+        if ($filtered && !($value = wpinv_get_option($field))) {
649 649
             continue;
650 650
         }
651 651
         
652
-        $bank_info[$field] = array( 'label' => $label, 'value' => $value );
652
+        $bank_info[$field] = array('label' => $label, 'value' => $value);
653 653
     }
654 654
     
655
-    return apply_filters( 'wpinv_bank_info', $bank_info, $filtered );
655
+    return apply_filters('wpinv_bank_info', $bank_info, $filtered);
656 656
 }
657 657
 
658
-function wpinv_process_before_send_to_gateway( $invoice, $invoice_data = array() ) {
659
-    if ( !empty( $invoice ) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring( true ) ) {        
658
+function wpinv_process_before_send_to_gateway($invoice, $invoice_data = array()) {
659
+    if (!empty($invoice) && $invoice->is_recurring() && $subscription_item = $invoice->get_recurring(true)) {        
660 660
         $args                          = array();
661 661
         $args['item_id']               = $subscription_item->ID;
662
-        $args['initial_amount']        = wpinv_round_amount( $invoice->get_total() );
663
-        $args['recurring_amount']      = wpinv_round_amount( $invoice->get_recurring_details( 'total' ) );
662
+        $args['initial_amount']        = wpinv_round_amount($invoice->get_total());
663
+        $args['recurring_amount']      = wpinv_round_amount($invoice->get_recurring_details('total'));
664 664
         $args['currency']              = $invoice->get_currency();
665 665
         $args['period']                = $subscription_item->get_recurring_period();
666 666
         $args['interval']              = $subscription_item->get_recurring_interval();
667
-        if ( $subscription_item->has_free_trial() ) {
667
+        if ($subscription_item->has_free_trial()) {
668 668
             $args['trial_period']      = $subscription_item->get_trial_period();
669 669
             $args['trial_interval']    = $subscription_item->get_trial_interval();
670 670
         } else {
@@ -673,25 +673,25 @@  discard block
 block discarded – undo
673 673
         }
674 674
         $args['bill_times']            = (int)$subscription_item->get_recurring_limit();
675 675
         
676
-        $invoice->update_subscription( $args );
676
+        $invoice->update_subscription($args);
677 677
     }
678 678
 }
679
-add_action( 'wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2 );
679
+add_action('wpinv_checkout_before_send_to_gateway', 'wpinv_process_before_send_to_gateway', 10, 2);
680 680
 
681
-function wpinv_get_post_data( $method = 'request' ) {
681
+function wpinv_get_post_data($method = 'request') {
682 682
     $data       = array();
683 683
     $request    = $_REQUEST;
684 684
     
685
-    if ( $method == 'post' ) {
686
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'POST' ) {
685
+    if ($method == 'post') {
686
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'POST') {
687 687
             return $data;
688 688
         }
689 689
         
690 690
         $request = $_POST;
691 691
     }
692 692
     
693
-    if ( $method == 'get' ) {
694
-        if ( isset( $_SERVER['REQUEST_METHOD'] ) && $_SERVER['REQUEST_METHOD'] != 'GET' ) {
693
+    if ($method == 'get') {
694
+        if (isset($_SERVER['REQUEST_METHOD']) && $_SERVER['REQUEST_METHOD'] != 'GET') {
695 695
             return $data;
696 696
         }
697 697
         
@@ -702,11 +702,11 @@  discard block
 block discarded – undo
702 702
     $post_data = '';
703 703
     
704 704
     // Fallback just in case post_max_size is lower than needed
705
-    if ( ini_get( 'allow_url_fopen' ) ) {
706
-        $post_data = file_get_contents( 'php://input' );
705
+    if (ini_get('allow_url_fopen')) {
706
+        $post_data = file_get_contents('php://input');
707 707
     } else {
708 708
         // If allow_url_fopen is not enabled, then make sure that post_max_size is large enough
709
-        ini_set( 'post_max_size', '12M' );
709
+        ini_set('post_max_size', '12M');
710 710
     }
711 711
     // Start the encoded data collection with notification command
712 712
     $encoded_data = 'cmd=_notify-validate';
@@ -715,58 +715,58 @@  discard block
 block discarded – undo
715 715
     $arg_separator = wpinv_get_php_arg_separator_output();
716 716
 
717 717
     // Verify there is a post_data
718
-    if ( $post_data || strlen( $post_data ) > 0 ) {
718
+    if ($post_data || strlen($post_data) > 0) {
719 719
         // Append the data
720 720
         $encoded_data .= $arg_separator . $post_data;
721 721
     } else {
722 722
         // Check if POST is empty
723
-        if ( empty( $request ) ) {
723
+        if (empty($request)) {
724 724
             // Nothing to do
725 725
             return;
726 726
         } else {
727 727
             // Loop through each POST
728
-            foreach ( $request as $key => $value ) {
728
+            foreach ($request as $key => $value) {
729 729
                 // Encode the value and append the data
730
-                $encoded_data .= $arg_separator . "$key=" . urlencode( $value );
730
+                $encoded_data .= $arg_separator . "$key=" . urlencode($value);
731 731
             }
732 732
         }
733 733
     }
734 734
 
735 735
     // Convert collected post data to an array
736
-    parse_str( $encoded_data, $data );
736
+    parse_str($encoded_data, $data);
737 737
 
738
-    foreach ( $data as $key => $value ) {
739
-        if ( false !== strpos( $key, 'amp;' ) ) {
740
-            $new_key = str_replace( '&amp;', '&', $key );
741
-            $new_key = str_replace( 'amp;', '&' , $new_key );
738
+    foreach ($data as $key => $value) {
739
+        if (false !== strpos($key, 'amp;')) {
740
+            $new_key = str_replace('&amp;', '&', $key);
741
+            $new_key = str_replace('amp;', '&', $new_key);
742 742
 
743
-            unset( $data[ $key ] );
744
-            $data[ $new_key ] = sanitize_text_field( $value );
743
+            unset($data[$key]);
744
+            $data[$new_key] = sanitize_text_field($value);
745 745
         }
746 746
     }
747 747
     
748 748
     return $data;
749 749
 }
750 750
 
751
-function wpinv_gateway_support_subscription( $gateway ) {
751
+function wpinv_gateway_support_subscription($gateway) {
752 752
     $return = false;
753 753
     
754
-    if ( wpinv_is_gateway_active( $gateway ) ) {
755
-        $return = apply_filters( 'wpinv_' . $gateway . '_support_subscription', false );
754
+    if (wpinv_is_gateway_active($gateway)) {
755
+        $return = apply_filters('wpinv_' . $gateway . '_support_subscription', false);
756 756
     }
757 757
     
758 758
     return $return;
759 759
 }
760 760
 
761
-function wpinv_payment_gateways_on_cart( $gateways = array() ) {
762
-    if ( !empty( $gateways ) && wpinv_cart_has_recurring_item() ) {
763
-        foreach ( $gateways as $gateway => $info ) {
764
-            if ( !wpinv_gateway_support_subscription( $gateway ) ) {
765
-                unset( $gateways[$gateway] );
761
+function wpinv_payment_gateways_on_cart($gateways = array()) {
762
+    if (!empty($gateways) && wpinv_cart_has_recurring_item()) {
763
+        foreach ($gateways as $gateway => $info) {
764
+            if (!wpinv_gateway_support_subscription($gateway)) {
765
+                unset($gateways[$gateway]);
766 766
             }
767 767
         }
768 768
     }
769 769
     
770 770
     return $gateways;
771 771
 }
772
-add_filter( 'wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1 );
773 772
\ No newline at end of file
773
+add_filter('wpinv_payment_gateways_on_cart', 'wpinv_payment_gateways_on_cart', 10, 1);
774 774
\ No newline at end of file
Please login to merge, or discard this patch.