Passed
Push — master ( 65b60e...ed9391 )
by Brian
10:46
created
includes/wpinv-address-functions.php 1 patch
Spacing   +142 added lines, -142 removed lines patch added patch discarded remove patch
@@ -7,15 +7,15 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 // MUST have WordPress.
10
-if ( ! defined( 'WPINC' ) ) {
10
+if (!defined('WPINC')) {
11 11
     exit;
12 12
 }
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+	$country = wpinv_get_option('default_country', 'UK');
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+	return apply_filters('wpinv_default_country', $country);
19 19
 }
20 20
 
21 21
 /**
@@ -23,8 +23,8 @@  discard block
 block discarded – undo
23 23
  *
24 24
  * @return string
25 25
  */
26
-function getpaid_get_ip_country( $ip_address = '' ) {
27
-    $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true );
26
+function getpaid_get_ip_country($ip_address = '') {
27
+    $country = GetPaid_Geolocation::geolocate_ip($ip_address, true);
28 28
     return $country['country'];
29 29
 }
30 30
 
@@ -34,59 +34,59 @@  discard block
 block discarded – undo
34 34
  * @param string $country The country code to sanitize
35 35
  * @return array
36 36
  */
37
-function wpinv_sanitize_country( $country ) {
37
+function wpinv_sanitize_country($country) {
38 38
 
39 39
 	// Enure the country is specified
40
-    if ( empty( $country ) ) {
40
+    if (empty($country)) {
41 41
         $country = wpinv_get_default_country();
42 42
     }
43
-    return trim( wpinv_utf8_strtoupper( $country ) );
43
+    return trim(wpinv_utf8_strtoupper($country));
44 44
 
45 45
 }
46 46
 
47
-function wpinv_is_base_country( $country ) {
47
+function wpinv_is_base_country($country) {
48 48
     $base_country = wpinv_get_default_country();
49 49
 
50
-    if ( $base_country === 'UK' ) {
50
+    if ($base_country === 'UK') {
51 51
         $base_country = 'GB';
52 52
     }
53
-    if ( $country == 'UK' ) {
53
+    if ($country == 'UK') {
54 54
         $country = 'GB';
55 55
     }
56 56
 
57
-    return ( $country && $country === $base_country ) ? true : false;
57
+    return ($country && $country === $base_country) ? true : false;
58 58
 }
59 59
 
60
-function wpinv_country_name( $country_code = '' ) {
60
+function wpinv_country_name($country_code = '') {
61 61
     $countries = wpinv_get_country_list();
62 62
     $country_code = $country_code == 'UK' ? 'GB' : $country_code;
63
-    $country = isset( $countries[ $country_code ] ) ? $countries[ $country_code ] : $country_code;
63
+    $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code;
64 64
 
65
-    return apply_filters( 'wpinv_country_name', $country, $country_code );
65
+    return apply_filters('wpinv_country_name', $country, $country_code);
66 66
 }
67 67
 
68 68
 function wpinv_get_default_state() {
69
-	$state = wpinv_get_option( 'default_state', '' );
69
+	$state = wpinv_get_option('default_state', '');
70 70
 
71
-	return apply_filters( 'wpinv_default_state', $state );
71
+	return apply_filters('wpinv_default_state', $state);
72 72
 }
73 73
 
74
-function wpinv_state_name( $state_code = '', $country_code = '' ) {
74
+function wpinv_state_name($state_code = '', $country_code = '') {
75 75
     $state = $state_code;
76 76
 
77
-    if ( ! empty( $country_code ) ) {
78
-        $states = wpinv_get_country_states( $country_code );
77
+    if (!empty($country_code)) {
78
+        $states = wpinv_get_country_states($country_code);
79 79
 
80
-        $state = ! empty( $states ) && isset( $states[ $state_code ] ) ? $states[ $state_code ] : $state;
80
+        $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state;
81 81
     }
82 82
 
83
-    return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code );
83
+    return apply_filters('wpinv_state_name', $state, $state_code, $country_code);
84 84
 }
85 85
 
86 86
 function wpinv_store_address() {
87
-    $address = wpinv_get_option( 'store_address', '' );
87
+    $address = wpinv_get_option('store_address', '');
88 88
 
89
-    return apply_filters( 'wpinv_store_address', $address );
89
+    return apply_filters('wpinv_store_address', $address);
90 90
 }
91 91
 
92 92
 /**
@@ -94,24 +94,24 @@  discard block
 block discarded – undo
94 94
  *
95 95
  * @param WPInv_Invoice $invoice
96 96
  */
97
-function getpaid_maybe_add_default_address( &$invoice ) {
97
+function getpaid_maybe_add_default_address(&$invoice) {
98 98
 
99 99
     $user_id = $invoice->get_user_id();
100 100
 
101 101
     // Abort if the invoice belongs to no one.
102
-    if ( empty( $user_id ) ) {
102
+    if (empty($user_id)) {
103 103
         return;
104 104
     }
105 105
 
106 106
     // Fill in defaults whenever necessary.
107
-    foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) {
107
+    foreach (wpinv_get_user_address($user_id) as $key => $value) {
108 108
 
109
-        if ( is_callable( $invoice, "get_$key" ) ) {
110
-            $current = call_user_func( array( $invoice, "get_$key" ) );
109
+        if (is_callable($invoice, "get_$key")) {
110
+            $current = call_user_func(array($invoice, "get_$key"));
111 111
 
112
-            if ( empty( $current ) ) {
112
+            if (empty($current)) {
113 113
                 $method = "set_$key";
114
-                $invoice->$method( $value );
114
+                $invoice->$method($value);
115 115
             }
116 116
 }
117 117
 }
@@ -128,22 +128,22 @@  discard block
 block discarded – undo
128 128
     $address_fields = apply_filters(
129 129
         'getpaid_user_address_fields',
130 130
         array(
131
-            'first_name' => __( 'First Name', 'invoicing' ),
132
-            'last_name'  => __( 'Last Name', 'invoicing' ),
133
-            'address'    => __( 'Address', 'invoicing' ),
134
-            'city'       => __( 'City', 'invoicing' ),
135
-            'country'    => __( 'Country', 'invoicing' ),
136
-            'state'      => __( 'State', 'invoicing' ),
137
-            'zip'        => __( 'Zip/Postal Code', 'invoicing' ),
138
-            'phone'      => __( 'Phone Number', 'invoicing' ),
139
-            'company'    => __( 'Company', 'invoicing' ),
140
-            'company_id' => __( 'Company ID', 'invoicing' ),
141
-            'vat_number' => __( 'VAT Number', 'invoicing' ),
131
+            'first_name' => __('First Name', 'invoicing'),
132
+            'last_name'  => __('Last Name', 'invoicing'),
133
+            'address'    => __('Address', 'invoicing'),
134
+            'city'       => __('City', 'invoicing'),
135
+            'country'    => __('Country', 'invoicing'),
136
+            'state'      => __('State', 'invoicing'),
137
+            'zip'        => __('Zip/Postal Code', 'invoicing'),
138
+            'phone'      => __('Phone Number', 'invoicing'),
139
+            'company'    => __('Company', 'invoicing'),
140
+            'company_id' => __('Company ID', 'invoicing'),
141
+            'vat_number' => __('VAT Number', 'invoicing'),
142 142
         )
143 143
     );
144 144
 
145
-    if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) && ! wp_doing_ajax() ) {
146
-        unset( $address_fields['vat_number'] );
145
+    if (!wpinv_use_taxes() && isset($address_fields['vat_number']) && !wp_doing_ajax()) {
146
+        unset($address_fields['vat_number']);
147 147
     }
148 148
 
149 149
     return $address_fields;
@@ -154,8 +154,8 @@  discard block
 block discarded – undo
154 154
  *
155 155
  * @return bool
156 156
  */
157
-function getpaid_is_address_field_whitelisted( $key ) {
158
-    return array_key_exists( $key, getpaid_user_address_fields() );
157
+function getpaid_is_address_field_whitelisted($key) {
158
+    return array_key_exists($key, getpaid_user_address_fields());
159 159
 }
160 160
 
161 161
 /**
@@ -165,30 +165,30 @@  discard block
 block discarded – undo
165 165
  *
166 166
  * @param WPInv_Invoice $invoice
167 167
  */
168
-function getpaid_save_invoice_user_address( $invoice ) {
168
+function getpaid_save_invoice_user_address($invoice) {
169 169
 
170 170
     // Retrieve the invoice.
171
-    $invoice = wpinv_get_invoice( $invoice );
171
+    $invoice = wpinv_get_invoice($invoice);
172 172
 
173 173
     // Abort if it does not exist.
174
-    if ( empty( $invoice ) || $invoice->is_renewal() ) {
174
+    if (empty($invoice) || $invoice->is_renewal()) {
175 175
         return;
176 176
     }
177 177
 
178
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
178
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
179 179
 
180
-        if ( is_callable( array( $invoice, "get_$field" ) ) ) {
181
-            $value = call_user_func( array( $invoice, "get_$field" ) );
180
+        if (is_callable(array($invoice, "get_$field"))) {
181
+            $value = call_user_func(array($invoice, "get_$field"));
182 182
 
183 183
             // Only save if it is not empty.
184
-            if ( ! empty( $value ) ) {
185
-                update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value );
184
+            if (!empty($value)) {
185
+                update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value);
186 186
             }
187 187
         }
188 188
     }
189 189
 
190 190
 }
191
-add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' );
191
+add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address');
192 192
 
193 193
 /**
194 194
  * Retrieves a saved user address.
@@ -196,14 +196,14 @@  discard block
 block discarded – undo
196 196
  * @param int $user_id The user id whose address we should get. Defaults to the current user id.
197 197
  * @return array
198 198
  */
199
-function wpinv_get_user_address( $user_id = 0 ) {
199
+function wpinv_get_user_address($user_id = 0) {
200 200
 
201 201
     // Prepare the user id.
202
-    $user_id   = empty( $user_id ) ? get_current_user_id() : $user_id;
203
-    $user_info = get_userdata( $user_id );
202
+    $user_id   = empty($user_id) ? get_current_user_id() : $user_id;
203
+    $user_info = get_userdata($user_id);
204 204
 
205 205
     // Abort if non exists.
206
-    if ( empty( $user_info ) ) {
206
+    if (empty($user_info)) {
207 207
         return array();
208 208
     }
209 209
 
@@ -214,11 +214,11 @@  discard block
 block discarded – undo
214 214
         'display_name' => $user_info->display_name,
215 215
     );
216 216
 
217
-    foreach ( array_keys( getpaid_user_address_fields() ) as $field ) {
218
-        $address[ $field ] = getpaid_get_user_address_field( $user_id, $field );
217
+    foreach (array_keys(getpaid_user_address_fields()) as $field) {
218
+        $address[$field] = getpaid_get_user_address_field($user_id, $field);
219 219
     }
220 220
 
221
-    $address = array_filter( $address );
221
+    $address = array_filter($address);
222 222
 
223 223
     $defaults = array(
224 224
         'first_name' => $user_info->first_name,
@@ -227,7 +227,7 @@  discard block
 block discarded – undo
227 227
         'country'    => wpinv_get_default_country(),
228 228
     );
229 229
 
230
-    return getpaid_array_merge_if_empty( $address, $defaults );
230
+    return getpaid_array_merge_if_empty($address, $defaults);
231 231
 
232 232
 }
233 233
 
@@ -238,7 +238,7 @@  discard block
 block discarded – undo
238 238
  * @param string $field The field to use.
239 239
  * @return string|null
240 240
  */
241
-function getpaid_get_user_address_field( $user_id, $field ) {
241
+function getpaid_get_user_address_field($user_id, $field) {
242 242
 
243 243
     $prefixes = array(
244 244
         '_wpinv_',
@@ -246,15 +246,15 @@  discard block
 block discarded – undo
246 246
         '',
247 247
     );
248 248
 
249
-    foreach ( $prefixes as $prefix ) {
249
+    foreach ($prefixes as $prefix) {
250 250
 
251 251
         // Meta table.
252
-        $value = get_user_meta( $user_id, $prefix . $field, true );
252
+        $value = get_user_meta($user_id, $prefix . $field, true);
253 253
 
254 254
         // UWP table.
255
-        $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value;
255
+        $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value;
256 256
 
257
-        if ( ! empty( $value ) ) {
257
+        if (!empty($value)) {
258 258
             return $value;
259 259
         }
260 260
 }
@@ -270,16 +270,16 @@  discard block
 block discarded – undo
270 270
  * @param string $return What to return.
271 271
  * @return array
272 272
  */
273
-function wpinv_get_continents( $return = 'all' ) {
273
+function wpinv_get_continents($return = 'all') {
274 274
 
275
-    $continents = wpinv_get_data( 'continents' );
275
+    $continents = wpinv_get_data('continents');
276 276
 
277
-    switch ( $return ) {
277
+    switch ($return) {
278 278
         case 'name':
279
-            return wp_list_pluck( $continents, 'name' );
279
+            return wp_list_pluck($continents, 'name');
280 280
             break;
281 281
         case 'countries':
282
-            return wp_list_pluck( $continents, 'countries' );
282
+            return wp_list_pluck($continents, 'countries');
283 283
             break;
284 284
         default:
285 285
             return $continents;
@@ -295,12 +295,12 @@  discard block
 block discarded – undo
295 295
  * @param string $country Country code. If no code is specified, defaults to the default country.
296 296
  * @return string
297 297
  */
298
-function wpinv_get_continent_code_for_country( $country = false ) {
298
+function wpinv_get_continent_code_for_country($country = false) {
299 299
 
300
-    $country = wpinv_sanitize_country( $country );
300
+    $country = wpinv_sanitize_country($country);
301 301
 
302
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
303
-		if ( false !== array_search( $country, $countries, true ) ) {
302
+	foreach (wpinv_get_continents('countries') as $continent_code => $countries) {
303
+		if (false !== array_search($country, $countries, true)) {
304 304
 			return $continent_code;
305 305
 		}
306 306
 	}
@@ -316,13 +316,13 @@  discard block
 block discarded – undo
316 316
  * @param string $country Country code. If no code is specified, defaults to the default country.
317 317
  * @return array
318 318
  */
319
-function wpinv_get_country_calling_code( $country = null ) {
319
+function wpinv_get_country_calling_code($country = null) {
320 320
 
321
-    $country = wpinv_sanitize_country( $country );
322
-    $codes   = wpinv_get_data( 'phone-codes' );
323
-    $code    = isset( $codes[ $country ] ) ? $codes[ $country ] : '';
321
+    $country = wpinv_sanitize_country($country);
322
+    $codes   = wpinv_get_data('phone-codes');
323
+    $code    = isset($codes[$country]) ? $codes[$country] : '';
324 324
 
325
-    if ( is_array( $code ) ) {
325
+    if (is_array($code)) {
326 326
         return $code[0];
327 327
     }
328 328
     return $code;
@@ -335,8 +335,8 @@  discard block
 block discarded – undo
335 335
  * @param bool $first_empty Whether or not the first item in the list should be empty
336 336
  * @return array
337 337
  */
338
-function wpinv_get_country_list( $first_empty = false ) {
339
-    return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty );
338
+function wpinv_get_country_list($first_empty = false) {
339
+    return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty);
340 340
 }
341 341
 
342 342
 /**
@@ -346,22 +346,22 @@  discard block
 block discarded – undo
346 346
  * @param bool $first_empty Whether or not the first item in the list should be empty
347 347
  * @return array
348 348
  */
349
-function wpinv_get_country_states( $country = null, $first_empty = false ) {
349
+function wpinv_get_country_states($country = null, $first_empty = false) {
350 350
 
351 351
     // Prepare the country.
352
-    $country = wpinv_sanitize_country( $country );
352
+    $country = wpinv_sanitize_country($country);
353 353
 
354 354
     // Fetch all states.
355
-    $all_states = wpinv_get_data( 'states' );
355
+    $all_states = wpinv_get_data('states');
356 356
 
357 357
     // Fetch the specified country's states.
358
-    $states     = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array();
359
-    $states     = apply_filters( "wpinv_{$country}_states", $states );
360
-    $states     = apply_filters( 'wpinv_country_states', $states, $country );
358
+    $states     = isset($all_states[$country]) ? $all_states[$country] : array();
359
+    $states     = apply_filters("wpinv_{$country}_states", $states);
360
+    $states     = apply_filters('wpinv_country_states', $states, $country);
361 361
 
362
-    asort( $states );
362
+    asort($states);
363 363
 
364
-    return wpinv_maybe_add_empty_option( $states, $first_empty );
364
+    return wpinv_maybe_add_empty_option($states, $first_empty);
365 365
 }
366 366
 
367 367
 /**
@@ -371,7 +371,7 @@  discard block
 block discarded – undo
371 371
  * @return array
372 372
  */
373 373
 function wpinv_get_us_states_list() {
374
-    return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) );
374
+    return apply_filters('wpinv_usa_states', wpinv_get_country_states('US'));
375 375
 }
376 376
 
377 377
 /**
@@ -381,7 +381,7 @@  discard block
 block discarded – undo
381 381
  * @return array
382 382
  */
383 383
 function wpinv_get_canada_states_list() {
384
-    return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) );
384
+    return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA'));
385 385
 }
386 386
 
387 387
 /**
@@ -391,7 +391,7 @@  discard block
 block discarded – undo
391 391
  * @return array
392 392
  */
393 393
 function wpinv_get_australia_states_list() {
394
-    return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) );
394
+    return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU'));
395 395
 }
396 396
 
397 397
 /**
@@ -401,7 +401,7 @@  discard block
 block discarded – undo
401 401
  * @return array
402 402
  */
403 403
 function wpinv_get_bangladesh_states_list() {
404
-    return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) );
404
+    return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD'));
405 405
 }
406 406
 
407 407
 /**
@@ -411,7 +411,7 @@  discard block
 block discarded – undo
411 411
  * @return array
412 412
  */
413 413
 function wpinv_get_brazil_states_list() {
414
-    return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) );
414
+    return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR'));
415 415
 }
416 416
 
417 417
 /**
@@ -421,7 +421,7 @@  discard block
 block discarded – undo
421 421
  * @return array
422 422
  */
423 423
 function wpinv_get_bulgaria_states_list() {
424
-    return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) );
424
+    return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG'));
425 425
 }
426 426
 
427 427
 /**
@@ -431,7 +431,7 @@  discard block
 block discarded – undo
431 431
  * @return array
432 432
  */
433 433
 function wpinv_get_hong_kong_states_list() {
434
-    return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) );
434
+    return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK'));
435 435
 }
436 436
 
437 437
 /**
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
  * @return array
442 442
  */
443 443
 function wpinv_get_hungary_states_list() {
444
-    return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) );
444
+    return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU'));
445 445
 }
446 446
 
447 447
 /**
@@ -451,7 +451,7 @@  discard block
 block discarded – undo
451 451
  * @return array
452 452
  */
453 453
 function wpinv_get_japan_states_list() {
454
-    return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) );
454
+    return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP'));
455 455
 }
456 456
 
457 457
 /**
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
  * @return array
462 462
  */
463 463
 function wpinv_get_china_states_list() {
464
-    return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) );
464
+    return apply_filters('wpinv_china_states', wpinv_get_country_states('CN'));
465 465
 }
466 466
 
467 467
 /**
@@ -471,7 +471,7 @@  discard block
 block discarded – undo
471 471
  * @return array
472 472
  */
473 473
 function wpinv_get_new_zealand_states_list() {
474
-    return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) );
474
+    return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ'));
475 475
 }
476 476
 
477 477
 /**
@@ -481,7 +481,7 @@  discard block
 block discarded – undo
481 481
  * @return array
482 482
  */
483 483
 function wpinv_get_peru_states_list() {
484
-    return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) );
484
+    return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE'));
485 485
 }
486 486
 
487 487
 /**
@@ -491,7 +491,7 @@  discard block
 block discarded – undo
491 491
  * @return array
492 492
  */
493 493
 function wpinv_get_indonesia_states_list() {
494
-    return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) );
494
+    return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID'));
495 495
 }
496 496
 
497 497
 /**
@@ -501,7 +501,7 @@  discard block
 block discarded – undo
501 501
  * @return array
502 502
  */
503 503
 function wpinv_get_india_states_list() {
504
-    return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) );
504
+    return apply_filters('wpinv_india_states', wpinv_get_country_states('IN'));
505 505
 }
506 506
 
507 507
 /**
@@ -511,7 +511,7 @@  discard block
 block discarded – undo
511 511
  * @return array
512 512
  */
513 513
 function wpinv_get_iran_states_list() {
514
-    return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) );
514
+    return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR'));
515 515
 }
