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 1 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 1 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 1 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.