Passed
Push — master ( 21f781...583b1e )
by Brian
09:47 queued 04:40
created
includes/wpinv-tax-functions.php 1 patch
Indentation   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -192,16 +192,16 @@
 block discarded – undo
192 192
 function getpaid_prepare_item_tax( $item, $tax_name, $tax_amount, $recurring_tax_amount ) {
193 193
 
194 194
     $initial_tax   = $tax_amount;
195
-	$recurring_tax = 0;
195
+    $recurring_tax = 0;
196 196
 
197 197
     if ( $item->is_recurring() ) {
198
-		$recurring_tax = $recurring_tax_amount;
199
-	}
198
+        $recurring_tax = $recurring_tax_amount;
199
+    }
200 200
 
201
-	return array(
202
-		'name'          => sanitize_text_field( $tax_name ),
203
-		'initial_tax'   => $initial_tax,
204
-		'recurring_tax' => $recurring_tax,
201
+    return array(
202
+        'name'          => sanitize_text_field( $tax_name ),
203
+        'initial_tax'   => $initial_tax,
204
+        'recurring_tax' => $recurring_tax,
205 205
     );
206 206
 
207 207
 }
Please login to merge, or discard this patch.
includes/class-getpaid-tax.php 1 patch
Indentation   +159 added lines, -159 removed lines patch added patch discarded remove patch
@@ -13,164 +13,164 @@
 block discarded – undo
13 13
  */
14 14
 class GetPaid_Tax {
15 15
 
16
-	/**
17
-	 * Calculates tax for a line item.
18
-	 *
19
-	 * @param  float   $price              The price to calc tax on.
20
-	 * @param  array   $rates              The rates to apply.
21
-	 * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
-	 * @return array                       Array of tax name => tax amount.
23
-	 */
24
-	public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
-
26
-		if ( $price_includes_tax ) {
27
-			$taxes = self::calc_inclusive_tax( $price, $rates );
28
-		} else {
29
-			$taxes = self::calc_exclusive_tax( $price, $rates );
30
-		}
31
-
32
-		return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
-
34
-	}
35
-
36
-	/**
37
-	 * Calc tax from inclusive price.
38
-	 *
39
-	 * @param  float $price Price to calculate tax for.
40
-	 * @param  array $rates Array of tax rates.
41
-	 * @return array
42
-	 */
43
-	public static function calc_inclusive_tax( $price, $rates ) {
44
-		$taxes     = array();
45
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
-
47
-		// Add tax rates.
48
-		$tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
-
50
-		foreach ( $tax_rates as $name => $rate ) {
51
-			$the_rate       = ( $rate / 100 ) / $tax_rate;
52
-			$net_price      = $price - ( $the_rate * $price );
53
-			$tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
-			$taxes[ $name ] = $tax_amount;
55
-		}
56
-
57
-		// Round all taxes to precision (4DP) before passing them back.
58
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
-
60
-		return $taxes;
61
-	}
62
-
63
-	/**
64
-	 * Calc tax from exclusive price.
65
-	 *
66
-	 * @param  float $price Price to calculate tax for.
67
-	 * @param  array $rates Array of tax rates.
68
-	 * @return array
69
-	 */
70
-	public static function calc_exclusive_tax( $price, $rates ) {
71
-		$taxes     = array();
72
-		$tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
-
74
-		foreach ( $tax_rates as $name => $rate ) {
75
-
76
-			$tax_amount     = $price * ( $rate / 100 );
77
-			$taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
-
79
-		}
80
-
81
-		// Round all taxes to precision (4DP) before passing them back.
82
-		$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
-
84
-		return $taxes;
85
-	}
86
-
87
-	/**
88
-	 * Get's an array of all tax rates.
89
-	 *
90
-	 * @return array
91
-	 */
92
-	public static function get_all_tax_rates() {
93
-
94
-		$rates = get_option( 'wpinv_tax_rates', array() );
95
-
96
-		return apply_filters(
97
-			'getpaid_get_all_tax_rates',
98
-			array_filter( wpinv_parse_list( $rates ) )
99
-		);
100
-
101
-	}
102
-
103
-	/**
104
-	 * Get's an array of default tax rates.
105
-	 *
106
-	 * @return array
107
-	 */
108
-	public static function get_default_tax_rates() {
109
-
110
-		return apply_filters(
111
-			'getpaid_get_default_tax_rates',
112
-			array(
113
-				array(
114
-				'country'   => wpinv_get_default_country(),
115
-				'state'     => wpinv_get_default_state(),
116
-				'global'    => true,
117
-				'rate'      => wpinv_get_default_tax_rate(),
118
-				'name'      => __( 'Base Tax', 'invoicing' ),
119
-				)
120
-			)
121
-		);
122
-
123
-	}
124
-
125
-	/**
126
-	 * Get's an array of tax rates for a given address.
127
-	 *
128
-	 * @param string $country
129
-	 * @param string $state
130
-	 * @return array
131
-	 */
132
-	public static function get_address_tax_rates( $country, $state ) {
133
-
134
-		$all_tax_rates  = self::get_all_tax_rates();
135
-		$matching_rates = wp_list_filter( $all_tax_rates, array( 'country' => $country ) );
136
-
137
-		foreach ( $matching_rates as $i => $rate ) {
138
-
139
-			if ( empty( $rate['global'] ) && $rate['state'] != $state ) {
140
-				unset( $matching_rates[ $i ] );
141
-			}
142
-
143
-		}
144
-
145
-		return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
146
-
147
-	}
148
-
149
-	/**
150
-	 * Sums a set of taxes to form a single total. Result is rounded to precision.
151
-	 *
152
-	 * @param  array $taxes Array of taxes.
153
-	 * @return float
154
-	 */
155
-	public static function get_tax_total( $taxes ) {
156
-		return self::round( array_sum( $taxes ) );
157
-	}
158
-
159
-	/**
160
-	 * Round to precision.
161
-	 *
162
-	 * Filter example: to return rounding to .5 cents you'd use:
163
-	 *
164
-	 * function euro_5cent_rounding( $in ) {
165
-	 *      return round( $in / 5, 2 ) * 5;
166
-	 * }
167
-	 * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
168
-	 *
169
-	 * @param float|int $in Value to round.
170
-	 * @return float
171
-	 */
172
-	public static function round( $in ) {
173
-		return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
174
-	}
16
+    /**
17
+     * Calculates tax for a line item.
18
+     *
19
+     * @param  float   $price              The price to calc tax on.
20
+     * @param  array   $rates              The rates to apply.
21
+     * @param  boolean $price_includes_tax Whether the passed price has taxes included.
22
+     * @return array                       Array of tax name => tax amount.
23
+     */
24
+    public static function calc_tax( $price, $rates, $price_includes_tax = false ) {
25
+
26
+        if ( $price_includes_tax ) {
27
+            $taxes = self::calc_inclusive_tax( $price, $rates );
28
+        } else {
29
+            $taxes = self::calc_exclusive_tax( $price, $rates );
30
+        }
31
+
32
+        return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax );
33
+
34
+    }
35
+
36
+    /**
37
+     * Calc tax from inclusive price.
38
+     *
39
+     * @param  float $price Price to calculate tax for.
40
+     * @param  array $rates Array of tax rates.
41
+     * @return array
42
+     */
43
+    public static function calc_inclusive_tax( $price, $rates ) {
44
+        $taxes     = array();
45
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
46
+
47
+        // Add tax rates.
48
+        $tax_rate  = 1 + ( array_sum( $tax_rates ) / 100 );
49
+
50
+        foreach ( $tax_rates as $name => $rate ) {
51
+            $the_rate       = ( $rate / 100 ) / $tax_rate;
52
+            $net_price      = $price - ( $the_rate * $price );
53
+            $tax_amount     = apply_filters( 'getpaid_price_inc_tax_amount', $price - $net_price, $name, $rate, $price );
54
+            $taxes[ $name ] = $tax_amount;
55
+        }
56
+
57
+        // Round all taxes to precision (4DP) before passing them back.
58
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
59
+
60
+        return $taxes;
61
+    }
62
+
63
+    /**
64
+     * Calc tax from exclusive price.
65
+     *
66
+     * @param  float $price Price to calculate tax for.
67
+     * @param  array $rates Array of tax rates.
68
+     * @return array
69
+     */
70
+    public static function calc_exclusive_tax( $price, $rates ) {
71
+        $taxes     = array();
72
+        $tax_rates = wp_list_pluck( $rates, 'rate', 'name' );
73
+
74
+        foreach ( $tax_rates as $name => $rate ) {
75
+
76
+            $tax_amount     = $price * ( $rate / 100 );
77
+            $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price );
78
+
79
+        }
80
+
81
+        // Round all taxes to precision (4DP) before passing them back.
82
+        $taxes = array_map( array( __CLASS__, 'round' ), $taxes );
83
+
84
+        return $taxes;
85
+    }
86
+
87
+    /**
88
+     * Get's an array of all tax rates.
89
+     *
90
+     * @return array
91
+     */
92
+    public static function get_all_tax_rates() {
93
+
94
+        $rates = get_option( 'wpinv_tax_rates', array() );
95
+
96
+        return apply_filters(
97
+            'getpaid_get_all_tax_rates',
98
+            array_filter( wpinv_parse_list( $rates ) )
99
+        );
100
+
101
+    }
102
+
103
+    /**
104
+     * Get's an array of default tax rates.
105
+     *
106
+     * @return array
107
+     */
108
+    public static function get_default_tax_rates() {
109
+
110
+        return apply_filters(
111
+            'getpaid_get_default_tax_rates',
112
+            array(
113
+                array(
114
+                'country'   => wpinv_get_default_country(),
115
+                'state'     => wpinv_get_default_state(),
116
+                'global'    => true,
117
+                'rate'      => wpinv_get_default_tax_rate(),
118
+                'name'      => __( 'Base Tax', 'invoicing' ),
119
+                )
120
+            )
121
+        );
122
+
123
+    }
124
+
125
+    /**
126
+     * Get's an array of tax rates for a given address.
127
+     *
128
+     * @param string $country
129
+     * @param string $state
130
+     * @return array
131
+     */
132
+    public static function get_address_tax_rates( $country, $state ) {
133
+
134
+        $all_tax_rates  = self::get_all_tax_rates();
135
+        $matching_rates = wp_list_filter( $all_tax_rates, array( 'country' => $country ) );
136
+
137
+        foreach ( $matching_rates as $i => $rate ) {
138
+
139
+            if ( empty( $rate['global'] ) && $rate['state'] != $state ) {
140
+                unset( $matching_rates[ $i ] );
141
+            }
142
+
143
+        }
144
+
145
+        return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state );
146
+
147
+    }
148
+
149
+    /**
150
+     * Sums a set of taxes to form a single total. Result is rounded to precision.
151
+     *
152
+     * @param  array $taxes Array of taxes.
153
+     * @return float
154
+     */
155
+    public static function get_tax_total( $taxes ) {
156
+        return self::round( array_sum( $taxes ) );
157
+    }
158
+
159
+    /**
160
+     * Round to precision.
161
+     *
162
+     * Filter example: to return rounding to .5 cents you'd use:
163
+     *
164
+     * function euro_5cent_rounding( $in ) {
165
+     *      return round( $in / 5, 2 ) * 5;
166
+     * }
167
+     * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' );
168
+     *
169
+     * @param float|int $in Value to round.
170
+     * @return float
171
+     */
172
+    public static function round( $in ) {
173
+        return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in );
174
+    }
175 175
 
176 176
 }
Please login to merge, or discard this patch.
includes/admin/register-settings.php 1 patch
Indentation   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -196,11 +196,11 @@  discard block
 block discarded – undo
196 196
     $cb      = "wpinv_{$option['type']}_callback";
197 197
     $section = "wpinv_settings_{$tab}_$section";
198 198
 
199
-	if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
-		$tip   = esc_attr( $option['desc'] );
201
-		$name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
-		unset( $option['desc'] );
203
-	}
199
+    if ( isset( $option['desc'] ) && ! empty( $option['help-tip'] ) ) {
200
+        $tip   = esc_attr( $option['desc'] );
201
+        $name .= "<span class='dashicons dashicons-editor-help wpi-help-tip' title='$tip'></span>";
202
+        unset( $option['desc'] );
203
+    }
204 204
 
205 205
     // Loop through all tabs.
206 206
     add_settings_field(
@@ -279,10 +279,10 @@  discard block
 block discarded – undo
279 279
         }
280 280
 
281 281
         // General filter
282
-		$input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
282
+        $input[ $key ] = apply_filters( 'wpinv_settings_sanitize', $input[ $key ], $key );
283 283
 
284
-		// Key specific filter.
285
-		$input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
284
+        // Key specific filter.
285
+        $input[ $key ] = apply_filters( "wpinv_settings_sanitize_$key", $input[ $key ] );
286 286
     }