516 516
 
517 517
 /**
@@ -521,7 +521,7 @@  discard block
 block discarded – undo
521 521
  * @return array
522 522
  */
523 523
 function wpinv_get_italy_states_list() {
524
-    return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) );
524
+    return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT'));
525 525
 }
526 526
 
527 527
 /**
@@ -531,7 +531,7 @@  discard block
 block discarded – undo
531 531
  * @return array
532 532
  */
533 533
 function wpinv_get_malaysia_states_list() {
534
-    return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) );
534
+    return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY'));
535 535
 }
536 536
 
537 537
 /**
@@ -541,7 +541,7 @@  discard block
 block discarded – undo
541 541
  * @return array
542 542
  */
543 543
 function wpinv_get_mexico_states_list() {
544
-    return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) );
544
+    return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX'));
545 545
 }
546 546
 
547 547
 /**
@@ -551,7 +551,7 @@  discard block
 block discarded – undo
551 551
  * @return array
552 552
  */
553 553
 function wpinv_get_nepal_states_list() {
554
-    return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) );
554
+    return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP'));
555 555
 }
556 556
 
557 557
 /**
@@ -561,7 +561,7 @@  discard block
 block discarded – undo
561 561
  * @return array
562 562
  */
563 563
 function wpinv_get_south_africa_states_list() {
564
-    return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) );
564
+    return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA'));
565 565
 }
566 566
 
567 567
 /**
@@ -571,7 +571,7 @@  discard block
 block discarded – undo
571 571
  * @return array
572 572
  */
573 573
 function wpinv_get_thailand_states_list() {
574
-    return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) );
574
+    return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH'));
575 575
 }
576 576
 
577 577
 /**
@@ -581,7 +581,7 @@  discard block
 block discarded – undo
581 581
  * @return array
582 582
  */
583 583
 function wpinv_get_turkey_states_list() {
584
-    return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) );
584
+    return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR'));
585 585
 }
586 586
 
587 587
 /**
@@ -591,31 +591,31 @@  discard block
 block discarded – undo
591 591
  * @return array
592 592
  */
593 593
 function wpinv_get_spain_states_list() {
594
-    return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) );
594
+    return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES'));
595 595
 }
596 596
 
597 597
 function wpinv_get_states_field() {
598
-	if ( empty( $_POST['country'] ) ) {
598
+	if (empty($_POST['country'])) {
599 599
 		$_POST['country'] = wpinv_get_default_country();
600 600
 	}
601
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
601
+	$states = wpinv_get_country_states(sanitize_text_field($_POST['country']));
602 602
 
603
-	if ( ! empty( $states ) ) {
604
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
603
+	if (!empty($states)) {
604
+		$sanitized_field_name = sanitize_text_field($_POST['field_name']);
605 605
 
606
-        $class  = isset( $_POST['class'] ) ? esc_attr( sanitize_text_field( $_POST['class'] ) ) : '';
606
+        $class  = isset($_POST['class']) ? esc_attr(sanitize_text_field($_POST['class'])) : '';
607 607
         $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2";
608 608
 
609
-        $args  = array(
609
+        $args = array(
610 610
 			'name'             => $sanitized_field_name,
611 611
 			'id'               => $sanitized_field_name,
612
-			'class'            => implode( ' ', array_unique( explode( ' ', $class ) ) ),
613
-			'options'          => array_merge( array( '' => '' ), $states ),
612
+			'class'            => implode(' ', array_unique(explode(' ', $class))),
613
+			'options'          => array_merge(array('' => ''), $states),
614 614
 			'show_option_all'  => false,
615 615
 			'show_option_none' => false,
616 616
 		);
617 617
 
618
-		wpinv_html_select( $args );
618
+		wpinv_html_select($args);
619 619
 
620 620
 	} else {
621 621
 		echo 'nostates';
@@ -623,10 +623,10 @@  discard block
 block discarded – undo
623 623
 
624 624
 }
625 625
 
626
-function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
627
-    $country = ! empty( $country ) ? $country : wpinv_get_default_country();
626
+function wpinv_default_billing_country($country = '', $user_id = 0) {
627
+    $country = !empty($country) ? $country : wpinv_get_default_country();
628 628
 
629
-    return apply_filters( 'wpinv_default_billing_country', $country, $user_id );
629
+    return apply_filters('wpinv_default_billing_country', $country, $user_id);
630 630
 }
631 631
 
632 632
 /**
@@ -688,9 +688,9 @@  discard block
 block discarded – undo
688 688
  * @see `wpinv_get_invoice_address_replacements`
689 689
  * @return string
690 690
  */
691
-function wpinv_get_full_address_format( $country = false ) {
691
+function wpinv_get_full_address_format($country = false) {
692 692
 
693
-    if ( empty( $country ) ) {
693
+    if (empty($country)) {
694 694
         $country = wpinv_get_default_country();
695 695
     }
696 696
 
@@ -698,7 +698,7 @@  discard block
 block discarded – undo
698 698
 	$formats = wpinv_get_address_formats();
699 699
 
700 700
 	// Get format for the specified country.
701
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
701
+	$format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default'];
702 702
 
703 703
     /**
704 704
 	 * Filters the address format to use on Invoices.
@@ -710,7 +710,7 @@  discard block
 block discarded – undo
710 710
 	 * @param string $format  The address format to use.
711 711
      * @param string $country The country who's address format is being retrieved.
712 712
 	 */
713
-    return apply_filters( 'wpinv_get_full_address_format', $format, $country );
713
+    return apply_filters('wpinv_get_full_address_format', $format, $country);
714 714
 }
715 715
 
716 716
 /**
@@ -721,7 +721,7 @@  discard block
 block discarded – undo
721 721
  * @param array $billing_details customer's billing details
722 722
  * @return array
723 723
  */
724
-function wpinv_get_invoice_address_replacements( $billing_details ) {
724
+function wpinv_get_invoice_address_replacements($billing_details) {
725 725
 
726 726
     $default_args = array(
727 727
         'address'    => '',
@@ -734,15 +734,15 @@  discard block
 block discarded – undo
734 734
 		'company'    => '',
735 735
     );
736 736
 
737
-    $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
737
+    $args    = map_deep(wp_parse_args($billing_details, $default_args), 'trim');
738 738
     $state   = $args['state'];
739 739
     $country = $args['country'];
740 740
 
741 741
     // Handle full country name.
742
-    $full_country = empty( $country ) ? $country : wpinv_country_name( $country );
742
+    $full_country = empty($country) ? $country : wpinv_country_name($country);
743 743
 
744 744
     // Handle full state name.
745
-    $full_state   = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state;
745
+    $full_state   = ($country && $state) ? wpinv_state_name($state, $country) : $state;
746 746
 
747 747
     $args['postcode']    = $args['zip'];
748 748
     $args['name']        = $args['first_name'] . ' ' . $args['last_name'];
@@ -760,14 +760,14 @@  discard block
 block discarded – undo
760 760
 	 * @param array $replacements  The address replacements to use.
761 761
      * @param array $billing_details  The billing details to use.
762 762
 	 */
763
-    $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
763
+    $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details);
764 764
 
765 765
     $return = array();
766 766
 
767
-    foreach ( $replacements as $key => $value ) {
768
-        $value  = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : '';
769
-        $return[ '{{' . $key . '}}' ] = $value;
770
-        $return[ '{{' . $key . '_upper}}' ] = wpinv_utf8_strtoupper( $value );
767
+    foreach ($replacements as $key => $value) {
768
+        $value = is_scalar($value) ? trim(sanitize_text_field($value)) : '';
769
+        $return['{{' . $key . '}}'] = $value;
770
+        $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value);
771 771
     }
772 772
 
773 773
     return $return;
@@ -781,6 +781,6 @@  discard block
 block discarded – undo
781 781
  * @since 1.0.14
782 782
  * @return string
783 783
  */
784
-function wpinv_trim_formatted_address_line( $line ) {
785
-	return trim( $line, ', ' );
784
+function wpinv_trim_formatted_address_line($line) {
785
+	return trim($line, ', ');
786 786
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +874 added lines, -874 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,199 +10,199 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal' => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount' => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'     => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'    => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-		'shipping' => array(
54
-			'initial'   => 0,
55
-			'recurring' => 0,
56
-		),
57
-
58
-	);
59
-
60
-	/**
61
-	 * Sets the associated payment form.
62
-	 *
63
-	 * @var GetPaid_Payment_Form
64
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal' => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount' => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'     => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'    => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+        'shipping' => array(
54
+            'initial'   => 0,
55
+            'recurring' => 0,
56
+        ),
57
+
58
+    );
59
+
60
+    /**
61
+     * Sets the associated payment form.
62
+     *
63
+     * @var GetPaid_Payment_Form
64
+     */
65 65
     protected $payment_form = null;
66 66
 
67 67
     /**
68
-	 * The country for the submission.
69
-	 *
70
-	 * @var string
71
-	 */
72
-	public $country = null;
73
-
74
-    /**
75
-	 * The state for the submission.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var string
79
-	 */
80
-	public $state = null;
81
-
82
-	/**
83
-	 * The invoice associated with the submission.
84
-	 *
85
-	 * @var WPInv_Invoice
86
-	 */
87
-	protected $invoice = null;
88
-
89
-	/**
90
-	 * The recurring item for the submission.
91
-	 *
92
-	 * @var int
93
-	 */
94
-	public $has_recurring = 0;
95
-
96
-	/**
97
-	 * An array of fees for the submission.
98
-	 *
99
-	 * @var array
100
-	 */
101
-	protected $fees = array();
102
-
103
-	/**
104
-	 * An array of discounts for the submission.
105
-	 *
106
-	 * @var array
107
-	 */
108
-	protected $discounts = array();
109
-
110
-	/**
111
-	 * An array of taxes for the submission.
112
-	 *
113
-	 * @var array
114
-	 */
115
-	protected $taxes = array();
116
-
117
-	/**
118
-	 * An array of items for the submission.
119
-	 *
120
-	 * @var GetPaid_Form_Item[]
121
-	 */
122
-	protected $items = array();
123
-
124
-	/**
125
-	 * The last error.
126
-	 *
127
-	 * @var string
128
-	 */
129
-	public $last_error = null;
130
-
131
-	/**
132
-	 * The last error code.
133
-	 *
134
-	 * @var string
135
-	 */
136
-	public $last_error_code = null;
137
-
138
-    /**
139
-	 * Class constructor.
140
-	 *
141
-	 */
142
-	public function __construct() {
143
-
144
-		// Set the state and country to the default state and country.
145
-		$this->country = wpinv_default_billing_country();
146
-		$this->state   = wpinv_get_default_state();
147
-
148
-		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) );
151
-		}
152
-
153
-	}
154
-
155
-	/**
156
-	 * Loads submission data.
157
-	 *
158
-	 * @param array $data
159
-	 */
160
-	public function load_data( $data ) {
161
-
162
-		// Allow plugins to filter the data.
163
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
164
-
165
-		// Cache it...
166
-		$this->data = $data;
167
-
168
-		// Then generate a unique id from the data.
169
-		$this->id   = md5( wp_json_encode( $data ) );
170
-
171
-		// Finally, process the submission.
172
-		try {
173
-
174
-			// Each process is passed an instance of the class (with reference)
175
-			// and should throw an Exception whenever it encounters one.
176
-			$processors = apply_filters(
177
-				'getpaid_payment_form_submission_processors',
178
-				array(
179
-					array( $this, 'process_payment_form' ),
180
-					array( $this, 'process_invoice' ),
181
-					array( $this, 'process_fees' ),
182
-					array( $this, 'process_items' ),
183
-					array( $this, 'process_discount' ),
184
-					array( $this, 'process_taxes' ),
185
-				),
186
-				$this
187
-			);
188
-
189
-			foreach ( $processors as $processor ) {
190
-				call_user_func_array( $processor, array( &$this ) );
191
-			}
68
+     * The country for the submission.
69
+     *
70
+     * @var string
71
+     */
72
+    public $country = null;
73
+
74
+    /**
75
+     * The state for the submission.
76
+     *
77
+     * @since 1.0.19
78
+     * @var string
79
+     */
80
+    public $state = null;
81
+
82
+    /**
83
+     * The invoice associated with the submission.
84
+     *
85
+     * @var WPInv_Invoice
86
+     */
87
+    protected $invoice = null;
88
+
89
+    /**
90
+     * The recurring item for the submission.
91
+     *
92
+     * @var int
93
+     */
94
+    public $has_recurring = 0;
95
+
96
+    /**
97
+     * An array of fees for the submission.
98
+     *
99
+     * @var array
100
+     */
101
+    protected $fees = array();
102
+
103
+    /**
104
+     * An array of discounts for the submission.
105
+     *
106
+     * @var array
107
+     */
108
+    protected $discounts = array();
109
+
110
+    /**
111
+     * An array of taxes for the submission.
112
+     *
113
+     * @var array
114
+     */
115
+    protected $taxes = array();
116
+
117
+    /**
118
+     * An array of items for the submission.
119
+     *
120
+     * @var GetPaid_Form_Item[]
121
+     */
122
+    protected $items = array();
123
+
124
+    /**
125
+     * The last error.
126
+     *
127
+     * @var string
128
+     */
129
+    public $last_error = null;
130
+
131
+    /**
132
+     * The last error code.
133
+     *
134
+     * @var string
135
+     */
136
+    public $last_error_code = null;
137
+
138
+    /**
139
+     * Class constructor.
140
+     *
141
+     */
142
+    public function __construct() {
143
+
144
+        // Set the state and country to the default state and country.
145
+        $this->country = wpinv_default_billing_country();
146
+        $this->state   = wpinv_get_default_state();
147
+
148
+        // Do we have an actual submission?
149
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
+            $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) );
151
+        }
152
+
153
+    }
154
+
155
+    /**
156
+     * Loads submission data.
157
+     *
158
+     * @param array $data
159
+     */
160
+    public function load_data( $data ) {
161
+
162
+        // Allow plugins to filter the data.
163
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
164
+
165
+        // Cache it...
166
+        $this->data = $data;
167
+
168
+        // Then generate a unique id from the data.
169
+        $this->id   = md5( wp_json_encode( $data ) );
170
+
171
+        // Finally, process the submission.
172
+        try {
173
+
174
+            // Each process is passed an instance of the class (with reference)
175
+            // and should throw an Exception whenever it encounters one.
176
+            $processors = apply_filters(
177
+                'getpaid_payment_form_submission_processors',
178
+                array(
179
+                    array( $this, 'process_payment_form' ),
180
+                    array( $this, 'process_invoice' ),
181
+                    array( $this, 'process_fees' ),
182
+                    array( $this, 'process_items' ),
183
+                    array( $this, 'process_discount' ),
184
+                    array( $this, 'process_taxes' ),
185
+                ),
186
+                $this
187
+            );
188
+
189
+            foreach ( $processors as $processor ) {
190
+                call_user_func_array( $processor, array( &$this ) );
191
+            }
192 192
 } catch ( GetPaid_Payment_Exception $e ) {
193
-			$this->last_error      = $e->getMessage();
194
-			$this->last_error_code = $e->getErrorCode();
195
-		} catch ( Exception $e ) {
196
-			$this->last_error      = $e->getMessage();
197
-			$this->last_error_code = $e->getCode();
198
-		}
193
+            $this->last_error      = $e->getMessage();
194
+            $this->last_error_code = $e->getErrorCode();
195
+        } catch ( Exception $e ) {
196
+            $this->last_error      = $e->getMessage();
197
+            $this->last_error_code = $e->getCode();
198
+        }
199 199
 
200
-		// Fired when we are done processing a submission.
201
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
200
+        // Fired when we are done processing a submission.
201
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
202 202
 
203
-	}
203
+    }
204 204
 
205
-	/*
205
+    /*
206 206
 	|--------------------------------------------------------------------------
207 207
 	| Payment Forms.
208 208
 	|--------------------------------------------------------------------------
@@ -211,39 +211,39 @@  discard block
 block discarded – undo
211 211
 	| submission has an active payment form etc.
212 212
     */
213 213
 
214
-	/**
215
-	 * Prepares the submission's payment form.
216
-	 *
217
-	 * @since 1.0.19
218
-	 */
219
-	public function process_payment_form() {
214
+    /**
215
+     * Prepares the submission's payment form.
216
+     *
217
+     * @since 1.0.19
218
+     */
219
+    public function process_payment_form() {
220 220
 
221
-		// Every submission needs an active payment form.
222
-		if ( empty( $this->data['form_id'] ) ) {
223
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
224
-		}
221
+        // Every submission needs an active payment form.
222
+        if ( empty( $this->data['form_id'] ) ) {
223
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
224
+        }
225 225
 
226
-		// Fetch the payment form.
227
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
226
+        // Fetch the payment form.
227
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
228 228
 
229
-		if ( ! $this->payment_form->is_active() ) {
230
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
231
-		}
229
+        if ( ! $this->payment_form->is_active() ) {
230
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
231
+        }
232 232
 
233
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
234
-	}
233
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
234
+    }
235 235
 
236 236
     /**
237
-	 * Returns the payment form.
238
-	 *
239
-	 * @since 1.0.19
240
-	 * @return GetPaid_Payment_Form
241
-	 */
242
-	public function get_payment_form() {
243
-		return $this->payment_form;
244
-	}
237
+     * Returns the payment form.
238
+     *
239
+     * @since 1.0.19
240
+     * @return GetPaid_Payment_Form
241
+     */
242
+    public function get_payment_form() {
243
+        return $this->payment_form;
244
+    }
245 245
 
246
-	/*
246
+    /*
247 247
 	|--------------------------------------------------------------------------
248 248
 	| Invoices.
249 249
 	|--------------------------------------------------------------------------
@@ -252,95 +252,95 @@  discard block
 block discarded – undo
252 252
 	| might be for an existing invoice.
253 253
 	*/
254 254
 
255
-	/**
256
-	 * Prepares the submission's invoice.
257
-	 *
258
-	 * @since 1.0.19
259
-	 */
260
-	public function process_invoice() {
261
-
262
-		// Abort if there is no invoice.
263
-		if ( empty( $this->data['invoice_id'] ) ) {
264
-
265
-			// Check if we are resuming a payment.
266
-			if ( empty( $this->data['maybe_use_invoice'] ) ) {
267
-				return;
268
-			}
269
-
270
-			$invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] );
271
-			if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) {
272
-				return;
273
-			}
274
-		}
275
-
276
-		// If the submission is for an existing invoice, ensure that it exists
277
-		// and that it is not paid for.
278
-		if ( empty( $invoice ) ) {
279
-			$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
280
-		}
255
+    /**
256
+     * Prepares the submission's invoice.
257
+     *
258
+     * @since 1.0.19
259
+     */
260
+    public function process_invoice() {
261
+
262
+        // Abort if there is no invoice.
263
+        if ( empty( $this->data['invoice_id'] ) ) {
264
+
265
+            // Check if we are resuming a payment.
266
+            if ( empty( $this->data['maybe_use_invoice'] ) ) {
267
+                return;
268
+            }
269
+
270
+            $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] );
271
+            if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) {
272
+                return;
273
+            }
274
+        }
275
+
276
+        // If the submission is for an existing invoice, ensure that it exists
277
+        // and that it is not paid for.
278
+        if ( empty( $invoice ) ) {
279
+            $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
280
+        }
281 281
 
