Passed
Push — master ( ed459e...214561 )
by Brian
09:30
created
includes/wpinv-tax-functions.php 1 patch
Spacing   +124 added lines, -124 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
  * Returns an array of eu states.
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
  * @return array
13 13
  */
14 14
 function getpaid_get_eu_states() {
15
-    return wpinv_get_data( 'eu-states' );
15
+    return wpinv_get_data('eu-states');
16 16
 }
17 17
 
18 18
 /**
@@ -20,8 +20,8 @@  discard block
 block discarded – undo
20 20
  * 
21 21
  * @return bool
22 22
  */
23
-function getpaid_is_eu_state( $country ) {
24
-    return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_eu_states() ) ? true : false;
23
+function getpaid_is_eu_state($country) {
24
+    return !empty($country) && in_array(strtoupper($country), getpaid_get_eu_states()) ? true : false;
25 25
 }
26 26
 
27 27
 /**
@@ -30,7 +30,7 @@  discard block
 block discarded – undo
30 30
  * @return array
31 31
  */
32 32
 function getpaid_get_gst_states() {
33
-    return array( 'AU', 'NZ', 'CA', 'CN' );
33
+    return array('AU', 'NZ', 'CA', 'CN');
34 34
 }
35 35
 
36 36
 /**
@@ -38,8 +38,8 @@  discard block
 block discarded – undo
38 38
  * 
39 39
  * @return bool
40 40
  */