287 287
 
288 288
     // Loop through the whitelist and unset any that are empty for the tab being saved
@@ -338,15 +338,15 @@  discard block
 block discarded – undo
338 338
 
339 339
     foreach ( $new_rates as $rate ) {
340 340
 
341
-		if ( ! empty( $rate['country'] ) ) {
342
-			$rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
-			$rate['name']    = sanitize_text_field( $rate['name'] );
344
-			$rate['state']   = sanitize_text_field( $rate['state'] );
345
-			$rate['country'] = sanitize_text_field( $rate['country'] );
346
-			$tax_rates[]     = $rate;
347
-		}
341
+        if ( ! empty( $rate['country'] ) ) {
342
+            $rate['rate']    = wpinv_sanitize_amount( $rate['rate'] );
343
+            $rate['name']    = sanitize_text_field( $rate['name'] );
344
+            $rate['state']   = sanitize_text_field( $rate['state'] );
345
+            $rate['country'] = sanitize_text_field( $rate['country'] );
346
+            $tax_rates[]     = $rate;
347
+        }
348 348
 
349
-	}
349
+    }
350 350
 
351 351
     update_option( 'wpinv_tax_rates', $tax_rates );
352 352
 
@@ -426,51 +426,51 @@  discard block
 block discarded – undo
426 426
 }
427 427
 
428 428
 function wpinv_get_pages( $with_slug = false, $default_label = NULL ) {
429
-	$pages_options = array();
429
+    $pages_options = array();
430 430
 
431
-	if( $default_label !== NULL && $default_label !== false ) {
432
-		$pages_options = array( '' => $default_label ); // Blank option
433
-	}
431
+    if( $default_label !== NULL && $default_label !== false ) {
432
+        $pages_options = array( '' => $default_label ); // Blank option
433
+    }
434 434
 
435
-	$pages = get_pages();
436
-	if ( $pages ) {
437
-		foreach ( $pages as $page ) {
438
-			$title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
435
+    $pages = get_pages();
436
+    if ( $pages ) {
437
+        foreach ( $pages as $page ) {
438
+            $title = $with_slug ? $page->post_title . ' (' . $page->post_name . ')' : $page->post_title;
439 439
             $pages_options[ $page->ID ] = $title;
440
-		}
441
-	}
440
+        }
441
+    }
442 442
 
443
-	return $pages_options;
443
+    return $pages_options;
444 444
 }
445 445
 
446 446
 function wpinv_header_callback( $args ) {
447
-	if ( !empty( $args['desc'] ) ) {
447
+    if ( !empty( $args['desc'] ) ) {
448 448
         echo $args['desc'];
449 449
     }
450 450
 }
451 451
 
452 452
 function wpinv_hidden_callback( $args ) {
453
-	global $wpinv_options;
454
-
455
-	if ( isset( $args['set_value'] ) ) {
456
-		$value = $args['set_value'];
457
-	} elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
458
-		$value = $wpinv_options[ $args['id'] ];
459
-	} else {
460
-		$value = isset( $args['std'] ) ? $args['std'] : '';
461
-	}
462
-
463
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
464
-		$args['readonly'] = true;
465
-		$value = isset( $args['std'] ) ? $args['std'] : '';
466
-		$name  = '';
467
-	} else {
468
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
469
-	}
470
-
471
-	$html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
453
+    global $wpinv_options;
454
+
455
+    if ( isset( $args['set_value'] ) ) {
456
+        $value = $args['set_value'];
457
+    } elseif ( isset( $wpinv_options[ $args['id'] ] ) ) {
458
+        $value = $wpinv_options[ $args['id'] ];
459
+    } else {
460
+        $value = isset( $args['std'] ) ? $args['std'] : '';
461
+    }
462
+
463
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
464
+        $args['readonly'] = true;
465
+        $value = isset( $args['std'] ) ? $args['std'] : '';
466
+        $name  = '';
467
+    } else {
468
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
469
+    }
470
+
471
+    $html = '<input type="hidden" id="wpinv_settings[' . wpinv_sanitize_key( $args['id'] ) . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '" />';
472 472
     
473
-	echo $html;
473
+    echo $html;
474 474
 }
475 475
 
476 476
 /**
@@ -478,12 +478,12 @@  discard block
 block discarded – undo
478 478
  */
479 479
 function wpinv_checkbox_callback( $args ) {
480 480
 
481
-	$std = isset( $args['std'] ) ? $args['std'] : '';
482
-	$std = wpinv_get_option( $args['id'], $std );
483
-	$id  = esc_attr( $args['id'] );
481
+    $std = isset( $args['std'] ) ? $args['std'] : '';
482
+    $std = wpinv_get_option( $args['id'], $std );
483
+    $id  = esc_attr( $args['id'] );
484 484
 
485
-	getpaid_hidden_field( "wpinv_settings[$id]", '0' );
486
-	?>
485
+    getpaid_hidden_field( "wpinv_settings[$id]", '0' );
486
+    ?>
487 487
 		<fieldset>
488 488
 			<label>
489 489
 				<input id="wpinv-settings-<?php echo $id; ?>" name="wpinv_settings[<?php echo $id; ?>]" <?php checked( empty( $std ), false ); ?> value="1" type="checkbox">
@@ -495,77 +495,77 @@  discard block
 block discarded – undo
495 495
 
496 496
 function wpinv_multicheck_callback( $args ) {
497 497
 	
498
-	global $wpinv_options;
498
+    global $wpinv_options;
499 499
 
500
-	$sanitize_id = wpinv_sanitize_key( $args['id'] );
501
-	$class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
500
+    $sanitize_id = wpinv_sanitize_key( $args['id'] );
501
+    $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
502 502
 
503
-	if ( ! empty( $args['options'] ) ) {
503
+    if ( ! empty( $args['options'] ) ) {
504 504
 
505
-		$std     = isset( $args['std'] ) ? $args['std'] : array();
506
-		$value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
505
+        $std     = isset( $args['std'] ) ? $args['std'] : array();
506
+        $value   = isset( $wpinv_options[ $args['id'] ] ) ? $wpinv_options[ $args['id'] ] : $std;
507 507
 
508
-		echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
508
+        echo '<div class="wpi-mcheck-rows wpi-mcheck-' . $sanitize_id . $class . '">';
509 509
         foreach( $args['options'] as $key => $option ):
510
-			$sanitize_key = wpinv_sanitize_key( $key );
511
-			if ( in_array( $sanitize_key, $value ) ) { 
512
-				$enabled = $sanitize_key;
513
-			} else { 
514
-				$enabled = NULL; 
515
-			}
516
-			echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
517
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
518
-		endforeach;
519
-		echo '</div>';
520
-		echo '<p class="description">' . $args['desc'] . '</p>';
521
-	}
510
+            $sanitize_key = wpinv_sanitize_key( $key );
511
+            if ( in_array( $sanitize_key, $value ) ) { 
512
+                $enabled = $sanitize_key;
513
+            } else { 
514
+                $enabled = NULL; 
515
+            }
516
+            echo '<div class="wpi-mcheck-row"><input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $sanitize_key ) . '" ' . checked( $sanitize_key, $enabled, false ) . '/>&nbsp;';
517
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . wp_kses_post( $option ) . '</label></div>';
518
+        endforeach;
519
+        echo '</div>';
520
+        echo '<p class="description">' . $args['desc'] . '</p>';
521
+    }
522 522
 }
523 523
 
524 524
 function wpinv_payment_icons_callback( $args ) {
525
-	global $wpinv_options;
525
+    global $wpinv_options;
526 526
     
527 527
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
528 528
 
529
-	if ( ! empty( $args['options'] ) ) {
530
-		foreach( $args['options'] as $key => $option ) {
529
+    if ( ! empty( $args['options'] ) ) {
530
+        foreach( $args['options'] as $key => $option ) {
531 531
             $sanitize_key = wpinv_sanitize_key( $key );
532 532
             
533
-			if( isset( $wpinv_options[$args['id']][$key] ) ) {
534
-				$enabled = $option;
535
-			} else {
536
-				$enabled = NULL;
537
-			}
538
-
539
-			echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
540
-
541
-				echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
542
-
543
-				if ( wpinv_string_is_image_url( $key ) ) {
544
-					echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
545
-				} else {
546
-					$card = strtolower( str_replace( ' ', '', $option ) );
547
-
548
-					if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
549
-						$image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
550
-					} else {
551
-						$image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
552
-						$content_dir = WP_CONTENT_DIR;
553
-
554
-						if ( function_exists( 'wp_normalize_path' ) ) {
555
-							// Replaces backslashes with forward slashes for Windows systems
556
-							$image = wp_normalize_path( $image );
557
-							$content_dir = wp_normalize_path( $content_dir );
558
-						}
559
-
560
-						$image = str_replace( $content_dir, content_url(), $image );
561
-					}
562
-
563
-					echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
564
-				}
565
-			echo $option . '</label>';
566
-		}
567
-		echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
568
-	}
533
+            if( isset( $wpinv_options[$args['id']][$key] ) ) {
534
+                $enabled = $option;
535
+            } else {
536
+                $enabled = NULL;
537
+            }
538
+
539
+            echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" style="margin-right:10px;line-height:16px;height:16px;display:inline-block;">';
540
+
541
+                echo '<input name="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="' . esc_attr( $option ) . '" ' . checked( $option, $enabled, false ) . '/>&nbsp;';
542
+
543
+                if ( wpinv_string_is_image_url( $key ) ) {
544
+                    echo '<img class="payment-icon" src="' . esc_url( $key ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
545
+                } else {
546
+                    $card = strtolower( str_replace( ' ', '', $option ) );
547
+
548
+                    if ( has_filter( 'wpinv_accepted_payment_' . $card . '_image' ) ) {
549
+                        $image = apply_filters( 'wpinv_accepted_payment_' . $card . '_image', '' );
550
+                    } else {
551
+                        $image       = wpinv_locate_template( 'images' . DIRECTORY_SEPARATOR . 'icons' . DIRECTORY_SEPARATOR . $card . '.gif', false );
552
+                        $content_dir = WP_CONTENT_DIR;
553
+
554
+                        if ( function_exists( 'wp_normalize_path' ) ) {
555
+                            // Replaces backslashes with forward slashes for Windows systems
556
+                            $image = wp_normalize_path( $image );
557
+                            $content_dir = wp_normalize_path( $content_dir );
558
+                        }
559
+
560
+                        $image = str_replace( $content_dir, content_url(), $image );
561
+                    }
562
+
563
+                    echo '<img class="payment-icon" src="' . esc_url( $image ) . '" style="width:32px;height:24px;position:relative;top:6px;margin-right:5px;"/>';
564
+                }
565
+            echo $option . '</label>';
566
+        }
567
+        echo '<p class="description" style="margin-top:16px;">' . wp_kses_post( $args['desc'] ) . '</p>';
568
+    }
569 569
 }
570 570
 
571 571
 /**
@@ -573,9 +573,9 @@  discard block
 block discarded – undo
573 573
  */
574 574
 function wpinv_radio_callback( $args ) {
575 575
 
576
-	$std = isset( $args['std'] ) ? $args['std'] : '';
577
-	$std = wpinv_get_option( $args['id'], $std );
578
-	?>
576
+    $std = isset( $args['std'] ) ? $args['std'] : '';
577
+    $std = wpinv_get_option( $args['id'], $std );
578
+    ?>
579 579
 		<fieldset>
580 580
 			<ul id="wpinv-settings-<?php echo esc_attr( $args['id'] ); ?>" style="margin-top: 0;">
581 581
 				<?php foreach( $args['options'] as $key => $option ) : ?>
@@ -589,7 +589,7 @@  discard block
 block discarded – undo
589 589
 			</ul>
590 590
 		</fieldset>
591 591
 	<?php
592
-	getpaid_settings_description_callback( $args );
592
+    getpaid_settings_description_callback( $args );
593 593
 }
594 594
 
595 595
 /**
@@ -597,176 +597,176 @@  discard block
 block discarded – undo
597 597
  */
598 598
 function getpaid_settings_description_callback( $args ) {
599 599
 
600
-	if ( ! empty( $args['desc'] ) ) {
601
-		$description = wp_kses_post( $args['desc'] );
602
-		echo "<p class='description'>$description</p>";
603
-	}
600
+    if ( ! empty( $args['desc'] ) ) {
601
+        $description = wp_kses_post( $args['desc'] );
602
+        echo "<p class='description'>$description</p>";
603
+    }
604 604
 
605 605
 }
606 606
 
607 607
 function wpinv_gateways_callback( $args ) {
608
-	global $wpinv_options;
608
+    global $wpinv_options;
609 609
     
610 610
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
611 611
 
612
-	foreach ( $args['options'] as $key => $option ) :
613
-		$sanitize_key = wpinv_sanitize_key( $key );
612
+    foreach ( $args['options'] as $key => $option ) :
613
+        $sanitize_key = wpinv_sanitize_key( $key );
614 614
         
615 615
         if ( isset( $wpinv_options['gateways'][ $key ] ) )
616
-			$enabled = '1';
617
-		else
618
-			$enabled = null;
616
+            $enabled = '1';
617
+        else
618
+            $enabled = null;
619 619
 
620
-		echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
621
-		echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
622
-	endforeach;
620
+        echo '<input name="wpinv_settings[' . esc_attr( $args['id'] ) . '][' . $sanitize_key . ']" id="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']" type="checkbox" value="1" ' . checked('1', $enabled, false) . '/>&nbsp;';
621
+        echo '<label for="wpinv_settings[' . $sanitize_id . '][' . $sanitize_key . ']">' . esc_html( $option['admin_label'] ) . '</label><br/>';
622
+    endforeach;
623 623
 }