282 282
         if ( empty( $invoice ) ) {
283
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
284
-		}
285
-
286
-		if ( $invoice->is_paid() ) {
287
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
288
-		}
289
-
290
-		$this->payment_form->invoice = $invoice;
291
-		if ( ! $this->payment_form->is_default() ) {
292
-
293
-			$items    = array();
294
-			$item_ids = array();
295
-
296
-			foreach ( $invoice->get_items() as $item ) {
297
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
298
-					$item_ids[] = $item->get_id();
299
-					$items[]    = $item;
300
-				}
301
-			}
302
-
303
-			foreach ( $this->payment_form->get_items() as $item ) {
304
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
305
-					$item_ids[] = $item->get_id();
306
-					$items[]    = $item;
307
-				}
308
-			}
309
-
310
-			$this->payment_form->set_items( $items );
311
-
312
-		} else {
313
-			$this->payment_form->set_items( $invoice->get_items() );
314
-		}
315
-
316
-		$this->country = $invoice->get_country();
317
-		$this->state   = $invoice->get_state();
318
-		$this->invoice = $invoice;
319
-
320
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
321
-	}
322
-
323
-	/**
324
-	 * Returns the associated invoice.
325
-	 *
326
-	 * @since 1.0.19
327
-	 * @return WPInv_Invoice
328
-	 */
329
-	public function get_invoice() {
330
-		return $this->invoice;
331
-	}
332
-
333
-	/**
334
-	 * Checks whether there is an invoice associated with this submission.
335
-	 *
336
-	 * @since 1.0.19
337
-	 * @return bool
338
-	 */
339
-	public function has_invoice() {
340
-		return ! empty( $this->invoice );
341
-	}
342
-
343
-	/*
283
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
284
+        }
285
+
286
+        if ( $invoice->is_paid() ) {
287
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
288
+        }
289
+
290
+        $this->payment_form->invoice = $invoice;
291
+        if ( ! $this->payment_form->is_default() ) {
292
+
293
+            $items    = array();
294
+            $item_ids = array();
295
+
296
+            foreach ( $invoice->get_items() as $item ) {
297
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
298
+                    $item_ids[] = $item->get_id();
299
+                    $items[]    = $item;
300
+                }
301
+            }
302
+
303
+            foreach ( $this->payment_form->get_items() as $item ) {
304
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
305
+                    $item_ids[] = $item->get_id();
306
+                    $items[]    = $item;
307
+                }
308
+            }
309
+
310
+            $this->payment_form->set_items( $items );
311
+
312
+        } else {
313
+            $this->payment_form->set_items( $invoice->get_items() );
314
+        }
315
+
316
+        $this->country = $invoice->get_country();
317
+        $this->state   = $invoice->get_state();
318
+        $this->invoice = $invoice;
319
+
320
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
321
+    }
322
+
323
+    /**
324
+     * Returns the associated invoice.
325
+     *
326
+     * @since 1.0.19
327
+     * @return WPInv_Invoice
328
+     */
329
+    public function get_invoice() {
330
+        return $this->invoice;
331
+    }
332
+
333
+    /**
334
+     * Checks whether there is an invoice associated with this submission.
335
+     *
336
+     * @since 1.0.19
337
+     * @return bool
338
+     */
339
+    public function has_invoice() {
340
+        return ! empty( $this->invoice );
341
+    }
342
+
343
+    /*
344 344
 	|--------------------------------------------------------------------------
345 345
 	| Items.
346 346
 	|--------------------------------------------------------------------------
@@ -349,129 +349,129 @@  discard block
 block discarded – undo
349 349
 	| recurring item. But can have an unlimited number of non-recurring items.
350 350
 	*/
351 351
 
352
-	/**
353
-	 * Prepares the submission's items.
354
-	 *
355
-	 * @since 1.0.19
356
-	 */
357
-	public function process_items() {
358
-
359
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
360
-
361
-		foreach ( $processor->items as $item ) {
362
-			$this->add_item( $item );
363
-		}
364
-
365
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
366
-	}
367
-
368
-	/**
369
-	 * Adds an item to the submission.
370
-	 *
371
-	 * @since 1.0.19
372
-	 * @param GetPaid_Form_Item $item
373
-	 */
374
-	public function add_item( $item ) {
375
-
376
-		// Make sure that it is available for purchase.
377
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
378
-			return;
379
-		}
380
-
381
-		// Each submission can only contain one recurring item.
382
-		if ( $item->is_recurring() ) {
383
-			$this->has_recurring = $item->get_id();
384
-		}
385
-
386
-		// Update the items and totals.
387
-		$this->items[ $item->get_id() ]         = $item;
388
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
389
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
390
-
391
-	}
392
-
393
-	/**
394
-	 * Removes a specific item.
395
-	 *
396
-	 * You should not call this method after the discounts and taxes
397
-	 * have been calculated.
398
-	 *
399
-	 * @since 1.0.19
400
-	 */
401
-	public function remove_item( $item_id ) {
402
-
403
-		if ( isset( $this->items[ $item_id ] ) ) {
404
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
405
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
406
-
407
-			if ( $this->items[ $item_id ]->is_recurring() ) {
408
-				$this->has_recurring = 0;
409
-			}
410
-
411
-			unset( $this->items[ $item_id ] );
412
-		}
413
-
414
-	}
415
-
416
-	/**
417
-	 * Returns the subtotal.
418
-	 *
419
-	 * @since 1.0.19
420
-	 */
421
-	public function get_subtotal() {
422
-
423
-		if ( wpinv_prices_include_tax() ) {
424
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
425
-		}
426
-
427
-		return $this->totals['subtotal']['initial'];
428
-	}
429
-
430
-	/**
431
-	 * Returns the recurring subtotal.
432
-	 *
433
-	 * @since 1.0.19
434
-	 */
435
-	public function get_recurring_subtotal() {
436
-
437
-		if ( wpinv_prices_include_tax() ) {
438
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
439
-		}
440
-
441
-		return $this->totals['subtotal']['recurring'];
442
-	}
443
-
444
-	/**
445
-	 * Returns all items.
446
-	 *
447
-	 * @since 1.0.19
448
-	 * @return GetPaid_Form_Item[]
449
-	 */
450
-	public function get_items() {
451
-		return $this->items;
452
-	}
453
-
454
-	/**
455
-	 * Checks if there's a single subscription group in the submission.
456
-	 *
457
-	 * @since 2.3.0
458
-	 * @return bool
459
-	 */
460
-	public function has_subscription_group() {
461
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
462
-	}
463
-
464
-	/**
465
-	 * Checks if there are multipe subscription groups in the submission.
466
-	 *
467
-	 * @since 2.3.0
468
-	 * @return bool
469
-	 */
470
-	public function has_multiple_subscription_groups() {
471
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
472
-	}
473
-
474
-	/*
352
+    /**
353
+     * Prepares the submission's items.
354
+     *
355
+     * @since 1.0.19
356
+     */
357
+    public function process_items() {
358
+
359
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
360
+
361
+        foreach ( $processor->items as $item ) {
362
+            $this->add_item( $item );
363
+        }
364
+
365
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
366
+    }
367
+
368
+    /**
369
+     * Adds an item to the submission.
370
+     *
371
+     * @since 1.0.19
372
+     * @param GetPaid_Form_Item $item
373
+     */
374
+    public function add_item( $item ) {
375
+
376
+        // Make sure that it is available for purchase.
377
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
378
+            return;
379
+        }
380
+
381
+        // Each submission can only contain one recurring item.
382
+        if ( $item->is_recurring() ) {
383
+            $this->has_recurring = $item->get_id();
384
+        }
385
+
386
+        // Update the items and totals.
387
+        $this->items[ $item->get_id() ]         = $item;
388
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
389
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
390
+
391
+    }
392
+
393
+    /**
394
+     * Removes a specific item.
395
+     *
396
+     * You should not call this method after the discounts and taxes
397
+     * have been calculated.
398
+     *
399
+     * @since 1.0.19
400
+     */
401
+    public function remove_item( $item_id ) {
402
+
403
+        if ( isset( $this->items[ $item_id ] ) ) {
404
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
405
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
406
+
407
+            if ( $this->items[ $item_id ]->is_recurring() ) {
408
+                $this->has_recurring = 0;
409
+            }
410
+
411
+            unset( $this->items[ $item_id ] );
412
+        }
413
+
414
+    }
415
+
416
+    /**
417
+     * Returns the subtotal.
418
+     *
419
+     * @since 1.0.19
420
+     */
421
+    public function get_subtotal() {
422
+
423
+        if ( wpinv_prices_include_tax() ) {
424
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
425
+        }
426
+
427
+        return $this->totals['subtotal']['initial'];
428
+    }
429
+
430
+    /**
431
+     * Returns the recurring subtotal.
432
+     *
433
+     * @since 1.0.19
434
+     */
435
+    public function get_recurring_subtotal() {
436
+
437
+        if ( wpinv_prices_include_tax() ) {
438
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
439
+        }
440
+
441
+        return $this->totals['subtotal']['recurring'];
442
+    }
443
+
444
+    /**
445
+     * Returns all items.
446
+     *
447
+     * @since 1.0.19
448
+     * @return GetPaid_Form_Item[]
449
+     */
450
+    public function get_items() {
451
+        return $this->items;
452
+    }
453
+
454
+    /**
455
+     * Checks if there's a single subscription group in the submission.
456
+     *
457
+     * @since 2.3.0
458
+     * @return bool
459
+     */
460
+    public function has_subscription_group() {
461
+        return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
462
+    }
463
+
464
+    /**
465
+     * Checks if there are multipe subscription groups in the submission.
466
+     *
467
+     * @since 2.3.0
468
+     * @return bool
469
+     */
470
+    public function has_multiple_subscription_groups() {
471
+        return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
472
+    }
473
+
474
+    /*
475 475
 	|--------------------------------------------------------------------------
476 476
 	| Taxes
477 477
 	|--------------------------------------------------------------------------
@@ -480,128 +480,128 @@  discard block
 block discarded – undo
480 480
 	| or only one-time.
481 481
     */
482 482
 
483
-	/**
484
-	 * Prepares the submission's taxes.
485
-	 *
486
-	 * @since 1.0.19
487
-	 */
488
-	public function process_taxes() {
489
-
490
-		// Abort if we're not using taxes.
491
-		if ( ! $this->use_taxes() ) {
492
-			return;
493
-		}
494
-
495
-		// If a custom country && state has been passed in, use it to calculate taxes.
496
-		$country = $this->get_field( 'wpinv_country', 'billing' );
497
-		if ( ! empty( $country ) ) {
498
-			$this->country = $country;
499
-		}
500
-
501
-		$state = $this->get_field( 'wpinv_state', 'billing' );
502
-		if ( ! empty( $state ) ) {
503
-			$this->state = $state;
504
-		}
505
-
506
-		// Confirm if the provided country and the ip country are similar.
507
-		$address_confirmed = $this->get_field( 'confirm-address' );
508
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
509
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
510
-		}
511
-
512
-		// Abort if the country is not taxable.
513
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
514
-			return;
515
-		}
516
-
517
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
518
-
519
-		foreach ( $processor->taxes as $tax ) {
520
-			$this->add_tax( $tax );
521
-		}
522
-
523
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
524
-	}
525
-
526
-	/**
527
-	 * Adds a tax to the submission.
528
-	 *
529
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
530
-	 * @since 1.0.19
531
-	 */
532
-	public function add_tax( $tax ) {
533
-
534
-		if ( wpinv_round_tax_per_tax_rate() ) {
535
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
536
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
537
-		}
538
-
539
-		$this->taxes[ $tax['name'] ]         = $tax;
540
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
541
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
542
-
543
-	}
544
-
545
-	/**
546
-	 * Removes a specific tax.
547
-	 *
548
-	 * @since 1.0.19
549
-	 */
550
-	public function remove_tax( $tax_name ) {
551
-
552
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
553
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
554
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
555
-			unset( $this->taxes[ $tax_name ] );
556
-		}
557
-
558
-	}
559
-
560
-	/**
561
-	 * Whether or not we'll use taxes for the submission.
562
-	 *
563
-	 * @since 1.0.19
564
-	 */
565
-	public function use_taxes() {
566
-
567
-		$use_taxes = wpinv_use_taxes();
568
-
569
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
570
-			$use_taxes = false;
571
-		}
572
-
573
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
574
-
575
-	}
576
-
577
-	/**
578
-	 * Returns the tax.
579
-	 *
580
-	 * @since 1.0.19
581
-	 */
582
-	public function get_tax() {
583
-		return $this->totals['taxes']['initial'];
584
-	}
585
-
586
-	/**
587
-	 * Returns the recurring tax.
588
-	 *
589
-	 * @since 1.0.19
590
-	 */
591
-	public function get_recurring_tax() {
592
-		return $this->totals['taxes']['recurring'];
593
-	}
594
-
595
-	/**
596
-	 * Returns all taxes.
597
-	 *
598
-	 * @since 1.0.19
599
-	 */
600
-	public function get_taxes() {
601
-		return $this->taxes;
602
-	}
603
-
604
-	/*
483
+    /**
484
+     * Prepares the submission's taxes.
485
+     *
486
+     * @since 1.0.19
487
+     */
488
+    public function process_taxes() {
489
+
490
+        // Abort if we're not using taxes.
491
+        if ( ! $this->use_taxes() ) {
492
+            return;
493
+        }
494
+
495
+        // If a custom country && state has been passed in, use it to calculate taxes.
496
+        $country = $this->get_field( 'wpinv_country', 'billing' );
497
+        if ( ! empty( $country ) ) {
498
+            $this->country = $country;
499
+        }
500
+
501
+        $state = $this->get_field( 'wpinv_state', 'billing' );
502
+        if ( ! empty( $state ) ) {
503
+            $this->state = $state;
504
+        }
505
+
506
+        // Confirm if the provided country and the ip country are similar.
507
+        $address_confirmed = $this->get_field( 'confirm-address' );
508
+        if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
509
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
510
+        }
511
+
512
+        // Abort if the country is not taxable.
513
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
514
+            return;
515
+        }
516
+
517
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
518
+
519
+        foreach ( $processor->taxes as $tax ) {
520
+            $this->add_tax( $tax );
521
+        }
522
+
523
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
524
+    }
525
+
526
+    /**
527
+     * Adds a tax to the submission.
528
+     *
529
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
530
+     * @since 1.0.19
531
+     */
532
+    public function add_tax( $tax ) {
533
+
534
+        if ( wpinv_round_tax_per_tax_rate() ) {
535
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
536
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
537
+        }
538
+
539
+        $this->taxes[ $tax['name'] ]         = $tax;
540
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
541
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
542
+
543
+    }
544
+
545
+    /**
546
+     * Removes a specific tax.
547
+     *
548
+     * @since 1.0.19
549
+     */
550
+    public function remove_tax( $tax_name ) {
551
+
552
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
553
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
554
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
555
+            unset( $this->taxes[ $tax_name ] );
556
+        }
557
+
558
+    }
559
+
560
+    /**
561
+     * Whether or not we'll use taxes for the submission.
562
+     *
563
+     * @since 1.0.19
564
+     */
565
+    public function use_taxes() {
566
+
567
+        $use_taxes = wpinv_use_taxes();
568
+
569
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
570
+            $use_taxes = false;
571
+        }
572
+
573
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
574
+
575
+    }
576
+
577
+    /**
578
+     * Returns the tax.
579
+     *
580
+     * @since 1.0.19
581
+     */
582
+    public function get_tax() {
583
+        return $this->totals['taxes']['initial'];
584
+    }
585
+
586
+    /**
587
+     * Returns the recurring tax.
588
+     *
589
+     * @since 1.0.19
590
+     */
591
+    public function get_recurring_tax() {
592
+        return $this->totals['taxes']['recurring'];
593
+    }
594
+
595
+    /**
596
+     * Returns all taxes.
597
+     *
598
+     * @since 1.0.19
599
+     */
600
+    public function get_taxes() {
601
+        return $this->taxes;
602
+    }
603
+
604
+    /*
605 605
 	|--------------------------------------------------------------------------
606 606
 	| Discounts
607 607
 	|--------------------------------------------------------------------------
@@ -610,99 +610,99 @@  discard block
 block discarded – undo
610 610
 	| or only one-time. They also do not have to come from a discount code.
611 611
     */
612 612
 
613
-	/**
614
-	 * Prepares the submission's discount.
615
-	 *
616
-	 * @since 1.0.19
617
-	 */
618
-	public function process_discount() {
619
-
620
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
621
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
622
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
623
-
624
-		foreach ( $processor->discounts as $discount ) {
625
-			$this->add_discount( $discount );
626
-		}
627
-
628
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
629
-	}
630
-
631
-	/**
632
-	 * Adds a discount to the submission.
633
-	 *
634
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
635
-	 * @since 1.0.19
636
-	 */
637
-	public function add_discount( $discount ) {
638
-		$this->discounts[ $discount['name'] ]   = $discount;
639
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
640
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
641
-	}
642
-
643
-	/**
644
-	 * Removes a discount from the submission.
645
-	 *
646
-	 * @since 1.0.19
647
-	 */
648
-	public function remove_discount( $name ) {
649
-
650
-		if ( isset( $this->discounts[ $name ] ) ) {
651
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
652
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
653
-			unset( $this->discounts[ $name ] );
654
-		}
655
-
656
-	}
657
-
658
-	/**
659
-	 * Checks whether there is a discount code associated with this submission.
660
-	 *
661
-	 * @since 1.0.19
662
-	 * @return bool
663
-	 */
664
-	public function has_discount_code() {
665
-		return ! empty( $this->discounts['discount_code'] );
666
-	}
667
-
668
-	/**
669
-	 * Returns the discount code.
670
-	 *
671
-	 * @since 1.0.19
672
-	 * @return string
673
-	 */
674
-	public function get_discount_code() {
675
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
676
-	}
677
-
678
-	/**
679
-	 * Returns the discount.
680
-	 *
681
-	 * @since 1.0.19
682
-	 */
683
-	public function get_discount() {
684
-		return $this->totals['discount']['initial'];
685
-	}
686
-
687
-	/**
688
-	 * Returns the recurring discount.
689
-	 *
690
-	 * @since 1.0.19
691
-	 */
692
-	public function get_recurring_discount() {
693
-		return $this->totals['discount']['recurring'];
694
-	}
695
-
696
-	/**
697
-	 * Returns all discounts.
698
-	 *
699
-	 * @since 1.0.19
700
-	 */
701
-	public function get_discounts() {
702
-		return $this->discounts;
703
-	}
704
-
705
-	/*
613
+    /**
614
+     * Prepares the submission's discount.
615
+     *
616
+     * @since 1.0.19
617
+     */
618
+    public function process_discount() {
619
+
620
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
621
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
622
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
623
+
624
+        foreach ( $processor->discounts as $discount ) {
625
+            $this->add_discount( $discount );
626
+        }
627
+
628
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
629
+    }
630
+
631
+    /**
632
+     * Adds a discount to the submission.
633
+     *
634
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
635
+     * @since 1.0.19
636
+     */
637
+    public function add_discount( $discount ) {
638
+        $this->discounts[ $discount['name'] ]   = $discount;
639
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
640
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
641
+    }
642
+
643
+    /**
644
+     * Removes a discount from the submission.
645
+     *
646
+     * @since 1.0.19
647
+     */
648
+    public function remove_discount( $name ) {
649
+
650
+        if ( isset( $this->discounts[ $name ] ) ) {
651
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
652
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
653
+            unset( $this->discounts[ $name ] );
654
+        }
655
+
656
+    }
657
+
658
+    /**
659
+     * Checks whether there is a discount code associated with this submission.
660
+     *
661
+     * @since 1.0.19
662
+     * @return bool
663
+     */
664
+    public function has_discount_code() {
665
+        return ! empty( $this->discounts['discount_code'] );
666
+    }
667
+
668
+    /**
669
+     * Returns the discount code.
670
+     *
671
+     * @since 1.0.19
672
+     * @return string
673
+     */
674
+    public function get_discount_code() {
675
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
676
+    }
677
+
678
+    /**
679
+     * Returns the discount.
680
+     *
681
+     * @since 1.0.19
682
+     */
683
+    public function get_discount() {
684
+        return $this->totals['discount']['initial'];
685
+    }
686
+
687
+    /**
688
+     * Returns the recurring discount.
689
+     *
690
+     * @since 1.0.19
691
+     */
692
+    public function get_recurring_discount() {
693
+        return $this->totals['discount']['recurring'];
694
+    }
695
+
696
+    /**
697
+     * Returns all discounts.
698
+     *
699
+     * @since 1.0.19
700
+     */
701
+    public function get_discounts() {
702
+        return $this->discounts;
703
+    }
704
+
705
+    /*
706 706
 	|--------------------------------------------------------------------------
707 707
 	| Fees
708 708
 	|--------------------------------------------------------------------------
@@ -712,100 +712,100 @@  discard block
 block discarded – undo
712 712
 	| fees.
713 713
     */