41
-function getpaid_is_gst_country( $country ) {
42
-    return ! empty( $country ) && in_array( strtoupper( $country ), getpaid_get_gst_states() ) ? true : false;
41
+function getpaid_is_gst_country($country) {
42
+    return !empty($country) && in_array(strtoupper($country), getpaid_get_gst_states()) ? true : false;
43 43
 }
44 44
 
45 45
 /**
@@ -49,8 +49,8 @@  discard block
 block discarded – undo
49 49
  */
50 50
 function wpinv_use_taxes() {
51 51
 
52
-    $ret = wpinv_get_option( 'enable_taxes', false );
53
-    return (bool) apply_filters( 'wpinv_use_taxes', ! empty( $ret ) );
52
+    $ret = wpinv_get_option('enable_taxes', false);
53
+    return (bool) apply_filters('wpinv_use_taxes', !empty($ret));
54 54
 
55 55
 }
56 56
 
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
  * @param WPInv_Invoice $invoice
61 61
  * @return bool
62 62
  */
63
-function wpinv_is_invoice_taxable( $invoice ) {
63
+function wpinv_is_invoice_taxable($invoice) {
64 64
     return $invoice->is_taxable();
65 65
 }
66 66
 
@@ -70,11 +70,11 @@  discard block
 block discarded – undo
70 70
  * @param string $country
71 71
  * @return bool
72 72
  */
73
-function wpinv_is_country_taxable( $country ) {
74
-    $is_eu     = getpaid_is_eu_state( $country );
75
-    $is_exempt = $is_eu && $country == wpinv_is_base_country( $country ) && wpinv_same_country_exempt_vat();
73
+function wpinv_is_country_taxable($country) {
74
+    $is_eu     = getpaid_is_eu_state($country);
75
+    $is_exempt = $is_eu && $country == wpinv_is_base_country($country) && wpinv_same_country_exempt_vat();
76 76
 
77
-    return (bool) apply_filters( 'wpinv_is_country_taxable', ! $is_exempt, $country ); 
77
+    return (bool) apply_filters('wpinv_is_country_taxable', !$is_exempt, $country); 
78 78
 
79 79
 }
80 80
 
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
  * @param WPInv_Item|GetPaid_Form_Item $item
85 85
  * @return bool
86 86
  */
87
-function wpinv_is_item_taxable( $item ) {
87
+function wpinv_is_item_taxable($item) {
88 88
     return '_exempt' != $item->get_vat_rule();
89 89
 }
90 90
 
@@ -94,8 +94,8 @@  discard block
 block discarded – undo
94 94
  * @return bool
95 95
  */
96 96
 function wpinv_use_store_address_as_tax_base() {
97
-    $use_base = wpinv_get_option( 'tax_base', 'billing' ) == 'base';
98
-    return (bool) apply_filters( 'wpinv_use_store_address_as_tax_base', $use_base );
97
+    $use_base = wpinv_get_option('tax_base', 'billing') == 'base';
98
+    return (bool) apply_filters('wpinv_use_store_address_as_tax_base', $use_base);
99 99
 }
100 100
 
101 101
 /**
@@ -104,8 +104,8 @@  discard block
 block discarded – undo
104 104
  * @return bool
105 105
  */
106 106
 function wpinv_prices_include_tax() {
107
-    $is_inclusive = wpinv_get_option( 'prices_include_tax', 'no' ) == 'yes';
108
-    return (bool) apply_filters( 'wpinv_prices_include_tax', $is_inclusive );
107
+    $is_inclusive = wpinv_get_option('prices_include_tax', 'no') == 'yes';
108
+    return (bool) apply_filters('wpinv_prices_include_tax', $is_inclusive);
109 109
 }
110 110
 
111 111
 /**
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
  * @return bool
115 115
  */
116 116
 function wpinv_round_tax_per_tax_rate() {
117
-    $subtotal_rounding = wpinv_get_option( 'tax_subtotal_rounding', 1 );
118
-    return (bool) apply_filters( 'wpinv_round_tax_per_tax_rate', empty( $subtotal_rounding ) );
117
+    $subtotal_rounding = wpinv_get_option('tax_subtotal_rounding', 1);
118
+    return (bool) apply_filters('wpinv_round_tax_per_tax_rate', empty($subtotal_rounding));
119 119
 }
120 120
 
121 121
 /**
@@ -124,8 +124,8 @@  discard block
 block discarded – undo
124 124
  * @return bool
125 125
  */
126 126
 function wpinv_display_individual_tax_rates() {
127
-    $individual = wpinv_get_option( 'tax_display_totals', 'single' ) == 'individual';
128
-    return (bool) apply_filters( 'wpinv_display_individual_tax_rates', $individual );
127
+    $individual = wpinv_get_option('tax_display_totals', 'single') == 'individual';
128
+    return (bool) apply_filters('wpinv_display_individual_tax_rates', $individual);
129 129
 }
130 130
 
131 131
 /**
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
  * @return float
135 135
  */
136 136
 function wpinv_get_default_tax_rate() {
137
-    $rate = wpinv_get_option( 'tax_rate', 20 );
138
-    return (float) apply_filters( 'wpinv_get_default_tax_rate', floatval( $rate ) );
137
+    $rate = wpinv_get_option('tax_rate', 20);
138
+    return (float) apply_filters('wpinv_get_default_tax_rate', floatval($rate));
139 139
 }
140 140
 
141 141
 /**
@@ -144,7 +144,7 @@  discard block
 block discarded – undo
144 144
  * @return bool
145 145
  */
146 146
 function wpinv_same_country_exempt_vat() {
147
-    return 'no' == wpinv_get_option( 'vat_same_country_rule', 'always' );
147
+    return 'no' == wpinv_get_option('vat_same_country_rule', 'always');
148 148
 }
149 149
 
150 150
 /**
@@ -164,28 +164,28 @@  discard block
 block discarded – undo
164 164
  * @param string $state
165 165
  * @return array
166 166
  */
167
-function getpaid_get_item_tax_rates( $item, $country = '', $state = '' ) {
167
+function getpaid_get_item_tax_rates($item, $country = '', $state = '') {
168 168
 
169 169
     // Abort if the item is not taxable.
170
-    if ( ! wpinv_is_item_taxable( $item ) ) {
170
+    if (!wpinv_is_item_taxable($item)) {
171 171
         return array();
172 172
     }
173 173
 
174 174
     // Maybe use the store address.
175
-    if ( wpinv_use_store_address_as_tax_base() ) {
175
+    if (wpinv_use_store_address_as_tax_base()) {
176 176
         $country = wpinv_get_default_country();
177 177
         $state   = wpinv_get_default_state();
178 178
     }
179 179
 
180 180
     // Retrieve tax rates.
181
-    $tax_rates = GetPaid_Tax::get_address_tax_rates( $country, $state );
181
+    $tax_rates = GetPaid_Tax::get_address_tax_rates($country, $state);
182 182
 
183 183
     // Fallback to the default tax rates if non were found.
184
-    if ( empty( $tax_rates ) ) {
184
+    if (empty($tax_rates)) {
185 185
         $tax_rates = GetPaid_Tax::get_default_tax_rates();
186 186
     }
187 187
 
188
-    return apply_filters( 'getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state );
188
+    return apply_filters('getpaid_get_item_tax_rates', $tax_rates, $item, $country, $state);
189 189
 }
190 190
 
191 191
 /**
@@ -195,23 +195,23 @@  discard block
 block discarded – undo
195 195
  * @param array $rates
196 196
  * @return array
197 197
  */
198
-function getpaid_filter_item_tax_rates( $item, $rates ) {
198
+function getpaid_filter_item_tax_rates($item, $rates) {
199 199
 
200 200
     $tax_class = $item->get_vat_class();
201 201
 
202
-    foreach ( $rates as $i => $rate ) {
202
+    foreach ($rates as $i => $rate) {
203 203
 
204
-        if ( $tax_class == '_reduced' ) {
205
-            $rates[ $i ]['rate'] = empty( $rate['reduced_rate'] ) ? 0 : $rate['reduced_rate'];
204
+        if ($tax_class == '_reduced') {
205
+            $rates[$i]['rate'] = empty($rate['reduced_rate']) ? 0 : $rate['reduced_rate'];
206 206
         }
207 207
 
208
-        if ( $tax_class == '_exempt' ) {
209
-            $rates[ $i ]['rate'] = 0;
208
+        if ($tax_class == '_exempt') {
209
+            $rates[$i]['rate'] = 0;
210 210
         }
211 211
 
212 212
     }
213 213
 
214
-    return apply_filters( 'getpaid_filter_item_tax_rates', $rates, $item );
214
+    return apply_filters('getpaid_filter_item_tax_rates', $rates, $item);
215 215
 }
216 216
 
217 217
 /**
@@ -221,12 +221,12 @@  discard block
 block discarded – undo
221 221
  * @param array $rates
222 222
  * @return array
223 223
  */
224
-function getpaid_calculate_item_taxes( $amount, $rates ) {
224
+function getpaid_calculate_item_taxes($amount, $rates) {
225 225
 
226 226
     $is_inclusive = wpinv_prices_include_tax();
227
-    $taxes        = GetPaid_Tax::calc_tax( $amount, $rates, $is_inclusive );
227
+    $taxes        = GetPaid_Tax::calc_tax($amount, $rates, $is_inclusive);
228 228
 
229
-    return apply_filters( 'getpaid_calculate_taxes', $taxes, $amount, $rates );
229
+    return apply_filters('getpaid_calculate_taxes', $taxes, $amount, $rates);
230 230
 }
231 231
 
232 232
 /**
@@ -238,17 +238,17 @@  discard block
 block discarded – undo
238 238
  * @param float $recurring_tax_amount
239 239
  * @return array
240 240
  */
241
-function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) {
241
+function getpaid_prepare_item_tax($item, $tax_name, $tax_amount, $recurring_tax_amount) {
242 242
 
243
-    $initial_tax   = $tax_amount;
243
+    $initial_tax = $tax_amount;
244 244
 	$recurring_tax = 0;
245 245
 
246
-    if ( $item->is_recurring() ) {
246
+    if ($item->is_recurring()) {
247 247
 		$recurring_tax = $recurring_tax_amount;
248 248
 	}
249 249
 
250 250
 	return array(
251
-		'name'          => sanitize_text_field( $tax_name ),
251
+		'name'          => sanitize_text_field($tax_name),
252 252
 		'initial_tax'   => $initial_tax,
253 253
 		'recurring_tax' => $recurring_tax,
254 254
     );
@@ -261,8 +261,8 @@  discard block
 block discarded – undo
261 261
  * @param string $vat_number
262 262
  * @return string
263 263
  */
264
-function wpinv_sanitize_vat_number( $vat_number ) {
265
-    return str_replace( array(' ', '.', '-', '_', ',' ), '', strtoupper( trim( $vat_number ) ) );
264
+function wpinv_sanitize_vat_number($vat_number) {
265
+    return str_replace(array(' ', '.', '-', '_', ','), '', strtoupper(trim($vat_number)));
266 266
 }
267 267
 
268 268
 /**
@@ -271,22 +271,22 @@  discard block
 block discarded – undo
271 271
  * @param string $vat_number
272 272
  * @return bool
273 273
  */
274
-function wpinv_regex_validate_vat_number( $vat_number ) {
274
+function wpinv_regex_validate_vat_number($vat_number) {
275 275
 
276
-    $country    = substr( $vat_number, 0, 2 );
277
-    $vatin      = substr( $vat_number, 2 );
278
-    $regexes    = wpinv_get_data( 'vat-number-regexes' );
276
+    $country    = substr($vat_number, 0, 2);
277
+    $vatin      = substr($vat_number, 2);
278
+    $regexes    = wpinv_get_data('vat-number-regexes');
279 279
 
280
-    if ( isset( $regexes[ $country ] ) ) {
280
+    if (isset($regexes[$country])) {
281 281
 
282
-        $regex = $regexes[ $country ];
282
+        $regex = $regexes[$country];
283 283
         $regex = '/^(?:' . $regex . ')$/';
284
-        return 1 === preg_match( $regex, $vatin );
284
+        return 1 === preg_match($regex, $vatin);
285 285
 
286 286
     }
287 287
 
288 288
     // Not an EU state, use filters to validate the number.
289
-    return apply_filters( 'wpinv_regex_validate_vat_number', true, $vat_number );
289
+    return apply_filters('wpinv_regex_validate_vat_number', true, $vat_number);
290 290
 }
291 291
 
292 292
 /**
@@ -295,29 +295,29 @@  discard block
 block discarded – undo
295 295
  * @param string $vat_number
296 296
  * @return bool
297 297
  */
298
-function wpinv_vies_validate_vat_number( $vat_number ) {
298
+function wpinv_vies_validate_vat_number($vat_number) {
299 299
 
300
-    $country    = substr( $vat_number, 0, 2 );
301
-    $vatin      = substr( $vat_number, 2 );
300
+    $country    = substr($vat_number, 0, 2);
301
+    $vatin      = substr($vat_number, 2);
302 302
 
303 303
     $url        = add_query_arg(
304 304
         array(
305
-            'ms'  => urlencode( $country ),
306
-            'iso' => urlencode( $country ),
307
-            'vat' => urlencode( $vatin ),
305
+            'ms'  => urlencode($country),
306
+            'iso' => urlencode($country),
307
+            'vat' => urlencode($vatin),
308 308
         ),
309 309
         'http://ec.europa.eu/taxation_customs/vies/viesquer.do'
310 310
     );
311 311
 
312
-    $response   = wp_remote_get( $url );
313
-    $response   = wp_remote_retrieve_body( $response );
312
+    $response   = wp_remote_get($url);
313
+    $response   = wp_remote_retrieve_body($response);
314 314
 
315 315
     // Fallback gracefully if the VIES website is down.
316
-    if ( empty( $response ) ) {
316
+    if (empty($response)) {
317 317
         return true;
318 318
     }
319 319
 
320
-    return 1 !== preg_match( '/invalid VAT number/i', $response );
320
+    return 1 !== preg_match('/invalid VAT number/i', $response);
321 321
 
322 322
 }
323 323
 
@@ -328,18 +328,18 @@  discard block
 block discarded – undo
328 328
  * @param string $country
329 329
  * @return bool
330 330
  */
331
-function wpinv_validate_vat_number( $vat_number, $country ) {
331
+function wpinv_validate_vat_number($vat_number, $country) {
332 332
 
333 333
     // In case the vat number does not have a country code...
334
-    $vat_number = wpinv_sanitize_vat_number( $vat_number );
335
-    $_country   = substr( $vat_number, 0, 2 );
336
-    $_country   = $_country == wpinv_country_name( $_country );
334
+    $vat_number = wpinv_sanitize_vat_number($vat_number);
335
+    $_country   = substr($vat_number, 0, 2);
336
+    $_country   = $_country == wpinv_country_name($_country);
337 337
 
338
-    if ( $_country ) {
339
-        $vat_number = strtoupper( $country ) . $vat_number;
338
+    if ($_country) {
339
+        $vat_number = strtoupper($country) . $vat_number;
340 340
     }
341 341
 
342
-    return wpinv_regex_validate_vat_number( $vat_number ) && wpinv_vies_validate_vat_number( $vat_number );
342
+    return wpinv_regex_validate_vat_number($vat_number) && wpinv_vies_validate_vat_number($vat_number);
343 343
 }
344 344
 
345 345
 /**
@@ -348,40 +348,40 @@  discard block
 block discarded – undo
348 348
  * @return bool
349 349
  */
350 350
 function wpinv_should_validate_vat_number() {
351
-    $validate = wpinv_get_option( 'validate_vat_number' );
352
-	return ! empty( $validate );
351
+    $validate = wpinv_get_option('validate_vat_number');
352
+	return !empty($validate);
353 353
 }
354 354
 
355
-function wpinv_sales_tax_for_year( $year = null ) {
356
-    return wpinv_price( wpinv_get_sales_tax_for_year( $year ) );
355
+function wpinv_sales_tax_for_year($year = null) {
356
+    return wpinv_price(wpinv_get_sales_tax_for_year($year));
357 357
 }
358 358
 
359
-function wpinv_get_sales_tax_for_year( $year = null ) {
359
+function wpinv_get_sales_tax_for_year($year = null) {
360 360
     global $wpdb;
361 361
 
362 362
     // Start at zero
363 363
     $tax = 0;
364 364
 
365
-    if ( ! empty( $year ) ) {
365
+    if (!empty($year)) {
366 366
         $args = array(
367 367
             'post_type'      => 'wpi_invoice',
368
-            'post_status'    => array( 'publish' ),
368
+            'post_status'    => array('publish'),
369 369
             'posts_per_page' => -1,
370 370
             'year'           => $year,
371 371
             'fields'         => 'ids'
372 372
         );
373 373
 
374
-        $payments    = get_posts( $args );
375
-        $payment_ids = implode( ',', $payments );
374
+        $payments    = get_posts($args);
375
+        $payment_ids = implode(',', $payments);
376 376
 
377
-        if ( count( $payments ) > 0 ) {
377
+        if (count($payments) > 0) {
378 378
             $sql = "SELECT SUM( meta_value ) FROM $wpdb->postmeta WHERE meta_key = '_wpinv_tax' AND post_id IN( $payment_ids )";
379
-            $tax = $wpdb->get_var( $sql );
379
+            $tax = $wpdb->get_var($sql);
380 380
         }
381 381
 
382 382
     }
383 383
 
384
-    return apply_filters( 'wpinv_get_sales_tax_for_year', $tax, $year );
384
+    return apply_filters('wpinv_get_sales_tax_for_year', $tax, $year);
385 385
 }
386 386
 
387 387
 function wpinv_is_cart_taxed() {
@@ -390,33 +390,33 @@  discard block
 block discarded – undo
390 390
 
391 391
 function wpinv_prices_show_tax_on_checkout() {
392 392
     return false; // TODO
393
-    $ret = ( wpinv_get_option( 'checkout_include_tax', false ) == 'yes' && wpinv_use_taxes() );
393
+    $ret = (wpinv_get_option('checkout_include_tax', false) == 'yes' && wpinv_use_taxes());
394 394
 
395
-    return apply_filters( 'wpinv_taxes_on_prices_on_checkout', $ret );
395
+    return apply_filters('wpinv_taxes_on_prices_on_checkout', $ret);
396 396
 }
397 397
 
398 398
 function wpinv_display_tax_rate() {
399
-    $ret = wpinv_use_taxes() && wpinv_get_option( 'display_tax_rate', false );
399
+    $ret = wpinv_use_taxes() && wpinv_get_option('display_tax_rate', false);
400 400
 
401
-    return apply_filters( 'wpinv_display_tax_rate', $ret );
401
+    return apply_filters('wpinv_display_tax_rate', $ret);
402 402
 }
403 403
 
404 404
 function wpinv_cart_needs_tax_address_fields() {
405
-    if( !wpinv_is_cart_taxed() )
405
+    if (!wpinv_is_cart_taxed())
406 406
         return false;
407 407
 
408
-    return ! did_action( 'wpinv_after_cc_fields', 'wpinv_default_cc_address_fields' );
408
+    return !did_action('wpinv_after_cc_fields', 'wpinv_default_cc_address_fields');
409 409
 }
410 410
 
411
-function wpinv_item_is_tax_exclusive( $item_id = 0 ) {
412
-    $ret = (bool)get_post_meta( $item_id, '_wpinv_tax_exclusive', false );
413
-    return apply_filters( 'wpinv_is_tax_exclusive', $ret, $item_id );
411
+function wpinv_item_is_tax_exclusive($item_id = 0) {
412
+    $ret = (bool) get_post_meta($item_id, '_wpinv_tax_exclusive', false);
413
+    return apply_filters('wpinv_is_tax_exclusive', $ret, $item_id);
414 414
 }
415 415
 
416
-function wpinv_currency_decimal_filter( $decimals = 2 ) {
416
+function wpinv_currency_decimal_filter($decimals = 2) {
417 417
     $currency = wpinv_get_currency();
418 418
 
419
-    switch ( $currency ) {
419
+    switch ($currency) {
420 420
         case 'RIAL' :
421 421
         case 'JPY' :
422 422
         case 'TWD' :
@@ -425,13 +425,13 @@  discard block
 block discarded – undo
425 425
             break;
426 426
     }
427 427
 
428
-    return apply_filters( 'wpinv_currency_decimal_count', $decimals, $currency );
428
+    return apply_filters('wpinv_currency_decimal_count', $decimals, $currency);
429 429
 }
430 430
 
431 431
 function wpinv_tax_amount() {
432 432
     $output = 0.00;
433 433
     
434
-    return apply_filters( 'wpinv_tax_amount', $output );
434
+    return apply_filters('wpinv_tax_amount', $output);
435 435
 }
436 436
 
437 437
 /**
@@ -439,25 +439,25 @@  discard block
 block discarded – undo
439 439
  * 
440 440
  * @param string|bool|null $vat_rule
441 441
  */
442
-function getpaid_filter_vat_rule( $vat_rule ) {
442
+function getpaid_filter_vat_rule($vat_rule) {
443 443
 
444
-    if ( empty( $vat_rule ) ) {        
444
+    if (empty($vat_rule)) {        
445 445
         return 'digital';
446 446
     }
447 447
 
448 448
     return $vat_rule;
449 449
 }
450
-add_filter( 'wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule' );
450
+add_filter('wpinv_get_item_vat_rule', 'getpaid_filter_vat_rule');
451 451
 
452 452
 /**
453 453
  * Filters the VAT class to ensure that each item has a VAT class.
454 454
  * 
455 455
  * @param string|bool|null $vat_rule
456 456
  */
457
-function getpaid_filter_vat_class( $vat_class ) {
458
-    return empty( $vat_class ) ? '_standard' : $vat_class;
457
+function getpaid_filter_vat_class($vat_class) {
458
+    return empty($vat_class) ? '_standard' : $vat_class;
459 459
 }
460
-add_filter( 'wpinv_get_item_vat_class', 'getpaid_filter_vat_class' );
460
+add_filter('wpinv_get_item_vat_class', 'getpaid_filter_vat_class');
461 461
 
462 462
 /**
463 463
  * Returns a list of all tax classes.
@@ -469,9 +469,9 @@  discard block
 block discarded – undo
469 469
     return apply_filters(
470 470
         'getpaid_tax_classes',
471 471
         array(
472
-            '_standard' => __( 'Standard Tax Rate', 'invoicing' ),
473
-            '_reduced'  => __( 'Reduced Tax Rate', 'invoicing' ),
474
-            '_exempt'   => __( 'Tax Exempt', 'invoicing' ),
472
+            '_standard' => __('Standard Tax Rate', 'invoicing'),
473
+            '_reduced'  => __('Reduced Tax Rate', 'invoicing'),
474
+            '_exempt'   => __('Tax Exempt', 'invoicing'),
475 475
         )
476 476
     );
477 477
 
@@ -487,8 +487,8 @@  discard block
 block discarded – undo
487 487
     return apply_filters(
488 488
         'getpaid_tax_rules',
489 489
         array(
490
-            'physical' => __( 'Physical Item', 'invoicing' ),
491
-            'digital'  => __( 'Digital Item', 'invoicing' ),
490
+            'physical' => __('Physical Item', 'invoicing'),
491
+            'digital'  => __('Digital Item', 'invoicing'),
492 492
         )
493 493
     );
494 494
 
@@ -500,15 +500,15 @@  discard block
 block discarded – undo
500 500
  * @param string $tax_class
501 501
  * @return string
502 502
  */
503
-function getpaid_get_tax_class_label( $tax_class ) {
503
+function getpaid_get_tax_class_label($tax_class) {
504 504
 
505 505
     $classes = getpaid_get_tax_classes();
506 506
 
507
-    if ( isset( $classes[ $tax_class ] ) ) {
508
-        return sanitize_text_field( $classes[ $tax_class ] );
507
+    if (isset($classes[$tax_class])) {
508
+        return sanitize_text_field($classes[$tax_class]);
509 509
     }
510 510
 
511
-    return sanitize_text_field( $tax_class );
511
+    return sanitize_text_field($tax_class);
512 512
 
513 513
 }
514 514
 
@@ -518,15 +518,15 @@  discard block
 block discarded – undo
518 518
  * @param string $tax_rule
519 519
  * @return string
520 520
  */
521
-function getpaid_get_tax_rule_label( $tax_rule ) {
521
+function getpaid_get_tax_rule_label($tax_rule) {
522 522
 
523 523
     $rules = getpaid_get_tax_rules();
524 524
 
525
-    if ( isset( $rules[ $tax_rule ] ) ) {
526
-        return sanitize_text_field( $rules[ $tax_rule ] );
525
+    if (isset($rules[$tax_rule])) {
526
+        return sanitize_text_field($rules[$tax_rule]);
527 527
     }
528 528
 
529
-    return sanitize_text_field( $tax_rule );
529
+    return sanitize_text_field($tax_rule);
530 530
 
531 531
 }
532 532
 
@@ -539,21 +539,21 @@  discard block
 block discarded – undo
539 539
  * @param string $recurring
540 540
  * @return string
541 541
  */
542
-function getpaid_get_taxable_amount( $item_id, $item_total, $discount_code, $recurring = false ) {
542
+function getpaid_get_taxable_amount($item_id, $item_total, $discount_code, $recurring = false) {
543 543
 
544 544
     $taxable_amount = $item_total;
545 545
 
546 546
     // Do we have a $discount_code?
547
-    if ( ! empty( $discount_code ) ) {
547
+    if (!empty($discount_code)) {
548 548
 
549
-        $discount = new WPInv_Discount( $discount_code );
549
+        $discount = new WPInv_Discount($discount_code);
550 550
 
551
-        if ( $discount->exists() && $discount->is_valid_for_items( $item_id ) && ( ! $recurring || $discount->is_recurring() ) ) {
552
-            $taxable_amount = $item_total - $discount->get_discounted_amount( $item_total );
551
+        if ($discount->exists() && $discount->is_valid_for_items($item_id) && (!$recurring || $discount->is_recurring())) {
552
+            $taxable_amount = $item_total - $discount->get_discounted_amount($item_total);
553 553
         }
554 554
 
555 555
     }
556 556
 
557
-    $taxable_amount = max( 0, $taxable_amount );
558
-    return apply_filters( 'getpaid_taxable_amount', $taxable_amount, $item_id, $item_total, $discount_code, $recurring );
557
+    $taxable_amount = max(0, $taxable_amount);
558
+    return apply_filters('getpaid_taxable_amount', $taxable_amount, $item_id, $item_total, $discount_code, $recurring);
559 559
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 2 patches
Indentation   +533 added lines, -533 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,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'               => 'draft',
34
-		'version'              => '',
35
-		'date_created'         => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'               => 'draft',
34
+        'version'              => '',
35
+        'date_created'         => null,
36 36
         'date_modified'        => null,
37 37
         'name'                 => '',
38 38
         'author'               => 1,
39 39
         'elements'             => null,
40
-		'items'                => null,
41
-		'earned'               => 0,
42
-		'refunded'             => 0,
43
-		'cancelled'            => 0,
44
-		'failed'               => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'                => null,
41
+        'earned'               => 0,
42
+        'refunded'             => 0,
43
+        'cancelled'            => 0,
44
+        'failed'               => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,35 +68,35 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98 98
 
99
-	}
99
+    }
100 100
 
101 101
     /*
102 102
 	|--------------------------------------------------------------------------
@@ -114,358 +114,358 @@  discard block
 block discarded – undo
114 114
     */
115 115
 
116 116
     /**
117
-	 * Get plugin version when the form was created.
118
-	 *
119
-	 * @since 1.0.19
120
-	 * @param  string $context View or edit context.
121
-	 * @return string
122
-	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
117
+     * Get plugin version when the form was created.
118
+     *
119
+     * @since 1.0.19
120
+     * @param  string $context View or edit context.
121
+     * @return string
122
+     */
123
+    public function get_version( $context = 'view' ) {
124
+        return $this->get_prop( 'version', $context );
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get date when the form was created.
129
-	 *
130
-	 * @since 1.0.19
131
-	 * @param  string $context View or edit context.
132
-	 * @return string
133
-	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
128
+     * Get date when the form was created.
129
+     *
130
+     * @since 1.0.19
131
+     * @param  string $context View or edit context.
132
+     * @return string
133
+     */
134
+    public function get_date_created( $context = 'view' ) {
135
+        return $this->get_prop( 'date_created', $context );
136 136
     }
137 137
 
138 138
     /**
139
-	 * Get GMT date when the form was created.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param  string $context View or edit context.
143
-	 * @return string
144
-	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
139
+     * Get GMT date when the form was created.
140
+     *
141
+     * @since 1.0.19
142
+     * @param  string $context View or edit context.
143
+     * @return string
144
+     */
145
+    public function get_date_created_gmt( $context = 'view' ) {
146 146
         $date = $this->get_date_created( $context );
147 147
 
148 148
         if ( $date ) {
149 149
             $date = get_gmt_from_date( $date );
150 150
         }
151
-		return $date;
151
+        return $date;
152 152
     }
153 153
 
154 154
     /**
155
-	 * Get date when the form was last modified.
156
-	 *
157
-	 * @since 1.0.19
158
-	 * @param  string $context View or edit context.
159
-	 * @return string
160
-	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
155
+     * Get date when the form was last modified.
156
+     *
157
+     * @since 1.0.19
158
+     * @param  string $context View or edit context.
159
+     * @return string
160
+     */
161
+    public function get_date_modified( $context = 'view' ) {
162
+        return $this->get_prop( 'date_modified', $context );
163 163
     }
164 164
 
165 165
     /**
166
-	 * Get GMT date when the form was last modified.
167
-	 *
168
-	 * @since 1.0.19
169
-	 * @param  string $context View or edit context.
170
-	 * @return string
171
-	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
166
+     * Get GMT date when the form was last modified.
167
+     *
168
+     * @since 1.0.19
169
+     * @param  string $context View or edit context.
170
+     * @return string
171
+     */
172
+    public function get_date_modified_gmt( $context = 'view' ) {
173 173
         $date = $this->get_date_modified( $context );
174 174
 
175 175
         if ( $date ) {
176 176
             $date = get_gmt_from_date( $date );
177 177
         }
178
-		return $date;
178
+        return $date;
179 179
     }
180 180
 
181 181
     /**
182
-	 * Get the form name.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return string
187
-	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
182
+     * Get the form name.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return string
187
+     */
188
+    public function get_name( $context = 'view' ) {
189
+        return $this->get_prop( 'name', $context );
190 190
     }
191 191
 
192 192
     /**
193
-	 * Alias of self::get_name().
194
-	 *
195
-	 * @since 1.0.19
196
-	 * @param  string $context View or edit context.
197
-	 * @return string
198
-	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
201
-	}
193
+     * Alias of self::get_name().
194
+     *
195
+     * @since 1.0.19
196
+     * @param  string $context View or edit context.
197
+     * @return string
198
+     */
199
+    public function get_title( $context = 'view' ) {
200
+        return $this->get_name( $context );
201
+    }
202 202
 
203 203
     /**
204
-	 * Get the owner of the form.
205
-	 *
206
-	 * @since 1.0.19
207
-	 * @param  string $context View or edit context.
208
-	 * @return int
209
-	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
204
+     * Get the owner of the form.
205
+     *
206
+     * @since 1.0.19
207
+     * @param  string $context View or edit context.
208
+     * @return int
209
+     */
210
+    public function get_author( $context = 'view' ) {
211
+        return (int) $this->get_prop( 'author', $context );
212 212
     }
213 213
 
214 214
     /**
215
-	 * Get the elements that make up the form.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return array
220
-	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
215
+     * Get the elements that make up the form.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return array
220
+     */
221
+    public function get_elements( $context = 'view' ) {
222
+        $elements = $this->get_prop( 'elements', $context );
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
225 225
             return wpinv_get_data( 'sample-payment-form' );
226
-		}
226
+        }
227 227
 
228
-		// Ensure that all required elements exist.
229
-		$_elements = array();
230
-		foreach ( $elements as $element ) {
228
+        // Ensure that all required elements exist.
229
+        $_elements = array();
230
+        foreach ( $elements as $element ) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
233 233
 
234
-				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
236
-					'id'          => 'gtscicd',
237
-					'name'        => 'gtscicd',
238
-					'type'        => 'gateway_select',
239
-					'premade'     => true
234
+                $_elements[] = array(
235
+                    'text'        => __( 'Select Payment Method', 'invoicing' ),
236
+                    'id'          => 'gtscicd',
237
+                    'name'        => 'gtscicd',
238
+                    'type'        => 'gateway_select',
239
+                    'premade'     => true
240 240
 			
241
-				);
241
+                );
242 242
 
243
-			}
243
+            }
244 244
 
245
-			$_elements[] = $element;
245
+            $_elements[] = $element;
246 246
 
247
-		}
247
+        }
248 248
 
249 249
         return $_elements;
250
-	}
251
-
252
-	/**
253
-	 * Get the items sold via the form.
254
-	 *
255
-	 * @since 1.0.19
256
-	 * @param  string $context View or edit context.
257
-	 * @param  string $return objects or arrays.
258
-	 * @return GetPaid_Form_Item[]
259
-	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
262
-
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
250
+    }
251
+
252
+    /**
253
+     * Get the items sold via the form.
254
+     *
255
+     * @since 1.0.19
256
+     * @param  string $context View or edit context.
257
+     * @param  string $return objects or arrays.
258
+     * @return GetPaid_Form_Item[]
259
+     */
260
+    public function get_items( $context = 'view', $return = 'objects' ) {
261
+        $items = $this->get_prop( 'items', $context );
262
+
263
+        if ( empty( $items ) || ! is_array( $items ) ) {
264 264
             $items = wpinv_get_data( 'sample-payment-form-items' );
265
-		}
265
+        }
266
+
267
+        // Convert the items.
268
+        $prepared = array();
266 269
 
267
-		// Convert the items.
268
-		$prepared = array();
270
+        foreach ( $items as $key => $value ) {
269 271
 
270
-		foreach ( $items as $key => $value ) {
272
+            // Form items.
273
+            if ( $value instanceof GetPaid_Form_Item ) {
271 274
 
272
-			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
275
+                if ( $value->can_purchase() ) {
276
+                    $prepared[] = $value;
277
+                }
274 278
 
275
-				if ( $value->can_purchase() ) {
276
-					$prepared[] = $value;
277
-				}
279
+                continue;
278 280
 
279
-				continue;
281
+            }
280 282
 
281
-			}
283
+            // $item_id => $quantity (buy buttons)
284
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
+                $item = new GetPaid_Form_Item( $key );
282 286
 
283
-			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
287
+                if ( $item->can_purchase() ) {
286 288
 
287
-				if ( $item->can_purchase() ) {
289
+                    $value = (float) $value;
290
+                    $item->set_quantity( $value );
291
+                    if ( 0 == $value ) {
292
+                        $item->set_quantity( 1 );
293
+                        $item->set_allow_quantities( true );
294
+                    }
288 295
 
289
-					$value = (float) $value;
290
-					$item->set_quantity( $value );
291
-					if ( 0 == $value ) {
292
-						$item->set_quantity( 1 );
293
-						$item->set_allow_quantities( true );
294
-					}
296
+                    $prepared[] = $item;
297
+                }
295 298
 
296
-					$prepared[] = $item;
297
-				}
299
+                continue;
300
+            }
298 301
 
299
-				continue;
300
-			}
302
+            // Items saved via payment forms editor.
303
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
301 304
 
302
-			// Items saved via payment forms editor.
303
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
305
+                $item = new GetPaid_Form_Item( $value['id'] );
304 306
 
305
-				$item = new GetPaid_Form_Item( $value['id'] );
307
+                if ( ! $item->can_purchase() ) {
308
+                    continue;
309
+                }
306 310
 
307
-				if ( ! $item->can_purchase() ) {
308
-					continue;
309
-				}
311
+                // Sub-total (Cart items).
312
+                if ( isset( $value['subtotal'] ) ) {
313
+                    $item->set_price( $value['subtotal'] );
314
+                }
310 315
 
311
-				// Sub-total (Cart items).
312
-				if ( isset( $value['subtotal'] ) ) {
313
-					$item->set_price( $value['subtotal'] );
314
-				}
316
+                if ( isset( $value['quantity'] ) ) {
317
+                    $item->set_quantity( $value['quantity'] );
318
+                }
315 319
 
316
-				if ( isset( $value['quantity'] ) ) {
317
-					$item->set_quantity( $value['quantity'] );
318
-				}
320
+                if ( isset( $value['allow_quantities'] ) ) {
321
+                    $item->set_allow_quantities( $value['allow_quantities'] );
322
+                }
319 323
 
320
-				if ( isset( $value['allow_quantities'] ) ) {
321
-					$item->set_allow_quantities( $value['allow_quantities'] );
322
-				}
324
+                if ( isset( $value['required'] ) ) {
325
+                    $item->set_is_required( $value['required'] );
326
+                }
323 327
 
324
-				if ( isset( $value['required'] ) ) {
325
-					$item->set_is_required( $value['required'] );
326
-				}
328
+                if ( isset( $value['description'] ) ) {
329
+                    $item->set_custom_description( $value['description'] );
330
+                }
327 331
 
328
-				if ( isset( $value['description'] ) ) {
329
-					$item->set_custom_description( $value['description'] );
330
-				}
332
+                $prepared[] = $item;
333
+                continue;
331 334
 
332
-				$prepared[] = $item;
333
-				continue;
335
+            }
336
+
337
+            // $item_id => array( 'price' => 10 ) (item variations)
338
+            if ( is_numeric( $key ) && is_array( $value ) ) {
339
+                $item = new GetPaid_Form_Item( $key );
340
+
341
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
+                    $item->set_price( $value['price'] );
343
+                }
344
+
345
+                if ( $item->can_purchase() ) {
346
+                    $prepared[] = $item;
347
+                }
348
+
349
+                continue;
350
+            }
351
+
352
+        }
353
+
354
+        if ( 'objects' == $return && 'view' == $context ) {
355
+            return $prepared;
356
+        }
357
+
358
+        $items = array();
359
+        foreach ( $prepared as $item ) {
360
+            $items[] = $item->prepare_data_for_use();
361
+        }
362
+
363
+        return $items;
364
+    }
365
+
366
+    /**
367
+     * Get a single item belonging to the form.
368
+     *
369
+     * @since 1.0.19
370
+     * @param  int $item_id The item id to return.
371
+     * @return GetPaid_Form_Item|bool
372
+     */
373
+    public function get_item( $item_id ) {
374
+
375
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
376
+            return false;
377
+        }
378
+
379
+        foreach( $this->get_items() as $item ) {
380
+            if ( $item->get_id() == (int) $item_id ) {
381
+                return $item;
382
+            }
383
+        }
384
+
385
+        return false;
386
+
387
+    }
388
+
389
+    /**
390
+     * Gets a single element.
391
+     *
392
+     * @since 1.0.19
393
+     * @param  string $element_type The element type to return.
394
+     * @return array|bool
395
+     */
396
+    public function get_element_type( $element_type ) {
397
+
398
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
399
+            return false;
400
+        }
401
+
402
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
403
+
404
+            if ( $element['type'] == $element_type ) {
405
+                return $element;
406
+            }
407
+
408
+        }
409
+
410
+        return false;
411
+
412
+    }
413
+
414
+    /**
415
+     * Get the total amount earned via this form.
416
+     *
417
+     * @since 1.0.19
418
+     * @param  string $context View or edit context.
419
+     * @return float
420
+     */
421
+    public function get_earned( $context = 'view' ) {
422
+        return $this->get_prop( 'earned', $context );
423
+    }
424
+
425
+    /**
426
+     * Get the total amount refunded via this form.
427
+     *
428
+     * @since 1.0.19
429
+     * @param  string $context View or edit context.
430
+     * @return float
431
+     */
432
+    public function get_refunded( $context = 'view' ) {
433
+        return $this->get_prop( 'refunded', $context );
434
+    }
334 435
 
335
-			}
436
+    /**
437
+     * Get the total amount cancelled via this form.
438
+     *
439
+     * @since 1.0.19
440
+     * @param  string $context View or edit context.
441
+     * @return float
442
+     */
443
+    public function get_cancelled( $context = 'view' ) {
444
+        return $this->get_prop( 'cancelled', $context );
445
+    }
336 446
 
337
-			// $item_id => array( 'price' => 10 ) (item variations)
338
-			if ( is_numeric( $key ) && is_array( $value ) ) {
339
-				$item = new GetPaid_Form_Item( $key );
447
+    /**
448
+     * Get the total amount failed via this form.
449
+     *
450
+     * @since 1.0.19
451
+     * @param  string $context View or edit context.
452
+     * @return float
453
+     */
454
+    public function get_failed( $context = 'view' ) {
455
+        return $this->get_prop( 'failed', $context );
456
+    }
340 457
 
341
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
-					$item->set_price( $value['price'] );
343
-				}
344
-
345
-				if ( $item->can_purchase() ) {
346
-					$prepared[] = $item;
347
-				}
348
-
349
-				continue;
350
-			}
351
-
352
-		}
353
-
354
-		if ( 'objects' == $return && 'view' == $context ) {
355
-			return $prepared;
356
-		}
357
-
358
-		$items = array();
359
-		foreach ( $prepared as $item ) {
360
-			$items[] = $item->prepare_data_for_use();
361
-		}
362
-
363
-		return $items;
364
-	}
365
-
366
-	/**
367
-	 * Get a single item belonging to the form.
368
-	 *
369
-	 * @since 1.0.19
370
-	 * @param  int $item_id The item id to return.
371
-	 * @return GetPaid_Form_Item|bool
372
-	 */
373
-	public function get_item( $item_id ) {
374
-
375
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
376
-			return false;
377
-		}
378
-
379
-		foreach( $this->get_items() as $item ) {
380
-			if ( $item->get_id() == (int) $item_id ) {
381
-				return $item;
382
-			}
383
-		}
384
-
385
-		return false;
386
-
387
-	}
388
-
389
-	/**
390
-	 * Gets a single element.
391
-	 *
392
-	 * @since 1.0.19
393
-	 * @param  string $element_type The element type to return.
394
-	 * @return array|bool
395
-	 */
396
-	public function get_element_type( $element_type ) {
397
-
398
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
399
-			return false;
400
-		}
401
-
402
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
403
-
404
-			if ( $element['type'] == $element_type ) {
405
-				return $element;
406
-			}
407
-
408
-		}
409
-
410
-		return false;
411
-
412
-	}
413
-
414
-	/**
415
-	 * Get the total amount earned via this form.
416
-	 *
417
-	 * @since 1.0.19
418
-	 * @param  string $context View or edit context.
419
-	 * @return float
420
-	 */
421
-	public function get_earned( $context = 'view' ) {
422
-		return $this->get_prop( 'earned', $context );
423
-	}
424
-
425
-	/**
426
-	 * Get the total amount refunded via this form.
427
-	 *
428
-	 * @since 1.0.19
429
-	 * @param  string $context View or edit context.
430
-	 * @return float
431
-	 */
432
-	public function get_refunded( $context = 'view' ) {
433
-		return $this->get_prop( 'refunded', $context );
434
-	}
435
-
436
-	/**
437
-	 * Get the total amount cancelled via this form.
438
-	 *
439
-	 * @since 1.0.19
440
-	 * @param  string $context View or edit context.
441
-	 * @return float
442
-	 */
443
-	public function get_cancelled( $context = 'view' ) {
444
-		return $this->get_prop( 'cancelled', $context );
445
-	}
446
-
447
-	/**
448
-	 * Get the total amount failed via this form.
449
-	 *
450
-	 * @since 1.0.19
451
-	 * @param  string $context View or edit context.
452
-	 * @return float
453
-	 */
454
-	public function get_failed( $context = 'view' ) {
455
-		return $this->get_prop( 'failed', $context );
456
-	}
457
-
458
-	/**
459
-	 * Get the currency.
460
-	 *
461
-	 * @since 1.0.19
462
-	 * @param  string $context View or edit context.
463
-	 * @return string
464
-	 */
465
-	public function get_currency() {
466
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
467
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
468
-	}
458
+    /**
459
+     * Get the currency.
460
+     *
461
+     * @since 1.0.19
462
+     * @param  string $context View or edit context.
463
+     * @return string
464
+     */
465
+    public function get_currency() {
466
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
467
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
468
+    }
469 469
 
470 470
     /*
471 471
 	|--------------------------------------------------------------------------
@@ -478,22 +478,22 @@  discard block
 block discarded – undo
478 478
     */
479 479
 
480 480
     /**
481
-	 * Set plugin version when the item was created.
482
-	 *
483
-	 * @since 1.0.19
484
-	 */
485
-	public function set_version( $value ) {
486
-		$this->set_prop( 'version', $value );
481
+     * Set plugin version when the item was created.
482
+     *
483
+     * @since 1.0.19
484
+     */
485
+    public function set_version( $value ) {
486
+        $this->set_prop( 'version', $value );
487 487
     }
488 488
 
489 489
     /**
490
-	 * Set date when the item was created.
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param string $value Value to set.
490
+     * Set date when the item was created.
491
+     *
492
+     * @since 1.0.19
493
+     * @param string $value Value to set.
494 494
      * @return bool Whether or not the date was set.
495
-	 */
496
-	public function set_date_created( $value ) {
495
+     */
496
+    public function set_date_created( $value ) {
497 497
         $date = strtotime( $value );
498 498
 
499 499
         if ( $date ) {
@@ -506,13 +506,13 @@  discard block
 block discarded – undo
506 506
     }
507 507
 
508 508
     /**
509
-	 * Set date when the item was last modified.
510
-	 *
511
-	 * @since 1.0.19
512
-	 * @param string $value Value to set.
509
+     * Set date when the item was last modified.
510
+     *
511
+     * @since 1.0.19
512
+     * @param string $value Value to set.
513 513
      * @return bool Whether or not the date was set.
514
-	 */
515
-	public function set_date_modified( $value ) {
514
+     */
515
+    public function set_date_modified( $value ) {
516 516
         $date = strtotime( $value );
517 517
 
518 518
         if ( $date ) {
@@ -525,118 +525,118 @@  discard block
 block discarded – undo
525 525
     }
526 526
 
527 527
     /**
528
-	 * Set the item name.
529
-	 *
530
-	 * @since 1.0.19
531
-	 * @param  string $value New name.
532
-	 */
533
-	public function set_name( $value ) {
534
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
535
-    }
536
-
537
-    /**
538
-	 * Alias of self::set_name().
539
-	 *
540
-	 * @since 1.0.19
541
-	 * @param  string $value New name.
542
-	 */
543
-	public function set_title( $value ) {
544
-		$this->set_name( $value );
545
-    }
546
-
547
-    /**
548
-	 * Set the owner of the item.
549
-	 *
550
-	 * @since 1.0.19
551
-	 * @param  int $value New author.
552
-	 */
553
-	public function set_author( $value ) {
554
-		$this->set_prop( 'author', (int) $value );
555
-	}
556
-
557
-	/**
558
-	 * Set the form elements.
559
-	 *
560
-	 * @since 1.0.19
561
-	 * @param  array $value Form elements.
562
-	 */
563
-	public function set_elements( $value ) {
564
-		if ( is_array( $value ) ) {
565
-			$this->set_prop( 'elements', $value );
566
-		}
567
-	}
568
-
569
-	/**
570
-	 * Set the form items.
571
-	 *
572
-	 * @since 1.0.19
573
-	 * @param  array $value Form elements.
574
-	 */
575
-	public function set_items( $value ) {
576
-		if ( is_array( $value ) ) {
577
-			$this->set_prop( 'items', $value );
578
-		}
579
-	}
580
-
581
-	/**
582
-	 * Set the total amount earned via this form.
583
-	 *
584
-	 * @since 1.0.19
585
-	 * @param  float $value Amount earned.
586
-	 */
587
-	public function set_earned( $value ) {
588
-		$value = max( (float) $value, 0 );
589
-		$this->set_prop( 'earned', $value );
590
-	}
591
-
592
-	/**
593
-	 * Set the total amount refunded via this form.
594
-	 *
595
-	 * @since 1.0.19
596
-	 * @param  float $value Amount refunded.
597
-	 */
598
-	public function set_refunded( $value ) {
599
-		$value = max( (float) $value, 0 );
600
-		$this->set_prop( 'refunded', $value );
601
-	}
602
-
603
-	/**
604
-	 * Set the total amount cancelled via this form.
605
-	 *
606
-	 * @since 1.0.19
607
-	 * @param  float $value Amount cancelled.
608
-	 */
609
-	public function set_cancelled( $value ) {
610
-		$value = max( (float) $value, 0 );
611
-		$this->set_prop( 'cancelled', $value );
612
-	}
613
-
614
-	/**
615
-	 * Set the total amount failed via this form.
616
-	 *
617
-	 * @since 1.0.19
618
-	 * @param  float $value Amount cancelled.
619
-	 */
620
-	public function set_failed( $value ) {
621
-		$value = max( (float) $value, 0 );
622
-		$this->set_prop( 'failed', $value );
623
-	}
528
+     * Set the item name.
529
+     *
530
+     * @since 1.0.19
531
+     * @param  string $value New name.
532
+     */
533
+    public function set_name( $value ) {
534
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
535
+    }
536
+
537
+    /**
538
+     * Alias of self::set_name().
539
+     *
540
+     * @since 1.0.19
541
+     * @param  string $value New name.
542
+     */
543
+    public function set_title( $value ) {
544
+        $this->set_name( $value );
545
+    }
546
+
547
+    /**
548
+     * Set the owner of the item.
549
+     *
550
+     * @since 1.0.19
551
+     * @param  int $value New author.
552
+     */
553
+    public function set_author( $value ) {
554
+        $this->set_prop( 'author', (int) $value );
555
+    }
556
+
557
+    /**
558
+     * Set the form elements.
559
+     *
560
+     * @since 1.0.19
561
+     * @param  array $value Form elements.
562
+     */
563
+    public function set_elements( $value ) {
564
+        if ( is_array( $value ) ) {
565
+            $this->set_prop( 'elements', $value );
566
+        }
567
+    }
568
+
569
+    /**
570
+     * Set the form items.
571
+     *
572
+     * @since 1.0.19
573
+     * @param  array $value Form elements.
574
+     */
575
+    public function set_items( $value ) {
576
+        if ( is_array( $value ) ) {
577
+            $this->set_prop( 'items', $value );
578
+        }
579
+    }
580
+
581
+    /**
582
+     * Set the total amount earned via this form.
583
+     *
584
+     * @since 1.0.19
585
+     * @param  float $value Amount earned.
586
+     */
587
+    public function set_earned( $value ) {
588
+        $value = max( (float) $value, 0 );
589
+        $this->set_prop( 'earned', $value );
590
+    }
591
+
592
+    /**
593
+     * Set the total amount refunded via this form.
594
+     *
595
+     * @since 1.0.19
596
+     * @param  float $value Amount refunded.
597
+     */
598
+    public function set_refunded( $value ) {
599
+        $value = max( (float) $value, 0 );
600
+        $this->set_prop( 'refunded', $value );
601
+    }
602
+
603
+    /**
604
+     * Set the total amount cancelled via this form.
605
+     *
606
+     * @since 1.0.19
607
+     * @param  float $value Amount cancelled.
608
+     */
609
+    public function set_cancelled( $value ) {
610
+        $value = max( (float) $value, 0 );
611
+        $this->set_prop( 'cancelled', $value );
612
+    }
613
+
614
+    /**
615
+     * Set the total amount failed via this form.
616
+     *
617
+     * @since 1.0.19
618
+     * @param  float $value Amount cancelled.
619
+     */
620
+    public function set_failed( $value ) {
621
+        $value = max( (float) $value, 0 );
622
+        $this->set_prop( 'failed', $value );
623
+    }
624 624
 
625 625
     /**
626 626
      * Create an item. For backwards compatibilty.
627 627
      *
628 628
      * @deprecated
629
-	 * @return int item id
629
+     * @return int item id
630 630
      */
631 631
     public function create( $data = array() ) {
632 632
 
633
-		// Set the properties.
634
-		if ( is_array( $data ) ) {
635
-			$this->set_props( $data );
636
-		}
633
+        // Set the properties.
634
+        if ( is_array( $data ) ) {
635
+            $this->set_props( $data );
636
+        }
637 637
 
638
-		// Save the item.
639
-		return $this->save();
638
+        // Save the item.
639
+        return $this->save();
640 640
 
641 641
     }
642 642
 
@@ -644,7 +644,7 @@  discard block
 block discarded – undo
644 644
      * Updates an item. For backwards compatibilty.
645 645
      *
646 646
      * @deprecated
647
-	 * @return int item id
647
+     * @return int item id
648 648
      */
649 649
     public function update( $data = array() ) {
650 650
         return $this->create( $data );
@@ -660,22 +660,22 @@  discard block
 block discarded – undo
660 660
 	*/
661 661
 
662 662
     /**
663
-	 * Checks whether this is the default payment form.
664
-	 *
665
-	 * @since 1.0.19
666
-	 * @return bool
667
-	 */
663
+     * Checks whether this is the default payment form.
664
+     *
665
+     * @since 1.0.19
666
+     * @return bool
667
+     */
668 668
     public function is_default() {
669 669
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
670 670
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
671
-	}
671
+    }
672 672
 
673 673
     /**
674
-	 * Checks whether the form is active.
675
-	 *
676
-	 * @since 1.0.19
677
-	 * @return bool
678
-	 */
674
+     * Checks whether the form is active.
675
+     *
676
+     * @since 1.0.19
677
+     * @return bool
678
+     */
679 679
     public function is_active() {
680 680
         $is_active = 0 !== (int) $this->get_id();
681 681
 
@@ -684,76 +684,76 @@  discard block
 block discarded – undo
684 684
         }
685 685
 
686 686
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
687
-	}
688
-
689
-	/**
690
-	 * Checks whether the form has a given item.
691
-	 *
692
-	 * @since 1.0.19
693
-	 * @return bool
694
-	 */
687
+    }
688
+
689
+    /**
690
+     * Checks whether the form has a given item.
691
+     *
692
+     * @since 1.0.19
693
+     * @return bool
694
+     */
695 695
     public function has_item( $item_id ) {
696 696
         return false !== $this->get_item( $item_id );
697
-	}
698
-
699
-	/**
700
-	 * Checks whether the form has a given element.
701
-	 *
702
-	 * @since 1.0.19
703
-	 * @return bool
704
-	 */
697
+    }
698
+
699
+    /**
700
+     * Checks whether the form has a given element.
701
+     *
702
+     * @since 1.0.19
703
+     * @return bool
704
+     */
705 705
     public function has_element_type( $element_type ) {
706 706
         return false !== $this->get_element_type( $element_type );
707
-	}
708
-
709
-	/**
710
-	 * Checks whether this form is recurring or not.
711
-	 *
712
-	 * @since 1.0.19
713
-	 * @return bool
714
-	 */
707
+    }
708
+
709
+    /**
710
+     * Checks whether this form is recurring or not.
711
+     *
712
+     * @since 1.0.19
713
+     * @return bool
714
+     */
715 715
     public function is_recurring() {
716 716
 
717
-		if ( ! empty( $this->invoice ) ) {
718
-			return $this->invoice->is_recurring();
719
-		}
717
+        if ( ! empty( $this->invoice ) ) {
718
+            return $this->invoice->is_recurring();
719
+        }
720 720
 
721
-		foreach ( $this->get_items() as $item ) {
721
+        foreach ( $this->get_items() as $item ) {
722 722
 
723
-			if ( $item->is_recurring() ) {
724
-				return true;
725
-			}
723
+            if ( $item->is_recurring() ) {
724
+                return true;
725
+            }
726 726
 
727
-		}
727
+        }
728 728
 
729 729
         return false;
730
-	}
730
+    }
731 731
 
732
-	/**
733
-	 * Retrieves the form's html.
734
-	 *
735
-	 * @since 1.0.19
736
-	 */
732
+    /**
733
+     * Retrieves the form's html.
734
+     *
735
+     * @since 1.0.19
736
+     */
737 737
     public function get_html( $extra_markup = '' ) {
738 738
 
739
-		// Return the HTML.
740
-		return wpinv_get_template_html(
741
-			'payment-forms/form.php',
742
-			array(
743
-				'form'         => $this,
744
-				'extra_markup' => $extra_markup,
745
-			)
746
-		);
747
-
748
-	}
749
-
750
-	/**
751
-	 * Displays the payment form.
752
-	 *
753
-	 * @since 1.0.19
754
-	 */
739
+        // Return the HTML.
740
+        return wpinv_get_template_html(
741
+            'payment-forms/form.php',
742
+            array(
743
+                'form'         => $this,
744
+                'extra_markup' => $extra_markup,
745
+            )
746
+        );
747
+
748
+    }
749
+
750
+    /**
751
+     * Displays the payment form.
752
+     *
753
+     * @since 1.0.19
754
+     */
755 755
     public function display( $extra_markup = '' ) {
756
-		echo $this->get_html( $extra_markup );
756
+        echo $this->get_html( $extra_markup );
757 757
     }
758 758
 
759 759
 }
Please login to merge, or discard this patch.
Spacing   +145 added lines, -145 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
 
@@ -72,28 +72,28 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74 74
 	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
75
+	public function __construct($form = 0) {
76
+		parent::__construct($form);
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+		if (is_numeric($form) && $form > 0) {
79
+			$this->set_id($form);
80
+		} elseif ($form instanceof self) {
81 81
 
82
-			$this->set_id( $form->get_id() );
82
+			$this->set_id($form->get_id());
83 83
 			$this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
85
+		} elseif (!empty($form->ID)) {
86
+			$this->set_id($form->ID);
87 87
 		} else {
88
-			$this->set_object_read( true );
88
+			$this->set_object_read(true);
89 89
 		}
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
93 93
 
94
-		if ( $this->get_id() > 0 ) {
95
-            $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
94
+		if ($this->get_id() > 0) {
95
+            $this->post = get_post($this->get_id());
96
+			$this->data_store->read($this);
97 97
         }
98 98
 
99 99
 	}
@@ -120,8 +120,8 @@  discard block
 block discarded – undo
120 120
 	 * @param  string $context View or edit context.
121 121
 	 * @return string
122 122
 	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
123
+	public function get_version($context = 'view') {
124
+		return $this->get_prop('version', $context);
125 125
     }
126 126
 
127 127
     /**
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param  string $context View or edit context.
132 132
 	 * @return string
133 133
 	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
134
+	public function get_date_created($context = 'view') {
135
+		return $this->get_prop('date_created', $context);
136 136
     }
137 137
 
138 138
     /**
@@ -142,11 +142,11 @@  discard block
 block discarded – undo
142 142
 	 * @param  string $context View or edit context.
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
146
-        $date = $this->get_date_created( $context );
145
+	public function get_date_created_gmt($context = 'view') {
146
+        $date = $this->get_date_created($context);
147 147
 
148
-        if ( $date ) {
149
-            $date = get_gmt_from_date( $date );
148
+        if ($date) {
149
+            $date = get_gmt_from_date($date);
150 150
         }
151 151
 		return $date;
152 152
     }
@@ -158,8 +158,8 @@  discard block
 block discarded – undo
158 158
 	 * @param  string $context View or edit context.
159 159
 	 * @return string
160 160
 	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
161
+	public function get_date_modified($context = 'view') {
162
+		return $this->get_prop('date_modified', $context);
163 163
     }
164 164
 
165 165
     /**
@@ -169,11 +169,11 @@  discard block
 block discarded – undo
169 169
 	 * @param  string $context View or edit context.
170 170
 	 * @return string
171 171
 	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
173
-        $date = $this->get_date_modified( $context );
172
+	public function get_date_modified_gmt($context = 'view') {
173
+        $date = $this->get_date_modified($context);
174 174
 
175
-        if ( $date ) {
176
-            $date = get_gmt_from_date( $date );
175
+        if ($date) {
176
+            $date = get_gmt_from_date($date);
177 177
         }
178 178
 		return $date;
179 179
     }
@@ -185,8 +185,8 @@  discard block
 block discarded – undo
185 185
 	 * @param  string $context View or edit context.
186 186
 	 * @return string
187 187
 	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
188
+	public function get_name($context = 'view') {
189
+		return $this->get_prop('name', $context);
190 190
     }
191 191
 
192 192
     /**
@@ -196,8 +196,8 @@  discard block
 block discarded – undo
196 196
 	 * @param  string $context View or edit context.
197 197
 	 * @return string
198 198
 	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
199
+	public function get_title($context = 'view') {
200
+		return $this->get_name($context);
201 201
 	}
202 202
 
203 203
     /**
@@ -207,8 +207,8 @@  discard block
 block discarded – undo
207 207
 	 * @param  string $context View or edit context.
208 208
 	 * @return int
209 209
 	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
210
+	public function get_author($context = 'view') {
211
+		return (int) $this->get_prop('author', $context);
212 212
     }
213 213
 
214 214
     /**
@@ -218,21 +218,21 @@  discard block
 block discarded – undo
218 218
 	 * @param  string $context View or edit context.
219 219
 	 * @return array
220 220
 	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
221
+	public function get_elements($context = 'view') {
222
+		$elements = $this->get_prop('elements', $context);
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
225
-            return wpinv_get_data( 'sample-payment-form' );
224
+		if (empty($elements) || !is_array($elements)) {
225
+            return wpinv_get_data('sample-payment-form');
226 226
 		}
227 227
 
228 228
 		// Ensure that all required elements exist.
229 229
 		$_elements = array();
230
-		foreach ( $elements as $element ) {
230
+		foreach ($elements as $element) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+			if ($element['type'] == 'pay_button' && !$this->has_element_type('gateway_select')) {
233 233
 
234 234
 				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
235
+					'text'        => __('Select Payment Method', 'invoicing'),
236 236
 					'id'          => 'gtscicd',
237 237
 					'name'        => 'gtscicd',
238 238
 					'type'        => 'gateway_select',
@@ -257,22 +257,22 @@  discard block
 block discarded – undo
257 257
 	 * @param  string $return objects or arrays.
258 258
 	 * @return GetPaid_Form_Item[]
259 259
 	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
260
+	public function get_items($context = 'view', $return = 'objects') {
261
+		$items = $this->get_prop('items', $context);
262 262
 
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
264
-            $items = wpinv_get_data( 'sample-payment-form-items' );
263
+		if (empty($items) || !is_array($items)) {
264
+            $items = wpinv_get_data('sample-payment-form-items');
265 265
 		}
266 266
 
267 267
 		// Convert the items.
268 268
 		$prepared = array();
269 269
 
270
-		foreach ( $items as $key => $value ) {
270
+		foreach ($items as $key => $value) {
271 271
 
272 272
 			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
273
+			if ($value instanceof GetPaid_Form_Item) {
274 274
 
275
-				if ( $value->can_purchase() ) {
275
+				if ($value->can_purchase()) {
276 276
 					$prepared[] = $value;
277 277
 				}
278 278
 
@@ -281,16 +281,16 @@  discard block
 block discarded – undo
281 281
 			}
282 282
 
283 283
 			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
284
+			if (is_numeric($key) && is_numeric($value)) {
285
+				$item = new GetPaid_Form_Item($key);
286 286
 
287
-				if ( $item->can_purchase() ) {
287
+				if ($item->can_purchase()) {
288 288
 
289 289
 					$value = (float) $value;
290
-					$item->set_quantity( $value );
291
-					if ( 0 == $value ) {
292
-						$item->set_quantity( 1 );
293
-						$item->set_allow_quantities( true );
290
+					$item->set_quantity($value);
291
+					if (0 == $value) {
292
+						$item->set_quantity(1);
293
+						$item->set_allow_quantities(true);
294 294
 					}
295 295
 
296 296
 					$prepared[] = $item;
@@ -300,33 +300,33 @@  discard block
 block discarded – undo
300 300
 			}
301 301
 
302 302
 			// Items saved via payment forms editor.
303
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
303
+			if (is_array($value) && isset($value['id'])) {
304 304
 
305
-				$item = new GetPaid_Form_Item( $value['id'] );
305
+				$item = new GetPaid_Form_Item($value['id']);
306 306
 
307
-				if ( ! $item->can_purchase() ) {
307
+				if (!$item->can_purchase()) {
308 308
 					continue;
309 309
 				}
310 310
 
311 311
 				// Sub-total (Cart items).
312
-				if ( isset( $value['subtotal'] ) ) {
313
-					$item->set_price( $value['subtotal'] );
312
+				if (isset($value['subtotal'])) {
313
+					$item->set_price($value['subtotal']);
314 314
 				}
315 315
 
316
-				if ( isset( $value['quantity'] ) ) {
317
-					$item->set_quantity( $value['quantity'] );
316
+				if (isset($value['quantity'])) {
317
+					$item->set_quantity($value['quantity']);
318 318
 				}
319 319
 
320
-				if ( isset( $value['allow_quantities'] ) ) {
321
-					$item->set_allow_quantities( $value['allow_quantities'] );
320
+				if (isset($value['allow_quantities'])) {
321
+					$item->set_allow_quantities($value['allow_quantities']);
322 322
 				}
323 323
 
324
-				if ( isset( $value['required'] ) ) {
325
-					$item->set_is_required( $value['required'] );
324
+				if (isset($value['required'])) {
325
+					$item->set_is_required($value['required']);
326 326
 				}
327 327
 
328
-				if ( isset( $value['description'] ) ) {
329
-					$item->set_custom_description( $value['description'] );
328
+				if (isset($value['description'])) {
329
+					$item->set_custom_description($value['description']);
330 330
 				}
331 331
 
332 332
 				$prepared[] = $item;
@@ -335,14 +335,14 @@  discard block
 block discarded – undo
335 335
 			}
336 336
 
337 337
 			// $item_id => array( 'price' => 10 ) (item variations)
338
-			if ( is_numeric( $key ) && is_array( $value ) ) {
339
-				$item = new GetPaid_Form_Item( $key );
338
+			if (is_numeric($key) && is_array($value)) {
339
+				$item = new GetPaid_Form_Item($key);
340 340
 
341
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
-					$item->set_price( $value['price'] );
341
+				if (isset($value['price']) && $item->user_can_set_their_price()) {
342
+					$item->set_price($value['price']);
343 343
 				}
344 344
 
345
-				if ( $item->can_purchase() ) {
345
+				if ($item->can_purchase()) {
346 346
 					$prepared[] = $item;
347 347
 				}
348 348
 
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
 
352 352
 		}
353 353
 
354
-		if ( 'objects' == $return && 'view' == $context ) {
354
+		if ('objects' == $return && 'view' == $context) {
355 355
 			return $prepared;
356 356
 		}
357 357
 
358 358
 		$items = array();
359
-		foreach ( $prepared as $item ) {
359
+		foreach ($prepared as $item) {
360 360
 			$items[] = $item->prepare_data_for_use();
361 361
 		}
362 362
 
@@ -370,14 +370,14 @@  discard block
 block discarded – undo
370 370
 	 * @param  int $item_id The item id to return.
371 371
 	 * @return GetPaid_Form_Item|bool
372 372
 	 */
373
-	public function get_item( $item_id ) {
373
+	public function get_item($item_id) {
374 374
 
375
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
375
+		if (empty($item_id) || !is_numeric($item_id)) {
376 376
 			return false;
377 377
 		}
378 378
 
379
-		foreach( $this->get_items() as $item ) {
380
-			if ( $item->get_id() == (int) $item_id ) {
379
+		foreach ($this->get_items() as $item) {
380
+			if ($item->get_id() == (int) $item_id) {
381 381
 				return $item;
382 382
 			}
383 383
 		}
@@ -393,15 +393,15 @@  discard block
 block discarded – undo
393 393
 	 * @param  string $element_type The element type to return.
394 394
 	 * @return array|bool
395 395
 	 */
396
-	public function get_element_type( $element_type ) {
396
+	public function get_element_type($element_type) {
397 397
 
398
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
398
+		if (empty($element_type) || !is_scalar($element_type)) {
399 399
 			return false;
400 400
 		}
401 401
 
402
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
402
+		foreach ($this->get_prop('elements') as $element) {
403 403
 
404
-			if ( $element['type'] == $element_type ) {
404
+			if ($element['type'] == $element_type) {
405 405
 				return $element;
406 406
 			}
407 407
 
@@ -418,8 +418,8 @@  discard block
 block discarded – undo
418 418
 	 * @param  string $context View or edit context.
419 419
 	 * @return float
420 420
 	 */
421
-	public function get_earned( $context = 'view' ) {
422
-		return $this->get_prop( 'earned', $context );
421
+	public function get_earned($context = 'view') {
422
+		return $this->get_prop('earned', $context);
423 423
 	}
424 424
 
425 425
 	/**
@@ -429,8 +429,8 @@  discard block
 block discarded – undo
429 429
 	 * @param  string $context View or edit context.
430 430
 	 * @return float
431 431
 	 */
432
-	public function get_refunded( $context = 'view' ) {
433
-		return $this->get_prop( 'refunded', $context );
432
+	public function get_refunded($context = 'view') {
433
+		return $this->get_prop('refunded', $context);
434 434
 	}
435 435
 
436 436
 	/**
@@ -440,8 +440,8 @@  discard block
 block discarded – undo
440 440
 	 * @param  string $context View or edit context.
441 441
 	 * @return float
442 442
 	 */
443
-	public function get_cancelled( $context = 'view' ) {
444
-		return $this->get_prop( 'cancelled', $context );
443
+	public function get_cancelled($context = 'view') {
444
+		return $this->get_prop('cancelled', $context);
445 445
 	}
446 446
 
447 447
 	/**
@@ -451,8 +451,8 @@  discard block
 block discarded – undo
451 451
 	 * @param  string $context View or edit context.
452 452
 	 * @return float
453 453
 	 */
454
-	public function get_failed( $context = 'view' ) {
455
-		return $this->get_prop( 'failed', $context );
454
+	public function get_failed($context = 'view') {
455
+		return $this->get_prop('failed', $context);
456 456
 	}
457 457
 
458 458
 	/**
@@ -463,8 +463,8 @@  discard block
 block discarded – undo
463 463
 	 * @return string
464 464
 	 */
465 465
 	public function get_currency() {
466
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
467
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
466
+		$currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency();
467
+		return apply_filters('getpaid-payment-form-currency', $currency, $this);
468 468
 	}
469 469
 
470 470
     /*
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
 	 *
483 483
 	 * @since 1.0.19
484 484
 	 */
485
-	public function set_version( $value ) {
486
-		$this->set_prop( 'version', $value );
485
+	public function set_version($value) {
486
+		$this->set_prop('version', $value);
487 487
     }
488 488
 
489 489
     /**
@@ -493,11 +493,11 @@  discard block
 block discarded – undo
493 493
 	 * @param string $value Value to set.
494 494
      * @return bool Whether or not the date was set.
495 495
 	 */
496
-	public function set_date_created( $value ) {
497
-        $date = strtotime( $value );
496
+	public function set_date_created($value) {
497
+        $date = strtotime($value);
498 498
 
499
-        if ( $date ) {
500
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
499
+        if ($date) {
500
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
501 501
             return true;
502 502
         }
503 503
 
@@ -512,11 +512,11 @@  discard block
 block discarded – undo
512 512
 	 * @param string $value Value to set.
513 513
      * @return bool Whether or not the date was set.
514 514
 	 */
515
-	public function set_date_modified( $value ) {
516
-        $date = strtotime( $value );
515
+	public function set_date_modified($value) {
516
+        $date = strtotime($value);
517 517
 
518
-        if ( $date ) {
519
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
518
+        if ($date) {
519
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
520 520
             return true;
521 521
         }
522 522
 
@@ -530,8 +530,8 @@  discard block
 block discarded – undo
530 530
 	 * @since 1.0.19
531 531
 	 * @param  string $value New name.
532 532
 	 */
533
-	public function set_name( $value ) {
534
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
533
+	public function set_name($value) {
534
+		$this->set_prop('name', sanitize_text_field($value));
535 535
     }
536 536
 
537 537
     /**
@@ -540,8 +540,8 @@  discard block
 block discarded – undo
540 540
 	 * @since 1.0.19
541 541
 	 * @param  string $value New name.
542 542
 	 */
543
-	public function set_title( $value ) {
544
-		$this->set_name( $value );
543
+	public function set_title($value) {
544
+		$this->set_name($value);
545 545
     }
546 546
 
547 547
     /**
@@ -550,8 +550,8 @@  discard block
 block discarded – undo
550 550
 	 * @since 1.0.19
551 551
 	 * @param  int $value New author.
552 552
 	 */
553
-	public function set_author( $value ) {
554
-		$this->set_prop( 'author', (int) $value );
553
+	public function set_author($value) {
554
+		$this->set_prop('author', (int) $value);
555 555
 	}
556 556
 
557 557
 	/**
@@ -560,9 +560,9 @@  discard block
 block discarded – undo
560 560
 	 * @since 1.0.19
561 561
 	 * @param  array $value Form elements.
562 562
 	 */
563
-	public function set_elements( $value ) {
564
-		if ( is_array( $value ) ) {
565
-			$this->set_prop( 'elements', $value );
563
+	public function set_elements($value) {
564
+		if (is_array($value)) {
565
+			$this->set_prop('elements', $value);
566 566
 		}
567 567
 	}
568 568
 
@@ -572,9 +572,9 @@  discard block
 block discarded – undo
572 572
 	 * @since 1.0.19
573 573
 	 * @param  array $value Form elements.
574 574
 	 */
575
-	public function set_items( $value ) {
576
-		if ( is_array( $value ) ) {
577
-			$this->set_prop( 'items', $value );
575
+	public function set_items($value) {
576
+		if (is_array($value)) {
577
+			$this->set_prop('items', $value);
578 578
 		}
579 579
 	}
580 580
 
@@ -584,9 +584,9 @@  discard block
 block discarded – undo
584 584
 	 * @since 1.0.19
585 585
 	 * @param  float $value Amount earned.
586 586
 	 */
587
-	public function set_earned( $value ) {
588
-		$value = max( (float) $value, 0 );
589
-		$this->set_prop( 'earned', $value );
587
+	public function set_earned($value) {
588
+		$value = max((float) $value, 0);
589
+		$this->set_prop('earned', $value);
590 590
 	}
591 591
 
592 592
 	/**
@@ -595,9 +595,9 @@  discard block
 block discarded – undo
595 595
 	 * @since 1.0.19
596 596
 	 * @param  float $value Amount refunded.
597 597
 	 */
598
-	public function set_refunded( $value ) {
599
-		$value = max( (float) $value, 0 );
600
-		$this->set_prop( 'refunded', $value );
598
+	public function set_refunded($value) {
599
+		$value = max((float) $value, 0);
600
+		$this->set_prop('refunded', $value);
601 601
 	}
602 602
 
603 603
 	/**
@@ -606,9 +606,9 @@  discard block
 block discarded – undo
606 606
 	 * @since 1.0.19
607 607
 	 * @param  float $value Amount cancelled.
608 608
 	 */
609
-	public function set_cancelled( $value ) {
610
-		$value = max( (float) $value, 0 );
611
-		$this->set_prop( 'cancelled', $value );
609
+	public function set_cancelled($value) {
610
+		$value = max((float) $value, 0);
611
+		$this->set_prop('cancelled', $value);
612 612
 	}
613 613
 
614 614
 	/**
@@ -617,9 +617,9 @@  discard block
 block discarded – undo
617 617
 	 * @since 1.0.19
618 618
 	 * @param  float $value Amount cancelled.
619 619
 	 */
620
-	public function set_failed( $value ) {
621
-		$value = max( (float) $value, 0 );
622
-		$this->set_prop( 'failed', $value );
620
+	public function set_failed($value) {
621
+		$value = max((float) $value, 0);
622
+		$this->set_prop('failed', $value);
623 623
 	}
624 624
 
625 625
     /**
@@ -628,11 +628,11 @@  discard block
 block discarded – undo
628 628
      * @deprecated
629 629
 	 * @return int item id
630 630
      */
631
-    public function create( $data = array() ) {
631
+    public function create($data = array()) {
632 632
 
633 633
 		// Set the properties.
634
-		if ( is_array( $data ) ) {
635
-			$this->set_props( $data );
634
+		if (is_array($data)) {
635
+			$this->set_props($data);
636 636
 		}
637 637
 
638 638
 		// Save the item.
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
      * @deprecated
647 647
 	 * @return int item id
648 648
      */
649
-    public function update( $data = array() ) {
650
-        return $this->create( $data );
649
+    public function update($data = array()) {
650
+        return $this->create($data);
651 651
     }
652 652
 
653 653
     /*
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
 	 */
668 668
     public function is_default() {
669 669
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
670
-        return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
670
+        return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this);
671 671
 	}
672 672
 
673 673
     /**
@@ -679,11 +679,11 @@  discard block
 block discarded – undo
679 679
     public function is_active() {
680 680
         $is_active = 0 !== (int) $this->get_id();
681 681
 
682
-        if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) {
682
+        if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') {
683 683
             $is_active = false;
684 684
         }
685 685
 
686
-        return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
686
+        return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this);
687 687
 	}
688 688
 
689 689
 	/**
@@ -692,8 +692,8 @@  discard block
 block discarded – undo
692 692
 	 * @since 1.0.19
693 693
 	 * @return bool
694 694
 	 */
695
-    public function has_item( $item_id ) {
696
-        return false !== $this->get_item( $item_id );
695
+    public function has_item($item_id) {
696
+        return false !== $this->get_item($item_id);
697 697
 	}
698 698
 
699 699
 	/**
@@ -702,8 +702,8 @@  discard block
 block discarded – undo
702 702
 	 * @since 1.0.19
703 703
 	 * @return bool
704 704
 	 */
705
-    public function has_element_type( $element_type ) {
706
-        return false !== $this->get_element_type( $element_type );
705
+    public function has_element_type($element_type) {
706
+        return false !== $this->get_element_type($element_type);
707 707
 	}
708 708
 
709 709
 	/**
@@ -714,13 +714,13 @@  discard block
 block discarded – undo
714 714
 	 */
715 715
     public function is_recurring() {
716 716
 
717
-		if ( ! empty( $this->invoice ) ) {
717
+		if (!empty($this->invoice)) {
718 718
 			return $this->invoice->is_recurring();
719 719
 		}
720 720
 
721
-		foreach ( $this->get_items() as $item ) {
721
+		foreach ($this->get_items() as $item) {
722 722
 
723
-			if ( $item->is_recurring() ) {
723
+			if ($item->is_recurring()) {
724 724
 				return true;
725 725
 			}
726 726
 
@@ -734,7 +734,7 @@  discard block
 block discarded – undo
734 734
 	 *
735 735
 	 * @since 1.0.19
736 736
 	 */
737
-    public function get_html( $extra_markup = '' ) {
737
+    public function get_html($extra_markup = '') {
738 738
 
739 739
 		// Return the HTML.
740 740
 		return wpinv_get_template_html(
@@ -752,8 +752,8 @@  discard block
 block discarded – undo
752 752
 	 *
753 753
 	 * @since 1.0.19
754 754
 	 */
755
-    public function display( $extra_markup = '' ) {
756
-		echo $this->get_html( $extra_markup );
755
+    public function display($extra_markup = '') {
756
+		echo $this->get_html($extra_markup);
757 757
     }
758 758
 
759 759
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 2 patches
Indentation   +205 added lines, -205 removed lines patch added patch discarded remove patch
@@ -12,223 +12,223 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Taxes {
14 14
 
15
-	/**
16
-	 * Submission taxes.
17
-	 * @var array
18
-	 */
19
-	public $taxes = array();
20
-
21
-	/**
22
-	 * Whether or not we should skip the taxes.
23
-	 * @var bool
24
-	 */
25
-	protected $skip_taxes = false;
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Whether or not we should skip the taxes.
23
+     * @var bool
24
+     */
25
+    protected $skip_taxes = false;
26
+
27
+    /**
28
+     * Class constructor
29
+     *
30
+     * @param GetPaid_Payment_Form_Submission $submission
31
+     */
32
+    public function __construct( $submission ) {
33
+
34
+        // Validate VAT number.
35
+        $this->validate_vat( $submission );
36
+
37
+        if ( $this->skip_taxes ) {
38
+            return;
39
+        }
40
+
41
+        foreach ( $submission->get_items() as $item ) {
42
+            $this->process_item_tax( $item, $submission );
43
+        }
44
+
45
+        // Process any existing invoice taxes.
46
+        if ( $submission->has_invoice() ) {
47
+            $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
+        }
49
+
50
+    }
51
+
52
+    /**
53
+     * Maybe process tax.
54
+     *
55
+     * @since 1.0.19
56
+     * @param GetPaid_Form_Item $item
57
+     * @param GetPaid_Payment_Form_Submission $submission
58
+     */
59
+    public function process_item_tax( $item, $submission ) {
60
+
61
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
+        $rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
+        $taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates );
64
+        $r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates );
65
+
66
+        foreach ( $taxes as $name => $amount ) {
67
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
+
70
+            if ( ! isset( $this->taxes[ $name ] ) ) {
71
+                $this->taxes[ $name ] = $tax;
72
+                continue;
73
+            }
74
+
75
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
76
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
+
78
+        }
79
+
80
+    }
81
+
82
+    /**
83
+     * Checks if the submission has a digital item.
84
+     *
85
+     * @param GetPaid_Payment_Form_Submission $submission
86
+     * @since 1.0.19
87
+     * @return bool
88
+     */
89
+    public function has_digital_item( $submission ) {
90
+
91
+        foreach ( $submission->get_items() as $item ) {
92
+
93
+            if ( 'digital' == $item->get_vat_rule() ) {
94
+                return true;
95
+            }
96
+
97
+        }
98
+
99
+        return false;
100
+    }
101
+
102
+    /**
103
+     * Checks if this is an eu store.
104
+     *
105
+     * @since 1.0.19
106
+     * @return bool
107
+     */
108
+    public function is_eu_store() {
109
+        return $this->is_eu_country( wpinv_get_default_country() );
110
+    }
111
+
112
+    /**
113
+     * Checks if this is an eu country.
114
+     *
115
+     * @param string $country
116
+     * @since 1.0.19
117
+     * @return bool
118
+     */
119
+    public function is_eu_country( $country ) {
120
+        return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
121
+    }
122
+
123
+    /**
124
+     * Checks if this is an eu purchase.
125
+     *
126
+     * @param string $customer_country
127
+     * @since 1.0.19
128
+     * @return bool
129
+     */
130
+    public function is_eu_transaction( $customer_country ) {
131
+        return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
132
+    }
133
+
134
+    /**
135
+     * Retrieves the vat number.
136
+     *
137
+     * @param GetPaid_Payment_Form_Submission $submission
138
+     * @since 1.0.19
139
+     * @return string
140
+     */
141
+    public function get_vat_number( $submission ) {
142
+
143
+        // Retrieve from the posted number.
144
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
145
+        if ( ! empty( $vat_number ) ) {
146
+            return wpinv_clean( $vat_number );
147
+        }
148
+
149
+        // Retrieve from the invoice.
150
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
151
+    }
152
+
153
+    /**
154
+     * Retrieves the company.
155
+     *
156
+     * @param GetPaid_Payment_Form_Submission $submission
157
+     * @since 1.0.19
158
+     * @return string
159
+     */
160
+    public function get_company( $submission ) {
161
+
162
+        // Retrieve from the posted data.
163
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
164
+        if ( ! empty( $company ) ) {
165
+            return wpinv_clean( $company );
166
+        }
167
+
168
+        // Retrieve from the invoice.
169
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
170
+    }
26 171
 
27 172
     /**
28
-	 * Class constructor
29
-	 *
30
-	 * @param GetPaid_Payment_Form_Submission $submission
31
-	 */
32
-	public function __construct( $submission ) {
33
-
34
-		// Validate VAT number.
35
-		$this->validate_vat( $submission );
36
-
37
-		if ( $this->skip_taxes ) {
38
-			return;
39
-		}
40
-
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
43
-		}
44
-
45
-		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
48
-		}
49
-
50
-	}
51
-
52
-	/**
53
-	 * Maybe process tax.
54
-	 *
55
-	 * @since 1.0.19
56
-	 * @param GetPaid_Form_Item $item
57
-	 * @param GetPaid_Payment_Form_Submission $submission
58
-	 */
59
-	public function process_item_tax( $item, $submission ) {
60
-
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates );
65
-
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
69
-
70
-			if ( ! isset( $this->taxes[ $name ] ) ) {
71
-				$this->taxes[ $name ] = $tax;
72
-				continue;
73
-			}
74
-
75
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
76
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
77
-
78
-		}
79
-
80
-	}
81
-
82
-	/**
83
-	 * Checks if the submission has a digital item.
84
-	 *
85
-	 * @param GetPaid_Payment_Form_Submission $submission
86
-	 * @since 1.0.19
87
-	 * @return bool
88
-	 */
89
-	public function has_digital_item( $submission ) {
90
-
91
-		foreach ( $submission->get_items() as $item ) {
92
-
93
-			if ( 'digital' == $item->get_vat_rule() ) {
94
-				return true;
95
-			}
96
-
97
-		}
98
-
99
-		return false;
100
-	}
101
-
102
-	/**
103
-	 * Checks if this is an eu store.
104
-	 *
105
-	 * @since 1.0.19
106
-	 * @return bool
107
-	 */
108
-	public function is_eu_store() {
109
-		return $this->is_eu_country( wpinv_get_default_country() );
110
-	}
111
-
112
-	/**
113
-	 * Checks if this is an eu country.
114
-	 *
115
-	 * @param string $country
116
-	 * @since 1.0.19
117
-	 * @return bool
118
-	 */
119
-	public function is_eu_country( $country ) {
120
-		return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
121
-	}
122
-
123
-	/**
124
-	 * Checks if this is an eu purchase.
125
-	 *
126
-	 * @param string $customer_country
127
-	 * @since 1.0.19
128
-	 * @return bool
129
-	 */
130
-	public function is_eu_transaction( $customer_country ) {
131
-		return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
132
-	}
133
-
134
-	/**
135
-	 * Retrieves the vat number.
136
-	 *
137
-	 * @param GetPaid_Payment_Form_Submission $submission
138
-	 * @since 1.0.19
139
-	 * @return string
140
-	 */
141
-	public function get_vat_number( $submission ) {
142
-
143
-		// Retrieve from the posted number.
144
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
145
-		if ( ! empty( $vat_number ) ) {
146
-			return wpinv_clean( $vat_number );
147
-		}
148
-
149
-		// Retrieve from the invoice.
150
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
151
-	}
152
-
153
-	/**
154
-	 * Retrieves the company.
155
-	 *
156
-	 * @param GetPaid_Payment_Form_Submission $submission
157
-	 * @since 1.0.19
158
-	 * @return string
159
-	 */
160
-	public function get_company( $submission ) {
161
-
162
-		// Retrieve from the posted data.
163
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
164
-		if ( ! empty( $company ) ) {
165
-			return wpinv_clean( $company );
166
-		}
167
-
168
-		// Retrieve from the invoice.
169
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
170
-	}
171
-
172
-	/**
173
-	 * Checks if we require a VAT number.
174
-	 *
175
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
176
-	 * @param bool $country_in_eu Whether the customer country is from the EU
177
-	 * @since 1.0.19
178
-	 * @return string
179
-	 */
180
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
181
-
182
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
183
-		$prevent_b2c = ! empty( $prevent_b2c );
184
-		$is_eu       = $ip_in_eu || $country_in_eu;
185
-
186
-		return $prevent_b2c && $is_eu;
187
-	}
188
-
189
-	/**
190
-	 * Validate VAT data.
191
-	 *
192
-	 * @param GetPaid_Payment_Form_Submission $submission
193
-	 * @since 1.0.19
194
-	 */
195
-	public function validate_vat( $submission ) {
196
-
197
-		$in_eu = $this->is_eu_transaction( $submission->country );
198
-
199
-		// Abort if we are not validating vat numbers.
200
-		if ( ! $in_eu || ! wpinv_should_validate_vat_number() ) {
173
+     * Checks if we require a VAT number.
174
+     *
175
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
176
+     * @param bool $country_in_eu Whether the customer country is from the EU
177
+     * @since 1.0.19
178
+     * @return string
179
+     */
180
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
181
+
182
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
183
+        $prevent_b2c = ! empty( $prevent_b2c );
184
+        $is_eu       = $ip_in_eu || $country_in_eu;
185
+
186
+        return $prevent_b2c && $is_eu;
187
+    }
188
+
189
+    /**
190
+     * Validate VAT data.
191
+     *
192
+     * @param GetPaid_Payment_Form_Submission $submission
193
+     * @since 1.0.19
194
+     */
195
+    public function validate_vat( $submission ) {
196
+
197
+        $in_eu = $this->is_eu_transaction( $submission->country );
198
+
199
+        // Abort if we are not validating vat numbers.
200
+        if ( ! $in_eu || ! wpinv_should_validate_vat_number() ) {
201 201
             return;
202
-		}
202
+        }
203 203
 
204
-		// Prepare variables.
205
-		$vat_number  = $this->get_vat_number( $submission );
206
-		$ip_country  = getpaid_get_ip_country();
204
+        // Prepare variables.
205
+        $vat_number  = $this->get_vat_number( $submission );
206
+        $ip_country  = getpaid_get_ip_country();
207 207
         $is_eu       = $this->is_eu_country( $submission->country );
208 208
         $is_ip_eu    = $this->is_eu_country( $ip_country );
209 209
 
210
-		// If we're preventing business to consumer purchases,
211
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
210
+        // If we're preventing business to consumer purchases,
211
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
212 212
 
213
-			// Ensure that a vat number has been specified.
214
-			throw new Exception(
215
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
216
-			);
213
+            // Ensure that a vat number has been specified.
214
+            throw new Exception(
215
+                __( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
216
+            );
217 217
 
218
-		}
218
+        }
219 219
 
220
-		if ( empty( $vat_number ) ) {
221
-			return;
222
-		}
220
+        if ( empty( $vat_number ) ) {
221
+            return;
222
+        }
223 223
 
224
-		if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
225
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
226
-		}
224
+        if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
225
+            throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
226
+        }
227 227
 
228
-		if ( 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) {
229
-			$this->skip_taxes = true;
230
-		}
228
+        if ( 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) {
229
+            $this->skip_taxes = true;
230
+        }
231 231
 
232
-	}
232
+    }
233 233
 
234 234
 }
Please login to merge, or discard this patch.
Spacing   +51 added lines, -51 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 taxes class
@@ -29,22 +29,22 @@  discard block
 block discarded – undo
29 29
 	 *
30 30
 	 * @param GetPaid_Payment_Form_Submission $submission
31 31
 	 */
32
-	public function __construct( $submission ) {
32
+	public function __construct($submission) {
33 33
 
34 34
 		// Validate VAT number.
35
-		$this->validate_vat( $submission );
35
+		$this->validate_vat($submission);
36 36
 
37
-		if ( $this->skip_taxes ) {
37
+		if ($this->skip_taxes) {
38 38
 			return;
39 39
 		}
40 40
 
41
-		foreach ( $submission->get_items() as $item ) {
42
-			$this->process_item_tax( $item, $submission );
41
+		foreach ($submission->get_items() as $item) {
42
+			$this->process_item_tax($item, $submission);
43 43
 		}
44 44
 
45 45
 		// Process any existing invoice taxes.
46
-		if ( $submission->has_invoice() ) {
47
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
46
+		if ($submission->has_invoice()) {
47
+			$this->taxes = array_replace($submission->get_invoice()->get_taxes(), $this->taxes);
48 48
 		}
49 49
 
50 50
 	}
@@ -56,24 +56,24 @@  discard block
 block discarded – undo
56 56
 	 * @param GetPaid_Form_Item $item
57 57
 	 * @param GetPaid_Payment_Form_Submission $submission
58 58
 	 */
59
-	public function process_item_tax( $item, $submission ) {
59
+	public function process_item_tax($item, $submission) {
60 60
 
61
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
62
-		$rates    = getpaid_filter_item_tax_rates( $item, $rates );
63
-		$taxes    = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false ), $rates );
64
-		$r_taxes  = getpaid_calculate_item_taxes( getpaid_get_taxable_amount( $item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true ), $rates );
61
+		$rates    = getpaid_get_item_tax_rates($item, $submission->country, $submission->state);
62
+		$rates    = getpaid_filter_item_tax_rates($item, $rates);
63
+		$taxes    = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item->get_id(), $item->get_sub_total(), $submission->get_discount_code(), false), $rates);
64
+		$r_taxes  = getpaid_calculate_item_taxes(getpaid_get_taxable_amount($item->get_id(), $item->get_recurring_sub_total(), $submission->get_discount_code(), true), $rates);
65 65
 
66
-		foreach ( $taxes as $name => $amount ) {
67
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
68
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
66
+		foreach ($taxes as $name => $amount) {
67
+			$recurring = isset($r_taxes[$name]) ? $r_taxes[$name] : 0;
68
+			$tax       = getpaid_prepare_item_tax($item, $name, $amount, $recurring);
69 69
 
70
-			if ( ! isset( $this->taxes[ $name ] ) ) {
71
-				$this->taxes[ $name ] = $tax;
70
+			if (!isset($this->taxes[$name])) {
71
+				$this->taxes[$name] = $tax;
72 72
 				continue;
73 73
 			}
74 74
 
75
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
76
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
75
+			$this->taxes[$name]['initial_tax']   += $tax['initial_tax'];
76
+			$this->taxes[$name]['recurring_tax'] += $tax['recurring_tax'];
77 77
 
78 78
 		}
79 79
 
@@ -86,11 +86,11 @@  discard block
 block discarded – undo
86 86
 	 * @since 1.0.19
87 87
 	 * @return bool
88 88
 	 */
89
-	public function has_digital_item( $submission ) {
89
+	public function has_digital_item($submission) {
90 90
 
91
-		foreach ( $submission->get_items() as $item ) {
91
+		foreach ($submission->get_items() as $item) {
92 92
 
93
-			if ( 'digital' == $item->get_vat_rule() ) {
93
+			if ('digital' == $item->get_vat_rule()) {
94 94
 				return true;
95 95
 			}
96 96
 
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
 	 * @return bool
107 107
 	 */
108 108
 	public function is_eu_store() {
109
-		return $this->is_eu_country( wpinv_get_default_country() );
109
+		return $this->is_eu_country(wpinv_get_default_country());
110 110
 	}
111 111
 
112 112
 	/**
@@ -116,8 +116,8 @@  discard block
 block discarded – undo
116 116
 	 * @since 1.0.19
117 117
 	 * @return bool
118 118
 	 */
119
-	public function is_eu_country( $country ) {
120
-		return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
119
+	public function is_eu_country($country) {
120
+		return getpaid_is_eu_state($country) || getpaid_is_gst_country($country);
121 121
 	}
122 122
 
123 123
 	/**
@@ -127,8 +127,8 @@  discard block
 block discarded – undo
127 127
 	 * @since 1.0.19
128 128
 	 * @return bool
129 129
 	 */
130
-	public function is_eu_transaction( $customer_country ) {
131
-		return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
130
+	public function is_eu_transaction($customer_country) {
131
+		return $this->is_eu_country($customer_country) && $this->is_eu_store();
132 132
 	}
133 133
 
134 134
 	/**
@@ -138,12 +138,12 @@  discard block
 block discarded – undo
138 138
 	 * @since 1.0.19
139 139
 	 * @return string
140 140
 	 */
141
-	public function get_vat_number( $submission ) {
141
+	public function get_vat_number($submission) {
142 142
 
143 143
 		// Retrieve from the posted number.
144
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
145
-		if ( ! empty( $vat_number ) ) {
146
-			return wpinv_clean( $vat_number );
144
+		$vat_number = $submission->get_field('wpinv_vat_number', 'billing');
145
+		if (!empty($vat_number)) {
146
+			return wpinv_clean($vat_number);
147 147
 		}
148 148
 
149 149
 		// Retrieve from the invoice.
@@ -157,12 +157,12 @@  discard block
 block discarded – undo
157 157
 	 * @since 1.0.19
158 158
 	 * @return string
159 159
 	 */
160
-	public function get_company( $submission ) {
160
+	public function get_company($submission) {
161 161
 
162 162
 		// Retrieve from the posted data.
163
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
164
-		if ( ! empty( $company ) ) {
165
-			return wpinv_clean( $company );
163
+		$company = $submission->get_field('wpinv_company', 'billing');
164
+		if (!empty($company)) {
165
+			return wpinv_clean($company);
166 166
 		}
167 167
 
168 168
 		// Retrieve from the invoice.
@@ -177,10 +177,10 @@  discard block
 block discarded – undo
177 177
 	 * @since 1.0.19
178 178
 	 * @return string
179 179
 	 */
180
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
180
+	public function requires_vat($ip_in_eu, $country_in_eu) {
181 181
 
182
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
183
-		$prevent_b2c = ! empty( $prevent_b2c );
182
+		$prevent_b2c = wpinv_get_option('vat_prevent_b2c_purchase');
183
+		$prevent_b2c = !empty($prevent_b2c);
184 184
 		$is_eu       = $ip_in_eu || $country_in_eu;
185 185
 
186 186
 		return $prevent_b2c && $is_eu;
@@ -192,40 +192,40 @@  discard block
 block discarded – undo
192 192
 	 * @param GetPaid_Payment_Form_Submission $submission
193 193
 	 * @since 1.0.19
194 194
 	 */
195
-	public function validate_vat( $submission ) {
195
+	public function validate_vat($submission) {
196 196
 
197
-		$in_eu = $this->is_eu_transaction( $submission->country );
197
+		$in_eu = $this->is_eu_transaction($submission->country);
198 198
 
199 199
 		// Abort if we are not validating vat numbers.
200
-		if ( ! $in_eu || ! wpinv_should_validate_vat_number() ) {
200
+		if (!$in_eu || !wpinv_should_validate_vat_number()) {
201 201
             return;
202 202
 		}
203 203
 
204 204
 		// Prepare variables.
205
-		$vat_number  = $this->get_vat_number( $submission );
205
+		$vat_number  = $this->get_vat_number($submission);
206 206
 		$ip_country  = getpaid_get_ip_country();
207
-        $is_eu       = $this->is_eu_country( $submission->country );
208
-        $is_ip_eu    = $this->is_eu_country( $ip_country );
207
+        $is_eu       = $this->is_eu_country($submission->country);
208
+        $is_ip_eu    = $this->is_eu_country($ip_country);
209 209
 
210 210
 		// If we're preventing business to consumer purchases,
211
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
211
+		if ($this->requires_vat($is_ip_eu, $is_eu) && empty($vat_number)) {
212 212
 
213 213
 			// Ensure that a vat number has been specified.
214 214
 			throw new Exception(
215
-				__( 'Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing' )
215
+				__('Please enter your VAT number to verify your purchase is by an EU business.', 'invoicing')
216 216
 			);
217 217
 
218 218
 		}
219 219
 
220
-		if ( empty( $vat_number ) ) {
220
+		if (empty($vat_number)) {
221 221
 			return;
222 222
 		}
223 223
 
224
-		if ( ! wpinv_validate_vat_number( $vat_number, $submission->country ) ) {
225
-			throw new Exception( __( 'Your VAT number is invalid', 'invoicing' ) );
224
+		if (!wpinv_validate_vat_number($vat_number, $submission->country)) {
225
+			throw new Exception(__('Your VAT number is invalid', 'invoicing'));
226 226
 		}
227 227
 
228
-		if ( 'vat_too' != wpinv_get_option( 'vat_same_country_rule' ) ) {
228
+		if ('vat_too' != wpinv_get_option('vat_same_country_rule')) {
229 229
 			$this->skip_taxes = true;
230 230
 		}
231 231
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +767 added lines, -767 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,187 +10,187 @@  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
-	);
54
-
55
-	/**
56
-	 * Sets the associated payment form.
57
-	 *
58
-	 * @var GetPaid_Payment_Form
59
-	 */
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
+    );
54
+
55
+    /**
56
+     * Sets the associated payment form.
57
+     *
58
+     * @var GetPaid_Payment_Form
59
+     */
60 60
     protected $payment_form = null;
61 61
 
62 62
     /**
63
-	 * The country for the submission.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	public $country = null;
68
-
69
-    /**
70
-	 * The state for the submission.
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $state = null;
76
-
77
-	/**
78
-	 * The invoice associated with the submission.
79
-	 *
80
-	 * @var WPInv_Invoice
81
-	 */
82
-	protected $invoice = null;
83
-
84
-	/**
85
-	 * The recurring item for the submission.
86
-	 *
87
-	 * @var int
88
-	 */
89
-	public $has_recurring = 0;
90
-
91
-	/**
92
-	 * An array of fees for the submission.
93
-	 *
94
-	 * @var array
95
-	 */
96
-	protected $fees = array();
97
-
98
-	/**
99
-	 * An array of discounts for the submission.
100
-	 *
101
-	 * @var array
102
-	 */
103
-	protected $discounts = array();
104
-
105
-	/**
106
-	 * An array of taxes for the submission.
107
-	 *
108
-	 * @var array
109
-	 */
110
-	protected $taxes = array();
111
-
112
-	/**
113
-	 * An array of items for the submission.
114
-	 *
115
-	 * @var GetPaid_Form_Item[]
116
-	 */
117
-	protected $items = array();
118
-
119
-	/**
120
-	 * The last error.
121
-	 *
122
-	 * @var string
123
-	 */
124
-	public $last_error = null;
125
-
126
-    /**
127
-	 * Class constructor.
128
-	 *
129
-	 */
130
-	public function __construct() {
131
-
132
-		// Set the state and country to the default state and country.
133
-		$this->country = wpinv_default_billing_country();
134
-		$this->state   = wpinv_get_default_state();
135
-
136
-		// Do we have an actual submission?
137
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
-			$this->load_data( $_POST );
139
-		}
140
-
141
-	}
142
-
143
-	/**
144
-	 * Loads submission data.
145
-	 *
146
-	 * @param array $data
147
-	 */
148
-	public function load_data( $data ) {
149
-
150
-		// Remove slashes from the submitted data...
151
-		$data       = wp_unslash( $data );
152
-
153
-		// Allow plugins to filter the data.
154
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
155
-
156
-		// Cache it...
157
-		$this->data = $data;
158
-
159
-		// Then generate a unique id from the data.
160
-		$this->id   = md5( wp_json_encode( $data ) );
161
-
162
-		// Finally, process the submission.
163
-		try {
164
-
165
-			// Each process is passed an instance of the class (with reference)
166
-			// and should throw an Exception whenever it encounters one.
167
-			$processors = apply_filters(
168
-				'getpaid_payment_form_submission_processors',
169
-				array(
170
-					array( $this, 'process_payment_form' ),
171
-					array( $this, 'process_invoice' ),
172
-					array( $this, 'process_fees' ),
173
-					array( $this, 'process_items' ),
174
-					array( $this, 'process_discount' ),
175
-					array( $this, 'process_taxes' ),
176
-				),
177
-				$this		
178
-			);
179
-
180
-			foreach ( $processors as $processor ) {
181
-				call_user_func_array( $processor, array( &$this ) );
182
-			}
183
-
184
-		} catch ( Exception $e ) {
185
-			$this->last_error = $e->getMessage();
186
-		}
187
-
188
-		// Fired when we are done processing a submission.
189
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
190
-
191
-	}
192
-
193
-	/*
63
+     * The country for the submission.
64
+     *
65
+     * @var string
66
+     */
67
+    public $country = null;
68
+
69
+    /**
70
+     * The state for the submission.
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $state = null;
76
+
77
+    /**
78
+     * The invoice associated with the submission.
79
+     *
80
+     * @var WPInv_Invoice
81
+     */
82
+    protected $invoice = null;
83
+
84
+    /**
85
+     * The recurring item for the submission.
86
+     *
87
+     * @var int
88
+     */
89
+    public $has_recurring = 0;
90
+
91
+    /**
92
+     * An array of fees for the submission.
93
+     *
94
+     * @var array
95
+     */
96
+    protected $fees = array();
97
+
98
+    /**
99
+     * An array of discounts for the submission.
100
+     *
101
+     * @var array
102
+     */
103
+    protected $discounts = array();
104
+
105
+    /**
106
+     * An array of taxes for the submission.
107
+     *
108
+     * @var array
109
+     */
110
+    protected $taxes = array();
111
+
112
+    /**
113
+     * An array of items for the submission.
114
+     *
115
+     * @var GetPaid_Form_Item[]
116
+     */
117
+    protected $items = array();
118
+
119
+    /**
120
+     * The last error.
121
+     *
122
+     * @var string
123
+     */
124
+    public $last_error = null;
125
+
126
+    /**
127
+     * Class constructor.
128
+     *
129
+     */
130
+    public function __construct() {
131
+
132
+        // Set the state and country to the default state and country.
133
+        $this->country = wpinv_default_billing_country();
134
+        $this->state   = wpinv_get_default_state();
135
+
136
+        // Do we have an actual submission?
137
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
+            $this->load_data( $_POST );
139
+        }
140
+
141
+    }
142
+
143
+    /**
144
+     * Loads submission data.
145
+     *
146
+     * @param array $data
147
+     */
148
+    public function load_data( $data ) {
149
+
150
+        // Remove slashes from the submitted data...
151
+        $data       = wp_unslash( $data );
152
+
153
+        // Allow plugins to filter the data.
154
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
155
+
156
+        // Cache it...
157
+        $this->data = $data;
158
+
159
+        // Then generate a unique id from the data.
160
+        $this->id   = md5( wp_json_encode( $data ) );
161
+
162
+        // Finally, process the submission.
163
+        try {
164
+
165
+            // Each process is passed an instance of the class (with reference)
166
+            // and should throw an Exception whenever it encounters one.
167
+            $processors = apply_filters(
168
+                'getpaid_payment_form_submission_processors',
169
+                array(
170
+                    array( $this, 'process_payment_form' ),
171
+                    array( $this, 'process_invoice' ),
172
+                    array( $this, 'process_fees' ),
173
+                    array( $this, 'process_items' ),
174
+                    array( $this, 'process_discount' ),
175
+                    array( $this, 'process_taxes' ),
176
+                ),
177
+                $this		
178
+            );
179
+
180
+            foreach ( $processors as $processor ) {
181
+                call_user_func_array( $processor, array( &$this ) );
182
+            }
183
+
184
+        } catch ( Exception $e ) {
185
+            $this->last_error = $e->getMessage();
186
+        }
187
+
188
+        // Fired when we are done processing a submission.
189
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
190
+
191
+    }
192
+
193
+    /*
194 194
 	|--------------------------------------------------------------------------
195 195
 	| Payment Forms.
196 196
 	|--------------------------------------------------------------------------
@@ -199,39 +199,39 @@  discard block
 block discarded – undo
199 199
 	| submission has an active payment form etc.
200 200
     */
201 201
 
202
-	/**
203
-	 * Prepares the submission's payment form.
204
-	 *
205
-	 * @since 1.0.19
206
-	 */
207
-	public function process_payment_form() {
202
+    /**
203
+     * Prepares the submission's payment form.
204
+     *
205
+     * @since 1.0.19
206
+     */
207
+    public function process_payment_form() {
208 208
 
209
-		// Every submission needs an active payment form.
210
-		if ( empty( $this->data['form_id'] ) ) {
211
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
212
-		}
209
+        // Every submission needs an active payment form.
210
+        if ( empty( $this->data['form_id'] ) ) {
211
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
212
+        }
213 213
 
214
-		// Fetch the payment form.
215
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
214
+        // Fetch the payment form.
215
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
216 216
 
217
-		if ( ! $this->payment_form->is_active() ) {
218
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
219
-		}
217
+        if ( ! $this->payment_form->is_active() ) {
218
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
219
+        }
220 220
 
221
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
222
-	}
221
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
222
+    }
223 223
 
224 224
     /**
225
-	 * Returns the payment form.
226
-	 *
227
-	 * @since 1.0.19
228
-	 * @return GetPaid_Payment_Form
229
-	 */
230
-	public function get_payment_form() {
231
-		return $this->payment_form;
232
-	}
225
+     * Returns the payment form.
226
+     *
227
+     * @since 1.0.19
228
+     * @return GetPaid_Payment_Form
229
+     */
230
+    public function get_payment_form() {
231
+        return $this->payment_form;
232
+    }
233 233
 
234
-	/*
234
+    /*
235 235
 	|--------------------------------------------------------------------------
236 236
 	| Invoices.
237 237
 	|--------------------------------------------------------------------------
@@ -240,61 +240,61 @@  discard block
 block discarded – undo
240 240
 	| might be for an existing invoice.
241 241
 	*/
242 242
 
243
-	/**
244
-	 * Prepares the submission's invoice.
245
-	 *
246
-	 * @since 1.0.19
247
-	 */
248
-	public function process_invoice() {
243
+    /**
244
+     * Prepares the submission's invoice.
245
+     *
246
+     * @since 1.0.19
247
+     */
248
+    public function process_invoice() {
249 249
 
250
-		// Abort if there is no invoice.
251
-		if ( empty( $this->data['invoice_id'] ) ) {
252
-			return;
253
-		}
250
+        // Abort if there is no invoice.
251
+        if ( empty( $this->data['invoice_id'] ) ) {
252
+            return;
253
+        }
254 254
 
255
-		// If the submission is for an existing invoice, ensure that it exists
256
-		// and that it is not paid for.
257
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
255
+        // If the submission is for an existing invoice, ensure that it exists
256
+        // and that it is not paid for.
257
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
258 258
 
259 259
         if ( empty( $invoice ) ) {
260
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
261
-		}
262
-
263
-		if ( $invoice->is_paid() ) {
264
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
-		}
266
-
267
-		$this->payment_form->set_items( $invoice->get_items() );
268
-		$this->payment_form->invoice = $invoice;
269
-
270
-		$this->country = $invoice->get_country();
271
-		$this->state   = $invoice->get_state();
272
-		$this->invoice = $invoice;
273
-
274
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
275
-	}
276
-
277
-	/**
278
-	 * Returns the associated invoice.
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @return WPInv_Invoice
282
-	 */
283
-	public function get_invoice() {
284
-		return $this->invoice;
285
-	}
286
-
287
-	/**
288
-	 * Checks whether there is an invoice associated with this submission.
289
-	 *
290
-	 * @since 1.0.19
291
-	 * @return bool
292
-	 */
293
-	public function has_invoice() {
294
-		return ! empty( $this->invoice );
295
-	}
296
-
297
-	/*
260
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
261
+        }
262
+
263
+        if ( $invoice->is_paid() ) {
264
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
265
+        }
266
+
267
+        $this->payment_form->set_items( $invoice->get_items() );
268
+        $this->payment_form->invoice = $invoice;
269
+
270
+        $this->country = $invoice->get_country();
271
+        $this->state   = $invoice->get_state();
272
+        $this->invoice = $invoice;
273
+
274
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
275
+    }
276
+
277
+    /**
278
+     * Returns the associated invoice.
279
+     *
280
+     * @since 1.0.19
281
+     * @return WPInv_Invoice
282
+     */
283
+    public function get_invoice() {
284
+        return $this->invoice;
285
+    }
286
+
287
+    /**
288
+     * Checks whether there is an invoice associated with this submission.
289
+     *
290
+     * @since 1.0.19
291
+     * @return bool
292
+     */
293
+    public function has_invoice() {
294
+        return ! empty( $this->invoice );
295
+    }
296
+
297
+    /*
298 298
 	|--------------------------------------------------------------------------
299 299
 	| Items.
300 300
 	|--------------------------------------------------------------------------
@@ -303,115 +303,115 @@  discard block
 block discarded – undo
303 303
 	| recurring item. But can have an unlimited number of non-recurring items.
304 304
 	*/
305 305
 
306
-	/**
307
-	 * Prepares the submission's items.
308
-	 *
309
-	 * @since 1.0.19
310
-	 */
311
-	public function process_items() {
312
-
313
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
314
-
315
-		foreach ( $processor->items as $item ) {
316
-			$this->add_item( $item );
317
-		}
318
-
319
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
320
-	}
321
-
322
-	/**
323
-	 * Adds an item to the submission.
324
-	 *
325
-	 * @since 1.0.19
326
-	 * @param GetPaid_Form_Item $item
327
-	 */
328
-	public function add_item( $item ) {
329
-
330
-		// Make sure that it is available for purchase.
331
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
332
-			return;
333
-		}
334
-
335
-		// Each submission can only contain one recurring item.
336
-		if ( $item->is_recurring() ) {
337
-
338
-			if ( $this->has_recurring != 0 ) {
339
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
340
-			}
341
-
342
-			$this->has_recurring = $item->get_id();
343
-
344
-		}
345
-
346
-		// Update the items and totals.
347
-		$this->items[ $item->get_id() ]         = $item;
348
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
349
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350
-
351
-	}
352
-
353
-	/**
354
-	 * Removes a specific item.
355
-	 * 
356
-	 * You should not call this method after the discounts and taxes
357
-	 * have been calculated.
358
-	 *
359
-	 * @since 1.0.19
360
-	 */
361
-	public function remove_item( $item_id ) {
362
-
363
-		if ( isset( $this->items[ $item_id ] ) ) {
364
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
366
-
367
-			if ( $this->items[ $item_id ]->is_recurring() ) {
368
-				$this->has_recurring = 0;
369
-			}
370
-
371
-			unset( $this->items[ $item_id ] );
372
-		}
373
-
374
-	}
375
-
376
-	/**
377
-	 * Returns the subtotal.
378
-	 *
379
-	 * @since 1.0.19
380
-	 */
381
-	public function get_subtotal() {
382
-
383
-		if ( wpinv_prices_include_tax() ) {
384
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
385
-		}
386
-
387
-		return $this->totals['subtotal']['initial'];
388
-	}
389
-
390
-	/**
391
-	 * Returns the recurring subtotal.
392
-	 *
393
-	 * @since 1.0.19
394
-	 */
395
-	public function get_recurring_subtotal() {
396
-
397
-		if ( wpinv_prices_include_tax() ) {
398
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
399
-		}
400
-
401
-		return $this->totals['subtotal']['recurring'];
402
-	}
403
-
404
-	/**
405
-	 * Returns all items.
406
-	 *
407
-	 * @since 1.0.19
408
-	 * @return GetPaid_Form_Item[]
409
-	 */
410
-	public function get_items() {
411
-		return $this->items;
412
-	}
413
-
414
-	/*
306
+    /**
307
+     * Prepares the submission's items.
308
+     *
309
+     * @since 1.0.19
310
+     */
311
+    public function process_items() {
312
+
313
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
314
+
315
+        foreach ( $processor->items as $item ) {
316
+            $this->add_item( $item );
317
+        }
318
+
319
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
320
+    }
321
+
322
+    /**
323
+     * Adds an item to the submission.
324
+     *
325
+     * @since 1.0.19
326
+     * @param GetPaid_Form_Item $item
327
+     */
328
+    public function add_item( $item ) {
329
+
330
+        // Make sure that it is available for purchase.
331
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
332
+            return;
333
+        }
334
+
335
+        // Each submission can only contain one recurring item.
336
+        if ( $item->is_recurring() ) {
337
+
338
+            if ( $this->has_recurring != 0 ) {
339
+                throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
340
+            }
341
+
342
+            $this->has_recurring = $item->get_id();
343
+
344
+        }
345
+
346
+        // Update the items and totals.
347
+        $this->items[ $item->get_id() ]         = $item;
348
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
349
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350
+
351
+    }
352
+
353
+    /**
354
+     * Removes a specific item.
355
+     * 
356
+     * You should not call this method after the discounts and taxes
357
+     * have been calculated.
358
+     *
359
+     * @since 1.0.19
360
+     */
361
+    public function remove_item( $item_id ) {
362
+
363
+        if ( isset( $this->items[ $item_id ] ) ) {
364
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
366
+
367
+            if ( $this->items[ $item_id ]->is_recurring() ) {
368
+                $this->has_recurring = 0;
369
+            }
370
+
371
+            unset( $this->items[ $item_id ] );
372
+        }
373
+
374
+    }
375
+
376
+    /**
377
+     * Returns the subtotal.
378
+     *
379
+     * @since 1.0.19
380
+     */
381
+    public function get_subtotal() {
382
+
383
+        if ( wpinv_prices_include_tax() ) {
384
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
385
+        }
386
+
387
+        return $this->totals['subtotal']['initial'];
388
+    }
389
+
390
+    /**
391
+     * Returns the recurring subtotal.
392
+     *
393
+     * @since 1.0.19
394
+     */
395
+    public function get_recurring_subtotal() {
396
+
397
+        if ( wpinv_prices_include_tax() ) {
398
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
399
+        }
400
+
401
+        return $this->totals['subtotal']['recurring'];
402
+    }
403
+
404
+    /**
405
+     * Returns all items.
406
+     *
407
+     * @since 1.0.19
408
+     * @return GetPaid_Form_Item[]
409
+     */
410
+    public function get_items() {
411
+        return $this->items;
412
+    }
413
+
414
+    /*
415 415
 	|--------------------------------------------------------------------------
416 416
 	| Taxes
417 417
 	|--------------------------------------------------------------------------
@@ -420,128 +420,128 @@  discard block
 block discarded – undo
420 420
 	| or only one-time.
421 421
     */
422 422
 
423
-	/**
424
-	 * Prepares the submission's taxes.
425
-	 *
426
-	 * @since 1.0.19
427
-	 */
428
-	public function process_taxes() {
429
-
430
-		// Abort if we're not using taxes.
431
-		if ( ! $this->use_taxes() ) {
432
-			return;
433
-		}
434
-
435
-		// If a custom country && state has been passed in, use it to calculate taxes.
436
-		$country = $this->get_field( 'wpinv_country', 'billing' );
437
-		if ( ! empty( $country ) ) {
438
-			$this->country = $country;
439
-		}
440
-
441
-		$state = $this->get_field( 'wpinv_state', 'billing' );
442
-		if ( ! empty( $state ) ) {
443
-			$this->state = $state;
444
-		}
445
-
446
-		// Confirm if the provided country and the ip country are similar.
447
-		$address_confirmed = $this->get_field( 'confirm-address' );
448
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
449
-			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' ) );
450
-		}
451
-
452
-		// Abort if the country is not taxable.
453
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
454
-			return;
455
-		}
456
-
457
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
458
-
459
-		foreach ( $processor->taxes as $tax ) {
460
-			$this->add_tax( $tax );
461
-		}
462
-
463
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
464
-	}
465
-
466
-	/**
467
-	 * Adds a tax to the submission.
468
-	 *
469
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
470
-	 * @since 1.0.19
471
-	 */
472
-	public function add_tax( $tax ) {
473
-
474
-		if ( wpinv_round_tax_per_tax_rate() ) {
475
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
476
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
477
-		}
478
-
479
-		$this->taxes[ $tax['name'] ]         = $tax;
480
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
481
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
482
-
483
-	}
484
-
485
-	/**
486
-	 * Removes a specific tax.
487
-	 *
488
-	 * @since 1.0.19
489
-	 */
490
-	public function remove_tax( $tax_name ) {
491
-
492
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
493
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
494
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
495
-			unset( $this->taxes[ $tax_name ] );
496
-		}
497
-
498
-	}
499
-
500
-	/**
501
-	 * Whether or not we'll use taxes for the submission.
502
-	 *
503
-	 * @since 1.0.19
504
-	 */
505
-	public function use_taxes() {
506
-
507
-		$use_taxes = wpinv_use_taxes();
508
-
509
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
510
-			$use_taxes = false;
511
-		}
512
-
513
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
514
-
515
-	}
516
-
517
-	/**
518
-	 * Returns the tax.
519
-	 *
520
-	 * @since 1.0.19
521
-	 */
522
-	public function get_tax() {
523
-		return $this->totals['taxes']['initial'];
524
-	}
525
-
526
-	/**
527
-	 * Returns the recurring tax.
528
-	 *
529
-	 * @since 1.0.19
530
-	 */
531
-	public function get_recurring_tax() {
532
-		return $this->totals['taxes']['recurring'];
533
-	}
534
-
535
-	/**
536
-	 * Returns all taxes.
537
-	 *
538
-	 * @since 1.0.19
539
-	 */
540
-	public function get_taxes() {
541
-		return $this->taxes;
542
-	}
543
-
544
-	/*
423
+    /**
424
+     * Prepares the submission's taxes.
425
+     *
426
+     * @since 1.0.19
427
+     */
428
+    public function process_taxes() {
429
+
430
+        // Abort if we're not using taxes.
431
+        if ( ! $this->use_taxes() ) {
432
+            return;
433
+        }
434
+
435
+        // If a custom country && state has been passed in, use it to calculate taxes.
436
+        $country = $this->get_field( 'wpinv_country', 'billing' );
437
+        if ( ! empty( $country ) ) {
438
+            $this->country = $country;
439
+        }
440
+
441
+        $state = $this->get_field( 'wpinv_state', 'billing' );
442
+        if ( ! empty( $state ) ) {
443
+            $this->state = $state;
444
+        }
445
+
446
+        // Confirm if the provided country and the ip country are similar.
447
+        $address_confirmed = $this->get_field( 'confirm-address' );
448
+        if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
449
+            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' ) );
450
+        }
451
+
452
+        // Abort if the country is not taxable.
453
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
454
+            return;
455
+        }
456
+
457
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
458
+
459
+        foreach ( $processor->taxes as $tax ) {
460
+            $this->add_tax( $tax );
461
+        }
462
+
463
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
464
+    }
465
+
466
+    /**
467
+     * Adds a tax to the submission.
468
+     *
469
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
470
+     * @since 1.0.19
471
+     */
472
+    public function add_tax( $tax ) {
473
+
474
+        if ( wpinv_round_tax_per_tax_rate() ) {
475
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
476
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
477
+        }
478
+
479
+        $this->taxes[ $tax['name'] ]         = $tax;
480
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
481
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
482
+
483
+    }
484
+
485
+    /**
486
+     * Removes a specific tax.
487
+     *
488
+     * @since 1.0.19
489
+     */
490
+    public function remove_tax( $tax_name ) {
491
+
492
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
493
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
494
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
495
+            unset( $this->taxes[ $tax_name ] );
496
+        }
497
+
498
+    }
499
+
500
+    /**
501
+     * Whether or not we'll use taxes for the submission.
502
+     *
503
+     * @since 1.0.19
504
+     */
505
+    public function use_taxes() {
506
+
507
+        $use_taxes = wpinv_use_taxes();
508
+
509
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
510
+            $use_taxes = false;
511
+        }
512
+
513
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
514
+
515
+    }
516
+
517
+    /**
518
+     * Returns the tax.
519
+     *
520
+     * @since 1.0.19
521
+     */
522
+    public function get_tax() {
523
+        return $this->totals['taxes']['initial'];
524
+    }
525
+
526
+    /**
527
+     * Returns the recurring tax.
528
+     *
529
+     * @since 1.0.19
530
+     */
531
+    public function get_recurring_tax() {
532
+        return $this->totals['taxes']['recurring'];
533
+    }
534
+
535
+    /**
536
+     * Returns all taxes.
537
+     *
538
+     * @since 1.0.19
539
+     */
540
+    public function get_taxes() {
541
+        return $this->taxes;
542
+    }
543
+
544
+    /*
545 545
 	|--------------------------------------------------------------------------
546 546
 	| Discounts
547 547
 	|--------------------------------------------------------------------------
@@ -550,99 +550,99 @@  discard block
 block discarded – undo
550 550
 	| or only one-time. They also do not have to come from a discount code.
551 551
     */
552 552
 
553
-	/**
554
-	 * Prepares the submission's discount.
555
-	 *
556
-	 * @since 1.0.19
557
-	 */
558
-	public function process_discount() {
559
-
560
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
561
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
562
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
563
-
564
-		foreach ( $processor->discounts as $discount ) {
565
-			$this->add_discount( $discount );
566
-		}
567
-
568
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
569
-	}
570
-
571
-	/**
572
-	 * Adds a discount to the submission.
573
-	 *
574
-	 * @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.
575
-	 * @since 1.0.19
576
-	 */
577
-	public function add_discount( $discount ) {
578
-		$this->discounts[ $discount['name'] ]   = $discount;
579
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
580
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
581
-	}
582
-
583
-	/**
584
-	 * Removes a discount from the submission.
585
-	 *
586
-	 * @since 1.0.19
587
-	 */
588
-	public function remove_discount( $name ) {
589
-
590
-		if ( isset( $this->discounts[ $name ] ) ) {
591
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
592
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
593
-			unset( $this->discounts[ $name ] );
594
-		}
595
-
596
-	}
597
-
598
-	/**
599
-	 * Checks whether there is a discount code associated with this submission.
600
-	 *
601
-	 * @since 1.0.19
602
-	 * @return bool
603
-	 */
604
-	public function has_discount_code() {
605
-		return ! empty( $this->discounts['discount_code'] );
606
-	}
607
-
608
-	/**
609
-	 * Returns the discount code.
610
-	 *
611
-	 * @since 1.0.19
612
-	 * @return string
613
-	 */
614
-	public function get_discount_code() {
615
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
616
-	}
617
-
618
-	/**
619
-	 * Returns the discount.
620
-	 *
621
-	 * @since 1.0.19
622
-	 */
623
-	public function get_discount() {
624
-		return $this->totals['discount']['initial'];
625
-	}
626
-
627
-	/**
628
-	 * Returns the recurring discount.
629
-	 *
630
-	 * @since 1.0.19
631
-	 */
632
-	public function get_recurring_discount() {
633
-		return $this->totals['discount']['recurring'];
634
-	}
635
-
636
-	/**
637
-	 * Returns all discounts.
638
-	 *
639
-	 * @since 1.0.19
640
-	 */
641
-	public function get_discounts() {
642
-		return $this->discounts;
643
-	}
644
-
645
-	/*
553
+    /**
554
+     * Prepares the submission's discount.
555
+     *
556
+     * @since 1.0.19
557
+     */
558
+    public function process_discount() {
559
+
560
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
561
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
562
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
563
+
564
+        foreach ( $processor->discounts as $discount ) {
565
+            $this->add_discount( $discount );
566
+        }
567
+
568
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
569
+    }
570
+
571
+    /**
572
+     * Adds a discount to the submission.
573
+     *
574
+     * @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.
575
+     * @since 1.0.19
576
+     */
577
+    public function add_discount( $discount ) {
578
+        $this->discounts[ $discount['name'] ]   = $discount;
579
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
580
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
581
+    }
582
+
583
+    /**
584
+     * Removes a discount from the submission.
585
+     *
586
+     * @since 1.0.19
587
+     */
588
+    public function remove_discount( $name ) {
589
+
590
+        if ( isset( $this->discounts[ $name ] ) ) {
591
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
592
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
593
+            unset( $this->discounts[ $name ] );
594
+        }
595
+
596
+    }
597
+
598
+    /**
599
+     * Checks whether there is a discount code associated with this submission.
600
+     *
601
+     * @since 1.0.19
602
+     * @return bool
603
+     */
604
+    public function has_discount_code() {
605
+        return ! empty( $this->discounts['discount_code'] );
606
+    }
607
+
608
+    /**
609
+     * Returns the discount code.
610
+     *
611
+     * @since 1.0.19
612
+     * @return string
613
+     */
614
+    public function get_discount_code() {
615
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
616
+    }
617
+
618
+    /**
619
+     * Returns the discount.
620
+     *
621
+     * @since 1.0.19
622
+     */
623
+    public function get_discount() {
624
+        return $this->totals['discount']['initial'];
625
+    }
626
+
627
+    /**
628
+     * Returns the recurring discount.
629
+     *
630
+     * @since 1.0.19
631
+     */
632
+    public function get_recurring_discount() {
633
+        return $this->totals['discount']['recurring'];
634
+    }
635
+
636
+    /**
637
+     * Returns all discounts.
638
+     *
639
+     * @since 1.0.19
640
+     */
641
+    public function get_discounts() {
642
+        return $this->discounts;
643
+    }
644
+
645
+    /*
646 646
 	|--------------------------------------------------------------------------
647 647
 	| Fees
648 648
 	|--------------------------------------------------------------------------
@@ -652,89 +652,89 @@  discard block
 block discarded – undo
652 652
 	| fees.
653 653
     */
654 654
 
655
-	/**
656
-	 * Prepares the submission's fees.
657
-	 *
658
-	 * @since 1.0.19
659
-	 */
660
-	public function process_fees() {
661
-
662
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
663
-
664
-		foreach ( $fees_processor->fees as $fee ) {
665
-			$this->add_fee( $fee );
666
-		}
667
-
668
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
669
-	}
670
-
671
-	/**
672
-	 * Adds a fee to the submission.
673
-	 *
674
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
675
-	 * @since 1.0.19
676
-	 */
677
-	public function add_fee( $fee ) {
678
-
679
-		$this->fees[ $fee['name'] ]         = $fee;
680
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
681
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
682
-
683
-	}
684
-
685
-	/**
686
-	 * Removes a fee from the submission.
687
-	 *
688
-	 * @since 1.0.19
689
-	 */
690
-	public function remove_fee( $name ) {
691
-
692
-		if ( isset( $this->fees[ $name ] ) ) {
693
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
694
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
695
-			unset( $this->fees[ $name ] );
696
-		}
697
-
698
-	}
699
-
700
-	/**
701
-	 * Returns the fees.
702
-	 *
703
-	 * @since 1.0.19
704
-	 */
705
-	public function get_fee() {
706
-		return $this->totals['fees']['initial'];
707
-	}
708
-
709
-	/**
710
-	 * Returns the recurring fees.
711
-	 *
712
-	 * @since 1.0.19
713
-	 */
714
-	public function get_recurring_fee() {
715
-		return $this->totals['fees']['recurring'];
716
-	}
717
-
718
-	/**
719
-	 * Returns all fees.
720
-	 *
721
-	 * @since 1.0.19
722
-	 */
723
-	public function get_fees() {
724
-		return $this->fees;
725
-	}
726
-
727
-	/**
728
-	 * Checks if there are any fees for the form.
729
-	 *
730
-	 * @return bool
731
-	 * @since 1.0.19
732
-	 */
733
-	public function has_fees() {
734
-		return count( $this->fees ) !== 0;
735
-	}
736
-
737
-	/*
655
+    /**
656
+     * Prepares the submission's fees.
657
+     *
658
+     * @since 1.0.19
659
+     */
660
+    public function process_fees() {
661
+
662
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
663
+
664
+        foreach ( $fees_processor->fees as $fee ) {
665
+            $this->add_fee( $fee );
666
+        }
667
+
668
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
669
+    }
670
+
671
+    /**
672
+     * Adds a fee to the submission.
673
+     *
674
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
675
+     * @since 1.0.19
676
+     */
677
+    public function add_fee( $fee ) {
678
+
679
+        $this->fees[ $fee['name'] ]         = $fee;
680
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
681
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
682
+
683
+    }
684
+
685
+    /**
686
+     * Removes a fee from the submission.
687
+     *
688
+     * @since 1.0.19
689
+     */
690
+    public function remove_fee( $name ) {
691
+
692
+        if ( isset( $this->fees[ $name ] ) ) {
693
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
694
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
695
+            unset( $this->fees[ $name ] );
696
+        }
697
+
698
+    }
699
+
700
+    /**
701
+     * Returns the fees.
702
+     *
703
+     * @since 1.0.19
704
+     */
705
+    public function get_fee() {
706
+        return $this->totals['fees']['initial'];
707
+    }
708
+
709
+    /**
710
+     * Returns the recurring fees.
711
+     *
712
+     * @since 1.0.19
713
+     */
714
+    public function get_recurring_fee() {
715
+        return $this->totals['fees']['recurring'];
716
+    }
717
+
718
+    /**
719
+     * Returns all fees.
720
+     *
721
+     * @since 1.0.19
722
+     */
723
+    public function get_fees() {
724
+        return $this->fees;
725
+    }
726
+
727
+    /**
728
+     * Checks if there are any fees for the form.
729
+     *
730
+     * @return bool
731
+     * @since 1.0.19
732
+     */
733
+    public function has_fees() {
734
+        return count( $this->fees ) !== 0;
735
+    }
736
+
737
+    /*
738 738
 	|--------------------------------------------------------------------------
739 739
 	| MISC
740 740
 	|--------------------------------------------------------------------------
@@ -742,109 +742,109 @@  discard block
 block discarded – undo
742 742
 	| Extra submission functions.
743 743
     */
744 744
 
745
-	/**
746
-	 * Returns the total amount to collect for this submission.
747
-	 *
748
-	 * @since 1.0.19
749
-	 */
750
-	public function get_total() {
751
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
752
-		return max( $total, 0 );
753
-	}
754
-
755
-	/**
756
-	 * Returns the recurring total amount to collect for this submission.
757
-	 *
758
-	 * @since 1.0.19
759
-	 */
760
-	public function get_recurring_total() {
761
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
762
-		return max( $total, 0 );
763
-	}
764
-
765
-	/**
766
-	 * Whether payment details should be collected for this submission.
767
-	 *
768
-	 * @since 1.0.19
769
-	 */
770
-	public function should_collect_payment_details() {
771
-		$initial   = $this->get_total();
772
-		$recurring = $this->get_recurring_total();
773
-
774
-		if ( $this->has_recurring == 0 ) {
775
-			$recurring = 0;
776
-		}
777
-
778
-		$collect = $initial > 0 || $recurring > 0;
779
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
780
-	}
781
-
782
-	/**
783
-	 * Returns the billing email of the user.
784
-	 *
785
-	 * @since 1.0.19
786
-	 */
787
-	public function get_billing_email() {
788
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
789
-	}
790
-
791
-	/**
792
-	 * Checks if the submitter has a billing email.
793
-	 *
794
-	 * @since 1.0.19
795
-	 */
796
-	public function has_billing_email() {
797
-		$billing_email = $this->get_billing_email();
798
-		return ! empty( $billing_email ) && is_email( $billing_email );
799
-	}
800
-
801
-	/**
802
-	 * Returns the appropriate currency for the submission.
803
-	 *
804
-	 * @since 1.0.19
805
-	 * @return string
806
-	 */
807
-	public function get_currency() {
808
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
809
-    }
810
-
811
-    /**
812
-	 * Returns the raw submission data.
813
-	 *
814
-	 * @since 1.0.19
815
-	 * @return array
816
-	 */
817
-	public function get_data() {
818
-		return $this->data;
819
-	}
820
-
821
-	/**
822
-	 * Returns a field from the submission data
823
-	 *
824
-	 * @param string $field
825
-	 * @since 1.0.19
826
-	 * @return mixed|null
827
-	 */
828
-	public function get_field( $field, $sub_array_key = null ) {
829
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
830
-	}
831
-
832
-	/**
833
-	 * Checks if a required field is set.
834
-	 *
835
-	 * @since 1.0.19
836
-	 */
837
-	public function is_required_field_set( $field ) {
838
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
839
-	}
840
-
841
-	/**
842
-	 * Formats an amount
843
-	 *
844
-	 * @since 1.0.19
845
-	 */
846
-	public function format_amount( $amount ) {
847
-		return wpinv_price( $amount, $this->get_currency() );
848
-	}
745
+    /**
746
+     * Returns the total amount to collect for this submission.
747
+     *
748
+     * @since 1.0.19
749
+     */
750
+    public function get_total() {
751
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
752
+        return max( $total, 0 );
753
+    }
754
+
755
+    /**
756
+     * Returns the recurring total amount to collect for this submission.
757
+     *
758
+     * @since 1.0.19
759
+     */
760
+    public function get_recurring_total() {
761
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
762
+        return max( $total, 0 );
763
+    }
764
+
765
+    /**
766
+     * Whether payment details should be collected for this submission.
767
+     *
768
+     * @since 1.0.19
769
+     */
770
+    public function should_collect_payment_details() {
771
+        $initial   = $this->get_total();
772
+        $recurring = $this->get_recurring_total();
773
+
774
+        if ( $this->has_recurring == 0 ) {
775
+            $recurring = 0;
776
+        }
777
+
778
+        $collect = $initial > 0 || $recurring > 0;
779
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
780
+    }
781
+
782
+    /**
783
+     * Returns the billing email of the user.
784
+     *
785
+     * @since 1.0.19
786
+     */
787
+    public function get_billing_email() {
788
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
789
+    }
790
+
791
+    /**
792
+     * Checks if the submitter has a billing email.
793
+     *
794
+     * @since 1.0.19
795
+     */
796
+    public function has_billing_email() {
797
+        $billing_email = $this->get_billing_email();
798
+        return ! empty( $billing_email ) && is_email( $billing_email );
799
+    }
800
+
801
+    /**
802
+     * Returns the appropriate currency for the submission.
803
+     *
804
+     * @since 1.0.19
805
+     * @return string
806
+     */
807
+    public function get_currency() {
808
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
809
+    }
810
+
811
+    /**
812
+     * Returns the raw submission data.
813
+     *
814
+     * @since 1.0.19
815
+     * @return array
816
+     */
817
+    public function get_data() {
818
+        return $this->data;
819
+    }
820
+
821
+    /**
822
+     * Returns a field from the submission data
823
+     *
824
+     * @param string $field
825
+     * @since 1.0.19
826
+     * @return mixed|null
827
+     */
828
+    public function get_field( $field, $sub_array_key = null ) {
829
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
830
+    }
831
+
832
+    /**
833
+     * Checks if a required field is set.
834
+     *
835
+     * @since 1.0.19
836
+     */
837
+    public function is_required_field_set( $field ) {
838
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
839
+    }
840
+
841
+    /**
842
+     * Formats an amount
843
+     *
844
+     * @since 1.0.19
845
+     */
846
+    public function format_amount( $amount ) {
847
+        return wpinv_price( $amount, $this->get_currency() );
848
+    }
849 849
 
850 850
 }
Please login to merge, or discard this patch.
Spacing   +117 added lines, -117 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
 
@@ -134,8 +134,8 @@  discard block
 block discarded – undo
134 134
 		$this->state   = wpinv_get_default_state();
135 135
 
136 136
 		// Do we have an actual submission?
137
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
138
-			$this->load_data( $_POST );
137
+		if (isset($_POST['getpaid_payment_form_submission'])) {
138
+			$this->load_data($_POST);
139 139
 		}
140 140
 
141 141
 	}
@@ -145,19 +145,19 @@  discard block
 block discarded – undo
145 145
 	 *
146 146
 	 * @param array $data
147 147
 	 */
148
-	public function load_data( $data ) {
148
+	public function load_data($data) {
149 149
 
150 150
 		// Remove slashes from the submitted data...
151
-		$data       = wp_unslash( $data );
151
+		$data       = wp_unslash($data);
152 152
 
153 153
 		// Allow plugins to filter the data.
154
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
154
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
155 155
 
156 156
 		// Cache it...
157 157
 		$this->data = $data;
158 158
 
159 159
 		// Then generate a unique id from the data.
160
-		$this->id   = md5( wp_json_encode( $data ) );
160
+		$this->id   = md5(wp_json_encode($data));
161 161
 
162 162
 		// Finally, process the submission.
163 163
 		try {
@@ -167,26 +167,26 @@  discard block
 block discarded – undo
167 167
 			$processors = apply_filters(
168 168
 				'getpaid_payment_form_submission_processors',
169 169
 				array(
170
-					array( $this, 'process_payment_form' ),
171
-					array( $this, 'process_invoice' ),
172
-					array( $this, 'process_fees' ),
173
-					array( $this, 'process_items' ),
174
-					array( $this, 'process_discount' ),
175
-					array( $this, 'process_taxes' ),
170
+					array($this, 'process_payment_form'),
171
+					array($this, 'process_invoice'),
172
+					array($this, 'process_fees'),
173
+					array($this, 'process_items'),
174
+					array($this, 'process_discount'),
175
+					array($this, 'process_taxes'),
176 176
 				),
177 177
 				$this		
178 178
 			);
179 179
 
180
-			foreach ( $processors as $processor ) {
181
-				call_user_func_array( $processor, array( &$this ) );
180
+			foreach ($processors as $processor) {
181
+				call_user_func_array($processor, array(&$this));
182 182
 			}
183 183
 
184
-		} catch ( Exception $e ) {
184
+		} catch (Exception $e) {
185 185
 			$this->last_error = $e->getMessage();
186 186
 		}
187 187
 
188 188
 		// Fired when we are done processing a submission.
189
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
189
+		do_action_ref_array('getpaid_process_submission', array(&$this));
190 190
 
191 191
 	}
192 192
 
@@ -207,18 +207,18 @@  discard block
 block discarded – undo
207 207
 	public function process_payment_form() {
208 208
 
209 209
 		// Every submission needs an active payment form.
210
-		if ( empty( $this->data['form_id'] ) ) {
211
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
210
+		if (empty($this->data['form_id'])) {
211
+			throw new Exception(__('Missing payment form', 'invoicing'));
212 212
 		}
213 213
 
214 214
 		// Fetch the payment form.
215
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
215
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
216 216
 
217
-		if ( ! $this->payment_form->is_active() ) {
218
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
217
+		if (!$this->payment_form->is_active()) {
218
+			throw new Exception(__('Payment form not active', 'invoicing'));
219 219
 		}
220 220
 
221
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
221
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
222 222
 	}
223 223
 
224 224
     /**
@@ -248,30 +248,30 @@  discard block
 block discarded – undo
248 248
 	public function process_invoice() {
249 249
 
250 250
 		// Abort if there is no invoice.
251
-		if ( empty( $this->data['invoice_id'] ) ) {
251
+		if (empty($this->data['invoice_id'])) {
252 252
 			return;
253 253
 		}
254 254
 
255 255
 		// If the submission is for an existing invoice, ensure that it exists
256 256
 		// and that it is not paid for.
257
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
257
+		$invoice = wpinv_get_invoice($this->data['invoice_id']);
258 258
 
259
-        if ( empty( $invoice ) ) {
260
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
259
+        if (empty($invoice)) {
260
+			throw new Exception(__('Invalid invoice', 'invoicing'));
261 261
 		}
262 262
 
263
-		if ( $invoice->is_paid() ) {
264
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
263
+		if ($invoice->is_paid()) {
264
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
265 265
 		}
266 266
 
267
-		$this->payment_form->set_items( $invoice->get_items() );
267
+		$this->payment_form->set_items($invoice->get_items());
268 268
 		$this->payment_form->invoice = $invoice;
269 269
 
270 270
 		$this->country = $invoice->get_country();
271 271
 		$this->state   = $invoice->get_state();
272 272
 		$this->invoice = $invoice;
273 273
 
274
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
274
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
275 275
 	}
276 276
 
277 277
 	/**
@@ -291,7 +291,7 @@  discard block
 block discarded – undo
291 291
 	 * @return bool
292 292
 	 */
293 293
 	public function has_invoice() {
294
-		return ! empty( $this->invoice );
294
+		return !empty($this->invoice);
295 295
 	}
296 296
 
297 297
 	/*
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
 	 */
311 311
 	public function process_items() {
312 312
 
313
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
313
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
314 314
 
315
-		foreach ( $processor->items as $item ) {
316
-			$this->add_item( $item );
315
+		foreach ($processor->items as $item) {
316
+			$this->add_item($item);
317 317
 		}
318 318
 
319
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
319
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
320 320
 	}
321 321
 
322 322
 	/**
@@ -325,18 +325,18 @@  discard block
 block discarded – undo
325 325
 	 * @since 1.0.19
326 326
 	 * @param GetPaid_Form_Item $item
327 327
 	 */
328
-	public function add_item( $item ) {
328
+	public function add_item($item) {
329 329
 
330 330
 		// Make sure that it is available for purchase.
331
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
331
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
332 332
 			return;
333 333
 		}
334 334
 
335 335
 		// Each submission can only contain one recurring item.
336
-		if ( $item->is_recurring() ) {
336
+		if ($item->is_recurring()) {
337 337
 
338
-			if ( $this->has_recurring != 0 ) {
339
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
338
+			if ($this->has_recurring != 0) {
339
+				throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing'));
340 340
 			}
341 341
 
342 342
 			$this->has_recurring = $item->get_id();
@@ -344,7 +344,7 @@  discard block
 block discarded – undo
344 344
 		}
345 345
 
346 346
 		// Update the items and totals.
347
-		$this->items[ $item->get_id() ]         = $item;
347
+		$this->items[$item->get_id()]         = $item;
348 348
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
349 349
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
350 350
 
@@ -358,17 +358,17 @@  discard block
 block discarded – undo
358 358
 	 *
359 359
 	 * @since 1.0.19
360 360
 	 */
361
-	public function remove_item( $item_id ) {
361
+	public function remove_item($item_id) {
362 362
 
363
-		if ( isset( $this->items[ $item_id ] ) ) {
364
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
365
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
363
+		if (isset($this->items[$item_id])) {
364
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
365
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
366 366
 
367
-			if ( $this->items[ $item_id ]->is_recurring() ) {
367
+			if ($this->items[$item_id]->is_recurring()) {
368 368
 				$this->has_recurring = 0;
369 369
 			}
370 370
 
371
-			unset( $this->items[ $item_id ] );
371
+			unset($this->items[$item_id]);
372 372
 		}
373 373
 
374 374
 	}
@@ -380,7 +380,7 @@  discard block
 block discarded – undo
380 380
 	 */
381 381
 	public function get_subtotal() {
382 382
 
383
-		if ( wpinv_prices_include_tax() ) {
383
+		if (wpinv_prices_include_tax()) {
384 384
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
385 385
 		}
386 386
 
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
 	 */
395 395
 	public function get_recurring_subtotal() {
396 396
 
397
-		if ( wpinv_prices_include_tax() ) {
397
+		if (wpinv_prices_include_tax()) {
398 398
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
399 399
 		}
400 400
 
@@ -428,39 +428,39 @@  discard block
 block discarded – undo
428 428
 	public function process_taxes() {
429 429
 
430 430
 		// Abort if we're not using taxes.
431
-		if ( ! $this->use_taxes() ) {
431
+		if (!$this->use_taxes()) {
432 432
 			return;
433 433
 		}
434 434
 
435 435
 		// If a custom country && state has been passed in, use it to calculate taxes.
436
-		$country = $this->get_field( 'wpinv_country', 'billing' );
437
-		if ( ! empty( $country ) ) {
436
+		$country = $this->get_field('wpinv_country', 'billing');
437
+		if (!empty($country)) {
438 438
 			$this->country = $country;
439 439
 		}
440 440
 
441
-		$state = $this->get_field( 'wpinv_state', 'billing' );
442
-		if ( ! empty( $state ) ) {
441
+		$state = $this->get_field('wpinv_state', 'billing');
442
+		if (!empty($state)) {
443 443
 			$this->state = $state;
444 444
 		}
445 445
 
446 446
 		// Confirm if the provided country and the ip country are similar.
447
-		$address_confirmed = $this->get_field( 'confirm-address' );
448
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
449
-			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' ) );
447
+		$address_confirmed = $this->get_field('confirm-address');
448
+		if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
449
+			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'));
450 450
 		}
451 451
 
452 452
 		// Abort if the country is not taxable.
453
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
453
+		if (!wpinv_is_country_taxable($this->country)) {
454 454
 			return;
455 455
 		}
456 456
 
457
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
457
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
458 458
 
459
-		foreach ( $processor->taxes as $tax ) {
460
-			$this->add_tax( $tax );
459
+		foreach ($processor->taxes as $tax) {
460
+			$this->add_tax($tax);
461 461
 		}
462 462
 
463
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
463
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
464 464
 	}
465 465
 
466 466
 	/**
@@ -469,16 +469,16 @@  discard block
 block discarded – undo
469 469
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
470 470
 	 * @since 1.0.19
471 471
 	 */
472
-	public function add_tax( $tax ) {
472
+	public function add_tax($tax) {
473 473
 
474
-		if ( wpinv_round_tax_per_tax_rate() ) {
475
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
476
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
474
+		if (wpinv_round_tax_per_tax_rate()) {
475
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
476
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
477 477
 		}
478 478
 
479
-		$this->taxes[ $tax['name'] ]         = $tax;
480
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
481
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
479
+		$this->taxes[$tax['name']]         = $tax;
480
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
481
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
482 482
 
483 483
 	}
484 484
 
@@ -487,12 +487,12 @@  discard block
 block discarded – undo
487 487
 	 *
488 488
 	 * @since 1.0.19
489 489
 	 */
490
-	public function remove_tax( $tax_name ) {
490
+	public function remove_tax($tax_name) {
491 491
 
492
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
493
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
494
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
495
-			unset( $this->taxes[ $tax_name ] );
492
+		if (isset($this->taxes[$tax_name])) {
493
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
494
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
495
+			unset($this->taxes[$tax_name]);
496 496
 		}
497 497
 
498 498
 	}
@@ -506,11 +506,11 @@  discard block
 block discarded – undo
506 506
 
507 507
 		$use_taxes = wpinv_use_taxes();
508 508
 
509
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
509
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
510 510
 			$use_taxes = false;
511 511
 		}
512 512
 
513
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
513
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
514 514
 
515 515
 	}
516 516
 
@@ -559,13 +559,13 @@  discard block
 block discarded – undo
559 559
 
560 560
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
561 561
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
562
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
562
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
563 563
 
564
-		foreach ( $processor->discounts as $discount ) {
565
-			$this->add_discount( $discount );
564
+		foreach ($processor->discounts as $discount) {
565
+			$this->add_discount($discount);
566 566
 		}
567 567
 
568
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
568
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
569 569
 	}
570 570
 
571 571
 	/**
@@ -574,10 +574,10 @@  discard block
 block discarded – undo
574 574
 	 * @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.
575 575
 	 * @since 1.0.19
576 576
 	 */
577
-	public function add_discount( $discount ) {
578
-		$this->discounts[ $discount['name'] ]   = $discount;
579
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
580
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
577
+	public function add_discount($discount) {
578
+		$this->discounts[$discount['name']]   = $discount;
579
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
580
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
581 581
 	}
582 582
 
583 583
 	/**
@@ -585,12 +585,12 @@  discard block
 block discarded – undo
585 585
 	 *
586 586
 	 * @since 1.0.19
587 587
 	 */
588
-	public function remove_discount( $name ) {
588
+	public function remove_discount($name) {
589 589
 
590
-		if ( isset( $this->discounts[ $name ] ) ) {
591
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
592
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
593
-			unset( $this->discounts[ $name ] );
590
+		if (isset($this->discounts[$name])) {
591
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
592
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
593
+			unset($this->discounts[$name]);
594 594
 		}
595 595
 
596 596
 	}
@@ -602,7 +602,7 @@  discard block
 block discarded – undo
602 602
 	 * @return bool
603 603
 	 */
604 604
 	public function has_discount_code() {
605
-		return ! empty( $this->discounts['discount_code'] );
605
+		return !empty($this->discounts['discount_code']);
606 606
 	}
607 607
 
608 608
 	/**
@@ -659,13 +659,13 @@  discard block
 block discarded – undo
659 659
 	 */
660 660
 	public function process_fees() {
661 661
 
662
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
662
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
663 663
 
664
-		foreach ( $fees_processor->fees as $fee ) {
665
-			$this->add_fee( $fee );
664
+		foreach ($fees_processor->fees as $fee) {
665
+			$this->add_fee($fee);
666 666
 		}
667 667
 
668
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
668
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
669 669
 	}
670 670
 
671 671
 	/**
@@ -674,11 +674,11 @@  discard block
 block discarded – undo
674 674
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
675 675
 	 * @since 1.0.19
676 676
 	 */
677
-	public function add_fee( $fee ) {
677
+	public function add_fee($fee) {
678 678
 
679
-		$this->fees[ $fee['name'] ]         = $fee;
680
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
681
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
679
+		$this->fees[$fee['name']]         = $fee;
680
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
681
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
682 682
 
683 683
 	}
684 684
 
@@ -687,12 +687,12 @@  discard block
 block discarded – undo
687 687
 	 *
688 688
 	 * @since 1.0.19
689 689
 	 */
690
-	public function remove_fee( $name ) {
690
+	public function remove_fee($name) {
691 691
 
692
-		if ( isset( $this->fees[ $name ] ) ) {
693
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
694
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
695
-			unset( $this->fees[ $name ] );
692
+		if (isset($this->fees[$name])) {
693
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
694
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
695
+			unset($this->fees[$name]);
696 696
 		}
697 697
 
698 698
 	}
@@ -731,7 +731,7 @@  discard block
 block discarded – undo
731 731
 	 * @since 1.0.19
732 732
 	 */
733 733
 	public function has_fees() {
734
-		return count( $this->fees ) !== 0;
734
+		return count($this->fees) !== 0;
735 735
 	}
736 736
 
737 737
 	/*
@@ -749,7 +749,7 @@  discard block
 block discarded – undo
749 749
 	 */
750 750
 	public function get_total() {
751 751
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
752
-		return max( $total, 0 );
752
+		return max($total, 0);
753 753
 	}
754 754
 
755 755
 	/**
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 	 */
760 760
 	public function get_recurring_total() {
761 761
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
762
-		return max( $total, 0 );
762
+		return max($total, 0);
763 763
 	}
764 764
 
765 765
 	/**
@@ -771,12 +771,12 @@  discard block
 block discarded – undo
771 771
 		$initial   = $this->get_total();
772 772
 		$recurring = $this->get_recurring_total();
773 773
 
774
-		if ( $this->has_recurring == 0 ) {
774
+		if ($this->has_recurring == 0) {
775 775
 			$recurring = 0;
776 776
 		}
777 777
 
778 778
 		$collect = $initial > 0 || $recurring > 0;
779
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
779
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
780 780
 	}
781 781
 
782 782
 	/**
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 	 * @since 1.0.19
786 786
 	 */
787 787
 	public function get_billing_email() {
788
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
788
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
789 789
 	}
790 790
 
791 791
 	/**
@@ -795,7 +795,7 @@  discard block
 block discarded – undo
795 795
 	 */
796 796
 	public function has_billing_email() {
797 797
 		$billing_email = $this->get_billing_email();
798
-		return ! empty( $billing_email ) && is_email( $billing_email );
798
+		return !empty($billing_email) && is_email($billing_email);
799 799
 	}
800 800
 
801 801
 	/**
@@ -825,8 +825,8 @@  discard block
 block discarded – undo
825 825
 	 * @since 1.0.19
826 826
 	 * @return mixed|null
827 827
 	 */
828
-	public function get_field( $field, $sub_array_key = null ) {
829
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
828
+	public function get_field($field, $sub_array_key = null) {
829
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
830 830
 	}
831 831
 
832 832
 	/**
@@ -834,8 +834,8 @@  discard block
 block discarded – undo
834 834
 	 *
835 835
 	 * @since 1.0.19
836 836
 	 */
837
-	public function is_required_field_set( $field ) {
838
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
837
+	public function is_required_field_set($field) {
838
+		return empty($field['required']) || !empty($this->data[$field['id']]);
839 839
 	}
840 840
 
841 841
 	/**
@@ -843,8 +843,8 @@  discard block
 block discarded – undo
843 843
 	 *
844 844
 	 * @since 1.0.19
845 845
 	 */
846
-	public function format_amount( $amount ) {
847
-		return wpinv_price( $amount, $this->get_currency() );
846
+	public function format_amount($amount) {
847
+		return wpinv_price($amount, $this->get_currency());
848 848
 	}
849 849
 
850 850
 }
Please login to merge, or discard this patch.