624 624
 
625 625
 function wpinv_gateway_select_callback($args) {
626
-	global $wpinv_options;
626
+    global $wpinv_options;
627 627
     
628 628
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
629 629
     $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
630 630
 
631
-	echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
631
+    echo '<select name="wpinv_settings[' . $sanitize_id . ']"" id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'" >';
632 632
 
633
-	foreach ( $args['options'] as $key => $option ) :
634
-		if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
633
+    foreach ( $args['options'] as $key => $option ) :
634
+        if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
635 635
             $selected = selected( $key, $args['selected'], false );
636 636
         } else {
637 637
             $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $key, $wpinv_options[$args['id']], false ) : '';
638 638
         }
639
-		echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
640
-	endforeach;
639
+        echo '<option value="' . wpinv_sanitize_key( $key ) . '"' . $selected . '>' . esc_html( $option['admin_label'] ) . '</option>';
640
+    endforeach;
641 641
 
642
-	echo '</select>';
643
-	echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
642
+    echo '</select>';
643
+    echo '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
644 644
 }
645 645
 
646 646
 function wpinv_text_callback( $args ) {
647
-	global $wpinv_options;
647
+    global $wpinv_options;
648 648
     
649 649
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
650 650
 
651
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
652
-		$value = $wpinv_options[ $args['id'] ];
653
-	} else {
654
-		$value = isset( $args['std'] ) ? $args['std'] : '';
655
-	}
656
-
657
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
658
-		$args['readonly'] = true;
659
-		$value = isset( $args['std'] ) ? $args['std'] : '';
660
-		$name  = '';
661
-	} else {
662
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
663
-	}
664
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
665
-
666
-	$readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
667
-	$size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
668
-	$html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
669
-	$html    .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
670
-
671
-	echo $html;
651
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
652
+        $value = $wpinv_options[ $args['id'] ];
653
+    } else {
654
+        $value = isset( $args['std'] ) ? $args['std'] : '';
655
+    }
656
+
657
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
658
+        $args['readonly'] = true;
659
+        $value = isset( $args['std'] ) ? $args['std'] : '';
660
+        $name  = '';
661
+    } else {
662
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
663
+    }
664
+    $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
665
+
666
+    $readonly = $args['readonly'] === true ? ' readonly="readonly"' : '';
667
+    $size     = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
668
+    $html     = '<input type="text" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"' . $readonly . '/>';
669
+    $html    .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
670
+
671
+    echo $html;
672 672
 }
673 673
 
674 674
 function wpinv_number_callback( $args ) {
675
-	global $wpinv_options;
675
+    global $wpinv_options;
676 676
     
677 677
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
678 678
 
679
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
680
-		$value = $wpinv_options[ $args['id'] ];
681
-	} else {
682
-		$value = isset( $args['std'] ) ? $args['std'] : '';
683
-	}
684
-
685
-	if ( isset( $args['faux'] ) && true === $args['faux'] ) {
686
-		$args['readonly'] = true;
687
-		$value = isset( $args['std'] ) ? $args['std'] : '';
688
-		$name  = '';
689
-	} else {
690
-		$name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
691
-	}
692
-
693
-	$max  = isset( $args['max'] ) ? $args['max'] : 999999;
694
-	$min  = isset( $args['min'] ) ? $args['min'] : 0;
695
-	$step = isset( $args['step'] ) ? $args['step'] : 1;
696
-	$class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
697
-
698
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
699
-	$html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
700
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
701
-
702
-	echo $html;
679
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
680
+        $value = $wpinv_options[ $args['id'] ];
681
+    } else {
682
+        $value = isset( $args['std'] ) ? $args['std'] : '';
683
+    }
684
+
685
+    if ( isset( $args['faux'] ) && true === $args['faux'] ) {
686
+        $args['readonly'] = true;
687
+        $value = isset( $args['std'] ) ? $args['std'] : '';
688
+        $name  = '';
689
+    } else {
690
+        $name = 'name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"';
691
+    }
692
+
693
+    $max  = isset( $args['max'] ) ? $args['max'] : 999999;
694
+    $min  = isset( $args['min'] ) ? $args['min'] : 0;
695
+    $step = isset( $args['step'] ) ? $args['step'] : 1;
696
+    $class = !empty( $args['class'] ) ? sanitize_html_class( $args['class'] ) : '';
697
+
698
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
699
+    $html = '<input type="number" step="' . esc_attr( $step ) . '" max="' . esc_attr( $max ) . '" min="' . esc_attr( $min ) . '" class="' . sanitize_html_class( $size ) . '-text ' . $class . '" id="wpinv_settings[' . $sanitize_id . ']" ' . $name . ' value="' . esc_attr( stripslashes( $value ) ) . '"/>';
700
+    $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
701
+
702
+    echo $html;
703 703
 }
704 704
 
705 705
 function wpinv_textarea_callback( $args ) {
706
-	global $wpinv_options;
706
+    global $wpinv_options;
707 707
     
708 708
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
709 709
 
710
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
711
-		$value = $wpinv_options[ $args['id'] ];
712
-	} else {
713
-		$value = isset( $args['std'] ) ? $args['std'] : '';
714
-	}
710
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
711
+        $value = $wpinv_options[ $args['id'] ];
712
+    } else {
713
+        $value = isset( $args['std'] ) ? $args['std'] : '';
714
+    }
715 715
     
716 716
     $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
717 717
     $class = ( isset( $args['class'] ) && ! is_null( $args['class'] ) ) ? $args['class'] : 'large-text';
718 718
 
719
-	$html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
720
-	$html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
719
+    $html = '<textarea class="' . sanitize_html_class( $class ) . ' txtarea-' . sanitize_html_class( $size ) . ' wpi-' . esc_attr( sanitize_html_class( $sanitize_id ) ) . ' " cols="' . $args['cols'] . '" rows="' . $args['rows'] . '" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
720
+    $html .= '<br /><label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
721 721
 
722
-	echo $html;
722
+    echo $html;
723 723
 }
724 724
 
725 725
 function wpinv_password_callback( $args ) {
726
-	global $wpinv_options;
726
+    global $wpinv_options;
727 727
     
728 728
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
729 729
 
730
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
731
-		$value = $wpinv_options[ $args['id'] ];
732
-	} else {
733
-		$value = isset( $args['std'] ) ? $args['std'] : '';
734
-	}
730
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
731
+        $value = $wpinv_options[ $args['id'] ];
732
+    } else {
733
+        $value = isset( $args['std'] ) ? $args['std'] : '';
734
+    }
735 735
 
736
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
737
-	$html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
738
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
736
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
737
+    $html = '<input type="password" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '"/>';
738
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
739 739
 
740
-	echo $html;
740
+    echo $html;
741 741
 }
742 742
 
743 743
 function wpinv_missing_callback($args) {
744
-	printf(
745
-		__( 'The callback function used for the %s setting is missing.', 'invoicing' ),
746
-		'<strong>' . $args['id'] . '</strong>'
747
-	);
744
+    printf(
745
+        __( 'The callback function used for the %s setting is missing.', 'invoicing' ),
746
+        '<strong>' . $args['id'] . '</strong>'
747
+    );
748 748
 }
749 749
 
750 750
 function wpinv_select_callback($args) {
751
-	global $wpinv_options;
751
+    global $wpinv_options;
752 752
     
753 753
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
754 754
 
755
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
756
-		$value = $wpinv_options[ $args['id'] ];
757
-	} else {
758
-		$value = isset( $args['std'] ) ? $args['std'] : '';
759
-	}
755
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
756
+        $value = $wpinv_options[ $args['id'] ];
757
+    } else {
758
+        $value = isset( $args['std'] ) ? $args['std'] : '';
759
+    }
760 760
     
761 761
     if ( isset( $args['selected'] ) && $args['selected'] !== null && $args['selected'] !== false ) {
762 762
         $value = $args['selected'];
763 763
     }
764 764
 
765
-	if ( isset( $args['placeholder'] ) ) {
766
-		$placeholder = $args['placeholder'];
767
-	} else {
768
-		$placeholder = '';
769
-	}
765
+    if ( isset( $args['placeholder'] ) ) {
766
+        $placeholder = $args['placeholder'];
767
+    } else {
768
+        $placeholder = '';
769
+    }
770 770
     
771 771
     if( !empty( $args['onchange'] ) ) {
772 772
         $onchange = ' onchange="' . esc_attr( $args['onchange'] ) . '"';
@@ -776,142 +776,142 @@  discard block
 block discarded – undo
776 776
 
777 777
     $class = !empty( $args['class'] ) ? ' ' . esc_attr( $args['class'] ) : '';
778 778
 
779
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'"  name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
779
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" class="'.$class.'"  name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" data-placeholder="' . esc_html( $placeholder ) . '"' . $onchange . ' />';
780 780
 
781
-	foreach ( $args['options'] as $option => $name ) {
782
-		$selected = selected( $option, $value, false );
783
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
784
-	}
781
+    foreach ( $args['options'] as $option => $name ) {
782
+        $selected = selected( $option, $value, false );
783
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
784
+    }
785 785
 
786
-	$html .= '</select>';
787
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
786
+    $html .= '</select>';
787
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
788 788
 
789
-	echo $html;
789
+    echo $html;
790 790
 }
791 791
 
792 792
 function wpinv_color_select_callback( $args ) {
793
-	global $wpinv_options;
793
+    global $wpinv_options;
794 794
     
795 795
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
796 796
 
797
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
798
-		$value = $wpinv_options[ $args['id'] ];
799
-	} else {
800
-		$value = isset( $args['std'] ) ? $args['std'] : '';
801
-	}
797
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
798
+        $value = $wpinv_options[ $args['id'] ];
799
+    } else {
800
+        $value = isset( $args['std'] ) ? $args['std'] : '';
801
+    }
802 802
 
803
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
803
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"/>';
804 804
 
805
-	foreach ( $args['options'] as $option => $color ) {
806
-		$selected = selected( $option, $value, false );
807
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
808
-	}
805
+    foreach ( $args['options'] as $option => $color ) {
806
+        $selected = selected( $option, $value, false );
807
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $color['label'] ) . '</option>';
808
+    }
809 809
 
810
-	$html .= '</select>';
811
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
810
+    $html .= '</select>';
811
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
812 812
 
813
-	echo $html;
813
+    echo $html;
814 814
 }
815 815
 
816 816
 function wpinv_rich_editor_callback( $args ) {
817
-	global $wpinv_options, $wp_version;
817
+    global $wpinv_options, $wp_version;
818 818
     
819 819
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
820 820
 
821
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
822
-		$value = $wpinv_options[ $args['id'] ];
821
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
822
+        $value = $wpinv_options[ $args['id'] ];
823 823
 
824
-		if( empty( $args['allow_blank'] ) && empty( $value ) ) {
825
-			$value = isset( $args['std'] ) ? $args['std'] : '';
826
-		}
827
-	} else {
828
-		$value = isset( $args['std'] ) ? $args['std'] : '';
829
-	}
824
+        if( empty( $args['allow_blank'] ) && empty( $value ) ) {
825
+            $value = isset( $args['std'] ) ? $args['std'] : '';
826
+        }
827
+    } else {
828
+        $value = isset( $args['std'] ) ? $args['std'] : '';
829
+    }
830 830
 
831
-	$rows = isset( $args['size'] ) ? $args['size'] : 20;
831
+    $rows = isset( $args['size'] ) ? $args['size'] : 20;
832 832
 