714 714
 
715
-	/**
716
-	 * Prepares the submission's fees.
717
-	 *
718
-	 * @since 1.0.19
719
-	 */
720
-	public function process_fees() {
721
-
722
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
723
-
724
-		foreach ( $fees_processor->fees as $fee ) {
725
-			$this->add_fee( $fee );
726
-		}
727
-
728
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
729
-	}
730
-
731
-	/**
732
-	 * Adds a fee to the submission.
733
-	 *
734
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
735
-	 * @since 1.0.19
736
-	 */
737
-	public function add_fee( $fee ) {
738
-
739
-		if ( $fee['name'] == 'shipping' ) {
740
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
741
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
742
-			return;
743
-		}
744
-
745
-		$this->fees[ $fee['name'] ]         = $fee;
746
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
747
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
748
-
749
-	}
750
-
751
-	/**
752
-	 * Removes a fee from the submission.
753
-	 *
754
-	 * @since 1.0.19
755
-	 */
756
-	public function remove_fee( $name ) {
757
-
758
-		if ( isset( $this->fees[ $name ] ) ) {
759
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
760
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
761
-			unset( $this->fees[ $name ] );
762
-		}
763
-
764
-		if ( 'shipping' == $name ) {
765
-			$this->totals['shipping']['initial']   = 0;
766
-			$this->totals['shipping']['recurring'] = 0;
767
-		}
768
-
769
-	}
770
-
771
-	/**
772
-	 * Returns the fees.
773
-	 *
774
-	 * @since 1.0.19
775
-	 */
776
-	public function get_fee() {
777
-		return $this->totals['fees']['initial'];
778
-	}
779
-
780
-	/**
781
-	 * Returns the recurring fees.
782
-	 *
783
-	 * @since 1.0.19
784
-	 */
785
-	public function get_recurring_fee() {
786
-		return $this->totals['fees']['recurring'];
787
-	}
788
-
789
-	/**
790
-	 * Returns all fees.
791
-	 *
792
-	 * @since 1.0.19
793
-	 */
794
-	public function get_fees() {
795
-		return $this->fees;
796
-	}
797
-
798
-	/**
799
-	 * Checks if there are any fees for the form.
800
-	 *
801
-	 * @return bool
802
-	 * @since 1.0.19
803
-	 */
804
-	public function has_fees() {
805
-		return count( $this->fees ) !== 0;
806
-	}
807
-
808
-	/*
715
+    /**
716
+     * Prepares the submission's fees.
717
+     *
718
+     * @since 1.0.19
719
+     */
720
+    public function process_fees() {
721
+
722
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
723
+
724
+        foreach ( $fees_processor->fees as $fee ) {
725
+            $this->add_fee( $fee );
726
+        }
727
+
728
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
729
+    }
730
+
731
+    /**
732
+     * Adds a fee to the submission.
733
+     *
734
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
735
+     * @since 1.0.19
736
+     */
737
+    public function add_fee( $fee ) {
738
+
739
+        if ( $fee['name'] == 'shipping' ) {
740
+            $this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
741
+            $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
742
+            return;
743
+        }
744
+
745
+        $this->fees[ $fee['name'] ]         = $fee;
746
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
747
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
748
+
749
+    }
750
+
751
+    /**
752
+     * Removes a fee from the submission.
753
+     *
754
+     * @since 1.0.19
755
+     */
756
+    public function remove_fee( $name ) {
757
+
758
+        if ( isset( $this->fees[ $name ] ) ) {
759
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
760
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
761
+            unset( $this->fees[ $name ] );
762
+        }
763
+
764
+        if ( 'shipping' == $name ) {
765
+            $this->totals['shipping']['initial']   = 0;
766
+            $this->totals['shipping']['recurring'] = 0;
767
+        }
768
+
769
+    }
770
+
771
+    /**
772
+     * Returns the fees.
773
+     *
774
+     * @since 1.0.19
775
+     */
776
+    public function get_fee() {
777
+        return $this->totals['fees']['initial'];
778
+    }
779
+
780
+    /**
781
+     * Returns the recurring fees.
782
+     *
783
+     * @since 1.0.19
784
+     */
785
+    public function get_recurring_fee() {
786
+        return $this->totals['fees']['recurring'];
787
+    }
788
+
789
+    /**
790
+     * Returns all fees.
791
+     *
792
+     * @since 1.0.19
793
+     */
794
+    public function get_fees() {
795
+        return $this->fees;
796
+    }
797
+
798
+    /**
799
+     * Checks if there are any fees for the form.
800
+     *
801
+     * @return bool
802
+     * @since 1.0.19
803
+     */
804
+    public function has_fees() {
805
+        return count( $this->fees ) !== 0;
806
+    }
807
+
808
+    /*
809 809
 	|--------------------------------------------------------------------------
810 810
 	| MISC
811 811
 	|--------------------------------------------------------------------------
@@ -813,147 +813,147 @@  discard block
 block discarded – undo
813 813
 	| Extra submission functions.
814 814
     */
815 815
 
816
-	/**
817
-	 * Returns the shipping amount.
818
-	 *
819
-	 * @since 1.0.19
820
-	 */
821
-	public function get_shipping() {
822
-		return $this->totals['shipping']['initial'];
823
-	}
824
-
825
-	/**
826
-	 * Returns the recurring shipping.
827
-	 *
828
-	 * @since 1.0.19
829
-	 */
830
-	public function get_recurring_shipping() {
831
-		return $this->totals['shipping']['recurring'];
832
-	}
833
-
834
-	/**
835
-	 * Checks if there are any shipping fees for the form.
836
-	 *
837
-	 * @return bool
838
-	 * @since 1.0.19
839
-	 */
840
-	public function has_shipping() {
841
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
842
-	}
843
-
844
-	/**
845
-	 * Checks if this is the initial fetch.
846
-	 *
847
-	 * @return bool
848
-	 * @since 1.0.19
849
-	 */
850
-	public function is_initial_fetch() {
851
-		return empty( $this->data['initial_state'] );
852
-	}
853
-
854
-	/**
855
-	 * Returns the total amount to collect for this submission.
856
-	 *
857
-	 * @since 1.0.19
858
-	 */
859
-	public function get_total() {
860
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
861
-		return max( $total, 0 );
862
-	}
863
-
864
-	/**
865
-	 * Returns the recurring total amount to collect for this submission.
866
-	 *
867
-	 * @since 1.0.19
868
-	 */
869
-	public function get_recurring_total() {
870
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
871
-		return max( $total, 0 );
872
-	}
873
-
874
-	/**
875
-	 * Whether payment details should be collected for this submission.
876
-	 *
877
-	 * @since 1.0.19
878
-	 */
879
-	public function should_collect_payment_details() {
880
-		$initial   = $this->get_total();
881
-		$recurring = $this->get_recurring_total();
882
-
883
-		if ( $this->has_recurring == 0 ) {
884
-			$recurring = 0;
885
-		}
886
-
887
-		$collect = $initial > 0 || $recurring > 0;
888
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this );
889
-	}
890
-
891
-	/**
892
-	 * Returns the billing email of the user.
893
-	 *
894
-	 * @since 1.0.19
895
-	 */
896
-	public function get_billing_email() {
897
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this );
898
-	}
899
-
900
-	/**
901
-	 * Checks if the submitter has a billing email.
902
-	 *
903
-	 * @since 1.0.19
904
-	 */
905
-	public function has_billing_email() {
906
-		$billing_email = $this->get_billing_email();
907
-		return ! empty( $billing_email ) && is_email( $billing_email );
908
-	}
909
-
910
-	/**
911
-	 * Returns the appropriate currency for the submission.
912
-	 *
913
-	 * @since 1.0.19
914
-	 * @return string
915
-	 */
916
-	public function get_currency() {
917
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
918
-    }
919
-
920
-    /**
921
-	 * Returns the raw submission data.
922
-	 *
923
-	 * @since 1.0.19
924
-	 * @return array
925
-	 */
926
-	public function get_data() {
927
-		return $this->data;
928
-	}
929
-
930
-	/**
931
-	 * Returns a field from the submission data
932
-	 *
933
-	 * @param string $field
934
-	 * @since 1.0.19
935
-	 * @return mixed|null
936
-	 */
937
-	public function get_field( $field, $sub_array_key = null ) {
938
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
939
-	}
940
-
941
-	/**
942
-	 * Checks if a required field is set.
943
-	 *
944
-	 * @since 1.0.19
945
-	 */
946
-	public function is_required_field_set( $field ) {
947
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
948
-	}
949
-
950
-	/**
951
-	 * Formats an amount
952
-	 *
953
-	 * @since 1.0.19
954
-	 */
955
-	public function format_amount( $amount ) {
956
-		return wpinv_price( $amount, $this->get_currency() );
957
-	}
816
+    /**
817
+     * Returns the shipping amount.
818
+     *
819
+     * @since 1.0.19
820
+     */
821
+    public function get_shipping() {
822
+        return $this->totals['shipping']['initial'];
823
+    }
824
+
825
+    /**
826
+     * Returns the recurring shipping.
827
+     *
828
+     * @since 1.0.19
829
+     */
830
+    public function get_recurring_shipping() {
831
+        return $this->totals['shipping']['recurring'];
832
+    }
833
+
834
+    /**
835
+     * Checks if there are any shipping fees for the form.
836
+     *
837
+     * @return bool
838
+     * @since 1.0.19
839
+     */
840
+    public function has_shipping() {
841
+        return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
842
+    }
843
+
844
+    /**
845
+     * Checks if this is the initial fetch.
846
+     *
847
+     * @return bool
848
+     * @since 1.0.19
849
+     */
850
+    public function is_initial_fetch() {
851
+        return empty( $this->data['initial_state'] );
852
+    }
853
+
854
+    /**
855
+     * Returns the total amount to collect for this submission.
856
+     *
857
+     * @since 1.0.19
858
+     */
859
+    public function get_total() {
860
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
861
+        return max( $total, 0 );
862
+    }
863
+
864
+    /**
865
+     * Returns the recurring total amount to collect for this submission.
866
+     *
867
+     * @since 1.0.19
868
+     */
869
+    public function get_recurring_total() {
870
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
871
+        return max( $total, 0 );
872
+    }
873
+
874
+    /**
875
+     * Whether payment details should be collected for this submission.
876
+     *
877
+     * @since 1.0.19
878
+     */
879
+    public function should_collect_payment_details() {
880
+        $initial   = $this->get_total();
881
+        $recurring = $this->get_recurring_total();
882
+
883
+        if ( $this->has_recurring == 0 ) {
884
+            $recurring = 0;
885
+        }
886
+
887
+        $collect = $initial > 0 || $recurring > 0;
888
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this );
889
+    }
890
+
891
+    /**
892
+     * Returns the billing email of the user.
893
+     *
894
+     * @since 1.0.19
895
+     */
896
+    public function get_billing_email() {
897
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this );
898
+    }
899
+
900
+    /**
901
+     * Checks if the submitter has a billing email.
902
+     *
903
+     * @since 1.0.19
904
+     */
905
+    public function has_billing_email() {
906
+        $billing_email = $this->get_billing_email();
907
+        return ! empty( $billing_email ) && is_email( $billing_email );
908
+    }
909
+
910
+    /**
911
+     * Returns the appropriate currency for the submission.
912
+     *
913
+     * @since 1.0.19
914
+     * @return string
915
+     */
916
+    public function get_currency() {
917
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
918
+    }
919
+
920
+    /**
921
+     * Returns the raw submission data.
922
+     *
923
+     * @since 1.0.19
924
+     * @return array
925
+     */
926
+    public function get_data() {
927
+        return $this->data;
928
+    }
929
+
930
+    /**
931
+     * Returns a field from the submission data
932
+     *
933
+     * @param string $field
934
+     * @since 1.0.19
935
+     * @return mixed|null
936
+     */
937
+    public function get_field( $field, $sub_array_key = null ) {
938
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
939
+    }
940
+
941
+    /**
942
+     * Checks if a required field is set.
943
+     *
944
+     * @since 1.0.19
945
+     */
946
+    public function is_required_field_set( $field ) {
947
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
948
+    }
949
+
950
+    /**
951
+     * Formats an amount
952
+     *
953
+     * @since 1.0.19
954
+     */
955
+    public function format_amount( $amount ) {
956
+        return wpinv_price( $amount, $this->get_currency() );
957
+    }
958 958
 
959 959
 }
Please login to merge, or discard this patch.
Spacing   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 		$this->state   = wpinv_get_default_state();
147 147
 
148 148
 		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) );
149
+		if (isset($_POST['getpaid_payment_form_submission'])) {
150
+			$this->load_data(wp_kses_post_deep(wp_unslash($_POST)));
151 151
 		}
152 152
 
153 153
 	}
@@ -157,16 +157,16 @@  discard block
 block discarded – undo
157 157
 	 *
158 158
 	 * @param array $data
159 159
 	 */
160
-	public function load_data( $data ) {
160
+	public function load_data($data) {
161 161
 
162 162
 		// Allow plugins to filter the data.
163
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
163
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
164 164
 
165 165
 		// Cache it...
166 166
 		$this->data = $data;
167 167
 
168 168
 		// Then generate a unique id from the data.
169
-		$this->id   = md5( wp_json_encode( $data ) );
169
+		$this->id   = md5(wp_json_encode($data));
170 170
 
171 171
 		// Finally, process the submission.
172 172
 		try {
@@ -176,29 +176,29 @@  discard block
 block discarded – undo
176 176
 			$processors = apply_filters(
177 177
 				'getpaid_payment_form_submission_processors',
178 178
 				array(
179
-					array( $this, 'process_payment_form' ),
180
-					array( $this, 'process_invoice' ),
181
-					array( $this, 'process_fees' ),
182
-					array( $this, 'process_items' ),
183
-					array( $this, 'process_discount' ),
184
-					array( $this, 'process_taxes' ),
179
+					array($this, 'process_payment_form'),
180
+					array($this, 'process_invoice'),
181
+					array($this, 'process_fees'),
182
+					array($this, 'process_items'),
183
+					array($this, 'process_discount'),
184
+					array($this, 'process_taxes'),
185 185
 				),
186 186
 				$this
187 187
 			);
188 188
 
189
-			foreach ( $processors as $processor ) {
190
-				call_user_func_array( $processor, array( &$this ) );
189
+			foreach ($processors as $processor) {
190
+				call_user_func_array($processor, array(&$this));
191 191
 			}
192
-} catch ( GetPaid_Payment_Exception $e ) {
192
+} catch (GetPaid_Payment_Exception $e) {
193 193
 			$this->last_error      = $e->getMessage();
194 194
 			$this->last_error_code = $e->getErrorCode();
195
-		} catch ( Exception $e ) {
195
+		} catch (Exception $e) {
196 196
 			$this->last_error      = $e->getMessage();
197 197
 			$this->last_error_code = $e->getCode();
198 198
 		}
199 199
 
200 200
 		// Fired when we are done processing a submission.
201
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
201
+		do_action_ref_array('getpaid_process_submission', array(&$this));
202 202
 
203 203
 	}
204 204
 
@@ -219,18 +219,18 @@  discard block
 block discarded – undo
219 219
 	public function process_payment_form() {
220 220
 
221 221
 		// Every submission needs an active payment form.
222
-		if ( empty( $this->data['form_id'] ) ) {
223
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
222
+		if (empty($this->data['form_id'])) {
223
+			throw new Exception(__('Missing payment form', 'invoicing'));
224 224
 		}
225 225
 
226 226
 		// Fetch the payment form.
227
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
227
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
228 228
 
229
-		if ( ! $this->payment_form->is_active() ) {
230
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
229
+		if (!$this->payment_form->is_active()) {
230
+			throw new Exception(__('Payment form not active', 'invoicing'));
231 231
 		}
232 232
 
233
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
233
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
234 234
 	}
235 235
 
236 236
     /**
@@ -260,64 +260,64 @@  discard block
 block discarded – undo
260 260
 	public function process_invoice() {
261 261
 
262 262
 		// Abort if there is no invoice.
263
-		if ( empty( $this->data['invoice_id'] ) ) {
263
+		if (empty($this->data['invoice_id'])) {
264 264
 
265 265
 			// Check if we are resuming a payment.
266
-			if ( empty( $this->data['maybe_use_invoice'] ) ) {
266
+			if (empty($this->data['maybe_use_invoice'])) {
267 267
 				return;
268 268
 			}
269 269
 
270
-			$invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] );
271
-			if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) {
270
+			$invoice = wpinv_get_invoice($this->data['maybe_use_invoice']);
271
+			if (empty($invoice) || !$invoice->has_status('draft, auto-draft, wpi-pending')) {
272 272
 				return;
273 273
 			}
274 274
 		}
275 275
 
276 276
 		// If the submission is for an existing invoice, ensure that it exists
277 277
 		// and that it is not paid for.
278
-		if ( empty( $invoice ) ) {
279
-			$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
278
+		if (empty($invoice)) {
279
+			$invoice = wpinv_get_invoice($this->data['invoice_id']);
280 280
 		}
281 281
 
282
-        if ( empty( $invoice ) ) {
283
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
282
+        if (empty($invoice)) {
283
+			throw new Exception(__('Invalid invoice', 'invoicing'));
284 284
 		}
285 285
 
286
-		if ( $invoice->is_paid() ) {
287
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
286
+		if ($invoice->is_paid()) {
287
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
288 288
 		}
289 289
 
290 290
 		$this->payment_form->invoice = $invoice;
291
-		if ( ! $this->payment_form->is_default() ) {
291
+		if (!$this->payment_form->is_default()) {
292 292
 
293 293
 			$items    = array();
294 294
 			$item_ids = array();
295 295
 
296
-			foreach ( $invoice->get_items() as $item ) {
297
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
296
+			foreach ($invoice->get_items() as $item) {
297
+				if (!in_array($item->get_id(), $item_ids)) {
298 298
 					$item_ids[] = $item->get_id();
299 299
 					$items[]    = $item;
300 300
 				}
301 301
 			}
302 302
 
303
-			foreach ( $this->payment_form->get_items() as $item ) {
304
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
303
+			foreach ($this->payment_form->get_items() as $item) {
304
+				if (!in_array($item->get_id(), $item_ids)) {
305 305
 					$item_ids[] = $item->get_id();
306 306
 					$items[]    = $item;
307 307
 				}
308 308
 			}
309 309
 
310
-			$this->payment_form->set_items( $items );
310
+			$this->payment_form->set_items($items);
311 311
 
312 312
 		} else {
313
-			$this->payment_form->set_items( $invoice->get_items() );
313
+			$this->payment_form->set_items($invoice->get_items());
314 314
 		}
315 315
 
316 316
 		$this->country = $invoice->get_country();
317 317
 		$this->state   = $invoice->get_state();
318 318
 		$this->invoice = $invoice;
319 319
 
320
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
320
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
321 321
 	}
322 322
 
323 323
 	/**
@@ -337,7 +337,7 @@  discard block
 block discarded – undo
337 337
 	 * @return bool
338 338
 	 */
339 339
 	public function has_invoice() {
340
-		return ! empty( $this->invoice );
340
+		return !empty($this->invoice);
341 341
 	}
342 342
 
343 343
 	/*
@@ -356,13 +356,13 @@  discard block
 block discarded – undo
356 356
 	 */
357 357
 	public function process_items() {
358 358
 
359
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
359
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
360 360
 
361
-		foreach ( $processor->items as $item ) {
362
-			$this->add_item( $item );
361
+		foreach ($processor->items as $item) {
362
+			$this->add_item($item);
363 363
 		}
364 364
 
365
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
365
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
366 366
 	}
367 367
 
368 368
 	/**
@@ -371,20 +371,20 @@  discard block
 block discarded – undo
371 371
 	 * @since 1.0.19
372 372
 	 * @param GetPaid_Form_Item $item
373 373
 	 */
374
-	public function add_item( $item ) {
374
+	public function add_item($item) {
375 375
 
376 376
 		// Make sure that it is available for purchase.
377
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
377
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
378 378
 			return;
379 379
 		}
380 380
 
381 381
 		// Each submission can only contain one recurring item.
382
-		if ( $item->is_recurring() ) {
382
+		if ($item->is_recurring()) {
383 383
 			$this->has_recurring = $item->get_id();
384 384
 		}
385 385
 
386 386
 		// Update the items and totals.
387
-		$this->items[ $item->get_id() ]         = $item;
387
+		$this->items[$item->get_id()]         = $item;
388 388
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
389 389
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
390 390
 
@@ -398,17 +398,17 @@  discard block
 block discarded – undo
398 398
 	 *
399 399
 	 * @since 1.0.19
400 400
 	 */
401
-	public function remove_item( $item_id ) {
401
+	public function remove_item($item_id) {
402 402
 
403
-		if ( isset( $this->items[ $item_id ] ) ) {
404
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
405
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
403
+		if (isset($this->items[$item_id])) {
404
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
405
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
406 406
 
407
-			if ( $this->items[ $item_id ]->is_recurring() ) {
407
+			if ($this->items[$item_id]->is_recurring()) {
408 408
 				$this->has_recurring = 0;
409 409
 			}
410 410
 
411
-			unset( $this->items[ $item_id ] );
411
+			unset($this->items[$item_id]);
412 412
 		}
413 413
 
414 414
 	}
@@ -420,7 +420,7 @@  discard block
 block discarded – undo
420 420
 	 */
421 421
 	public function get_subtotal() {
422 422
 
423
-		if ( wpinv_prices_include_tax() ) {
423
+		if (wpinv_prices_include_tax()) {
424 424
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
425 425
 		}
426 426
 
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 	 */
435 435
 	public function get_recurring_subtotal() {
436 436
 
437
-		if ( wpinv_prices_include_tax() ) {
437
+		if (wpinv_prices_include_tax()) {
438 438
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
439 439
 		}
440 440
 
@@ -458,7 +458,7 @@  discard block
 block discarded – undo
458 458
 	 * @return bool
459 459
 	 */
460 460
 	public function has_subscription_group() {
461
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
461
+		return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this));
462 462
 	}
463 463
 
464 464
 	/**
@@ -468,7 +468,7 @@  discard block
 block discarded – undo
468 468
 	 * @return bool
469 469
 	 */
470 470
 	public function has_multiple_subscription_groups() {
471
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
471
+		return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this));
472 472
 	}
473 473
 
474 474
 	/*
@@ -488,39 +488,39 @@  discard block
 block discarded – undo
488 488
 	public function process_taxes() {
489 489
 
490 490
 		// Abort if we're not using taxes.
491
-		if ( ! $this->use_taxes() ) {
491
+		if (!$this->use_taxes()) {
492 492
 			return;
493 493
 		}
494 494
 
495 495
 		// If a custom country && state has been passed in, use it to calculate taxes.
496
-		$country = $this->get_field( 'wpinv_country', 'billing' );
497
-		if ( ! empty( $country ) ) {
496
+		$country = $this->get_field('wpinv_country', 'billing');
497
+		if (!empty($country)) {
498 498
 			$this->country = $country;
499 499
 		}
500 500
 
501
-		$state = $this->get_field( 'wpinv_state', 'billing' );
502
-		if ( ! empty( $state ) ) {
501
+		$state = $this->get_field('wpinv_state', 'billing');
502
+		if (!empty($state)) {
503 503
 			$this->state = $state;
504 504
 		}
505 505
 
506 506
 		// Confirm if the provided country and the ip country are similar.
507
-		$address_confirmed = $this->get_field( 'confirm-address' );
508
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
509
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
507
+		$address_confirmed = $this->get_field('confirm-address');
508
+		if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
509
+			throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing'));
510 510
 		}
511 511
 
512 512
 		// Abort if the country is not taxable.
513
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
513
+		if (!wpinv_is_country_taxable($this->country)) {
514 514
 			return;
515 515
 		}
516 516
 
517
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
517
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
518 518
 
519
-		foreach ( $processor->taxes as $tax ) {
520
-			$this->add_tax( $tax );
519
+		foreach ($processor->taxes as $tax) {
520
+			$this->add_tax($tax);
521 521
 		}
522 522
 
523
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
523
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
524 524
 	}
525 525
 
526 526
 	/**
@@ -529,16 +529,16 @@  discard block
 block discarded – undo
529 529
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
530 530
 	 * @since 1.0.19
531 531
 	 */
532
-	public function add_tax( $tax ) {
532
+	public function add_tax($tax) {
533 533
 
534
-		if ( wpinv_round_tax_per_tax_rate() ) {
535
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
536
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
534
+		if (wpinv_round_tax_per_tax_rate()) {
535
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
536
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
537 537
 		}
538 538
 
539
-		$this->taxes[ $tax['name'] ]         = $tax;
540
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
541
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
539
+		$this->taxes[$tax['name']]         = $tax;
540
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
541
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
542 542
 
543 543
 	}
544 544
 
@@ -547,12 +547,12 @@  discard block
 block discarded – undo
547 547
 	 *
548 548
 	 * @since 1.0.19
549 549
 	 */
550
-	public function remove_tax( $tax_name ) {
550
+	public function remove_tax($tax_name) {
551 551
 
552
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
553
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
554
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
555
-			unset( $this->taxes[ $tax_name ] );
552
+		if (isset($this->taxes[$tax_name])) {
553
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
554
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
555
+			unset($this->taxes[$tax_name]);
556 556
 		}
557 557
 
558 558
 	}
@@ -566,11 +566,11 @@  discard block
 block discarded – undo
566 566
 
567 567
 		$use_taxes = wpinv_use_taxes();
568 568
 
569
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
569
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
570 570
 			$use_taxes = false;
571 571
 		}
572 572
 
573
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
573
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
574 574
 
575 575
 	}
576 576
 
@@ -619,13 +619,13 @@  discard block
 block discarded – undo
619 619
 
620 620
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
621 621
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
622
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
622
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
623 623
 
624
-		foreach ( $processor->discounts as $discount ) {
625
-			$this->add_discount( $discount );
624
+		foreach ($processor->discounts as $discount) {
625
+			$this->add_discount($discount);
626 626
 		}
627 627
 
628
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
628
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
629 629
 	}
630 630
 
631 631
 	/**
@@ -634,10 +634,10 @@  discard block
 block discarded – undo
634 634
 	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
635 635
 	 * @since 1.0.19
636 636
 	 */
637
-	public function add_discount( $discount ) {
638
-		$this->discounts[ $discount['name'] ]   = $discount;
639
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
640
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
637
+	public function add_discount($discount) {
638
+		$this->discounts[$discount['name']]   = $discount;
639
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
640
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
641 641
 	}
642 642
 
643 643
 	/**
@@ -645,12 +645,12 @@  discard block
 block discarded – undo
645 645
 	 *
646 646
 	 * @since 1.0.19
647 647
 	 */
648
-	public function remove_discount( $name ) {
648
+	public function remove_discount($name) {
649 649
 
650
-		if ( isset( $this->discounts[ $name ] ) ) {
651
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
652
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
653
-			unset( $this->discounts[ $name ] );
650
+		if (isset($this->discounts[$name])) {
651
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
652
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
653
+			unset($this->discounts[$name]);
654 654
 		}
655 655
 
656 656
 	}
@@ -662,7 +662,7 @@  discard block
 block discarded – undo
662 662
 	 * @return bool
663 663
 	 */
664 664
 	public function has_discount_code() {
665
-		return ! empty( $this->discounts['discount_code'] );
665
+		return !empty($this->discounts['discount_code']);
666 666
 	}
667 667
 
668 668
 	/**
@@ -719,13 +719,13 @@  discard block
 block discarded – undo
719 719
 	 */
720 720
 	public function process_fees() {
721 721
 
722
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
722
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
723 723
 
724
-		foreach ( $fees_processor->fees as $fee ) {
725
-			$this->add_fee( $fee );
724
+		foreach ($fees_processor->fees as $fee) {
725
+			$this->add_fee($fee);
726 726
 		}
727 727
 
728
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
728
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
729 729
 	}
730 730
 
731 731
 	/**
@@ -734,17 +734,17 @@  discard block
 block discarded – undo
734 734
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
735 735
 	 * @since 1.0.19
736 736
 	 */
737
-	public function add_fee( $fee ) {
737
+	public function add_fee($fee) {
738 738
 
739
-		if ( $fee['name'] == 'shipping' ) {
740
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
741
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
739
+		if ($fee['name'] == 'shipping') {
740
+			$this->totals['shipping']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
741
+			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
742 742
 			return;
743 743
 		}
744 744
 
745
-		$this->fees[ $fee['name'] ]         = $fee;
746
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
747
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
745
+		$this->fees[$fee['name']]         = $fee;
746
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
747
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
748 748
 
749 749
 	}
750 750
 
@@ -753,15 +753,15 @@  discard block
 block discarded – undo
753 753
 	 *
754 754
 	 * @since 1.0.19
755 755
 	 */
756
-	public function remove_fee( $name ) {
756
+	public function remove_fee($name) {
757 757
 
758
-		if ( isset( $this->fees[ $name ] ) ) {
759
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
760
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
761
-			unset( $this->fees[ $name ] );
758
+		if (isset($this->fees[$name])) {
759
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
760
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
761
+			unset($this->fees[$name]);
762 762
 		}
763 763
 
764
-		if ( 'shipping' == $name ) {
764
+		if ('shipping' == $name) {
765 765
 			$this->totals['shipping']['initial']   = 0;
766 766
 			$this->totals['shipping']['recurring'] = 0;
767 767
 		}
@@ -802,7 +802,7 @@  discard block
 block discarded – undo
802 802
 	 * @since 1.0.19
803 803
 	 */
804 804
 	public function has_fees() {
805
-		return count( $this->fees ) !== 0;
805
+		return count($this->fees) !== 0;
806 806
 	}
807 807
 
808 808
 	/*
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 	 * @since 1.0.19
839 839
 	 */
840 840
 	public function has_shipping() {
841
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
841
+		return apply_filters('getpaid_payment_form_has_shipping', false, $this);
842 842
 	}
843 843
 
844 844
 	/**
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	 * @since 1.0.19
849 849
 	 */
850 850
 	public function is_initial_fetch() {
851
-		return empty( $this->data['initial_state'] );
851
+		return empty($this->data['initial_state']);
852 852
 	}
853 853
 
854 854
 	/**
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	public function get_total() {
860 860
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
861
-		return max( $total, 0 );
861
+		return max($total, 0);
862 862
 	}
863 863
 
864 864
 	/**
@@ -868,7 +868,7 @@  discard block
 block discarded – undo
868 868
 	 */
869 869
 	public function get_recurring_total() {
870 870
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
871
-		return max( $total, 0 );
871
+		return max($total, 0);
872 872
 	}
873 873
 
874 874
 	/**
@@ -880,12 +880,12 @@  discard block
 block discarded – undo
880 880
 		$initial   = $this->get_total();
881 881
 		$recurring = $this->get_recurring_total();
882 882
 
883
-		if ( $this->has_recurring == 0 ) {
883
+		if ($this->has_recurring == 0) {
884 884
 			$recurring = 0;
885 885
 		}
886 886
 
887 887
 		$collect = $initial > 0 || $recurring > 0;
888
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this );
888
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
889 889
 	}
890 890
 
891 891
 	/**
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 	 * @since 1.0.19
895 895
 	 */
896 896
 	public function get_billing_email() {
897
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this );
897
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
898 898
 	}
899 899
 
900 900
 	/**
@@ -904,7 +904,7 @@  discard block
 block discarded – undo
904 904
 	 */
905 905
 	public function has_billing_email() {
906 906
 		$billing_email = $this->get_billing_email();
907
-		return ! empty( $billing_email ) && is_email( $billing_email );
907
+		return !empty($billing_email) && is_email($billing_email);
908 908
 	}
909 909
 
910 910
 	/**
@@ -934,8 +934,8 @@  discard block
 block discarded – undo
934 934
 	 * @since 1.0.19
935 935
 	 * @return mixed|null
936 936
 	 */
937
-	public function get_field( $field, $sub_array_key = null ) {
938
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
937
+	public function get_field($field, $sub_array_key = null) {
938
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
939 939
 	}
940 940
 
941 941
 	/**
@@ -943,8 +943,8 @@  discard block
 block discarded – undo
943 943
 	 *
944 944
 	 * @since 1.0.19
945 945
 	 */
946
-	public function is_required_field_set( $field ) {
947
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
946
+	public function is_required_field_set($field) {
947
+		return empty($field['required']) || !empty($this->data[$field['id']]);
948 948
 	}
949 949
 
950 950
 	/**
@@ -952,8 +952,8 @@  discard block
 block discarded – undo
952 952
 	 *
953 953
 	 * @since 1.0.19
954 954
 	 */
955
-	public function format_amount( $amount ) {
956
-		return wpinv_price( $amount, $this->get_currency() );
955
+	public function format_amount($amount) {
956
+		return wpinv_price($amount, $this->get_currency());
957 957
 	}
958 958
 
959 959
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 2 patches
Indentation   +257 added lines, -257 removed lines patch added patch discarded remove patch
@@ -12,295 +12,295 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id'                    => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31
-			'has_subscription_group'           => $submission->has_subscription_group(),
32
-			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
31
+            'has_subscription_group'           => $submission->has_subscription_group(),
32
+            'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33 33
             'is_free'                          => ! $submission->should_collect_payment_details(),
34
-		);
35
-
36
-		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
38
-			$this->response['invoice'] = $payment_form->invoice->get_id();
39
-		}
40
-
41
-		$this->add_totals( $submission );
42
-		$this->add_texts( $submission );
43
-		$this->add_items( $submission );
44
-		$this->add_fees( $submission );
45
-		$this->add_discounts( $submission );
46
-		$this->add_taxes( $submission );
47
-		$this->add_gateways( $submission );
48
-		$this->add_data( $submission );
49
-
50
-	}
51
-
52
-	/**
53
-	 * Adds totals to a response for submission refresh prices.
54
-	 *
55
-	 * @param GetPaid_Payment_Form_Submission $submission
56
-	 */
57
-	public function add_totals( $submission ) {
58
-
59
-		$this->response = array_merge(
60
-			$this->response,
61
-			array(
62
-
63
-				'totals'      => array(
64
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
65
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
66
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
67
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
68
-					'total'     => $submission->format_amount( $submission->get_total() ),
69
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
70
-				),
71
-
72
-				'recurring'   => array(
73
-					'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
74
-					'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
75
-					'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
76
-					'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
77
-					'total'    => $submission->format_amount( $submission->get_recurring_total() ),
78
-				),
79
-
80
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
81
-				'currency'    => $submission->get_currency(),
82
-
83
-			)
84
-		);
85
-
86
-	}
87
-
88
-	/**
89
-	 * Adds texts to a response for submission refresh prices.
90
-	 *
91
-	 * @param GetPaid_Payment_Form_Submission $submission
92
-	 */
93
-	public function add_texts( $submission ) {
94
-
95
-		$payable = $submission->format_amount( $submission->get_total() );
96
-		$groups  = getpaid_get_subscription_groups( $submission );
97
-
98
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
99
-
100
-			$recurring = new WPInv_Item( $submission->has_recurring );
101
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
102
-			$main_item = reset( $groups );
103
-
104
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
105
-				$payable = "$payable / $period";
106
-			} elseif ( $main_item ) {
107
-
108
-				$main_item = reset( $main_item );
109
-
110
-				// Calculate the next renewal date.
111
-				$_period      = $main_item->get_recurring_period( true );
112
-				$_interval    = $main_item->get_recurring_interval();
113
-
114
-				// If the subscription item has a trial period...
115
-				if ( $main_item->has_free_trial() ) {
116
-					$_period   = $main_item->get_trial_period( true );
117
-					$_interval = $main_item->get_trial_interval();
118
-				}
119
-
120
-				$payable = sprintf(
121
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
122
-					$submission->format_amount( $submission->get_total() ),
123
-					$submission->format_amount( $submission->get_recurring_total() ),
124
-					$period
125
-				);
126
-
127
-				$payable .= sprintf(
128
-					'<small class="text-muted form-text">%s</small>',
129
-					sprintf(
130
-						__( 'First renewal on %s', 'invoicing' ),
131
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
132
-					)
133
-				);
134
-
135
-			} else {
136
-				$payable = sprintf(
137
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
138
-					$submission->format_amount( $submission->get_total() ),
139
-					$submission->format_amount( $submission->get_recurring_total() ),
140
-					$period
141
-				);
142
-			}
143
-}
34
+        );
35
+
36
+        $payment_form = $submission->get_payment_form();
37
+        if ( ! empty( $payment_form->invoice ) ) {
38
+            $this->response['invoice'] = $payment_form->invoice->get_id();
39
+        }
40
+
41
+        $this->add_totals( $submission );
42
+        $this->add_texts( $submission );
43
+        $this->add_items( $submission );
44
+        $this->add_fees( $submission );
45
+        $this->add_discounts( $submission );
46
+        $this->add_taxes( $submission );
47
+        $this->add_gateways( $submission );
48
+        $this->add_data( $submission );
49
+
50
+    }
51
+
52
+    /**
53
+     * Adds totals to a response for submission refresh prices.
54
+     *
55
+     * @param GetPaid_Payment_Form_Submission $submission
56
+     */
57
+    public function add_totals( $submission ) {
58
+
59
+        $this->response = array_merge(
60
+            $this->response,
61
+            array(
62
+
63
+                'totals'      => array(
64
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
65
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
66
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
67
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
68
+                    'total'     => $submission->format_amount( $submission->get_total() ),
69
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
70
+                ),
71
+
72
+                'recurring'   => array(
73
+                    'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
74
+                    'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
75
+                    'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
76
+                    'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
77
+                    'total'    => $submission->format_amount( $submission->get_recurring_total() ),
78
+                ),
79
+
80
+                'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
81
+                'currency'    => $submission->get_currency(),
82
+
83
+            )
84
+        );
85
+
86
+    }
144 87
 
145
-		$texts = array(
146
-			'.getpaid-checkout-total-payable' => $payable,
147
-		);
88
+    /**
89
+     * Adds texts to a response for submission refresh prices.
90
+     *
91
+     * @param GetPaid_Payment_Form_Submission $submission
92
+     */
93
+    public function add_texts( $submission ) {
94
+
95
+        $payable = $submission->format_amount( $submission->get_total() );
96
+        $groups  = getpaid_get_subscription_groups( $submission );
97
+
98
+        if ( $submission->has_recurring && 2 > count( $groups ) ) {
99
+
100
+            $recurring = new WPInv_Item( $submission->has_recurring );
101
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
102
+            $main_item = reset( $groups );
103
+
104
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
105
+                $payable = "$payable / $period";
106
+            } elseif ( $main_item ) {
107
+
108
+                $main_item = reset( $main_item );
109
+
110
+                // Calculate the next renewal date.
111
+                $_period      = $main_item->get_recurring_period( true );
112
+                $_interval    = $main_item->get_recurring_interval();
113
+
114
+                // If the subscription item has a trial period...
115
+                if ( $main_item->has_free_trial() ) {
116
+                    $_period   = $main_item->get_trial_period( true );
117
+                    $_interval = $main_item->get_trial_interval();
118
+                }
119
+
120
+                $payable = sprintf(
121
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
122
+                    $submission->format_amount( $submission->get_total() ),
123
+                    $submission->format_amount( $submission->get_recurring_total() ),
124
+                    $period
125
+                );
126
+
127
+                $payable .= sprintf(
128
+                    '<small class="text-muted form-text">%s</small>',
129
+                    sprintf(
130
+                        __( 'First renewal on %s', 'invoicing' ),
131
+                        getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
132
+                    )
133
+                );
134
+
135
+            } else {
136
+                $payable = sprintf(
137
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
138
+                    $submission->format_amount( $submission->get_total() ),
139
+                    $submission->format_amount( $submission->get_recurring_total() ),
140
+                    $period
141
+                );
142
+            }
143
+}
148 144
 
149
-		foreach ( $submission->get_items() as $item ) {
150
-			$item_id                                               = $item->get_id();
151
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
152
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
153
-			$texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
154
-			$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
145
+        $texts = array(
146
+            '.getpaid-checkout-total-payable' => $payable,
147
+        );
155 148
 
156
-			if ( $item->get_quantity() == 1 ) {
157
-				$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
158
-			}
149
+        foreach ( $submission->get_items() as $item ) {
150
+            $item_id                                               = $item->get_id();
151
+            $initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
152
+            $recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
153
+            $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
154
+            $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
155
+
156
+            if ( $item->get_quantity() == 1 ) {
157
+                $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
158
+            }
159 159
 }
160 160
 
161
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
161
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
162 162
 
163
-	}
163
+    }
164 164
 
165
-	/**
166
-	 * Adds items to a response for submission refresh prices.
167
-	 *
168
-	 * @param GetPaid_Payment_Form_Submission $submission
169
-	 */
170
-	public function add_items( $submission ) {
165
+    /**
166
+     * Adds items to a response for submission refresh prices.
167
+     *
168
+     * @param GetPaid_Payment_Form_Submission $submission
169
+     */
170
+    public function add_items( $submission ) {
171 171
 
172
-		// Add items.
173
-		$items = array();
172
+        // Add items.
173
+        $items = array();
174 174
 
175 175
         foreach ( $submission->get_items() as $item ) {
176
-			$item_id           = $item->get_id();
177
-			$items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
178
-		}
176
+            $item_id           = $item->get_id();
177
+            $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
178
+        }
179 179
 
180
-		$this->response = array_merge(
181
-			$this->response,
182
-			array( 'items' => $items )
183
-		);
180
+        $this->response = array_merge(
181
+            $this->response,
182
+            array( 'items' => $items )
183
+        );
184 184
 
185
-	}
185
+    }
186 186
 
187
-	/**
188
-	 * Adds fees to a response for submission refresh prices.
189
-	 *
190
-	 * @param GetPaid_Payment_Form_Submission $submission
191
-	 */
192
-	public function add_fees( $submission ) {
187
+    /**
188
+     * Adds fees to a response for submission refresh prices.
189
+     *
190
+     * @param GetPaid_Payment_Form_Submission $submission
191
+     */
192
+    public function add_fees( $submission ) {
193 193
 
194
-		$fees = array();
194
+        $fees = array();
195 195
 
196 196
         foreach ( $submission->get_fees() as $name => $data ) {
197
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
198
-		}
197
+            $fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
198
+        }
199 199
 
200
-		$this->response = array_merge(
201
-			$this->response,
202
-			array( 'fees' => $fees )
203
-		);
200
+        $this->response = array_merge(
201
+            $this->response,
202
+            array( 'fees' => $fees )
203
+        );
204 204
 
205
-	}
205
+    }
206 206
 
207
-	/**
208
-	 * Adds discounts to a response for submission refresh prices.
209
-	 *
210
-	 * @param GetPaid_Payment_Form_Submission $submission
211
-	 */
212
-	public function add_discounts( $submission ) {
207
+    /**
208
+     * Adds discounts to a response for submission refresh prices.
209
+     *
210
+     * @param GetPaid_Payment_Form_Submission $submission
211
+     */
212
+    public function add_discounts( $submission ) {
213 213
 
214
-		$discounts = array();
214
+        $discounts = array();
215 215
 
216 216
         foreach ( $submission->get_discounts() as $name => $data ) {
217
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
218
-		}
219
-
220
-		$this->response = array_merge(
221
-			$this->response,
222
-			array( 'discounts' => $discounts )
223
-		);
217
+            $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
218
+        }
224 219
 
225
-	}
220
+        $this->response = array_merge(
221
+            $this->response,
222
+            array( 'discounts' => $discounts )
223
+        );
226 224
 
227
-	/**
228
-	 * Adds taxes to a response for submission refresh prices.
229
-	 *
230
-	 * @param GetPaid_Payment_Form_Submission $submission
231
-	 */
232
-	public function add_taxes( $submission ) {
225
+    }
233 226
 
234
-		$taxes  = array();
235
-		$markup = '';
227
+    /**
228
+     * Adds taxes to a response for submission refresh prices.
229
+     *
230
+     * @param GetPaid_Payment_Form_Submission $submission
231
+     */
232
+    public function add_taxes( $submission ) {
233
+
234
+        $taxes  = array();
235
+        $markup = '';
236 236
         foreach ( $submission->get_taxes() as $name => $data ) {
237
-			$name          = sanitize_text_field( $name );
238
-			$amount        = $submission->format_amount( $data['initial_tax'] );
239
-			$taxes[ $name ]  = $amount;
240
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
241
-		}
242
-
243
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
244
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
245
-		}
246
-
247
-		$this->response = array_merge(
248
-			$this->response,
249
-			array( 'taxes' => $taxes )
250
-		);
251
-
252
-	}
253
-
254
-	/**
255
-	 * Adds gateways to a response for submission refresh prices.
256
-	 *
257
-	 * @param GetPaid_Payment_Form_Submission $submission
258
-	 */
259
-	public function add_gateways( $submission ) {
260
-
261
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
262
-
263
-		if ( $this->response['has_recurring'] ) {
264
-
265
-			foreach ( $gateways as $i => $gateway ) {
266
-
267
-				if (
268
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
269
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
270
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
271
-					unset( $gateways[ $i ] );
272
-				}
237
+            $name          = sanitize_text_field( $name );
238
+            $amount        = $submission->format_amount( $data['initial_tax'] );
239
+            $taxes[ $name ]  = $amount;
240
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
241
+        }
242
+
243
+        if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
244
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
245
+        }
246
+
247
+        $this->response = array_merge(
248
+            $this->response,
249
+            array( 'taxes' => $taxes )
250
+        );
251
+
252
+    }
253
+
254
+    /**
255
+     * Adds gateways to a response for submission refresh prices.
256
+     *
257
+     * @param GetPaid_Payment_Form_Submission $submission
258
+     */
259
+    public function add_gateways( $submission ) {
260
+
261
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
262
+
263
+        if ( $this->response['has_recurring'] ) {
264
+
265
+            foreach ( $gateways as $i => $gateway ) {
266
+
267
+                if (
268
+                    ! getpaid_payment_gateway_supports( $gateway, 'subscription' )
269
+                    || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
270
+                    || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
271
+                    unset( $gateways[ $i ] );
272
+                }
273 273
 }
274 274
 }
275 275
 
276
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
277
-		$this->response = array_merge(
278
-			$this->response,
279
-			array( 'gateways' => $gateways )
280
-		);
281
-
282
-	}
283
-
284
-	/**
285
-	 * Adds data to a response for submission refresh prices.
286
-	 *
287
-	 * @param GetPaid_Payment_Form_Submission $submission
288
-	 */
289
-	public function add_data( $submission ) {
290
-
291
-		$this->response = array_merge(
292
-			$this->response,
293
-			array(
294
-				'js_data' => apply_filters(
295
-					'getpaid_submission_js_data',
296
-					array(
297
-						'is_recurring' => $this->response['has_recurring'],
298
-					),
299
-					$submission
300
-				),
301
-			)
302
-		);
303
-
304
-	}
276
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
277
+        $this->response = array_merge(
278
+            $this->response,
279
+            array( 'gateways' => $gateways )
280
+        );
281
+
282
+    }
283
+
284
+    /**
285
+     * Adds data to a response for submission refresh prices.
286
+     *
287
+     * @param GetPaid_Payment_Form_Submission $submission
288
+     */
289
+    public function add_data( $submission ) {
290
+
291
+        $this->response = array_merge(
292
+            $this->response,
293
+            array(
294
+                'js_data' => apply_filters(
295
+                    'getpaid_submission_js_data',
296
+                    array(
297
+                        'is_recurring' => $this->response['has_recurring'],
298
+                    ),
299
+                    $submission
300
+                ),
301
+            )
302
+        );
303
+
304
+    }
305 305
 
306 306
 }
Please login to merge, or discard this patch.
Spacing   +85 added lines, -85 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission refresh prices class
@@ -23,29 +23,29 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$this->response = array(
29 29
 			'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31 31
 			'has_subscription_group'           => $submission->has_subscription_group(),
32 32
 			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33
-            'is_free'                          => ! $submission->should_collect_payment_details(),
33
+            'is_free'                          => !$submission->should_collect_payment_details(),
34 34
 		);
35 35
 
36 36
 		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
37
+		if (!empty($payment_form->invoice)) {
38 38
 			$this->response['invoice'] = $payment_form->invoice->get_id();
39 39
 		}
40 40
 
41
-		$this->add_totals( $submission );
42
-		$this->add_texts( $submission );
43
-		$this->add_items( $submission );
44
-		$this->add_fees( $submission );
45
-		$this->add_discounts( $submission );
46
-		$this->add_taxes( $submission );
47
-		$this->add_gateways( $submission );
48
-		$this->add_data( $submission );
41
+		$this->add_totals($submission);
42
+		$this->add_texts($submission);
43
+		$this->add_items($submission);
44
+		$this->add_fees($submission);
45
+		$this->add_discounts($submission);
46
+		$this->add_taxes($submission);
47
+		$this->add_gateways($submission);
48
+		$this->add_data($submission);
49 49
 
50 50
 	}
51 51
 
@@ -54,30 +54,30 @@  discard block
 block discarded – undo
54 54
 	 *
55 55
 	 * @param GetPaid_Payment_Form_Submission $submission
56 56
 	 */
57
-	public function add_totals( $submission ) {
57
+	public function add_totals($submission) {
58 58
 
59 59
 		$this->response = array_merge(
60 60
 			$this->response,
61 61
 			array(
62 62
 
63 63
 				'totals'      => array(
64
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
65
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
66
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
67
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
68
-					'total'     => $submission->format_amount( $submission->get_total() ),
69
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
64
+					'subtotal'  => $submission->format_amount($submission->get_subtotal()),
65
+					'discount'  => $submission->format_amount($submission->get_discount()),
66
+					'fees'      => $submission->format_amount($submission->get_fee()),
67
+					'tax'       => $submission->format_amount($submission->get_tax()),
68
+					'total'     => $submission->format_amount($submission->get_total()),
69
+					'raw_total' => html_entity_decode(sanitize_text_field($submission->format_amount($submission->get_total())), ENT_QUOTES),
70 70
 				),
71 71
 
72 72
 				'recurring'   => array(
73
-					'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
74
-					'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
75
-					'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
76
-					'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
77
-					'total'    => $submission->format_amount( $submission->get_recurring_total() ),
73
+					'subtotal' => $submission->format_amount($submission->get_recurring_subtotal()),
74
+					'discount' => $submission->format_amount($submission->get_recurring_discount()),
75
+					'fees'     => $submission->format_amount($submission->get_recurring_fee()),
76
+					'tax'      => $submission->format_amount($submission->get_recurring_tax()),
77
+					'total'    => $submission->format_amount($submission->get_recurring_total()),
78 78
 				),
79 79
 
80
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
80
+				'initial_amt' => wpinv_round_amount($submission->get_total(), null, true),
81 81
 				'currency'    => $submission->get_currency(),
82 82
 
83 83
 			)
@@ -90,53 +90,53 @@  discard block
 block discarded – undo
90 90
 	 *
91 91
 	 * @param GetPaid_Payment_Form_Submission $submission
92 92
 	 */
93
-	public function add_texts( $submission ) {
93
+	public function add_texts($submission) {
94 94
 
95
-		$payable = $submission->format_amount( $submission->get_total() );
96
-		$groups  = getpaid_get_subscription_groups( $submission );
95
+		$payable = $submission->format_amount($submission->get_total());
96
+		$groups  = getpaid_get_subscription_groups($submission);
97 97
 
98
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
98
+		if ($submission->has_recurring && 2 > count($groups)) {
99 99
 
100
-			$recurring = new WPInv_Item( $submission->has_recurring );
101
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
102
-			$main_item = reset( $groups );
100
+			$recurring = new WPInv_Item($submission->has_recurring);
101
+			$period    = getpaid_get_subscription_period_label($recurring->get_recurring_period(true), $recurring->get_recurring_interval(), '');
102
+			$main_item = reset($groups);
103 103
 
104
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
104
+			if ($submission->get_total() == $submission->get_recurring_total()) {
105 105
 				$payable = "$payable / $period";
106
-			} elseif ( $main_item ) {
106
+			} elseif ($main_item) {
107 107
 
108
-				$main_item = reset( $main_item );
108
+				$main_item = reset($main_item);
109 109
 
110 110
 				// Calculate the next renewal date.
111
-				$_period      = $main_item->get_recurring_period( true );
111
+				$_period      = $main_item->get_recurring_period(true);
112 112
 				$_interval    = $main_item->get_recurring_interval();
113 113
 
114 114
 				// If the subscription item has a trial period...
115
-				if ( $main_item->has_free_trial() ) {
116
-					$_period   = $main_item->get_trial_period( true );
115
+				if ($main_item->has_free_trial()) {
116
+					$_period   = $main_item->get_trial_period(true);
117 117
 					$_interval = $main_item->get_trial_interval();
118 118
 				}
119 119
 
120 120
 				$payable = sprintf(
121
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
122
-					$submission->format_amount( $submission->get_total() ),
123
-					$submission->format_amount( $submission->get_recurring_total() ),
121
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
122
+					$submission->format_amount($submission->get_total()),
123
+					$submission->format_amount($submission->get_recurring_total()),
124 124
 					$period
125 125
 				);
126 126
 
127 127
 				$payable .= sprintf(
128 128
 					'<small class="text-muted form-text">%s</small>',
129 129
 					sprintf(
130
-						__( 'First renewal on %s', 'invoicing' ),
131
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
130
+						__('First renewal on %s', 'invoicing'),
131
+						getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp'))))
132 132
 					)
133 133
 				);
134 134
 
135 135
 			} else {
136 136
 				$payable = sprintf(
137
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
138
-					$submission->format_amount( $submission->get_total() ),
139
-					$submission->format_amount( $submission->get_recurring_total() ),
137
+					__('%1$s (renews at %2$s / %3$s)', 'invoicing'),
138
+					$submission->format_amount($submission->get_total()),
139
+					$submission->format_amount($submission->get_recurring_total()),
140 140
 					$period
141 141
 				);
142 142
 			}
@@ -146,19 +146,19 @@  discard block
 block discarded – undo
146 146
 			'.getpaid-checkout-total-payable' => $payable,
147 147
 		);
148 148
 
149
-		foreach ( $submission->get_items() as $item ) {
149
+		foreach ($submission->get_items() as $item) {
150 150
 			$item_id                                               = $item->get_id();
151
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
152
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
153
-			$texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
154
-			$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
151
+			$initial_price                                         = $submission->format_amount($item->get_sub_total() - $item->item_discount);
152
+			$recurring_price                                       = $submission->format_amount($item->get_recurring_sub_total() - $item->recurring_item_discount);
153
+			$texts[".item-$item_id .getpaid-form-item-price-desc"] = getpaid_item_recurring_price_help_text($item, $submission->get_currency(), $initial_price, $recurring_price);
154
+			$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = sprintf(__('Subtotal: %s', 'invoicing'), $submission->format_amount($item->get_sub_total()));
155 155
 
156
-			if ( $item->get_quantity() == 1 ) {
157
-				$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
156
+			if ($item->get_quantity() == 1) {
157
+				$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = '';
158 158
 			}
159 159
 }
160 160
 
161
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
161
+		$this->response = array_merge($this->response, array('texts' => $texts));
162 162
 
163 163
 	}
164 164
 
@@ -167,19 +167,19 @@  discard block
 block discarded – undo
167 167
 	 *
168 168
 	 * @param GetPaid_Payment_Form_Submission $submission
169 169
 	 */
170
-	public function add_items( $submission ) {
170
+	public function add_items($submission) {
171 171
 
172 172
 		// Add items.
173 173
 		$items = array();
174 174
 
175
-        foreach ( $submission->get_items() as $item ) {
176
-			$item_id           = $item->get_id();
177
-			$items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
175
+        foreach ($submission->get_items() as $item) {
176
+			$item_id = $item->get_id();
177
+			$items["$item_id"] = $submission->format_amount($item->get_sub_total());
178 178
 		}
179 179
 
180 180
 		$this->response = array_merge(
181 181
 			$this->response,
182
-			array( 'items' => $items )
182
+			array('items' => $items)
183 183
 		);
184 184
 
185 185
 	}
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
 	 *
190 190
 	 * @param GetPaid_Payment_Form_Submission $submission
191 191
 	 */
192
-	public function add_fees( $submission ) {
192
+	public function add_fees($submission) {
193 193
 
194 194
 		$fees = array();
195 195
 
196
-        foreach ( $submission->get_fees() as $name => $data ) {
197
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
196
+        foreach ($submission->get_fees() as $name => $data) {
197
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
198 198
 		}
199 199
 
200 200
 		$this->response = array_merge(
201 201
 			$this->response,
202
-			array( 'fees' => $fees )
202
+			array('fees' => $fees)
203 203
 		);
204 204
 
205 205
 	}
@@ -209,17 +209,17 @@  discard block
 block discarded – undo
209 209
 	 *
210 210
 	 * @param GetPaid_Payment_Form_Submission $submission
211 211
 	 */
212
-	public function add_discounts( $submission ) {
212
+	public function add_discounts($submission) {
213 213
 
214 214
 		$discounts = array();
215 215
 
216
-        foreach ( $submission->get_discounts() as $name => $data ) {
217
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
216
+        foreach ($submission->get_discounts() as $name => $data) {
217
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
218 218
 		}
219 219
 
220 220
 		$this->response = array_merge(
221 221
 			$this->response,
222
-			array( 'discounts' => $discounts )
222
+			array('discounts' => $discounts)
223 223
 		);
224 224
 
225 225
 	}
@@ -229,24 +229,24 @@  discard block
 block discarded – undo
229 229
 	 *
230 230
 	 * @param GetPaid_Payment_Form_Submission $submission
231 231
 	 */
232
-	public function add_taxes( $submission ) {
232
+	public function add_taxes($submission) {
233 233
 
234 234
 		$taxes  = array();
235 235
 		$markup = '';
236
-        foreach ( $submission->get_taxes() as $name => $data ) {
237
-			$name          = sanitize_text_field( $name );
238
-			$amount        = $submission->format_amount( $data['initial_tax'] );
239
-			$taxes[ $name ]  = $amount;
236
+        foreach ($submission->get_taxes() as $name => $data) {
237
+			$name          = sanitize_text_field($name);
238
+			$amount        = $submission->format_amount($data['initial_tax']);
239
+			$taxes[$name] = $amount;
240 240
 			$markup       .= "<small class='form-text'>$name : $amount</small>";
241 241
 		}
242 242
 
243
-		if ( wpinv_display_individual_tax_rates() && ! empty( $taxes ) ) {
243
+		if (wpinv_display_individual_tax_rates() && !empty($taxes)) {
244 244
 			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
245 245
 		}
246 246
 
247 247
 		$this->response = array_merge(
248 248
 			$this->response,
249
-			array( 'taxes' => $taxes )
249
+			array('taxes' => $taxes)
250 250
 		);
251 251
 
252 252
 	}
@@ -256,27 +256,27 @@  discard block
 block discarded – undo
256 256
 	 *
257 257
 	 * @param GetPaid_Payment_Form_Submission $submission
258 258
 	 */
259
-	public function add_gateways( $submission ) {
259
+	public function add_gateways($submission) {
260 260
 
261
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
261
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
262 262
 
263
-		if ( $this->response['has_recurring'] ) {
263
+		if ($this->response['has_recurring']) {
264 264
 
265
-			foreach ( $gateways as $i => $gateway ) {
265
+			foreach ($gateways as $i => $gateway) {
266 266
 
267 267
 				if (
268
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
269
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
270
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
271
-					unset( $gateways[ $i ] );
268
+					!getpaid_payment_gateway_supports($gateway, 'subscription')
269
+					|| ($this->response['has_subscription_group'] && !getpaid_payment_gateway_supports($gateway, 'single_subscription_group'))
270
+					|| ($this->response['has_multiple_subscription_groups'] && !getpaid_payment_gateway_supports($gateway, 'multiple_subscription_groups')) ) {
271
+					unset($gateways[$i]);
272 272
 				}
273 273
 }
274 274
 }
275 275
 
276
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
276
+		$gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission);
277 277
 		$this->response = array_merge(
278 278
 			$this->response,
279
-			array( 'gateways' => $gateways )
279
+			array('gateways' => $gateways)
280 280
 		);
281 281
 
282 282
 	}
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 *
287 287
 	 * @param GetPaid_Payment_Form_Submission $submission
288 288
 	 */
289
-	public function add_data( $submission ) {
289
+	public function add_data($submission) {
290 290
 
291 291
 		$this->response = array_merge(
292 292
 			$this->response,
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
Indentation   +305 added lines, -305 removed lines patch added patch discarded remove patch
@@ -12,184 +12,184 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items      = $this->get_submission_items();
40
-		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared   = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items      = $this->get_submission_items();
40
+        $invoice    = $this->get_submission_invoice();
41
+        $invoice    = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared   = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	}
99
+    }
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
133 125
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
138 131
 
139
-		return $invoice;
140
-	}
132
+        $invoice = $submission->get_invoice();
141 133
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
150 138
 
151
-		$submission = $this->payment_form_submission;
139
+        return $invoice;
140
+    }
152 141
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150
+
151
+        $submission = $this->payment_form_submission;
152
+
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157 157
         $invoice->set_items( $items );
158 158
         $invoice->set_fees( $submission->get_fees() );
159 159
         $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
160
+        $invoice->set_discounts( $submission->get_discounts() );
161
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
+        $invoice->set_currency( $submission->get_currency() );
163 163
 
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
166
-		}
164
+        if ( $submission->has_shipping() ) {
165
+            $invoice->set_shipping( $submission->get_shipping() );
166
+        }
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+        $address_confirmed = $submission->get_field( 'confirm-address' );
169
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
170 170
 
171
-		if ( $submission->has_discount_code() ) {
171
+        if ( $submission->has_discount_code() ) {
172 172
             $invoice->set_discount_code( $submission->get_discount_code() );
173
-		}
174
-
175
-		getpaid_maybe_add_default_address( $invoice );
176
-		return $invoice;
177
-	}
178
-
179
-	/**
180
-	 * Retrieves the submission's customer.
181
-	 *
182
-	 * @return int The customer id.
183
-	 */
184
-	protected function get_submission_customer() {
185
-		$submission = $this->payment_form_submission;
186
-
187
-		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
189
-			return $submission->get_invoice()->get_user_id();
190
-		}
191
-
192
-		// (Maybe) create the user.
173
+        }
174
+
175
+        getpaid_maybe_add_default_address( $invoice );
176
+        return $invoice;
177
+    }
178
+
179
+    /**
180
+     * Retrieves the submission's customer.
181
+     *
182
+     * @return int The customer id.
183
+     */
184
+    protected function get_submission_customer() {
185
+        $submission = $this->payment_form_submission;
186
+
187
+        // If this is an existing invoice...
188
+        if ( $submission->has_invoice() ) {
189
+            return $submission->get_invoice()->get_user_id();
190
+        }
191
+
192
+        // (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195 195
         if ( empty( $user ) ) {
@@ -197,16 +197,16 @@  discard block
 block discarded – undo
197 197
         }
198 198
 
199 199
         if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
200
+            $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
+            $name = implode( '', array_filter( $name ) );
202 202
             $user = wpinv_create_user( $submission->get_billing_email(), $name );
203 203
 
204
-			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
208
-			}
209
-		}
204
+            // (Maybe) send new user notification.
205
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
+                wp_send_new_user_notifications( $user, 'user' );
208
+            }
209
+        }
210 210
 
211 211
         if ( is_wp_error( $user ) ) {
212 212
             wp_send_json_error( $user->get_error_message() );
@@ -214,49 +214,49 @@  discard block
 block discarded – undo
214 214
 
215 215
         if ( is_numeric( $user ) ) {
216 216
             return $user;
217
-		}
217
+        }
218 218
 
219
-		return $user->ID;
219
+        return $user->ID;
220 220
 
221
-	}
221
+    }
222 222
 
223
-	/**
223
+    /**
224 224
      * Prepares submission data for saving to the database.
225 225
      *
226
-	 * @return array
226
+     * @return array
227 227
      */
228 228
     public function prepare_submission_data_for_saving() {
229 229
 
230
-		$submission = $this->payment_form_submission;
230
+        $submission = $this->payment_form_submission;
231 231
 
232
-		// Prepared submission details.
232
+        // Prepared submission details.
233 233
         $prepared = array(
234
-			'all'  => array(),
235
-			'meta' => array(),
236
-		);
234
+            'all'  => array(),
235
+            'meta' => array(),
236
+        );
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+        $data     = $submission->get_data();
240 240
 
241
-		// Loop through the submitted details.
241
+        // Loop through the submitted details.
242 242
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
243 243
 
244
-			// Skip premade fields.
244
+            // Skip premade fields.
245 245
             if ( ! empty( $field['premade'] ) ) {
246 246
                 continue;
247 247
             }
248 248
 
249
-			// Ensure address is provided.
250
-			if ( $field['type'] == 'address' ) {
249
+            // Ensure address is provided.
250
+            if ( $field['type'] == 'address' ) {
251 251
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+                foreach ( $field['fields'] as $address_field ) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
-					}
258
-			}
259
-		}
255
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
257
+                    }
258
+            }
259
+        }
260 260
 
261 261
             // If it is required and not set, abort.
262 262
             if ( ! $submission->is_required_field_set( $field ) ) {
@@ -266,31 +266,31 @@  discard block
 block discarded – undo
266 266
             // Handle misc fields.
267 267
             if ( isset( $data[ $field['id'] ] ) ) {
268 268
 
269
-				// Uploads.
270
-				if ( $field['type'] === 'file_upload' ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
269
+                // Uploads.
270
+                if ( $field['type'] === 'file_upload' ) {
271
+                    $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
-					}
273
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
275
+                    }
276 276
 
277
-					$value = array();
277
+                    $value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
280
-						$value[] = sprintf(
281
-							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
284
-						);
285
-					}
279
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
280
+                        $value[] = sprintf(
281
+                            '<a href="%s" target="_blank">%s</a>',
282
+                            esc_url_raw( $url ),
283
+                            esc_html( $name )
284
+                        );
285
+                    }
286 286
 
287
-					$value = implode( ' | ', $value );
287
+                    $value = implode( ' | ', $value );
288 288
 
289
-				} elseif ( $field['type'] === 'checkbox' ) {
290
-					$value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
-				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
293
-				}
289
+                } elseif ( $field['type'] === 'checkbox' ) {
290
+                    $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
291
+                } else {
292
+                    $value = wp_kses_post( $data[ $field['id'] ] );
293
+                }
294 294
 
295 295
                 $label = $field['id'];
296 296
 
@@ -298,188 +298,188 @@  discard block
 block discarded – undo
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
-				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+                if ( ! empty( $field['add_meta'] ) ) {
302
+                    $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
303
+                }
304
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
305 305
 
306 306
             }
307
-		}
307
+        }
308 308
 
309
-		return $prepared;
309
+        return $prepared;
310 310
 
311
-	}
311
+    }
312 312
 
313
-	/**
313
+    /**
314 314
      * Retrieves address details.
315 315
      *
316
-	 * @return array
317
-	 * @param WPInv_Invoice $invoice
318
-	 * @param string $type
316
+     * @return array
317
+     * @param WPInv_Invoice $invoice
318
+     * @param string $type
319 319
      */
320 320
     public function prepare_address_details( $invoice, $type = 'billing' ) {
321 321
 
322
-		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
324
-		$address  = array();
325
-		$prepared = array();
322
+        $data     = $this->payment_form_submission->get_data();
323
+        $type     = sanitize_key( $type );
324
+        $address  = array();
325
+        $prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
329
-		}
327
+        if ( ! empty( $data[ $type ] ) ) {
328
+            $address = $data[ $type ];
329
+        }
330 330
 
331
-		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
-		}
331
+        // Clean address details.
332
+        foreach ( $address as $key => $value ) {
333
+            $key             = sanitize_key( $key );
334
+            $key             = str_replace( 'wpinv_', '', $key );
335
+            $value           = wpinv_clean( $value );
336
+            $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
337
+        }
338 338
 
339
-		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
339
+        // Filter address details.
340
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341 341
 
342
-		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
342
+        // Remove non-whitelisted values.
343
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344 344
 
345
-	}
345
+    }
346 346
 
347
-	/**
347
+    /**
348 348
      * Prepares the billing details.
349 349
      *
350
-	 * @return array
351
-	 * @param WPInv_Invoice $invoice
350
+     * @return array
351
+     * @param WPInv_Invoice $invoice
352 352
      */
353 353
     protected function prepare_billing_info( &$invoice ) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
356 356
 
357
-		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
357
+        // Update the invoice with the billing details.
358
+        $invoice->set_props( $billing_address );
359 359
 
360
-	}
360
+    }
361 361
 
362
-	/**
362
+    /**
363 363
      * Prepares the shipping details.
364 364
      *
365
-	 * @return array
366
-	 * @param WPInv_Invoice $invoice
365
+     * @return array
366
+     * @param WPInv_Invoice $invoice
367 367
      */
368 368
     protected function prepare_shipping_info( $invoice ) {
369 369
 
370
-		$data = $this->payment_form_submission->get_data();
370
+        $data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
374
-		}
372
+        if ( empty( $data['same-shipping-address'] ) ) {
373
+            return $this->prepare_address_details( $invoice, 'shipping' );
374
+        }
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+        return $this->prepare_address_details( $invoice, 'billing' );
377 377
 
378
-	}
378
+    }
379 379
 
380
-	/**
381
-	 * Confirms the submission is valid and send users to the gateway.
382
-	 *
383
-	 * @param WPInv_Invoice $invoice
384
-	 * @param array $prepared_payment_form_data
385
-	 * @param array $shipping
386
-	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
380
+    /**
381
+     * Confirms the submission is valid and send users to the gateway.
382
+     *
383
+     * @param WPInv_Invoice $invoice
384
+     * @param array $prepared_payment_form_data
385
+     * @param array $shipping
386
+     */
387
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
388 388
 
389
-		// Ensure the invoice exists.
389
+        // Ensure the invoice exists.
390 390
         if ( ! $invoice->exists() ) {
391 391
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
392 392
         }
393 393
 
394
-		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
394
+        // Save payment form data.
395
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396 396
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
397
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
+        if ( ! empty( $prepared_payment_form_data ) ) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
-			}
400
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
402
+            }
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
-			}
407
-		}
404
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
406
+            }
407
+        }
408 408
 