833
-	$html = '<div class="getpaid-settings-editor-input">';
834
-	if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
835
-		ob_start();
836
-		wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
837
-		$html .= ob_get_clean();
838
-	} else {
839
-		$html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
840
-	}
833
+    $html = '<div class="getpaid-settings-editor-input">';
834
+    if ( $wp_version >= 3.3 && function_exists( 'wp_editor' ) ) {
835
+        ob_start();
836
+        wp_editor( stripslashes( $value ), 'wpinv_settings_' . esc_attr( $args['id'] ), array( 'textarea_name' => 'wpinv_settings[' . esc_attr( $args['id'] ) . ']', 'textarea_rows' => absint( $rows ), 'media_buttons' => false ) );
837
+        $html .= ob_get_clean();
838
+    } else {
839
+        $html .= '<textarea class="large-text" rows="10" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" class="wpi-' . esc_attr( sanitize_html_class( $args['id'] ) ) . '">' . esc_textarea( stripslashes( $value ) ) . '</textarea>';
840
+    }
841 841
 
842
-	$html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
842
+    $html .= '</div><br/><label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
843 843
 
844
-	echo $html;
844
+    echo $html;
845 845
 }
846 846
 
847 847
 function wpinv_upload_callback( $args ) {
848
-	global $wpinv_options;
848
+    global $wpinv_options;
849 849
     
850 850
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
851 851
 
852
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
853
-		$value = $wpinv_options[$args['id']];
854
-	} else {
855
-		$value = isset($args['std']) ? $args['std'] : '';
856
-	}
852
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
853
+        $value = $wpinv_options[$args['id']];
854
+    } else {
855
+        $value = isset($args['std']) ? $args['std'] : '';
856
+    }
857 857
 
858
-	$size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
859
-	$html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
860
-	$html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
861
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
858
+    $size = ( isset( $args['size'] ) && ! is_null( $args['size'] ) ) ? $args['size'] : 'regular';
859
+    $html = '<input type="text" class="' . sanitize_html_class( $size ) . '-text" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( stripslashes( $value ) ) . '"/>';
860
+    $html .= '<span>&nbsp;<input type="button" class="wpinv_settings_upload_button button-secondary" value="' . __( 'Upload File', 'invoicing' ) . '"/></span>';
861
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> ' . wp_kses_post( $args['desc'] ) . '</label>';
862 862
 
863
-	echo $html;
863
+    echo $html;
864 864
 }
865 865
 
866 866
 function wpinv_color_callback( $args ) {
867
-	global $wpinv_options;
867
+    global $wpinv_options;
868 868
     
869 869
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
870 870
 
871
-	if ( isset( $wpinv_options[ $args['id'] ] ) ) {
872
-		$value = $wpinv_options[ $args['id'] ];
873
-	} else {
874
-		$value = isset( $args['std'] ) ? $args['std'] : '';
875
-	}
871
+    if ( isset( $wpinv_options[ $args['id'] ] ) ) {
872
+        $value = $wpinv_options[ $args['id'] ];
873
+    } else {
874
+        $value = isset( $args['std'] ) ? $args['std'] : '';
875
+    }
876 876
 
877
-	$default = isset( $args['std'] ) ? $args['std'] : '';
877
+    $default = isset( $args['std'] ) ? $args['std'] : '';
878 878
 
879
-	$html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
880
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
879
+    $html = '<input type="text" class="wpinv-color-picker" id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']" value="' . esc_attr( $value ) . '" data-default-color="' . esc_attr( $default ) . '" />';
880
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
881 881
 
882
-	echo $html;
882
+    echo $html;
883 883
 }
884 884
 
885 885
 function wpinv_country_states_callback($args) {
886
-	global $wpinv_options;
886
+    global $wpinv_options;
887 887
     
888 888
     $sanitize_id = wpinv_sanitize_key( $args['id'] );
889 889
 
890
-	if ( isset( $args['placeholder'] ) ) {
891
-		$placeholder = $args['placeholder'];
892
-	} else {
893
-		$placeholder = '';
894
-	}
890
+    if ( isset( $args['placeholder'] ) ) {
891
+        $placeholder = $args['placeholder'];
892
+    } else {
893
+        $placeholder = '';
894
+    }
895 895
 
896
-	$states = wpinv_get_country_states();
896
+    $states = wpinv_get_country_states();
897 897
 
898
-	$class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
899
-	$html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
898
+    $class = empty( $states ) ? ' class="wpinv-no-states"' : ' class="wpi_select2"';
899
+    $html = '<select id="wpinv_settings[' . $sanitize_id . ']" name="wpinv_settings[' . esc_attr( $args['id'] ) . ']"' . $class . 'data-placeholder="' . esc_html( $placeholder ) . '"/>';
900 900
 
901
-	foreach ( $states as $option => $name ) {
902
-		$selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
903
-		$html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
904
-	}
901
+    foreach ( $states as $option => $name ) {
902
+        $selected = isset( $wpinv_options[ $args['id'] ] ) ? selected( $option, $wpinv_options[$args['id']], false ) : '';
903
+        $html .= '<option value="' . esc_attr( $option ) . '" ' . $selected . '>' . esc_html( $name ) . '</option>';
904
+    }
905 905
 
906
-	$html .= '</select>';
907
-	$html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
906
+    $html .= '</select>';
907
+    $html .= '<label for="wpinv_settings[' . $sanitize_id . ']"> '  . wp_kses_post( $args['desc'] ) . '</label>';
908 908
 
909
-	echo $html;
909
+    echo $html;
910 910
 }
911 911
 
912 912
 function wpinv_tax_rates_callback($args) {
913
-	$rates = GetPaid_Tax::get_all_tax_rates();
914
-	ob_start(); ?>
913
+    $rates = GetPaid_Tax::get_all_tax_rates();
914
+    ob_start(); ?>
915 915
     </td><tr>
916 916
     <td colspan="2" class="wpinv_tax_tdbox">
917 917
 	<p><?php echo $args['desc']; ?></p>
@@ -935,40 +935,40 @@  discard block
 block discarded – undo
935 935
 			<tr>
936 936
 				<td class="wpinv_tax_country">
937 937
 					<?php
938
-					echo wpinv_html_select( array(
939
-						'options'          => wpinv_get_country_list( true ),
940
-						'name'             => 'tax_rates[' . $sanitized_key . '][country]',
938
+                    echo wpinv_html_select( array(
939
+                        'options'          => wpinv_get_country_list( true ),
940
+                        'name'             => 'tax_rates[' . $sanitized_key . '][country]',
941 941
                         'id'               => 'tax_rates[' . $sanitized_key . '][country]',
942
-						'selected'         => $rate['country'],
943
-						'show_option_all'  => false,
944
-						'show_option_none' => false,
945
-						'class'            => 'wpinv-tax-country wpi_select2',
946
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
947
-					) );
948
-					?>
942
+                        'selected'         => $rate['country'],
943
+                        'show_option_all'  => false,
944
+                        'show_option_none' => false,
945
+                        'class'            => 'wpinv-tax-country wpi_select2',
946
+                        'placeholder'      => __( 'Choose a country', 'invoicing' )
947
+                    ) );
948
+                    ?>
949 949
 				</td>
950 950
 				<td class="wpinv_tax_state">
951 951
 					<?php
952
-					$states = wpinv_get_country_states( $rate['country'] );
953
-					if( !empty( $states ) ) {
954
-						echo wpinv_html_select( array(
955
-							'options'          => array_merge( array( '' => '' ), $states ),
956
-							'name'             => 'tax_rates[' . $sanitized_key . '][state]',
952
+                    $states = wpinv_get_country_states( $rate['country'] );
953
+                    if( !empty( $states ) ) {
954
+                        echo wpinv_html_select( array(
955
+                            'options'          => array_merge( array( '' => '' ), $states ),
956
+                            'name'             => 'tax_rates[' . $sanitized_key . '][state]',
957 957
                             'id'               => 'tax_rates[' . $sanitized_key . '][state]',
958
-							'selected'         => $rate['state'],
959
-							'show_option_all'  => false,
960
-							'show_option_none' => false,
958
+                            'selected'         => $rate['state'],
959
+                            'show_option_all'  => false,
960
+                            'show_option_none' => false,
961 961
                             'class'            => 'wpi_select2',
962
-							'placeholder'      => __( 'Choose a state', 'invoicing' )
963
-						) );
964
-					} else {
965
-						echo wpinv_html_text( array(
966
-							'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
967
-							'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
962
+                            'placeholder'      => __( 'Choose a state', 'invoicing' )
963
+                        ) );
964
+                    } else {
965
+                        echo wpinv_html_text( array(
966
+                            'name'  => 'tax_rates[' . $sanitized_key . '][state]', $rate['state'],
967
+                            'value' => ! empty( $rate['state'] ) ? $rate['state'] : '',
968 968
                             'id'    => 'tax_rates[' . $sanitized_key . '][state]',
969
-						) );
970
-					}
971
-					?>
969
+                        ) );
970
+                    }
971
+                    ?>
972 972
 				</td>
973 973
 				<td class="wpinv_tax_global">
974 974
 					<input type="checkbox" name="tax_rates[<?php echo $sanitized_key; ?>][global]" id="tax_rates[<?php echo $sanitized_key; ?>][global]" value="1"<?php checked( true, ! empty( $rate['global'] ) ); ?>/>
@@ -983,19 +983,19 @@  discard block
 block discarded – undo
983 983
 			<tr>
984 984
 				<td class="wpinv_tax_country">
985 985
 					<?php
986
-					echo wpinv_html_select( array(
987
-						'options'          => wpinv_get_country_list( true ),
988
-						'name'             => 'tax_rates[0][country]',
989
-						'show_option_all'  => false,
990
-						'show_option_none' => false,
991
-						'class'            => 'wpinv-tax-country wpi_select2',
992
-						'placeholder'      => __( 'Choose a country', 'invoicing' )
993
-					) ); ?>
986
+                    echo wpinv_html_select( array(
987
+                        'options'          => wpinv_get_country_list( true ),
988
+                        'name'             => 'tax_rates[0][country]',
989
+                        'show_option_all'  => false,
990
+                        'show_option_none' => false,
991
+                        'class'            => 'wpinv-tax-country wpi_select2',
992
+                        'placeholder'      => __( 'Choose a country', 'invoicing' )
993
+                    ) ); ?>
994 994
 				</td>
995 995
 				<td class="wpinv_tax_state">
996 996
 					<?php echo wpinv_html_text( array(
997
-						'name' => 'tax_rates[0][state]'
998
-					) ); ?>
997
+                        'name' => 'tax_rates[0][state]'
998
+                    ) ); ?>
999 999
 				</td>
1000 1000
 				<td class="wpinv_tax_global">
1001 1001
 					<input type="checkbox" name="tax_rates[0][global]" id="tax_rates[0][global]" value="1"/>
@@ -1010,7 +1010,7 @@  discard block
 block discarded – undo
1010 1010
         <tfoot><tr><td colspan="5"></td><td class="wpinv_tax_action"><span class="button-secondary" id="wpinv_add_tax_rate"><?php _e( 'Add Tax Rate', 'invoicing' ); ?></span></td></tr></tfoot>
1011 1011
 	</table>
1012 1012
 	<?php
1013
-	echo ob_get_clean();
1013
+    echo ob_get_clean();
1014 1014
 }
1015 1015
 
1016 1016
 function wpinv_tools_callback($args) {
@@ -1038,15 +1038,15 @@  discard block
 block discarded – undo
1038 1038
 }
1039 1039
 
1040 1040
 function wpinv_descriptive_text_callback( $args ) {
1041
-	echo wp_kses_post( $args['desc'] );
1041
+    echo wp_kses_post( $args['desc'] );
1042 1042
 }
1043 1043
 
1044 1044
 function wpinv_hook_callback( $args ) {
1045
-	do_action( 'wpinv_' . $args['id'], $args );
1045
+    do_action( 'wpinv_' . $args['id'], $args );
1046 1046
 }
1047 1047
 
1048 1048
 function wpinv_set_settings_cap() {
1049
-	return wpinv_get_capability();
1049
+    return wpinv_get_capability();
1050 1050
 }
1051 1051
 add_filter( 'option_page_capability_wpinv_settings', 'wpinv_set_settings_cap' );
1052 1052
 
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Indentation   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -97,13 +97,13 @@  discard block
 block discarded – undo
97 97
  */