409
-		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
409
+        // Save payment form data.
410
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411 411
         if ( ! empty( $shipping ) ) {
412 412
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
413
-		}
413
+        }
414 414
 
415
-		// Backwards compatibility.
415
+        // Backwards compatibility.
416 416
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
417 417
 
418
-		$this->process_payment( $invoice );
418
+        $this->process_payment( $invoice );
419 419
 
420 420
         // If we are here, there was an error.
421
-		wpinv_send_back_to_checkout( $invoice );
421
+        wpinv_send_back_to_checkout( $invoice );
422 422
 
423
-	}
423
+    }
424 424
 
425
-	/**
426
-	 * Processes the actual payment.
427
-	 *
428
-	 * @param WPInv_Invoice $invoice
429
-	 */
430
-	protected function process_payment( $invoice ) {
425
+    /**
426
+     * Processes the actual payment.
427
+     *
428
+     * @param WPInv_Invoice $invoice
429
+     */
430
+    protected function process_payment( $invoice ) {
431 431
 
432
-		// Clear any checkout errors.
433
-		wpinv_clear_errors();
432
+        // Clear any checkout errors.
433
+        wpinv_clear_errors();
434 434
 
435
-		// No need to send free invoices to the gateway.
436
-		if ( $invoice->is_free() ) {
437
-			$this->process_free_payment( $invoice );
438
-		}
435
+        // No need to send free invoices to the gateway.
436
+        if ( $invoice->is_free() ) {
437
+            $this->process_free_payment( $invoice );
438
+        }
439 439
 
440
-		$submission = $this->payment_form_submission;
440
+        $submission = $this->payment_form_submission;
441 441
 
442
-		// Fires before sending to the gateway.
443
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
442
+        // Fires before sending to the gateway.
443
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
444 444
 
445
-		// Allow the sumission data to be modified before it is sent to the gateway.
446
-		$submission_data    = $submission->get_data();
447
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
445
+        // Allow the sumission data to be modified before it is sent to the gateway.
446
+        $submission_data    = $submission->get_data();
447
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
449 449
 
450
-		// Validate the currency.
451
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
-			wpinv_set_error( 'invalid_currency' );
453
-		}
450
+        // Validate the currency.
451
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
+            wpinv_set_error( 'invalid_currency' );
453
+        }
454 454
 