98 98
 function wpinv_get_invoice_statuses( $draft = false, $trashed = false, $invoice = false ) {
99 99
 
100
-	$invoice_statuses = array(
101
-		'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
100
+    $invoice_statuses = array(
101
+        'wpi-pending'    => _x( 'Pending payment', 'Invoice status', 'invoicing' ),
102 102
         'publish'        => _x( 'Paid', 'Invoice status', 'invoicing' ),
103 103
         'wpi-processing' => _x( 'Processing', 'Invoice status', 'invoicing' ),
104
-		'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
105
-		'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
106
-		'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
104
+        'wpi-onhold'     => _x( 'On hold', 'Invoice status', 'invoicing' ),
105
+        'wpi-cancelled'  => _x( 'Cancelled', 'Invoice status', 'invoicing' ),
106
+        'wpi-refunded'   => _x( 'Refunded', 'Invoice status', 'invoicing' ),
107 107
         'wpi-failed'     => _x( 'Failed', 'Invoice status', 'invoicing' ),
108 108
         'wpi-renewal'    => _x( 'Renewal Payment', 'Invoice status', 'invoicing' ),
109 109
     );
@@ -120,7 +120,7 @@  discard block
 block discarded – undo
120 120
         $invoice = $invoice->get_post_type();
121 121
     }
122 122
 
123
-	return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
123
+    return apply_filters( 'wpinv_statuses', $invoice_statuses, $invoice );
124 124
 }
125 125
 
126 126
 /**
@@ -238,25 +238,25 @@  discard block
 block discarded – undo
238 238
  * @return string
239 239
  */
240 240
 function getpaid_get_price_format() {
241
-	$currency_pos = wpinv_currency_position();
242
-	$format       = '%1$s%2$s';
243
-
244
-	switch ( $currency_pos ) {
245
-		case 'left':
246
-			$format = '%1$s%2$s';
247
-			break;
248
-		case 'right':
249
-			$format = '%2$s%1$s';
250
-			break;
251
-		case 'left_space':
252
-			$format = '%1$s&nbsp;%2$s';
253
-			break;
254
-		case 'right_space':
255
-			$format = '%2$s&nbsp;%1$s';
256
-			break;
257
-	}
258
-
259
-	return apply_filters( 'getpaid_price_format', $format, $currency_pos );
241
+    $currency_pos = wpinv_currency_position();
242
+    $format       = '%1$s%2$s';
243
+
244
+    switch ( $currency_pos ) {
245
+        case 'left':
246
+            $format = '%1$s%2$s';
247
+            break;
248
+        case 'right':
249
+            $format = '%2$s%1$s';
250
+            break;
251
+        case 'left_space':
252
+            $format = '%1$s&nbsp;%2$s';
253
+            break;
254
+        case 'right_space':
255
+            $format = '%2$s&nbsp;%1$s';
256
+            break;
257
+    }
258
+
259
+    return apply_filters( 'getpaid_price_format', $format, $currency_pos );
260 260
 }
261 261
 
262 262
 /**
@@ -359,13 +359,13 @@  discard block
 block discarded – undo
359 359
  * @param mixed  $value Value.
360 360
  */
361 361
 function getpaid_maybe_define_constant( $name, $value ) {
362
-	if ( ! defined( $name ) ) {
363
-		define( $name, $value );
364
-	}
362
+    if ( ! defined( $name ) ) {
363
+        define( $name, $value );
364
+    }
365 365
 }
366 366
 
367 367
 function wpinv_get_php_arg_separator_output() {
368
-	return ini_get( 'arg_separator.output' );
368
+    return ini_get( 'arg_separator.output' );
369 369
 }
370 370
 
371 371
 function wpinv_rgb_from_hex( $color ) {
@@ -716,11 +716,11 @@  discard block
 block discarded – undo
716 716
         $list = array();
717 717
     }
718 718
 
719
-	if ( ! is_array( $list ) ) {
720
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
721
-	}
719
+    if ( ! is_array( $list ) ) {
720
+        return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
721
+    }
722 722
 
723
-	return $list;
723
+    return $list;
724 724
 }
725 725
 
726 726
 /**
@@ -740,9 +740,9 @@  discard block
 block discarded – undo
740 740
     }
741 741
 
742 742
     $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
743
-	wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
743
+    wp_cache_set( "wpinv-data-$key", $data, 'wpinv' );
744 744
 
745
-	return $data;
745
+    return $data;
746 746
 }
747 747
 
748 748
 /**
@@ -771,17 +771,17 @@  discard block
 block discarded – undo
771 771
  */
772 772
 function wpinv_clean( $var ) {
773 773
 
774
-	if ( is_array( $var ) ) {
775
-		return array_map( 'wpinv_clean', $var );
774
+    if ( is_array( $var ) ) {
775
+        return array_map( 'wpinv_clean', $var );
776 776
     }
777 777
 
778 778
     if ( is_object( $var ) ) {
779
-		$object_vars = get_object_vars( $var );
780
-		foreach ( $object_vars as $property_name => $property_value ) {
781
-			$var->$property_name = wpinv_clean( $property_value );
779
+        $object_vars = get_object_vars( $var );
780
+        foreach ( $object_vars as $property_name => $property_value ) {
781
+            $var->$property_name = wpinv_clean( $property_value );
782 782
         }
783 783
         return $var;
784
-	}
784
+    }
785 785
     
786 786
     return is_string( $var ) ? sanitize_text_field( $var ) : $var;
787 787
 }
@@ -794,7 +794,7 @@  discard block
 block discarded – undo
794 794
  */
795 795
 function getpaid_convert_price_string_to_options( $str ) {
796 796
 
797
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
797
+    $raw_options = array_map( 'trim', explode( ',', $str ) );
798 798
     $options     = array();
799 799
 
800 800
     foreach ( $raw_options as $option ) {
@@ -872,7 +872,7 @@  discard block
 block discarded – undo
872 872
  * @return string
873 873
  */
874 874
 function getpaid_date_format() {
875
-	return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
875
+    return apply_filters( 'getpaid_date_format', get_option( 'date_format' ) );
876 876
 }
877 877
 
878 878
 /**
@@ -881,7 +881,7 @@  discard block
 block discarded – undo
881 881
  * @return string
882 882
  */
883 883
 function getpaid_time_format() {
884
-	return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
884
+    return apply_filters( 'getpaid_time_format', get_option( 'time_format' ) );
885 885
 }
886 886
 
887 887
 /**
@@ -894,15 +894,15 @@  discard block
 block discarded – undo
894 894
 function getpaid_limit_length( $string, $limit ) {
895 895
     $str_limit = $limit - 3;
896 896
 
897
-	if ( function_exists( 'mb_strimwidth' ) ) {
898
-		if ( mb_strlen( $string ) > $limit ) {
899
-			$string = mb_strimwidth( $string, 0, $str_limit ) . '...';
900
-		}
901
-	} else {
902
-		if ( strlen( $string ) > $limit ) {
903
-			$string = substr( $string, 0, $str_limit ) . '...';
904
-		}
905
-	}
897
+    if ( function_exists( 'mb_strimwidth' ) ) {
898
+        if ( mb_strlen( $string ) > $limit ) {
899
+            $string = mb_strimwidth( $string, 0, $str_limit ) . '...';
900
+        }
901
+    } else {
902
+        if ( strlen( $string ) > $limit ) {
903
+            $string = substr( $string, 0, $str_limit ) . '...';
904
+        }
905
+    }
906 906
     return $string;
907 907
 
908 908
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +184 added lines, -184 removed lines patch added patch discarded remove patch
@@ -12,224 +12,224 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id' => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id' => $submission->id,
30 30
             'has_recurring' => $submission->has_recurring,
31 31
             'is_free'       => ! $submission->should_collect_payment_details(),
32
-		);
33
-
34
-		$this->add_totals( $submission );
35
-		$this->add_texts( $submission );
36
-		$this->add_items( $submission );
37
-		$this->add_fees( $submission );
38
-		$this->add_discounts( $submission );
39
-		$this->add_taxes( $submission );
40
-		$this->add_gateways( $submission );
41
-
42
-	}
43
-
44
-	/**
45
-	 * Adds totals to a response for submission refresh prices.
46
-	 *
47
-	 * @param GetPaid_Payment_Form_Submission $submission
48
-	 */
49
-	public function add_totals( $submission ) {
50
-
51
-		$this->response = array_merge(
52
-			$this->response,
53
-			array(
54
-
55
-				'totals'        => array(
56
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
58
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
59
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
60
-					'total'     => $submission->format_amount( $submission->get_total() ),
61
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
62
-				),
63
-
64
-				'recurring'     => array(
65
-					'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
66
-					'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
67
-					'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
68
-					'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
69
-					'total'     => $submission->format_amount( $submission->get_recurring_total() ),
70
-				),
71
-
72
-			)
73
-		);
74
-
75
-	}
76
-
77
-	/**
78
-	 * Adds texts to a response for submission refresh prices.
79
-	 *
80
-	 * @param GetPaid_Payment_Form_Submission $submission
81
-	 */
82
-	public function add_texts( $submission ) {
83
-
84
-		$payable = $submission->format_amount( $submission->get_total() );
85
-
86
-		if ( $submission->has_recurring != 0 ) {
87
-
88
-			$recurring = new WPInv_Item( $submission->has_recurring );
89
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
90
-
91
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
92
-				$payable = "$payable / $period";
93
-			} else {
94
-				$payable = sprintf(
95
-					__( '%1$s (renews at %2$s / %3$s)'),
96
-					$submission->format_amount( $submission->get_total() ),
97
-					$submission->format_amount( $submission->get_recurring_total() ),
98
-					$period
99
-				);
100
-			}
101
-
102
-		}
103
-
104
-		$texts = array(
105
-			'.getpaid-checkout-total-payable' => $payable,
106
-		);
107
-
108
-		foreach ( $submission->get_items() as $item_id => $item ) {
109
-			$texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
110
-			$texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
111
-		}
112
-
113
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
114
-
115
-	}
116
-
117
-	/**
118
-	 * Adds items to a response for submission refresh prices.
119
-	 *
120
-	 * @param GetPaid_Payment_Form_Submission $submission
121
-	 */
122
-	public function add_items( $submission ) {
123
-
124
-		// Add items.
125
-		$items = array();
32
+        );
33
+
34
+        $this->add_totals( $submission );
35
+        $this->add_texts( $submission );
36
+        $this->add_items( $submission );
37
+        $this->add_fees( $submission );
38
+        $this->add_discounts( $submission );
39
+        $this->add_taxes( $submission );
40
+        $this->add_gateways( $submission );
41
+
42
+    }
43
+
44
+    /**
45
+     * Adds totals to a response for submission refresh prices.
46
+     *
47
+     * @param GetPaid_Payment_Form_Submission $submission
48
+     */
49
+    public function add_totals( $submission ) {
50
+
51
+        $this->response = array_merge(
52
+            $this->response,
53
+            array(
54
+
55
+                'totals'        => array(
56
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
57
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
58
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
59
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
60
+                    'total'     => $submission->format_amount( $submission->get_total() ),
61
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
62
+                ),
63
+
64
+                'recurring'     => array(
65
+                    'subtotal'  => $submission->format_amount( $submission->get_recurring_subtotal() ),
66
+                    'discount'  => $submission->format_amount( $submission->get_recurring_discount() ),
67
+                    'fees'      => $submission->format_amount( $submission->get_recurring_fee() ),
68
+                    'tax'       => $submission->format_amount( $submission->get_recurring_tax() ),
69
+                    'total'     => $submission->format_amount( $submission->get_recurring_total() ),
70
+                ),
71
+
72
+            )
73
+        );
74
+
75
+    }
76
+
77
+    /**
78
+     * Adds texts to a response for submission refresh prices.
79
+     *
80
+     * @param GetPaid_Payment_Form_Submission $submission
81
+     */
82
+    public function add_texts( $submission ) {
83
+
84
+        $payable = $submission->format_amount( $submission->get_total() );
85
+
86
+        if ( $submission->has_recurring != 0 ) {
87
+
88
+            $recurring = new WPInv_Item( $submission->has_recurring );
89
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
90
+
91
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
92
+                $payable = "$payable / $period";
93
+            } else {
94
+                $payable = sprintf(
95
+                    __( '%1$s (renews at %2$s / %3$s)'),
96
+                    $submission->format_amount( $submission->get_total() ),
97
+                    $submission->format_amount( $submission->get_recurring_total() ),
98
+                    $period
99
+                );
100
+            }
101
+
102
+        }
103
+
104
+        $texts = array(
105
+            '.getpaid-checkout-total-payable' => $payable,
106
+        );
126 107
 
127 108
         foreach ( $submission->get_items() as $item_id => $item ) {
128
-			$items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
129
-		}
109
+            $texts[".item-$item_id .getpaid-item-initial-price"]   = $submission->format_amount( $item->get_sub_total() );
110
+            $texts[".item-$item_id .getpaid-item-recurring-price"] = $submission->format_amount( $item->get_recurring_sub_total() );
111
+        }
130 112
 
131
-		$this->response = array_merge(
132
-			$this->response,
133
-			array( 'items' => $items )
134
-		);
113
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
135 114
 
136
-	}
115
+    }
137 116
 
138
-	/**
139
-	 * Adds fees to a response for submission refresh prices.
140
-	 *
141
-	 * @param GetPaid_Payment_Form_Submission $submission
142
-	 */
143
-	public function add_fees( $submission ) {
117
+    /**
118
+     * Adds items to a response for submission refresh prices.
119
+     *
120
+     * @param GetPaid_Payment_Form_Submission $submission
121
+     */
122
+    public function add_items( $submission ) {
123
+
124
+        // Add items.
125
+        $items = array();
126
+
127
+        foreach ( $submission->get_items() as $item_id => $item ) {
128
+            $items["$item_id"] = $submission->format_amount( $item->get_sub_total() );
129
+        }
130
+
131
+        $this->response = array_merge(
132
+            $this->response,
133
+            array( 'items' => $items )
134
+        );
135
+
136
+    }
144 137
 
145
-		$fees = array();
138
+    /**
139
+     * Adds fees to a response for submission refresh prices.
140
+     *
141
+     * @param GetPaid_Payment_Form_Submission $submission
142
+     */
143
+    public function add_fees( $submission ) {
144
+
145
+        $fees = array();
146 146
 
147 147
         foreach ( $submission->get_fees() as $name => $data ) {
148
-			$fees[$name] = $submission->format_amount( $data['initial_fee'] );
149
-		}
148
+            $fees[$name] = $submission->format_amount( $data['initial_fee'] );
149
+        }
150 150
 
151
-		$this->response = array_merge(
152
-			$this->response,
153
-			array( 'fees' => $fees )
154
-		);
151
+        $this->response = array_merge(
152
+            $this->response,
153
+            array( 'fees' => $fees )
154
+        );
155 155
 
156
-	}
156
+    }
157 157
 
158
-	/**
159
-	 * Adds discounts to a response for submission refresh prices.
160
-	 *
161
-	 * @param GetPaid_Payment_Form_Submission $submission
162
-	 */
163
-	public function add_discounts( $submission ) {
158
+    /**
159
+     * Adds discounts to a response for submission refresh prices.
160
+     *
161
+     * @param GetPaid_Payment_Form_Submission $submission
162
+     */
163
+    public function add_discounts( $submission ) {
164 164
 
165
-		$discounts = array();
165
+        $discounts = array();
166 166
 
167 167
         foreach ( $submission->get_discounts() as $name => $data ) {
168
-			$discounts[$name] = $submission->format_amount( $data['initial_discount'] );
169
-		}
168
+            $discounts[$name] = $submission->format_amount( $data['initial_discount'] );
169
+        }
170 170
 
171
-		$this->response = array_merge(
172
-			$this->response,
173
-			array( 'discounts' => $discounts )
174
-		);
171
+        $this->response = array_merge(
172
+            $this->response,
173
+            array( 'discounts' => $discounts )
174
+        );
175 175
 
176
-	}
176
+    }
177 177
 
178
-	/**
179
-	 * Adds taxes to a response for submission refresh prices.
180
-	 *
181
-	 * @param GetPaid_Payment_Form_Submission $submission
182
-	 */
183
-	public function add_taxes( $submission ) {
184
-
185
-		$taxes  = array();
186
-		$markup = '';
178
+    /**
179
+     * Adds taxes to a response for submission refresh prices.
180
+     *
181
+     * @param GetPaid_Payment_Form_Submission $submission
182
+     */
183
+    public function add_taxes( $submission ) {
184
+
185
+        $taxes  = array();
186
+        $markup = '';
187 187
         foreach ( $submission->get_taxes() as $name => $data ) {
188
-			$name          = sanitize_text_field( $name );
189
-			$amount        = $submission->format_amount( $data['initial_tax'] );
190
-			$taxes[$name]  = $amount;
191
-			$markup       .= "<small class='form-text'>$name : $amount</small>";
192
-		}
188
+            $name          = sanitize_text_field( $name );
189
+            $amount        = $submission->format_amount( $data['initial_tax'] );
190
+            $taxes[$name]  = $amount;
191
+            $markup       .= "<small class='form-text'>$name : $amount</small>";
192
+        }
193 193
 
194
-		if ( wpinv_display_individual_tax_rates() ) {
195
-			$this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
196
-		}
194
+        if ( wpinv_display_individual_tax_rates() ) {
195
+            $this->response['texts']['.getpaid-form-cart-totals-total-tax'] = $markup;
196
+        }
197 197
 
198
-		$this->response = array_merge(
199
-			$this->response,
200
-			array( 'taxes' => $taxes )
201
-		);
198
+        $this->response = array_merge(
199
+            $this->response,
200
+            array( 'taxes' => $taxes )
201
+        );
202 202
 
203
-	}
203
+    }
204 204
 
205
-	/**
206
-	 * Adds gateways to a response for submission refresh prices.
207
-	 *
208
-	 * @param GetPaid_Payment_Form_Submission $submission
209
-	 */
210
-	public function add_gateways( $submission ) {
205
+    /**
206
+     * Adds gateways to a response for submission refresh prices.
207
+     *
208
+     * @param GetPaid_Payment_Form_Submission $submission
209
+     */
210
+    public function add_gateways( $submission ) {
211 211
 
212
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
212
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
213 213
 
214
-		if ( $this->response['has_recurring'] ) {
214
+        if ( $this->response['has_recurring'] ) {
215 215
 
216
-			foreach ( $gateways as $i => $gateway ) {
216
+            foreach ( $gateways as $i => $gateway ) {
217 217
 
218
-				if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
219
-					unset( $gateways[ $i ] );
220
-				}
218
+                if ( ! wpinv_gateway_support_subscription( $gateway ) ) {
219
+                    unset( $gateways[ $i ] );
220
+                }
221 221
 
222
-			}
222
+            }
223 223
 
224
-		}
224
+        }
225 225
 
226 226
 
227
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
228
-		$this->response = array_merge(
229
-			$this->response,
230
-			array( 'gateways' => $gateways )
231
-		);
227
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
228
+        $this->response = array_merge(
229
+            $this->response,
230
+            array( 'gateways' => $gateways )
231
+        );
232 232
 
233
-	}
233
+    }
234 234
 
235 235
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-taxes.php 1 patch
Indentation   +197 added lines, -197 removed lines patch added patch discarded remove patch
@@ -12,216 +12,216 @@
 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();
15
+    /**
16
+     * Submission taxes.
17
+     * @var array
18
+     */
19
+    public $taxes = array();
20
+
21
+    /**
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        // Validate VAT number.
29
+        $this->validate_vat( $submission );
30
+
31
+        foreach ( $submission->get_items() as $item ) {
32
+            $this->process_item_tax( $item, $submission );
33
+        }
34
+
35
+        // Process any existing invoice taxes.
36
+        if ( $submission->has_invoice() ) {
37
+            $this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
38
+        }
39
+
40
+    }
41
+
42
+    /**
43
+     * Maybe process tax.
44
+     *
45
+     * @since 1.0.19
46
+     * @param GetPaid_Form_Item $item
47
+     * @param GetPaid_Payment_Form_Submission $submission
48
+     */
49
+    public function process_item_tax( $item, $submission ) {
50
+
51
+        $rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
52
+        $taxes    = getpaid_calculate_item_taxes( $item->get_sub_total(), $rates );
53
+        $r_taxes  = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $rates );
54
+
55
+        foreach ( $taxes as $name => $amount ) {
56
+            $recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
57
+            $tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
58
+
59
+            if ( ! isset( $this->taxes[ $name ] ) ) {
60
+                $this->taxes[ $name ] = $tax;
61
+                continue;
62
+            }
63
+
64
+            $this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
65
+            $this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
66
+
67
+        }
68
+
69
+    }
70
+
71
+    /**
72
+     * Checks if the submission has a digital item.
73
+     *
74
+     * @param GetPaid_Payment_Form_Submission $submission
75
+     * @since 1.0.19
76
+     * @return bool
77
+     */
78
+    public function has_digital_item( $submission ) {
79
+
80
+        foreach ( $submission->get_items() as $item ) {
81
+
82
+            if ( 'digital' == $item->get_vat_rule() ) {
83
+                return true;
84
+            }
85
+
86
+        }
87
+
88
+        return false;
89
+    }
90
+
91
+    /**
92
+     * Checks if this is an eu store.
93
+     *
94
+     * @since 1.0.19
95
+     * @return bool
96
+     */
97
+    public function is_eu_store() {
98
+        return $this->is_eu_country( wpinv_get_default_country() );
99
+    }
100
+
101
+    /**
102
+     * Checks if this is an eu country.
103
+     *
104
+     * @param string $country
105
+     * @since 1.0.19
106
+     * @return bool
107
+     */
108
+    public function is_eu_country( $country ) {
109
+        return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
110
+    }
111
+
112
+    /**
113
+     * Checks if this is an eu purchase.
114
+     *
115
+     * @param string $customer_country
116
+     * @since 1.0.19
117
+     * @return bool
118
+     */
119
+    public function is_eu_transaction( $customer_country ) {
120
+        return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
121
+    }
122
+
123
+    /**
124
+     * Retrieves the vat number.
125
+     *
126
+     * @param GetPaid_Payment_Form_Submission $submission
127
+     * @since 1.0.19
128
+     * @return string
129
+     */
130
+    public function get_vat_number( $submission ) {
131
+
132
+        // Retrieve from the posted number.
133
+        $vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
134
+        if ( ! empty( $vat_number ) ) {
135
+            return wpinv_clean( $vat_number );
136
+        }
137
+
138
+        // Retrieve from the invoice.
139
+        return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
140
+    }
141
+
142
+    /**
143
+     * Retrieves the company.
144
+     *
145
+     * @param GetPaid_Payment_Form_Submission $submission
146
+     * @since 1.0.19
147
+     * @return string
148
+     */
149
+    public function get_company( $submission ) {
150
+
151
+        // Retrieve from the posted data.
152
+        $company = $submission->get_field( 'wpinv_company', 'billing' );
153
+        if ( ! empty( $company ) ) {
154
+            return wpinv_clean( $company );
155
+        }
156
+
157
+        // Retrieve from the invoice.
158
+        return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
159
+    }
160
+
161
+    /**
162
+     * Checks if we requires a VAT number.
163
+     *
164
+     * @param bool $ip_in_eu Whether the customer IP is from the EU
165
+     * @param bool $country_in_eu Whether the customer country is from the EU
166
+     * @since 1.0.19
167
+     * @return string
168
+     */
169
+    public function requires_vat( $ip_in_eu, $country_in_eu ) {
170
+
171
+        $prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
172
+        $prevent_b2c = ! empty( $prevent_b2c );
173
+        $is_eu       = $ip_in_eu || $country_in_eu;
174
+
175
+        return $prevent_b2c && $is_eu;
176
+    }
20 177
 