455
-		// Check to see if we have any errors.
456
-		if ( wpinv_get_errors() ) {
457
-			wpinv_send_back_to_checkout( $invoice );
458
-		}
455
+        // Check to see if we have any errors.
456
+        if ( wpinv_get_errors() ) {
457
+            wpinv_send_back_to_checkout( $invoice );
458
+        }
459 459
 
460
-		// Send info to the gateway for payment processing
461
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
460
+        // Send info to the gateway for payment processing
461
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
462 462
 
463
-		// Backwards compatibility.
464
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
463
+        // Backwards compatibility.
464
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
465 465
 
466
-	}
466
+    }
467 467
 
468
-	/**
469
-	 * Marks the invoice as paid in case the checkout is free.
470
-	 *
471
-	 * @param WPInv_Invoice $invoice
472
-	 */
473
-	protected function process_free_payment( $invoice ) {
468
+    /**
469
+     * Marks the invoice as paid in case the checkout is free.
470
+     *
471
+     * @param WPInv_Invoice $invoice
472
+     */
473
+    protected function process_free_payment( $invoice ) {
474 474
 
475
-		$invoice->set_gateway( 'none' );
476
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
477
-		$invoice->mark_paid();
478
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
475
+        $invoice->set_gateway( 'none' );
476
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
477
+        $invoice->mark_paid();
478
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
479 479
 
480
-	}
480
+    }
481 481
 
482
-	/**
482
+    /**
483 483
      * Sends a redrect response to payment details.
484 484
      *
485 485
      */
Please login to merge, or discard this patch.
Spacing   +136 added lines, -136 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items      = $this->get_submission_items();
40 40
 		$invoice    = $this->get_submission_invoice();
41
-		$invoice    = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice    = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared   = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 50
 		$invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+		do_action('getpaid_checkout_invoice_updated', $invoice);
54 54
 
55 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 78
 		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
79
+		if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) {
80
+			wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing'));
81 81
 		}
82 82
 
83 83
 		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
84
+		if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) {
85
+			wp_send_json_error(__('The selected payment gateway is not active', 'invoicing'));
86 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	}
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 134
 		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,33 +146,33 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 
153 153
 		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