21 178
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		// Validate VAT number.
29
-		$this->validate_vat( $submission );
30
-
31
-		foreach ( $submission->get_items() as $item ) {
32
-			$this->process_item_tax( $item, $submission );
33
-		}
34
-
35
-		// Process any existing invoice taxes.
36
-		if ( $submission->has_invoice() ) {
37
-			$this->taxes = array_replace( $submission->get_invoice()->get_taxes(), $this->taxes );
38
-		}
39
-
40
-	}
41
-
42
-	/**
43
-	 * Maybe process tax.
44
-	 *
45
-	 * @since 1.0.19
46
-	 * @param GetPaid_Form_Item $item
47
-	 * @param GetPaid_Payment_Form_Submission $submission
48
-	 */
49
-	public function process_item_tax( $item, $submission ) {
50
-
51
-		$rates    = getpaid_get_item_tax_rates( $item, $submission->country, $submission->state );
52
-		$taxes    = getpaid_calculate_item_taxes( $item->get_sub_total(), $rates );
53
-		$r_taxes  = getpaid_calculate_item_taxes( $item->get_recurring_sub_total(), $rates );
54
-
55
-		foreach ( $taxes as $name => $amount ) {
56
-			$recurring = isset( $r_taxes[ $name ] ) ? $r_taxes[ $name ] : 0;
57
-			$tax       = getpaid_prepare_item_tax( $item, $name, $amount, $recurring );
58
-
59
-			if ( ! isset( $this->taxes[ $name ] ) ) {
60
-				$this->taxes[ $name ] = $tax;
61
-				continue;
62
-			}
63
-
64
-			$this->taxes[ $name ]['initial_tax']   += $tax['initial_tax'];
65
-			$this->taxes[ $name ]['recurring_tax'] += $tax['recurring_tax'];
66
-
67
-		}
68
-
69
-	}
70
-
71
-	/**
72
-	 * Checks if the submission has a digital item.
73
-	 *
74
-	 * @param GetPaid_Payment_Form_Submission $submission
75
-	 * @since 1.0.19
76
-	 * @return bool
77
-	 */
78
-	public function has_digital_item( $submission ) {
79
-
80
-		foreach ( $submission->get_items() as $item ) {
81
-
82
-			if ( 'digital' == $item->get_vat_rule() ) {
83
-				return true;
84
-			}
85
-
86
-		}
87
-
88
-		return false;
89
-	}
90
-
91
-	/**
92
-	 * Checks if this is an eu store.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @return bool
96
-	 */
97
-	public function is_eu_store() {
98
-		return $this->is_eu_country( wpinv_get_default_country() );
99
-	}
100
-
101
-	/**
102
-	 * Checks if this is an eu country.
103
-	 *
104
-	 * @param string $country
105
-	 * @since 1.0.19
106
-	 * @return bool
107
-	 */
108
-	public function is_eu_country( $country ) {
109
-		return getpaid_is_eu_state( $country ) || getpaid_is_gst_country( $country );
110
-	}
111
-
112
-	/**
113
-	 * Checks if this is an eu purchase.
114
-	 *
115
-	 * @param string $customer_country
116
-	 * @since 1.0.19
117
-	 * @return bool
118
-	 */
119
-	public function is_eu_transaction( $customer_country ) {
120
-		return $this->is_eu_country( $customer_country ) && $this->is_eu_store();
121
-	}
122
-
123
-	/**
124
-	 * Retrieves the vat number.
125
-	 *
126
-	 * @param GetPaid_Payment_Form_Submission $submission
127
-	 * @since 1.0.19
128
-	 * @return string
129
-	 */
130
-	public function get_vat_number( $submission ) {
131
-
132
-		// Retrieve from the posted number.
133
-		$vat_number = $submission->get_field( 'wpinv_vat_number', 'billing' );
134
-		if ( ! empty( $vat_number ) ) {
135
-			return wpinv_clean( $vat_number );
136
-		}
137
-
138
-		// Retrieve from the invoice.
139
-		return $submission->has_invoice() ? $submission->get_invoice()->get_vat_number() : '';
140
-	}
141
-
142
-	/**
143
-	 * Retrieves the company.
144
-	 *
145
-	 * @param GetPaid_Payment_Form_Submission $submission
146
-	 * @since 1.0.19
147
-	 * @return string
148
-	 */
149
-	public function get_company( $submission ) {
150
-
151
-		// Retrieve from the posted data.
152
-		$company = $submission->get_field( 'wpinv_company', 'billing' );
153
-		if ( ! empty( $company ) ) {
154
-			return wpinv_clean( $company );
155
-		}
156
-
157
-		// Retrieve from the invoice.
158
-		return $submission->has_invoice() ? $submission->get_invoice()->get_company() : '';
159
-	}
160
-
161
-	/**
162
-	 * Checks if we requires a VAT number.
163
-	 *
164
-	 * @param bool $ip_in_eu Whether the customer IP is from the EU
165
-	 * @param bool $country_in_eu Whether the customer country is from the EU
166
-	 * @since 1.0.19
167
-	 * @return string
168
-	 */
169
-	public function requires_vat( $ip_in_eu, $country_in_eu ) {
170
-
171
-		$prevent_b2c = wpinv_get_option( 'vat_prevent_b2c_purchase' );
172
-		$prevent_b2c = ! empty( $prevent_b2c );
173
-		$is_eu       = $ip_in_eu || $country_in_eu;
174
-
175
-		return $prevent_b2c && $is_eu;
176
-	}
177
-
178
-	/**
179
-	 * Validate VAT data.
180
-	 *
181
-	 * @param GetPaid_Payment_Form_Submission $submission
182
-	 * @since 1.0.19
183
-	 */
184
-	public function validate_vat( $submission ) {
185
-
186
-		$has_digital = $this->has_digital_item( $submission );
187
-		$in_eu       = $this->is_eu_transaction( $submission->country );
188
-
189
-		// Abort if we are not validating vat numbers.
190
-		if ( ! $has_digital && ! $in_eu ) {
179
+     * Validate VAT data.
180
+     *
181
+     * @param GetPaid_Payment_Form_Submission $submission
182
+     * @since 1.0.19
183
+     */
184
+    public function validate_vat( $submission ) {
185
+
186
+        $has_digital = $this->has_digital_item( $submission );
187
+        $in_eu       = $this->is_eu_transaction( $submission->country );
188
+
189
+        // Abort if we are not validating vat numbers.
190
+        if ( ! $has_digital && ! $in_eu ) {
191 191
             return;
192
-		}
192
+        }
193 193
 
194
-		// Prepare variables.
195
-		$vat_number  = $this->get_vat_number( $submission );
196
-		$company     = $this->get_company( $submission );
197
-		$ip_country  = getpaid_get_ip_country();
194
+        // Prepare variables.
195
+        $vat_number  = $this->get_vat_number( $submission );
196
+        $company     = $this->get_company( $submission );
197
+        $ip_country  = getpaid_get_ip_country();
198 198
         $is_eu       = $this->is_eu_country( $submission->country );
199 199
         $is_ip_eu    = $this->is_eu_country( $ip_country );
200 200
 
201
-		// If we're preventing business to consumer purchases, ensure
202
-		if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
201
+        // If we're preventing business to consumer purchases, ensure
202
+        if ( $this->requires_vat( $is_ip_eu, $is_eu ) && empty( $vat_number ) ) {
203 203
 
204
-			// Ensure that a vat number has been specified.
205
-			throw new Exception(
206
-				wp_sprintf(
207
-					__( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
208
-					getpaid_vat_name()
209
-				)
210
-			);
204
+            // Ensure that a vat number has been specified.
205
+            throw new Exception(
206
+                wp_sprintf(
207
+                    __( 'Please enter your %s number to verify your purchase is by an EU business.', 'invoicing' ),
208
+                    getpaid_vat_name()
209
+                )
210
+            );
211 211
 
212
-		}
212
+        }
213 213
 
214
-		// Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
215
-		if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
214
+        // Abort if we are not validating vat (vat number should exist, user should be in eu and business too).
215
+        if ( ! $is_eu || ! $in_eu || empty( $vat_number ) ) {
216 216
             return;
217
-		}
217
+        }
218 218
 
219
-		$is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
219
+        $is_valid = WPInv_EUVat::validate_vat_number( $vat_number, $company, $submission->country );
220 220
 
221
-		if ( is_string( $is_valid ) ) {
222
-			throw new Exception( $is_valid );
223
-		}
221
+        if ( is_string( $is_valid ) ) {
222
+            throw new Exception( $is_valid );
223
+        }
224 224
 
225
-	}
225
+    }
226 226
 
227 227
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Indentation   +756 added lines, -756 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_taxes' ),
175
-					array( $this, 'process_discount' ),
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_taxes' ),
175
+                    array( $this, 'process_discount' ),
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,117 +420,117 @@  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
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
447
-
448
-		foreach ( $processor->taxes as $tax ) {
449
-			$this->add_tax( $tax );
450
-		}
451
-
452
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
453
-	}
454
-
455
-	/**
456
-	 * Adds a tax to the submission.
457
-	 *
458
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
459
-	 * @since 1.0.19
460
-	 */
461
-	public function add_tax( $tax ) {
462
-
463
-		if ( wpinv_round_tax_per_tax_rate() ) {
464
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
465
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
466
-		}
467
-
468
-		$this->taxes[ $tax['name'] ]         = $tax;
469
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
470
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
471
-
472
-	}
473
-
474
-	/**
475
-	 * Removes a specific tax.
476
-	 *
477
-	 * @since 1.0.19
478
-	 */
479
-	public function remove_tax( $tax_name ) {
480
-
481
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
482
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
483
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
484
-			unset( $this->taxes[ $tax_name ] );
485
-		}
486
-
487
-	}
488
-
489
-	/**
490
-	 * Whether or not we'll use taxes for the submission.
491
-	 *
492
-	 * @since 1.0.19
493
-	 */
494
-	public function use_taxes() {
495
-
496
-		$use_taxes = wpinv_use_taxes();
497
-
498
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
499
-			$use_taxes = false;
500
-		}
501
-
502
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
503
-
504
-	}
505
-
506
-	/**
507
-	 * Returns the tax.
508
-	 *
509
-	 * @since 1.0.19
510
-	 */
511
-	public function get_tax() {
512
-		return $this->totals['taxes']['initial'];
513
-	}
514
-
515
-	/**
516
-	 * Returns the recurring tax.
517
-	 *
518
-	 * @since 1.0.19
519
-	 */
520
-	public function get_recurring_tax() {
521
-		return $this->totals['taxes']['recurring'];
522
-	}
523
-
524
-	/**
525
-	 * Returns all taxes.
526
-	 *
527
-	 * @since 1.0.19
528
-	 */
529
-	public function get_taxes() {
530
-		return $this->taxes;
531
-	}
532
-
533
-	/*
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
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
447
+
448
+        foreach ( $processor->taxes as $tax ) {
449
+            $this->add_tax( $tax );
450
+        }
451
+
452
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
453
+    }
454
+
455
+    /**
456
+     * Adds a tax to the submission.
457
+     *
458
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
459
+     * @since 1.0.19
460
+     */
461
+    public function add_tax( $tax ) {
462
+
463
+        if ( wpinv_round_tax_per_tax_rate() ) {
464
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
465
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
466
+        }
467
+
468
+        $this->taxes[ $tax['name'] ]         = $tax;
469
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
470
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
471
+
472
+    }
473
+
474
+    /**
475
+     * Removes a specific tax.
476
+     *
477
+     * @since 1.0.19
478
+     */
479
+    public function remove_tax( $tax_name ) {
480
+
481
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
482
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
483
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
484
+            unset( $this->taxes[ $tax_name ] );
485
+        }
486
+
487
+    }
488
+
489
+    /**
490
+     * Whether or not we'll use taxes for the submission.
491
+     *
492
+     * @since 1.0.19
493
+     */
494
+    public function use_taxes() {
495
+
496
+        $use_taxes = wpinv_use_taxes();
497
+
498
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
499
+            $use_taxes = false;
500
+        }
501
+
502
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
503
+
504
+    }
505
+
506
+    /**
507
+     * Returns the tax.
508
+     *
509
+     * @since 1.0.19
510
+     */
511
+    public function get_tax() {
512
+        return $this->totals['taxes']['initial'];
513
+    }
514
+
515
+    /**
516
+     * Returns the recurring tax.
517
+     *
518
+     * @since 1.0.19
519
+     */
520
+    public function get_recurring_tax() {
521
+        return $this->totals['taxes']['recurring'];
522
+    }
523
+
524
+    /**
525
+     * Returns all taxes.
526
+     *
527
+     * @since 1.0.19
528
+     */
529
+    public function get_taxes() {
530
+        return $this->taxes;
531
+    }
532
+
533
+    /*
534 534
 	|--------------------------------------------------------------------------
535 535
 	| Discounts
536 536
 	|--------------------------------------------------------------------------
@@ -539,99 +539,99 @@  discard block
 block discarded – undo
539 539
 	| or only one-time. They also do not have to come from a discount code.
540 540
     */
541 541
 