157
-        $invoice->set_items( $items );
158
-        $invoice->set_fees( $submission->get_fees() );
159
-        $invoice->set_taxes( $submission->get_taxes() );
160
-		$invoice->set_discounts( $submission->get_discounts() );
161
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
162
-		$invoice->set_currency( $submission->get_currency() );
163
-
164
-		if ( $submission->has_shipping() ) {
165
-			$invoice->set_shipping( $submission->get_shipping() );
154
+		$invoice->set_email(sanitize_email($submission->get_billing_email()));
155
+		$invoice->set_user_id($this->get_submission_customer());
156
+		$invoice->set_payment_form(absint($submission->get_payment_form()->get_id()));
157
+        $invoice->set_items($items);
158
+        $invoice->set_fees($submission->get_fees());
159
+        $invoice->set_taxes($submission->get_taxes());
160
+		$invoice->set_discounts($submission->get_discounts());
161
+		$invoice->set_gateway($submission->get_field('wpi-gateway'));
162
+		$invoice->set_currency($submission->get_currency());
163
+
164
+		if ($submission->has_shipping()) {
165
+			$invoice->set_shipping($submission->get_shipping());
166 166
 		}
167 167
 
168
-		$address_confirmed = $submission->get_field( 'confirm-address' );
169
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
168
+		$address_confirmed = $submission->get_field('confirm-address');
169
+		$invoice->set_address_confirmed(!empty($address_confirmed));
170 170
 
171
-		if ( $submission->has_discount_code() ) {
172
-            $invoice->set_discount_code( $submission->get_discount_code() );
171
+		if ($submission->has_discount_code()) {
172
+            $invoice->set_discount_code($submission->get_discount_code());
173 173
 		}
174 174
 
175
-		getpaid_maybe_add_default_address( $invoice );
175
+		getpaid_maybe_add_default_address($invoice);
176 176
 		return $invoice;
177 177
 	}
178 178
 
@@ -185,34 +185,34 @@  discard block
 block discarded – undo
185 185
 		$submission = $this->payment_form_submission;
186 186
 
187 187
 		// If this is an existing invoice...
188
-		if ( $submission->has_invoice() ) {
188
+		if ($submission->has_invoice()) {
189 189
 			return $submission->get_invoice()->get_user_id();
190 190
 		}
191 191
 
192 192
 		// (Maybe) create the user.
193 193
         $user = get_current_user_id();
194 194
 
195
-        if ( empty( $user ) ) {
196
-            $user = get_user_by( 'email', $submission->get_billing_email() );
195
+        if (empty($user)) {
196
+            $user = get_user_by('email', $submission->get_billing_email());
197 197
         }
198 198
 
199
-        if ( empty( $user ) ) {
200
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
201
-			$name = implode( '', array_filter( $name ) );
202
-            $user = wpinv_create_user( $submission->get_billing_email(), $name );
199
+        if (empty($user)) {
200
+			$name = array($submission->get_field('wpinv_first_name', 'billing'), $submission->get_field('wpinv_last_name', 'billing'));
201
+			$name = implode('', array_filter($name));
202
+            $user = wpinv_create_user($submission->get_billing_email(), $name);
203 203
 
204 204
 			// (Maybe) send new user notification.
205
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
206
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
207
-				wp_send_new_user_notifications( $user, 'user' );
205
+			$should_send_notification = wpinv_get_option('disable_new_user_emails');
206
+			if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) {
207
+				wp_send_new_user_notifications($user, 'user');
208 208
 			}
209 209
 		}
210 210
 
211
-        if ( is_wp_error( $user ) ) {
212
-            wp_send_json_error( $user->get_error_message() );
211
+        if (is_wp_error($user)) {
212
+            wp_send_json_error($user->get_error_message());
213 213
         }
214 214
 
215
-        if ( is_numeric( $user ) ) {
215
+        if (is_numeric($user)) {
216 216
             return $user;
217 217
 		}
218 218
 
@@ -236,72 +236,72 @@  discard block
 block discarded – undo
236 236
 		);
237 237
 
238 238
         // Raw submission details.
239
-		$data     = $submission->get_data();
239
+		$data = $submission->get_data();
240 240
 
241 241
 		// Loop through the submitted details.
242
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
242
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
243 243
 
244 244
 			// Skip premade fields.
245
-            if ( ! empty( $field['premade'] ) ) {
245
+            if (!empty($field['premade'])) {
246 246
                 continue;
247 247
             }
248 248
 
249 249
 			// Ensure address is provided.
250
-			if ( $field['type'] == 'address' ) {
251
-                $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
250
+			if ($field['type'] == 'address') {
251
+                $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
252 252
 
253
-				foreach ( $field['fields'] as $address_field ) {
253
+				foreach ($field['fields'] as $address_field) {
254 254
 
255
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) {
256
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
255
+					if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) {
256
+						wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
257 257
 					}
258 258
 			}
259 259
 		}
260 260
 
261 261
             // If it is required and not set, abort.
262
-            if ( ! $submission->is_required_field_set( $field ) ) {
263
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
262
+            if (!$submission->is_required_field_set($field)) {
263
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
264 264
             }
265 265
 
266 266
             // Handle misc fields.
267
-            if ( isset( $data[ $field['id'] ] ) ) {
267
+            if (isset($data[$field['id']])) {
268 268
 
269 269
 				// Uploads.
270
-				if ( $field['type'] === 'file_upload' ) {
271
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
270
+				if ($field['type'] === 'file_upload') {
271
+					$max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']);
272 272
 
273
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
274
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
273
+					if (count($data[$field['id']]) > $max_file_num) {
274
+						wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing'));
275 275
 					}
276 276
 
277 277
 					$value = array();
278 278
 
279
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
279
+					foreach ($data[$field['id']] as $url => $name) {
280 280
 						$value[] = sprintf(
281 281
 							'<a href="%s" target="_blank">%s</a>',
282
-							esc_url_raw( $url ),
283
-							esc_html( $name )
282
+							esc_url_raw($url),
283
+							esc_html($name)
284 284
 						);
285 285
 					}
286 286
 
287
-					$value = implode( ' | ', $value );
287
+					$value = implode(' | ', $value);
288 288
 
289
-				} elseif ( $field['type'] === 'checkbox' ) {
290
-					$value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
289
+				} elseif ($field['type'] === 'checkbox') {
290
+					$value = !empty($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing');
291 291
 				} else {
292
-					$value = wp_kses_post( $data[ $field['id'] ] );
292
+					$value = wp_kses_post($data[$field['id']]);
293 293
 				}
294 294
 
295 295
                 $label = $field['id'];
296 296
 
297
-                if ( isset( $field['label'] ) ) {
297
+                if (isset($field['label'])) {
298 298
                     $label = $field['label'];
299 299
                 }
300 300
 
301
-				if ( ! empty( $field['add_meta'] ) ) {
302
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
301
+				if (!empty($field['add_meta'])) {
302
+					$prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value);
303 303
 				}
304
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
+				$prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value);
305 305
 
306 306
             }
307 307
 		}
@@ -317,30 +317,30 @@  discard block
 block discarded – undo
317 317
 	 * @param WPInv_Invoice $invoice
318 318
 	 * @param string $type
319 319
      */
320
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
320
+    public function prepare_address_details($invoice, $type = 'billing') {
321 321
 
322 322
 		$data     = $this->payment_form_submission->get_data();
323
-		$type     = sanitize_key( $type );
323
+		$type     = sanitize_key($type);
324 324
 		$address  = array();
325 325
 		$prepared = array();
326 326
 
327
-		if ( ! empty( $data[ $type ] ) ) {
328
-			$address = $data[ $type ];
327
+		if (!empty($data[$type])) {
328
+			$address = $data[$type];
329 329
 		}
330 330
 
331 331
 		// Clean address details.
332
-		foreach ( $address as $key => $value ) {
333
-			$key             = sanitize_key( $key );
334
-			$key             = str_replace( 'wpinv_', '', $key );
335
-			$value           = wpinv_clean( $value );
336
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
332
+		foreach ($address as $key => $value) {
333
+			$key             = sanitize_key($key);
334
+			$key             = str_replace('wpinv_', '', $key);
335
+			$value           = wpinv_clean($value);
336
+			$prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice);
337 337
 		}
338 338
 
339 339
 		// Filter address details.
340
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
340
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
341 341
 
342 342
 		// Remove non-whitelisted values.
343
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
343
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
344 344
 
345 345
 	}
346 346
 
@@ -350,12 +350,12 @@  discard block
 block discarded – undo
350 350
 	 * @return array
351 351
 	 * @param WPInv_Invoice $invoice
352 352
      */
353
-    protected function prepare_billing_info( &$invoice ) {
353
+    protected function prepare_billing_info(&$invoice) {
354 354
 
355
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
355
+		$billing_address = $this->prepare_address_details($invoice, 'billing');
356 356
 
357 357
 		// Update the invoice with the billing details.
358
-		$invoice->set_props( $billing_address );
358
+		$invoice->set_props($billing_address);
359 359
 
360 360
 	}
361 361
 
@@ -365,15 +365,15 @@  discard block
 block discarded – undo
365 365
 	 * @return array
366 366
 	 * @param WPInv_Invoice $invoice
367 367
      */
368
-    protected function prepare_shipping_info( $invoice ) {
368
+    protected function prepare_shipping_info($invoice) {
369 369
 
370 370
 		$data = $this->payment_form_submission->get_data();
371 371
 
372
-		if ( empty( $data['same-shipping-address'] ) ) {
373
-			return $this->prepare_address_details( $invoice, 'shipping' );
372
+		if (empty($data['same-shipping-address'])) {
373
+			return $this->prepare_address_details($invoice, 'shipping');
374 374
 		}
375 375
 
376
-		return $this->prepare_address_details( $invoice, 'billing' );
376
+		return $this->prepare_address_details($invoice, 'billing');
377 377
 
378 378
 	}
379 379
 
@@ -384,41 +384,41 @@  discard block
 block discarded – undo
384 384
 	 * @param array $prepared_payment_form_data
385 385
 	 * @param array $shipping
386 386
 	 */
387
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
387
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
388 388
 
389 389
 		// Ensure the invoice exists.
390
-        if ( ! $invoice->exists() ) {
391
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
390
+        if (!$invoice->exists()) {
391
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
392 392
         }
393 393
 
394 394
 		// Save payment form data.
395
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
396
-        delete_post_meta( $invoice->get_id(), 'payment_form_data' );
397
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
398
-		if ( ! empty( $prepared_payment_form_data ) ) {
395
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
396
+        delete_post_meta($invoice->get_id(), 'payment_form_data');
397
+		delete_post_meta($invoice->get_id(), 'additional_meta_data');
398
+		if (!empty($prepared_payment_form_data)) {
399 399
 
400
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
401
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
400
+			if (!empty($prepared_payment_form_data['all'])) {
401
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
402 402
 			}
403 403
 
404
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
405
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
404
+			if (!empty($prepared_payment_form_data['meta'])) {
405
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
406 406
 			}
407 407
 		}
408 408
 
409 409
 		// Save payment form data.
410
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
411
-        if ( ! empty( $shipping ) ) {
412
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
410
+		$shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission);
411
+        if (!empty($shipping)) {
412
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
413 413
 		}
414 414
 
415 415
 		// Backwards compatibility.
416
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
416
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
417 417
 
418
-		$this->process_payment( $invoice );
418
+		$this->process_payment($invoice);
419 419
 
420 420
         // If we are here, there was an error.
421
-		wpinv_send_back_to_checkout( $invoice );
421
+		wpinv_send_back_to_checkout($invoice);
422 422
 
423 423
 	}
424 424
 
@@ -427,41 +427,41 @@  discard block
 block discarded – undo
427 427
 	 *
428 428
 	 * @param WPInv_Invoice $invoice
429 429
 	 */
430
-	protected function process_payment( $invoice ) {
430
+	protected function process_payment($invoice) {
431 431
 
432 432
 		// Clear any checkout errors.
433 433
 		wpinv_clear_errors();
434 434
 
435 435
 		// No need to send free invoices to the gateway.
436
-		if ( $invoice->is_free() ) {
437
-			$this->process_free_payment( $invoice );
436
+		if ($invoice->is_free()) {
437
+			$this->process_free_payment($invoice);
438 438
 		}
439 439
 
440 440
 		$submission = $this->payment_form_submission;
441 441
 
442 442
 		// Fires before sending to the gateway.
443
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
443
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
444 444
 
445 445
 		// Allow the sumission data to be modified before it is sent to the gateway.
446 446
 		$submission_data    = $submission->get_data();
447
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
448
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
447
+		$submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice);
448
+		$submission_data    = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice);
449 449
 
450 450
 		// Validate the currency.
451
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
452
-			wpinv_set_error( 'invalid_currency' );
451
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
452
+			wpinv_set_error('invalid_currency');
453 453
 		}
454 454
 
455 455
 		// Check to see if we have any errors.
456
-		if ( wpinv_get_errors() ) {
457
-			wpinv_send_back_to_checkout( $invoice );
456
+		if (wpinv_get_errors()) {
457
+			wpinv_send_back_to_checkout($invoice);
458 458
 		}
459 459
 
460 460
 		// Send info to the gateway for payment processing
461
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
461
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
462 462
 
463 463
 		// Backwards compatibility.
464
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
464
+		wpinv_send_to_gateway($submission_gateway, $invoice);
465 465
 
466 466
 	}
467 467
 
@@ -470,12 +470,12 @@  discard block
 block discarded – undo
470 470
 	 *
471 471
 	 * @param WPInv_Invoice $invoice
472 472
 	 */
473
-	protected function process_free_payment( $invoice ) {
473
+	protected function process_free_payment($invoice) {
474 474
 
475
-		$invoice->set_gateway( 'none' );
476
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
475
+		$invoice->set_gateway('none');
476
+		$invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true);
477 477
 		$invoice->mark_paid();
478
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
478
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
479 479
 
480 480
 	}
481 481
 
@@ -483,9 +483,9 @@  discard block
 block discarded – undo
483 483
      * Sends a redrect response to payment details.
484 484
      *
485 485
      */
486
-    public function send_redirect_response( $url ) {
487
-        $url = rawurlencode( $url );
488
-        wp_send_json_success( $url );
486
+    public function send_redirect_response($url) {
487
+        $url = rawurlencode($url);
488
+        wp_send_json_success($url);
489 489
     }
490 490
 
491 491
 }
Please login to merge, or discard this patch.
includes/error-functions.php 1 patch
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * Returns the errors as html
@@ -15,35 +15,35 @@  discard block
 block discarded – undo
15 15
  * @param bool $wrap whether or not to wrap the errors.
16 16
  * @since  1.0.19
17 17
  */
18
-function getpaid_get_errors_html( $clear = true, $wrap = true ) {
18
+function getpaid_get_errors_html($clear = true, $wrap = true) {
19 19
 
20 20
     $errors = '';
21
-    foreach ( wpinv_get_errors() as $id => $error ) {
22
-        $type     = 'error';
21
+    foreach (wpinv_get_errors() as $id => $error) {
22
+        $type = 'error';
23 23
 
24
-        if ( is_array( $error ) ) {
24
+        if (is_array($error)) {
25 25
             $type  = $error['type'];
26 26
             $error = $error['text'];
27 27
         }
28 28
 
29
-        if ( $wrap ) {
29
+        if ($wrap) {
30 30
 
31 31
             $errors .= aui()->alert(
32 32
                 array(
33
-                    'content' => wp_kses_post( $error ),
33
+                    'content' => wp_kses_post($error),
34 34
                     'type'    => $type,
35 35
                 )
36 36
             );
37 37
 
38 38
         } else {
39 39
 
40
-            $id      = esc_attr( $id );
41
-            $error   = wp_kses_post( $error );
40
+            $id      = esc_attr($id);
41
+            $error   = wp_kses_post($error);
42 42
             $errors .= "<div data-code='$id'>$error</div>";
43 43
         }
44 44
     }
45 45
 
46
-    if ( $clear ) {
46
+    if ($clear) {
47 47
         wpinv_clear_errors();
48 48
     }
49 49
 
@@ -55,7 +55,7 @@  discard block
 block discarded – undo
55 55
  * Prints (then clears) all available errors.
56 56
  */
57 57
 function wpinv_print_errors() {
58
-    echo wp_kses_post( getpaid_get_errors_html() );
58
+    echo wp_kses_post(getpaid_get_errors_html());
59 59
 }
60 60
 
61 61
 /**
@@ -69,54 +69,54 @@  discard block
 block discarded – undo
69 69
     $all_errors = array(
70 70
         'perm_cancel_subscription'   => array(
71 71
             'type' => 'error',
72
-            'text' => __( 'You do not have permission to cancel this subscription', 'invoicing' ),
72
+            'text' => __('You do not have permission to cancel this subscription', 'invoicing'),
73 73
         ),
74 74
         'cannot_cancel_subscription' => array(
75 75
             'type' => 'error',
76
-            'text' => __( 'This subscription cannot be cancelled as it is not active.', 'invoicing' ),
76
+            'text' => __('This subscription cannot be cancelled as it is not active.', 'invoicing'),
77 77
         ),
78 78
         'cancelled_subscription'     => array(
79 79
             'type' => 'success',
80
-            'text' => __( 'Subscription cancelled successfully.', 'invoicing' ),
80
+            'text' => __('Subscription cancelled successfully.', 'invoicing'),
81 81
         ),
82 82
         'address_updated'            => array(
83 83
             'type' => 'success',
84
-            'text' => __( 'Address updated successfully.', 'invoicing' ),
84
+            'text' => __('Address updated successfully.', 'invoicing'),
85 85
         ),
86 86
         'perm_delete_invoice'        => array(
87 87
             'type' => 'error',
88
-            'text' => __( 'You do not have permission to delete this invoice', 'invoicing' ),
88
+            'text' => __('You do not have permission to delete this invoice', 'invoicing'),
89 89
         ),
90 90
         'cannot_delete_invoice'      => array(
91 91
             'type' => 'error',
92
-            'text' => __( 'This invoice cannot be deleted as it has already been paid.', 'invoicing' ),
92
+            'text' => __('This invoice cannot be deleted as it has already been paid.', 'invoicing'),
93 93
         ),
94 94
         'deleted_invoice'            => array(
95 95
             'type' => 'success',
96
-            'text' => __( 'Invoice deleted successfully.', 'invoicing' ),
96
+            'text' => __('Invoice deleted successfully.', 'invoicing'),
97 97
         ),
98 98
         'card_declined'              => array(
99 99
             'type' => 'error',
100
-            'text' => __( 'Your card was declined.', 'invoicing' ),
100
+            'text' => __('Your card was declined.', 'invoicing'),
101 101
         ),
102 102
         'invalid_currency'           => array(
103 103
             'type' => 'error',
104
-            'text' => __( 'The chosen payment gateway does not support this currency.', 'invoicing' ),
104
+            'text' => __('The chosen payment gateway does not support this currency.', 'invoicing'),
105 105
         ),
106 106
     );
107 107
 
108
-    $errors = apply_filters( 'wpinv_errors', array() );
108
+    $errors = apply_filters('wpinv_errors', array());
109 109
 
110
-    if ( isset( $_GET['wpinv-notice'] ) && isset( $all_errors[ $_GET['wpinv-notice'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
111
-        $errors[ $_GET['wpinv-notice'] ] = $all_errors[ $_GET['wpinv-notice'] ]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
110
+    if (isset($_GET['wpinv-notice']) && isset($all_errors[$_GET['wpinv-notice']])) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
111
+        $errors[$_GET['wpinv-notice']] = $all_errors[$_GET['wpinv-notice']]; // phpcs:ignore WordPress.Security.NonceVerification.Recommended
112 112
     }
113 113
 
114
-    if ( isset( $GLOBALS['wpinv_notice'] ) && isset( $all_errors[ $GLOBALS['wpinv_notice'] ] ) ) {
115
-        $errors[ $GLOBALS['wpinv_notice'] ] = $all_errors[ $GLOBALS['wpinv_notice'] ];
114
+    if (isset($GLOBALS['wpinv_notice']) && isset($all_errors[$GLOBALS['wpinv_notice']])) {
115
+        $errors[$GLOBALS['wpinv_notice']] = $all_errors[$GLOBALS['wpinv_notice']];
116 116
     }
117 117
 
118
-    if ( isset( $GLOBALS['wpinv_custom_notice'] ) ) {
119
-        $errors[ $GLOBALS['wpinv_custom_notice']['code'] ] = $GLOBALS['wpinv_custom_notice'];
118
+    if (isset($GLOBALS['wpinv_custom_notice'])) {
119
+        $errors[$GLOBALS['wpinv_custom_notice']['code']] = $GLOBALS['wpinv_custom_notice'];
120 120
     }
121 121
 
122 122
     return $errors;
@@ -129,9 +129,9 @@  discard block
 block discarded – undo
129 129
  * @param string $error The error message.
130 130
  * @param string $type The error type.
131 131
  */
132
-function wpinv_set_error( $error_id, $message = '', $type = 'error' ) {
132
+function wpinv_set_error($error_id, $message = '', $type = 'error') {
133 133
 
134
-    if ( ! empty( $message ) ) {
134
+    if (!empty($message)) {
135 135
         $GLOBALS['wpinv_custom_notice'] = array(
136 136
             'code' => $error_id,
137 137
             'type' => $type,
@@ -147,7 +147,7 @@  discard block
 block discarded – undo
147 147
  *
148 148
  */
149 149
 function wpinv_has_errors() {
150
-    return count( wpinv_get_errors() ) > 0;
150
+    return count(wpinv_get_errors()) > 0;
151 151
 }
152 152
 
153 153
 /**
@@ -155,7 +155,7 @@  discard block
 block discarded – undo
155 155
  *
156 156
  */
157 157
 function wpinv_clear_errors() {
158
-    unset( $GLOBALS['wpinv_notice'] );
158
+    unset($GLOBALS['wpinv_notice']);
159 159
 }
160 160
 
161 161
 /**
@@ -163,7 +163,7 @@  discard block
 block discarded – undo
163 163
  *
164 164
  */
165 165
 function wpinv_unset_error() {
166
-    unset( $GLOBALS['wpinv_notice'] );
166
+    unset($GLOBALS['wpinv_notice']);
167 167
 }
168 168
 
169 169
 /**
@@ -174,15 +174,15 @@  discard block
 block discarded – undo
174 174
  * @param string $message Message to log.
175 175
  * @param string $version Version the message was added in.
176 176
  */
177
-function getpaid_doing_it_wrong( $function, $message, $version ) {
177
+function getpaid_doing_it_wrong($function, $message, $version) {
178 178
 
179 179
 	$message .= ' Backtrace: ' . wp_debug_backtrace_summary();
180 180
 
181
-	if ( wp_doing_ajax() || defined( 'REST_REQUEST' ) ) {
182
-		do_action( 'doing_it_wrong_run', $function, $message, $version );
183
-		error_log( "{$function} was called incorrectly. {$message}. This message was added in version {$version}." );
181
+	if (wp_doing_ajax() || defined('REST_REQUEST')) {
182
+		do_action('doing_it_wrong_run', $function, $message, $version);
183
+		error_log("{$function} was called incorrectly. {$message}. This message was added in version {$version}.");
184 184
 	} else {
185
-		_doing_it_wrong( esc_html( $function ), wp_kses_post( $message ), esc_html( $version ) );
185
+		_doing_it_wrong(esc_html($function), wp_kses_post($message), esc_html($version));
186 186
 	}
187 187
 
188 188
 }
@@ -196,41 +196,41 @@  discard block
 block discarded – undo
196 196
  * @param string $line The line that contains the error.
197 197
  * @param bool $exit Whether or not to exit function execution.
198 198
  */
199
-function wpinv_error_log( $log, $title = '', $file = '', $line = '', $exit = false ) {
199
+function wpinv_error_log($log, $title = '', $file = '', $line = '', $exit = false) {
200 200
 
201
-    if ( true === apply_filters( 'wpinv_log_errors', true ) ) {
201
+    if (true === apply_filters('wpinv_log_errors', true)) {
202 202
 
203 203
         // Ensure the log is a scalar.
204
-        if ( ! is_scalar( $log ) ) {
205
-            $log = print_r( $log, true );
204
+        if (!is_scalar($log)) {
205
+            $log = print_r($log, true);
206 206
         }
207 207
 
208 208
         // Add title.
209
-        if ( ! empty( $title ) ) {
210
-            $log  = $title . ' ' . trim( $log );
209
+        if (!empty($title)) {
210
+            $log = $title . ' ' . trim($log);
211 211
         }
212 212
 
213 213
         // Add the file to the label.
214
-        if ( ! empty( $file ) ) {
214
+        if (!empty($file)) {
215 215
             $log .= ' in ' . $file;
216 216
         }
217 217
 
218 218
         // Add the line number to the label.
219
-        if ( ! empty( $line ) ) {
219
+        if (!empty($line)) {
220 220
             $log .= ' on line ' . $line;
221 221
         }
222 222
 
223 223
         // Log the message.
224
-        error_log( trim( $log ) );
224
+        error_log(trim($log));
225 225
 
226 226
         // ... and a backtrace.
227
-        if ( false !== $title && false !== $file ) {
228
-            error_log( 'Backtrace ' . wp_debug_backtrace_summary() );
227
+        if (false !== $title && false !== $file) {
228
+            error_log('Backtrace ' . wp_debug_backtrace_summary());
229 229
         }
230 230
 }
231 231
 
232 232
     // Maybe exit.
233
-    if ( $exit ) {
233
+    if ($exit) {
234 234
         exit;
235 235
     }
236 236
 
Please login to merge, or discard this patch.