542
-	/**
543
-	 * Prepares the submission's discount.
544
-	 *
545
-	 * @since 1.0.19
546
-	 */
547
-	public function process_discount() {
548
-
549
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
550
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
551
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
552
-
553
-		foreach ( $processor->discounts as $discount ) {
554
-			$this->add_discount( $discount );
555
-		}
556
-
557
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
558
-	}
559
-
560
-	/**
561
-	 * Adds a discount to the submission.
562
-	 *
563
-	 * @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.
564
-	 * @since 1.0.19
565
-	 */
566
-	public function add_discount( $discount ) {
567
-		$this->discounts[ $discount['name'] ]   = $discount;
568
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
569
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
570
-	}
571
-
572
-	/**
573
-	 * Removes a discount from the submission.
574
-	 *
575
-	 * @since 1.0.19
576
-	 */
577
-	public function remove_discount( $name ) {
578
-
579
-		if ( isset( $this->discounts[ $name ] ) ) {
580
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
581
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
582
-			unset( $this->discounts[ $name ] );
583
-		}
584
-
585
-	}
586
-
587
-	/**
588
-	 * Checks whether there is a discount code associated with this submission.
589
-	 *
590
-	 * @since 1.0.19
591
-	 * @return bool
592
-	 */
593
-	public function has_discount_code() {
594
-		return ! empty( $this->discounts['discount_code'] );
595
-	}
596
-
597
-	/**
598
-	 * Returns the discount code.
599
-	 *
600
-	 * @since 1.0.19
601
-	 * @return string
602
-	 */
603
-	public function get_discount_code() {
604
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
605
-	}
606
-
607
-	/**
608
-	 * Returns the discount.
609
-	 *
610
-	 * @since 1.0.19
611
-	 */
612
-	public function get_discount() {
613
-		return $this->totals['discount']['initial'];
614
-	}
615
-
616
-	/**
617
-	 * Returns the recurring discount.
618
-	 *
619
-	 * @since 1.0.19
620
-	 */
621
-	public function get_recurring_discount() {
622
-		return $this->totals['discount']['recurring'];
623
-	}
624
-
625
-	/**
626
-	 * Returns all discounts.
627
-	 *
628
-	 * @since 1.0.19
629
-	 */
630
-	public function get_discounts() {
631
-		return $this->discounts;
632
-	}
633
-
634
-	/*
542
+    /**
543
+     * Prepares the submission's discount.
544
+     *
545
+     * @since 1.0.19
546
+     */
547
+    public function process_discount() {
548
+
549
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
550
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
551
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
552
+
553
+        foreach ( $processor->discounts as $discount ) {
554
+            $this->add_discount( $discount );
555
+        }
556
+
557
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
558
+    }
559
+
560
+    /**
561
+     * Adds a discount to the submission.
562
+     *
563
+     * @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.
564
+     * @since 1.0.19
565
+     */
566
+    public function add_discount( $discount ) {
567
+        $this->discounts[ $discount['name'] ]   = $discount;
568
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
569
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
570
+    }
571
+
572
+    /**
573
+     * Removes a discount from the submission.
574
+     *
575
+     * @since 1.0.19
576
+     */
577
+    public function remove_discount( $name ) {
578
+
579
+        if ( isset( $this->discounts[ $name ] ) ) {
580
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
581
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
582
+            unset( $this->discounts[ $name ] );
583
+        }
584
+
585
+    }
586
+
587
+    /**
588
+     * Checks whether there is a discount code associated with this submission.
589
+     *
590
+     * @since 1.0.19
591
+     * @return bool
592
+     */
593
+    public function has_discount_code() {
594
+        return ! empty( $this->discounts['discount_code'] );
595
+    }
596
+
597
+    /**
598
+     * Returns the discount code.
599
+     *
600
+     * @since 1.0.19
601
+     * @return string
602
+     */
603
+    public function get_discount_code() {
604
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
605
+    }
606
+
607
+    /**
608
+     * Returns the discount.
609
+     *
610
+     * @since 1.0.19
611
+     */
612
+    public function get_discount() {
613
+        return $this->totals['discount']['initial'];
614
+    }
615
+
616
+    /**
617
+     * Returns the recurring discount.
618
+     *
619
+     * @since 1.0.19
620
+     */
621
+    public function get_recurring_discount() {
622
+        return $this->totals['discount']['recurring'];
623
+    }
624
+
625
+    /**
626
+     * Returns all discounts.
627
+     *
628
+     * @since 1.0.19
629
+     */
630
+    public function get_discounts() {
631
+        return $this->discounts;
632
+    }
633
+
634
+    /*
635 635
 	|--------------------------------------------------------------------------
636 636
 	| Fees
637 637
 	|--------------------------------------------------------------------------
@@ -641,89 +641,89 @@  discard block
 block discarded – undo
641 641
 	| fees.
642 642
     */
643 643
 
644
-	/**
645
-	 * Prepares the submission's fees.
646
-	 *
647
-	 * @since 1.0.19
648
-	 */
649
-	public function process_fees() {
650
-
651
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
652
-
653
-		foreach ( $fees_processor->fees as $fee ) {
654
-			$this->add_fee( $fee );
655
-		}
656
-
657
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
658
-	}
659
-
660
-	/**
661
-	 * Adds a fee to the submission.
662
-	 *
663
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
664
-	 * @since 1.0.19
665
-	 */
666
-	public function add_fee( $fee ) {
667
-
668
-		$this->fees[ $fee['name'] ]         = $fee;
669
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
670
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
671
-
672
-	}
673
-
674
-	/**
675
-	 * Removes a fee from the submission.
676
-	 *
677
-	 * @since 1.0.19
678
-	 */
679
-	public function remove_fee( $name ) {
680
-
681
-		if ( isset( $this->fees[ $name ] ) ) {
682
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
683
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
684
-			unset( $this->fees[ $name ] );
685
-		}
686
-
687
-	}
688
-
689
-	/**
690
-	 * Returns the fees.
691
-	 *
692
-	 * @since 1.0.19
693
-	 */
694
-	public function get_fee() {
695
-		return $this->totals['fees']['initial'];
696
-	}
697
-
698
-	/**
699
-	 * Returns the recurring fees.
700
-	 *
701
-	 * @since 1.0.19
702
-	 */
703
-	public function get_recurring_fee() {
704
-		return $this->totals['fees']['recurring'];
705
-	}
706
-
707
-	/**
708
-	 * Returns all fees.
709
-	 *
710
-	 * @since 1.0.19
711
-	 */
712
-	public function get_fees() {
713
-		return $this->fees;
714
-	}
715
-
716
-	/**
717
-	 * Checks if there are any fees for the form.
718
-	 *
719
-	 * @return bool
720
-	 * @since 1.0.19
721
-	 */
722
-	public function has_fees() {
723
-		return count( $this->fees ) !== 0;
724
-	}
725
-
726
-	/*
644
+    /**
645
+     * Prepares the submission's fees.
646
+     *
647
+     * @since 1.0.19
648
+     */
649
+    public function process_fees() {
650
+
651
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
652
+
653
+        foreach ( $fees_processor->fees as $fee ) {
654
+            $this->add_fee( $fee );
655
+        }
656
+
657
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
658
+    }
659
+
660
+    /**
661
+     * Adds a fee to the submission.
662
+     *
663
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
664
+     * @since 1.0.19
665
+     */
666
+    public function add_fee( $fee ) {
667
+
668
+        $this->fees[ $fee['name'] ]         = $fee;
669
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
670
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
671
+
672
+    }
673
+
674
+    /**
675
+     * Removes a fee from the submission.
676
+     *
677
+     * @since 1.0.19
678
+     */
679
+    public function remove_fee( $name ) {
680
+
681
+        if ( isset( $this->fees[ $name ] ) ) {
682
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
683
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
684
+            unset( $this->fees[ $name ] );
685
+        }
686
+
687
+    }
688
+
689
+    /**
690
+     * Returns the fees.
691
+     *
692
+     * @since 1.0.19
693
+     */
694
+    public function get_fee() {
695
+        return $this->totals['fees']['initial'];
696
+    }
697
+
698
+    /**
699
+     * Returns the recurring fees.
700
+     *
701
+     * @since 1.0.19
702
+     */
703
+    public function get_recurring_fee() {
704
+        return $this->totals['fees']['recurring'];
705
+    }
706
+
707
+    /**
708
+     * Returns all fees.
709
+     *
710
+     * @since 1.0.19
711
+     */
712
+    public function get_fees() {
713
+        return $this->fees;
714
+    }
715
+
716
+    /**
717
+     * Checks if there are any fees for the form.
718
+     *
719
+     * @return bool
720
+     * @since 1.0.19
721
+     */
722
+    public function has_fees() {
723
+        return count( $this->fees ) !== 0;
724
+    }
725
+
726
+    /*
727 727
 	|--------------------------------------------------------------------------
728 728
 	| MISC
729 729
 	|--------------------------------------------------------------------------
@@ -731,109 +731,109 @@  discard block
 block discarded – undo
731 731
 	| Extra submission functions.
732 732
     */
733 733
 
734
-	/**
735
-	 * Returns the total amount to collect for this submission.
736
-	 *
737
-	 * @since 1.0.19
738
-	 */
739
-	public function get_total() {
740
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
741
-		return max( $total, 0 );
742
-	}
743
-
744
-	/**
745
-	 * Returns the recurring total amount to collect for this submission.
746
-	 *
747
-	 * @since 1.0.19
748
-	 */
749
-	public function get_recurring_total() {
750
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
751
-		return max( $total, 0 );
752
-	}
753
-
754
-	/**
755
-	 * Whether payment details should be collected for this submission.
756
-	 *
757
-	 * @since 1.0.19
758
-	 */
759
-	public function should_collect_payment_details() {
760
-		$initial   = $this->get_total();
761
-		$recurring = $this->get_recurring_total();
762
-
763
-		if ( $this->has_recurring == 0 ) {
764
-			$recurring = 0;
765
-		}
766
-
767
-		$collect = $initial > 0 || $recurring > 0;
768
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
769
-	}
770
-
771
-	/**
772
-	 * Returns the billing email of the user.
773
-	 *
774
-	 * @since 1.0.19
775
-	 */
776
-	public function get_billing_email() {
777
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
778
-	}
779
-
780
-	/**
781
-	 * Checks if the submitter has a billing email.
782
-	 *
783
-	 * @since 1.0.19
784
-	 */
785
-	public function has_billing_email() {
786
-		$billing_email = $this->get_billing_email();
787
-		return ! empty( $billing_email ) && is_email( $billing_email );
788
-	}
789
-
790
-	/**
791
-	 * Returns the appropriate currency for the submission.
792
-	 *
793
-	 * @since 1.0.19
794
-	 * @return string
795
-	 */
796
-	public function get_currency() {
797
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
798
-    }
799
-
800
-    /**
801
-	 * Returns the raw submission data.
802
-	 *
803
-	 * @since 1.0.19
804
-	 * @return array
805
-	 */
806
-	public function get_data() {
807
-		return $this->data;
808
-	}
809
-
810
-	/**
811
-	 * Returns a field from the submission data
812
-	 *
813
-	 * @param string $field
814
-	 * @since 1.0.19
815
-	 * @return mixed|null
816
-	 */
817
-	public function get_field( $field, $sub_array_key = null ) {
818
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
819
-	}
820
-
821
-	/**
822
-	 * Checks if a required field is set.
823
-	 *
824
-	 * @since 1.0.19
825
-	 */
826
-	public function is_required_field_set( $field ) {
827
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
828
-	}
829
-
830
-	/**
831
-	 * Formats an amount
832
-	 *
833
-	 * @since 1.0.19
834
-	 */
835
-	public function format_amount( $amount ) {
836
-		return wpinv_price( $amount, $this->get_currency() );
837
-	}
734
+    /**
735
+     * Returns the total amount to collect for this submission.
736
+     *
737
+     * @since 1.0.19
738
+     */
739
+    public function get_total() {
740
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
741
+        return max( $total, 0 );
742
+    }
743
+
744
+    /**
745
+     * Returns the recurring total amount to collect for this submission.
746
+     *
747
+     * @since 1.0.19
748
+     */
749
+    public function get_recurring_total() {
750
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
751
+        return max( $total, 0 );
752
+    }
753
+
754
+    /**
755
+     * Whether payment details should be collected for this submission.
756
+     *
757
+     * @since 1.0.19
758
+     */
759
+    public function should_collect_payment_details() {
760
+        $initial   = $this->get_total();
761
+        $recurring = $this->get_recurring_total();
762
+
763
+        if ( $this->has_recurring == 0 ) {
764
+            $recurring = 0;
765
+        }
766
+
767
+        $collect = $initial > 0 || $recurring > 0;
768
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
769
+    }
770
+
771
+    /**
772
+     * Returns the billing email of the user.
773
+     *
774
+     * @since 1.0.19
775
+     */
776
+    public function get_billing_email() {
777
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
778
+    }
779
+
780
+    /**
781
+     * Checks if the submitter has a billing email.
782
+     *
783
+     * @since 1.0.19
784
+     */
785
+    public function has_billing_email() {
786
+        $billing_email = $this->get_billing_email();
787
+        return ! empty( $billing_email ) && is_email( $billing_email );
788
+    }
789
+
790
+    /**
791
+     * Returns the appropriate currency for the submission.
792
+     *
793
+     * @since 1.0.19
794
+     * @return string
795
+     */
796
+    public function get_currency() {
797
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
798
+    }
799
+
800
+    /**
801
+     * Returns the raw submission data.
802
+     *
803
+     * @since 1.0.19
804
+     * @return array
805
+     */
806
+    public function get_data() {
807
+        return $this->data;
808
+    }
809
+
810
+    /**
811
+     * Returns a field from the submission data
812
+     *
813
+     * @param string $field
814
+     * @since 1.0.19
815
+     * @return mixed|null
816
+     */
817
+    public function get_field( $field, $sub_array_key = null ) {
818
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
819
+    }
820
+
821
+    /**
822
+     * Checks if a required field is set.
823
+     *
824
+     * @since 1.0.19
825
+     */
826
+    public function is_required_field_set( $field ) {
827
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
828
+    }
829
+
830
+    /**
831
+     * Formats an amount
832
+     *
833
+     * @since 1.0.19
834
+     */
835
+    public function format_amount( $amount ) {
836
+        return wpinv_price( $amount, $this->get_currency() );
837
+    }
838 838
 
839 839
 }
Please login to merge, or discard this patch.