@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | * @version 1.0.19 |
9 | 9 | */ |
10 | 10 | |
11 | -defined( 'ABSPATH' ) || exit; |
|
11 | +defined('ABSPATH') || exit; |
|
12 | 12 | |
13 | 13 | return array( |
14 | 14 | |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | 'global' => true, |
19 | 19 | 'rate' => 20, |
20 | 20 | 'reduced_rate' => 13, |
21 | - 'name' => __( 'VAT', 'invoicing' ), |
|
21 | + 'name' => __('VAT', 'invoicing'), |
|
22 | 22 | ), |
23 | 23 | |
24 | 24 | array( |
@@ -27,7 +27,7 @@ discard block |
||
27 | 27 | 'global' => true, |
28 | 28 | 'rate' => 21, |
29 | 29 | 'reduced_rate' => 12, |
30 | - 'name' => __( 'VAT', 'invoicing' ), |
|
30 | + 'name' => __('VAT', 'invoicing'), |
|
31 | 31 | ), |
32 | 32 | |
33 | 33 | array( |
@@ -36,7 +36,7 @@ discard block |
||
36 | 36 | 'global' => true, |
37 | 37 | 'rate' => 20, |
38 | 38 | 'reduced_rate' => 9, |
39 | - 'name' => __( 'VAT', 'invoicing' ), |
|
39 | + 'name' => __('VAT', 'invoicing'), |
|
40 | 40 | ), |
41 | 41 | |
42 | 42 | array( |
@@ -45,7 +45,7 @@ discard block |
||
45 | 45 | 'global' => true, |
46 | 46 | 'rate' => 19, |
47 | 47 | 'reduced_rate' => 9, |
48 | - 'name' => __( 'VAT', 'invoicing' ), |
|
48 | + 'name' => __('VAT', 'invoicing'), |
|
49 | 49 | ), |
50 | 50 | |
51 | 51 | array( |
@@ -54,7 +54,7 @@ discard block |
||
54 | 54 | 'global' => true, |
55 | 55 | 'rate' => 21, |
56 | 56 | 'reduced_rate' => 15, |
57 | - 'name' => __( 'VAT', 'invoicing' ), |
|
57 | + 'name' => __('VAT', 'invoicing'), |
|
58 | 58 | ), |
59 | 59 | |
60 | 60 | array( |
@@ -63,7 +63,7 @@ discard block |
||
63 | 63 | 'global' => true, |
64 | 64 | 'rate' => 25, |
65 | 65 | 'reduced_rate' => 25, |
66 | - 'name' => __( 'VAT', 'invoicing' ), |
|
66 | + 'name' => __('VAT', 'invoicing'), |
|
67 | 67 | ), |
68 | 68 | |
69 | 69 | array( |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'global' => true, |
73 | 73 | 'rate' => 16, |
74 | 74 | 'reduced_rate' => 5, |
75 | - 'name' => __( 'VAT', 'invoicing' ), |
|
75 | + 'name' => __('VAT', 'invoicing'), |
|
76 | 76 | ), |
77 | 77 | |
78 | 78 | array( |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | 'global' => true, |
82 | 82 | 'rate' => 20, |
83 | 83 | 'reduced_rate' => 9, |
84 | - 'name' => __( 'VAT', 'invoicing' ), |
|
84 | + 'name' => __('VAT', 'invoicing'), |
|
85 | 85 | ), |
86 | 86 | |
87 | 87 | array( |
@@ -90,7 +90,7 @@ discard block |
||
90 | 90 | 'global' => true, |
91 | 91 | 'rate' => 24, |
92 | 92 | 'reduced_rate' => 13, |
93 | - 'name' => __( 'VAT', 'invoicing' ), |
|
93 | + 'name' => __('VAT', 'invoicing'), |
|
94 | 94 | ), |
95 | 95 | |
96 | 96 | array( |
@@ -99,7 +99,7 @@ discard block |
||
99 | 99 | 'global' => true, |
100 | 100 | 'rate' => 21, |
101 | 101 | 'reduced_rate' => 10, |
102 | - 'name' => __( 'VAT', 'invoicing' ), |
|
102 | + 'name' => __('VAT', 'invoicing'), |
|
103 | 103 | ), |
104 | 104 | |
105 | 105 | array( |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | 'global' => true, |
109 | 109 | 'rate' => 24, |
110 | 110 | 'reduced_rate' => 14, |
111 | - 'name' => __( 'VAT', 'invoicing' ), |
|
111 | + 'name' => __('VAT', 'invoicing'), |
|
112 | 112 | ), |
113 | 113 | |
114 | 114 | array( |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | 'global' => true, |
118 | 118 | 'rate' => 20, |
119 | 119 | 'reduced_rate' => 10, |
120 | - 'name' => __( 'VAT', 'invoicing' ), |
|
120 | + 'name' => __('VAT', 'invoicing'), |
|
121 | 121 | ), |
122 | 122 | |
123 | 123 | array( |
@@ -126,7 +126,7 @@ discard block |
||
126 | 126 | 'global' => true, |
127 | 127 | 'rate' => 25, |
128 | 128 | 'reduced_rate' => 13, |
129 | - 'name' => __( 'VAT', 'invoicing' ), |
|
129 | + 'name' => __('VAT', 'invoicing'), |
|
130 | 130 | ), |
131 | 131 | |
132 | 132 | array( |
@@ -135,7 +135,7 @@ discard block |
||
135 | 135 | 'global' => true, |
136 | 136 | 'rate' => 25, |
137 | 137 | 'reduced_rate' => 13, |
138 | - 'name' => __( 'VAT', 'invoicing' ), |
|
138 | + 'name' => __('VAT', 'invoicing'), |
|
139 | 139 | ), |
140 | 140 | |
141 | 141 | array( |
@@ -144,7 +144,7 @@ discard block |
||
144 | 144 | 'global' => true, |
145 | 145 | 'rate' => 22, |
146 | 146 | 'reduced_rate' => 10, |
147 | - 'name' => __( 'VAT', 'invoicing' ), |
|
147 | + 'name' => __('VAT', 'invoicing'), |
|
148 | 148 | ), |
149 | 149 | |
150 | 150 | array( |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | 'global' => true, |
154 | 154 | 'rate' => 21, |
155 | 155 | 'reduced_rate' => 12, |
156 | - 'name' => __( 'VAT', 'invoicing' ), |
|
156 | + 'name' => __('VAT', 'invoicing'), |
|
157 | 157 | ), |
158 | 158 | |
159 | 159 | array( |
@@ -162,7 +162,7 @@ discard block |
||
162 | 162 | 'global' => true, |
163 | 163 | 'rate' => 21, |
164 | 164 | 'reduced_rate' => 9, |
165 | - 'name' => __( 'VAT', 'invoicing' ), |
|
165 | + 'name' => __('VAT', 'invoicing'), |
|
166 | 166 | ), |
167 | 167 | |
168 | 168 | array( |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | 'global' => true, |
172 | 172 | 'rate' => 17, |
173 | 173 | 'reduced_rate' => 14, |
174 | - 'name' => __( 'VAT', 'invoicing' ), |
|
174 | + 'name' => __('VAT', 'invoicing'), |
|
175 | 175 | ), |
176 | 176 | |
177 | 177 | array( |
@@ -180,7 +180,7 @@ discard block |
||
180 | 180 | 'global' => true, |
181 | 181 | 'rate' => 27, |
182 | 182 | 'reduced_rate' => 18, |
183 | - 'name' => __( 'VAT', 'invoicing' ), |
|
183 | + 'name' => __('VAT', 'invoicing'), |
|
184 | 184 | ), |
185 | 185 | |
186 | 186 | array( |
@@ -189,7 +189,7 @@ discard block |
||
189 | 189 | 'global' => true, |
190 | 190 | 'rate' => 21, |
191 | 191 | 'reduced_rate' => 13.5, |
192 | - 'name' => __( 'VAT', 'invoicing' ), |
|
192 | + 'name' => __('VAT', 'invoicing'), |
|
193 | 193 | ), |
194 | 194 | |
195 | 195 | array( |
@@ -198,7 +198,7 @@ discard block |
||
198 | 198 | 'global' => true, |
199 | 199 | 'rate' => 18, |
200 | 200 | 'reduced_rate' => 7, |
201 | - 'name' => __( 'VAT', 'invoicing' ), |
|
201 | + 'name' => __('VAT', 'invoicing'), |
|
202 | 202 | ), |
203 | 203 | |
204 | 204 | array( |
@@ -207,7 +207,7 @@ discard block |
||
207 | 207 | 'global' => true, |
208 | 208 | 'rate' => 21, |
209 | 209 | 'reduced_rate' => 9, |
210 | - 'name' => __( 'VAT', 'invoicing' ), |
|
210 | + 'name' => __('VAT', 'invoicing'), |
|
211 | 211 | ), |
212 | 212 | |
213 | 213 | array( |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | 'global' => true, |
217 | 217 | 'rate' => 23, |
218 | 218 | 'reduced_rate' => 8, |
219 | - 'name' => __( 'VAT', 'invoicing' ), |
|
219 | + 'name' => __('VAT', 'invoicing'), |
|
220 | 220 | ), |
221 | 221 | |
222 | 222 | array( |
@@ -225,7 +225,7 @@ discard block |
||
225 | 225 | 'global' => true, |
226 | 226 | 'rate' => 23, |
227 | 227 | 'reduced_rate' => 13, |
228 | - 'name' => __( 'VAT', 'invoicing' ), |
|
228 | + 'name' => __('VAT', 'invoicing'), |
|
229 | 229 | ), |
230 | 230 | |
231 | 231 | array( |
@@ -234,7 +234,7 @@ discard block |
||
234 | 234 | 'global' => true, |
235 | 235 | 'rate' => 19, |
236 | 236 | 'reduced_rate' => 9, |
237 | - 'name' => __( 'VAT', 'invoicing' ), |
|
237 | + 'name' => __('VAT', 'invoicing'), |
|
238 | 238 | ), |
239 | 239 | |
240 | 240 | array( |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | 'global' => true, |
244 | 244 | 'rate' => 22, |
245 | 245 | 'reduced_rate' => 9.5, |
246 | - 'name' => __( 'VAT', 'invoicing' ), |
|
246 | + 'name' => __('VAT', 'invoicing'), |
|
247 | 247 | ), |
248 | 248 | |
249 | 249 | array( |
@@ -252,7 +252,7 @@ discard block |
||
252 | 252 | 'global' => true, |
253 | 253 | 'rate' => 20, |
254 | 254 | 'reduced_rate' => 10, |
255 | - 'name' => __( 'VAT', 'invoicing' ), |
|
255 | + 'name' => __('VAT', 'invoicing'), |
|
256 | 256 | ), |
257 | 257 | |
258 | 258 | array( |
@@ -261,7 +261,7 @@ discard block |
||
261 | 261 | 'global' => true, |
262 | 262 | 'rate' => 25, |
263 | 263 | 'reduced_rate' => 12, |
264 | - 'name' => __( 'VAT', 'invoicing' ), |
|
264 | + 'name' => __('VAT', 'invoicing'), |
|
265 | 265 | ), |
266 | 266 | |
267 | 267 | array( |
@@ -270,7 +270,7 @@ discard block |
||
270 | 270 | 'global' => true, |
271 | 271 | 'rate' => 20, |
272 | 272 | 'reduced_rate' => 5, |
273 | - 'name' => __( 'VAT', 'invoicing' ), |
|
273 | + 'name' => __('VAT', 'invoicing'), |
|
274 | 274 | ) |
275 | 275 | |
276 | 276 | ); |
@@ -13,168 +13,168 @@ |
||
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 = array_merge( |
|
136 | - wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
137 | - wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
138 | - ); |
|
139 | - |
|
140 | - foreach ( $matching_rates as $i => $rate ) { |
|
141 | - |
|
142 | - $states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) ); |
|
143 | - if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) { |
|
144 | - unset( $matching_rates[ $i ] ); |
|
145 | - } |
|
146 | - |
|
147 | - } |
|
148 | - |
|
149 | - return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
150 | - |
|
151 | - } |
|
152 | - |
|
153 | - /** |
|
154 | - * Sums a set of taxes to form a single total. Result is rounded to precision. |
|
155 | - * |
|
156 | - * @param array $taxes Array of taxes. |
|
157 | - * @return float |
|
158 | - */ |
|
159 | - public static function get_tax_total( $taxes ) { |
|
160 | - return self::round( array_sum( $taxes ) ); |
|
161 | - } |
|
162 | - |
|
163 | - /** |
|
164 | - * Round to precision. |
|
165 | - * |
|
166 | - * Filter example: to return rounding to .5 cents you'd use: |
|
167 | - * |
|
168 | - * function euro_5cent_rounding( $in ) { |
|
169 | - * return round( $in / 5, 2 ) * 5; |
|
170 | - * } |
|
171 | - * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' ); |
|
172 | - * |
|
173 | - * @param float|int $in Value to round. |
|
174 | - * @return float |
|
175 | - */ |
|
176 | - public static function round( $in ) { |
|
177 | - return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
178 | - } |
|
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 = array_merge( |
|
136 | + wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
137 | + wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
138 | + ); |
|
139 | + |
|
140 | + foreach ( $matching_rates as $i => $rate ) { |
|
141 | + |
|
142 | + $states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) ); |
|
143 | + if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) { |
|
144 | + unset( $matching_rates[ $i ] ); |
|
145 | + } |
|
146 | + |
|
147 | + } |
|
148 | + |
|
149 | + return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
150 | + |
|
151 | + } |
|
152 | + |
|
153 | + /** |
|
154 | + * Sums a set of taxes to form a single total. Result is rounded to precision. |
|
155 | + * |
|
156 | + * @param array $taxes Array of taxes. |
|
157 | + * @return float |
|
158 | + */ |
|
159 | + public static function get_tax_total( $taxes ) { |
|
160 | + return self::round( array_sum( $taxes ) ); |
|
161 | + } |
|
162 | + |
|
163 | + /** |
|
164 | + * Round to precision. |
|
165 | + * |
|
166 | + * Filter example: to return rounding to .5 cents you'd use: |
|
167 | + * |
|
168 | + * function euro_5cent_rounding( $in ) { |
|
169 | + * return round( $in / 5, 2 ) * 5; |
|
170 | + * } |
|
171 | + * add_filter( 'getpaid_tax_round', 'euro_5cent_rounding' ); |
|
172 | + * |
|
173 | + * @param float|int $in Value to round. |
|
174 | + * @return float |
|
175 | + */ |
|
176 | + public static function round( $in ) { |
|
177 | + return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
178 | + } |
|
179 | 179 | |
180 | 180 | } |
@@ -5,7 +5,7 @@ discard block |
||
5 | 5 | * |
6 | 6 | */ |
7 | 7 | |
8 | -defined( 'ABSPATH' ) || exit; |
|
8 | +defined('ABSPATH') || exit; |
|
9 | 9 | |
10 | 10 | /** |
11 | 11 | * Class GetPaid_Tax |
@@ -21,15 +21,15 @@ discard block |
||
21 | 21 | * @param boolean $price_includes_tax Whether the passed price has taxes included. |
22 | 22 | * @return array Array of tax name => tax amount. |
23 | 23 | */ |
24 | - public static function calc_tax( $price, $rates, $price_includes_tax = false ) { |
|
24 | + public static function calc_tax($price, $rates, $price_includes_tax = false) { |
|
25 | 25 | |
26 | - if ( $price_includes_tax ) { |
|
27 | - $taxes = self::calc_inclusive_tax( $price, $rates ); |
|
26 | + if ($price_includes_tax) { |
|
27 | + $taxes = self::calc_inclusive_tax($price, $rates); |
|
28 | 28 | } else { |
29 | - $taxes = self::calc_exclusive_tax( $price, $rates ); |
|
29 | + $taxes = self::calc_exclusive_tax($price, $rates); |
|
30 | 30 | } |
31 | 31 | |
32 | - return apply_filters( 'getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax ); |
|
32 | + return apply_filters('getpaid_calc_tax', $taxes, $price, $rates, $price_includes_tax); |
|
33 | 33 | |
34 | 34 | } |
35 | 35 | |
@@ -40,22 +40,22 @@ discard block |
||
40 | 40 | * @param array $rates Array of tax rates. |
41 | 41 | * @return array |
42 | 42 | */ |
43 | - public static function calc_inclusive_tax( $price, $rates ) { |
|
43 | + public static function calc_inclusive_tax($price, $rates) { |
|
44 | 44 | $taxes = array(); |
45 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
45 | + $tax_rates = wp_list_pluck($rates, 'rate', 'name'); |
|
46 | 46 | |
47 | 47 | // Add tax rates. |
48 | - $tax_rate = 1 + ( array_sum( $tax_rates ) / 100 ); |
|
48 | + $tax_rate = 1 + (array_sum($tax_rates) / 100); |
|
49 | 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; |
|
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 | 55 | } |
56 | 56 | |
57 | 57 | // Round all taxes to precision (4DP) before passing them back. |
58 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
58 | + $taxes = array_map(array(__CLASS__, 'round'), $taxes); |
|
59 | 59 | |
60 | 60 | return $taxes; |
61 | 61 | } |
@@ -67,19 +67,19 @@ discard block |
||
67 | 67 | * @param array $rates Array of tax rates. |
68 | 68 | * @return array |
69 | 69 | */ |
70 | - public static function calc_exclusive_tax( $price, $rates ) { |
|
70 | + public static function calc_exclusive_tax($price, $rates) { |
|
71 | 71 | $taxes = array(); |
72 | - $tax_rates = wp_list_pluck( $rates, 'rate', 'name' ); |
|
72 | + $tax_rates = wp_list_pluck($rates, 'rate', 'name'); |
|
73 | 73 | |
74 | - foreach ( $tax_rates as $name => $rate ) { |
|
74 | + foreach ($tax_rates as $name => $rate) { |
|
75 | 75 | |
76 | - $tax_amount = $price * ( $rate / 100 ); |
|
77 | - $taxes[ $name ] = apply_filters( 'getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price ); |
|
76 | + $tax_amount = $price * ($rate / 100); |
|
77 | + $taxes[$name] = apply_filters('getpaid_price_ex_tax_amount', $tax_amount, $name, $rate, $price); |
|
78 | 78 | |
79 | 79 | } |
80 | 80 | |
81 | 81 | // Round all taxes to precision (4DP) before passing them back. |
82 | - $taxes = array_map( array( __CLASS__, 'round' ), $taxes ); |
|
82 | + $taxes = array_map(array(__CLASS__, 'round'), $taxes); |
|
83 | 83 | |
84 | 84 | return $taxes; |
85 | 85 | } |
@@ -91,11 +91,11 @@ discard block |
||
91 | 91 | */ |
92 | 92 | public static function get_all_tax_rates() { |
93 | 93 | |
94 | - $rates = get_option( 'wpinv_tax_rates', array() ); |
|
94 | + $rates = get_option('wpinv_tax_rates', array()); |
|
95 | 95 | |
96 | 96 | return apply_filters( |
97 | 97 | 'getpaid_get_all_tax_rates', |
98 | - array_filter( wpinv_parse_list( $rates ) ) |
|
98 | + array_filter(wpinv_parse_list($rates)) |
|
99 | 99 | ); |
100 | 100 | |
101 | 101 | } |
@@ -115,7 +115,7 @@ discard block |
||
115 | 115 | 'state' => wpinv_get_default_state(), |
116 | 116 | 'global' => true, |
117 | 117 | 'rate' => wpinv_get_default_tax_rate(), |
118 | - 'name' => __( 'Base Tax', 'invoicing' ), |
|
118 | + 'name' => __('Base Tax', 'invoicing'), |
|
119 | 119 | ) |
120 | 120 | ) |
121 | 121 | ); |
@@ -129,24 +129,24 @@ discard block |
||
129 | 129 | * @param string $state |
130 | 130 | * @return array |
131 | 131 | */ |
132 | - public static function get_address_tax_rates( $country, $state ) { |
|
132 | + public static function get_address_tax_rates($country, $state) { |
|
133 | 133 | |
134 | 134 | $all_tax_rates = self::get_all_tax_rates(); |
135 | 135 | $matching_rates = array_merge( |
136 | - wp_list_filter( $all_tax_rates, array( 'country' => $country ) ), |
|
137 | - wp_list_filter( $all_tax_rates, array( 'country' => '' ) ) |
|
136 | + wp_list_filter($all_tax_rates, array('country' => $country)), |
|
137 | + wp_list_filter($all_tax_rates, array('country' => '')) |
|
138 | 138 | ); |
139 | 139 | |
140 | - foreach ( $matching_rates as $i => $rate ) { |
|
140 | + foreach ($matching_rates as $i => $rate) { |
|
141 | 141 | |
142 | - $states = array_filter( wpinv_clean( explode( ',', $rate['state'] ) ) ); |
|
143 | - if ( empty( $rate['global'] ) && ! in_array( $state, $states ) ) { |
|
144 | - unset( $matching_rates[ $i ] ); |
|
142 | + $states = array_filter(wpinv_clean(explode(',', $rate['state']))); |
|
143 | + if (empty($rate['global']) && !in_array($state, $states)) { |
|
144 | + unset($matching_rates[$i]); |
|
145 | 145 | } |
146 | 146 | |
147 | 147 | } |
148 | 148 | |
149 | - return apply_filters( 'getpaid_get_address_tax_rates', $matching_rates, $country, $state ); |
|
149 | + return apply_filters('getpaid_get_address_tax_rates', $matching_rates, $country, $state); |
|
150 | 150 | |
151 | 151 | } |
152 | 152 | |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | * @param array $taxes Array of taxes. |
157 | 157 | * @return float |
158 | 158 | */ |
159 | - public static function get_tax_total( $taxes ) { |
|
160 | - return self::round( array_sum( $taxes ) ); |
|
159 | + public static function get_tax_total($taxes) { |
|
160 | + return self::round(array_sum($taxes)); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -173,8 +173,8 @@ discard block |
||
173 | 173 | * @param float|int $in Value to round. |
174 | 174 | * @return float |
175 | 175 | */ |
176 | - public static function round( $in ) { |
|
177 | - return apply_filters( 'getpaid_tax_round', round( $in, 4 ), $in ); |
|
176 | + public static function round($in) { |
|
177 | + return apply_filters('getpaid_tax_round', round($in, 4), $in); |
|
178 | 178 | } |
179 | 179 | |
180 | 180 | } |
@@ -6,7 +6,7 @@ |
||
6 | 6 | * @package Invoicing/data |
7 | 7 | */ |
8 | 8 | |
9 | -defined( 'ABSPATH' ) || exit; |
|
9 | +defined('ABSPATH') || exit; |
|
10 | 10 | |
11 | 11 | array( |
12 | 12 |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * The Subscriptions DB Class |
@@ -72,8 +72,8 @@ discard block |
||
72 | 72 | 'transaction_id' => '', |
73 | 73 | 'parent_payment_id' => 0, |
74 | 74 | 'product_id' => 0, |
75 | - 'created' => date( 'Y-m-d H:i:s' ), |
|
76 | - 'expiration' => date( 'Y-m-d H:i:s' ), |
|
75 | + 'created' => date('Y-m-d H:i:s'), |
|
76 | + 'expiration' => date('Y-m-d H:i:s'), |
|
77 | 77 | 'trial_period' => '', |
78 | 78 | 'status' => '', |
79 | 79 | 'profile_id' => '', |
@@ -86,8 +86,8 @@ discard block |
||
86 | 86 | * @access public |
87 | 87 | * @since 1.0.0 |
88 | 88 | */ |
89 | - public function get_subscriptions( $args = array() ) { |
|
90 | - return getpaid_get_subscriptions( $args ); |
|
89 | + public function get_subscriptions($args = array()) { |
|
90 | + return getpaid_get_subscriptions($args); |
|
91 | 91 | } |
92 | 92 | |
93 | 93 | /** |
@@ -96,8 +96,8 @@ discard block |
||
96 | 96 | * @access public |
97 | 97 | * @since 1.0.0 |
98 | 98 | */ |
99 | - public function count( $args = array() ) { |
|
100 | - return getpaid_get_subscriptions( $args, 'count' ); |
|
99 | + public function count($args = array()) { |
|
100 | + return getpaid_get_subscriptions($args, 'count'); |
|
101 | 101 | } |
102 | 102 | |
103 | 103 | /** |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | */ |
109 | 109 | public function create_table() { |
110 | 110 | |
111 | - require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); |
|
111 | + require_once(ABSPATH . 'wp-admin/includes/upgrade.php'); |
|
112 | 112 | |
113 | 113 | $sql = "CREATE TABLE " . $this->table_name . " ( |
114 | 114 | id bigint(20) NOT NULL AUTO_INCREMENT, |
@@ -133,9 +133,9 @@ discard block |
||
133 | 133 | KEY customer_and_status ( customer_id, status) |
134 | 134 | ) CHARACTER SET utf8 COLLATE utf8_general_ci;"; |
135 | 135 | |
136 | - dbDelta( $sql ); |
|
136 | + dbDelta($sql); |
|
137 | 137 | |
138 | - update_option( $this->table_name . '_db_version', $this->version ); |
|
138 | + update_option($this->table_name . '_db_version', $this->version); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
142 | 142 | \ No newline at end of file |
@@ -8,7 +8,7 @@ discard block |
||
8 | 8 | */ |
9 | 9 | |
10 | 10 | if ( ! defined( 'ABSPATH' ) ) { |
11 | - exit; // Exit if accessed directly |
|
11 | + exit; // Exit if accessed directly |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | /** |
@@ -17,10 +17,10 @@ discard block |
||
17 | 17 | class GetPaid_Meta_Box_Item_VAT { |
18 | 18 | |
19 | 19 | /** |
20 | - * Output the metabox. |
|
21 | - * |
|
22 | - * @param WP_Post $post |
|
23 | - */ |
|
20 | + * Output the metabox. |
|
21 | + * |
|
22 | + * @param WP_Post $post |
|
23 | + */ |
|
24 | 24 | public static function output( $post ) { |
25 | 25 | |
26 | 26 | // Prepare the item. |
@@ -46,10 +46,10 @@ discard block |
||
46 | 46 | } |
47 | 47 | |
48 | 48 | /** |
49 | - * Output the VAT rules settings. |
|
50 | - * |
|
51 | - * @param WPInv_Item $item |
|
52 | - */ |
|
49 | + * Output the VAT rules settings. |
|
50 | + * |
|
51 | + * @param WPInv_Item $item |
|
52 | + */ |
|
53 | 53 | public static function output_vat_rules( $item ) { |
54 | 54 | ?> |
55 | 55 | |
@@ -87,10 +87,10 @@ discard block |
||
87 | 87 | } |
88 | 88 | |
89 | 89 | /** |
90 | - * Output the VAT class settings. |
|
91 | - * |
|
92 | - * @param WPInv_Item $item |
|
93 | - */ |
|
90 | + * Output the VAT class settings. |
|
91 | + * |
|
92 | + * @param WPInv_Item $item |
|
93 | + */ |
|
94 | 94 | public static function output_vat_classes( $item ) { |
95 | 95 | ?> |
96 | 96 |
@@ -7,7 +7,7 @@ discard block |
||
7 | 7 | * |
8 | 8 | */ |
9 | 9 | |
10 | -if ( ! defined( 'ABSPATH' ) ) { |
|
10 | +if (!defined('ABSPATH')) { |
|
11 | 11 | exit; // Exit if accessed directly |
12 | 12 | } |
13 | 13 | |
@@ -21,26 +21,26 @@ discard block |
||
21 | 21 | * |
22 | 22 | * @param WP_Post $post |
23 | 23 | */ |
24 | - public static function output( $post ) { |
|
24 | + public static function output($post) { |
|
25 | 25 | |
26 | 26 | // Prepare the item. |
27 | - $item = new WPInv_Item( $post ); |
|
27 | + $item = new WPInv_Item($post); |
|
28 | 28 | |
29 | 29 | echo "<div class='bsui' style='max-width: 600px;padding-top: 10px;'>"; |
30 | 30 | |
31 | - do_action( 'wpinv_item_before_vat_metabox', $item ); |
|
31 | + do_action('wpinv_item_before_vat_metabox', $item); |
|
32 | 32 | |
33 | 33 | // Output the vat rules settings. |
34 | - do_action( 'wpinv_item_vat_metabox_before_vat_rules', $item ); |
|
35 | - self::output_vat_rules( $item ); |
|
36 | - do_action( 'wpinv_item_vat_metabox_vat_rules', $item ); |
|
34 | + do_action('wpinv_item_vat_metabox_before_vat_rules', $item); |
|
35 | + self::output_vat_rules($item); |
|
36 | + do_action('wpinv_item_vat_metabox_vat_rules', $item); |
|
37 | 37 | |
38 | 38 | // Output vat class settings. |
39 | - do_action( 'wpinv_item_vat_metabox_before_vat_rules', $item ); |
|
40 | - self::output_vat_classes( $item ); |
|
41 | - do_action( 'wpinv_item_vat_metabox_vat_class', $item ); |
|
39 | + do_action('wpinv_item_vat_metabox_before_vat_rules', $item); |
|
40 | + self::output_vat_classes($item); |
|
41 | + do_action('wpinv_item_vat_metabox_vat_class', $item); |
|
42 | 42 | |
43 | - do_action( 'wpinv_item_vat_metabox', $item ); |
|
43 | + do_action('wpinv_item_vat_metabox', $item); |
|
44 | 44 | |
45 | 45 | echo '</div>'; |
46 | 46 | } |
@@ -50,14 +50,14 @@ discard block |
||
50 | 50 | * |
51 | 51 | * @param WPInv_Item $item |
52 | 52 | */ |
53 | - public static function output_vat_rules( $item ) { |
|
53 | + public static function output_vat_rules($item) { |
|
54 | 54 | ?> |
55 | 55 | |
56 | 56 | <div class="wpinv_vat_rules"> |
57 | 57 | |
58 | 58 | <div class="form-group row"> |
59 | 59 | <label for="wpinv_vat_rules" class="col-sm-3 col-form-label"> |
60 | - <?php _e( 'Tax Rule', 'invoicing' );?> |
|
60 | + <?php _e('Tax Rule', 'invoicing'); ?> |
|
61 | 61 | </label> |
62 | 62 | <div class="col-sm-8"> |
63 | 63 | <?php |
@@ -65,8 +65,8 @@ discard block |
||
65 | 65 | array( |
66 | 66 | 'id' => 'wpinv_vat_rules', |
67 | 67 | 'name' => 'wpinv_vat_rules', |
68 | - 'placeholder' => __( 'Select tax rule', 'invoicing' ), |
|
69 | - 'value' => $item->get_vat_rule( 'edit' ), |
|
68 | + 'placeholder' => __('Select tax rule', 'invoicing'), |
|
69 | + 'value' => $item->get_vat_rule('edit'), |
|
70 | 70 | 'select2' => true, |
71 | 71 | 'data-allow-clear' => 'false', |
72 | 72 | 'no_wrap' => true, |
@@ -88,14 +88,14 @@ discard block |
||
88 | 88 | * |
89 | 89 | * @param WPInv_Item $item |
90 | 90 | */ |
91 | - public static function output_vat_classes( $item ) { |
|
91 | + public static function output_vat_classes($item) { |
|
92 | 92 | ?> |
93 | 93 | |
94 | 94 | <div class="wpinv_vat_classes"> |
95 | 95 | |
96 | 96 | <div class="form-group row"> |
97 | 97 | <label for="wpinv_vat_class" class="col-sm-3 col-form-label"> |
98 | - <?php _e( 'Tax Class', 'invoicing' );?> |
|
98 | + <?php _e('Tax Class', 'invoicing'); ?> |
|
99 | 99 | </label> |
100 | 100 | <div class="col-sm-8"> |
101 | 101 | <?php |
@@ -103,8 +103,8 @@ discard block |
||
103 | 103 | array( |
104 | 104 | 'id' => 'wpinv_vat_class', |
105 | 105 | 'name' => 'wpinv_vat_class', |
106 | - 'placeholder' => __( 'Select tax class', 'invoicing' ), |
|
107 | - 'value' => $item->get_vat_class( 'edit' ), |
|
106 | + 'placeholder' => __('Select tax class', 'invoicing'), |
|
107 | + 'value' => $item->get_vat_class('edit'), |
|
108 | 108 | 'select2' => true, |
109 | 109 | 'data-allow-clear' => 'false', |
110 | 110 | 'no_wrap' => true, |
@@ -7,12 +7,12 @@ discard block |
||
7 | 7 | * @version 1.0.19 |
8 | 8 | */ |
9 | 9 | |
10 | -defined( 'ABSPATH' ) || exit; |
|
10 | +defined('ABSPATH') || exit; |
|
11 | 11 | |
12 | 12 | // Prepare the company name. |
13 | -$company_name = wpinv_get_option( 'vat_company_name' ); |
|
13 | +$company_name = wpinv_get_option('vat_company_name'); |
|
14 | 14 | |
15 | -if ( empty( $company_name ) ) { |
|
15 | +if (empty($company_name)) { |
|
16 | 16 | $company_name = wpinv_get_business_name(); |
17 | 17 | } |
18 | 18 | |
@@ -22,30 +22,30 @@ discard block |
||
22 | 22 | <div class="row"> |
23 | 23 | |
24 | 24 | <div class="invoice-company-address-label col-2"> |
25 | - <strong><?php _e( 'From:', 'invoicing' ) ?></strong> |
|
25 | + <strong><?php _e('From:', 'invoicing') ?></strong> |
|
26 | 26 | </div> |
27 | 27 | |
28 | 28 | <div class="invoice-company-address-value col-10"> |
29 | 29 | |
30 | - <?php do_action( 'getpaid_company_address_top' ); ?> |
|
30 | + <?php do_action('getpaid_company_address_top'); ?> |
|
31 | 31 | |
32 | 32 | <div class="name"> |
33 | - <a target="_blank" class="text-dark" href="<?php echo esc_url( wpinv_get_business_website() ); ?>"> |
|
34 | - <?php echo esc_html( wpinv_get_business_name() ); ?> |
|
33 | + <a target="_blank" class="text-dark" href="<?php echo esc_url(wpinv_get_business_website()); ?>"> |
|
34 | + <?php echo esc_html(wpinv_get_business_name()); ?> |
|
35 | 35 | </a> |
36 | 36 | </div> |
37 | 37 | |
38 | - <?php if ( $address = wpinv_get_business_address() ) { ?> |
|
39 | - <?php echo $address;?> |
|
38 | + <?php if ($address = wpinv_get_business_address()) { ?> |
|
39 | + <?php echo $address; ?> |
|
40 | 40 | <?php } ?> |
41 | 41 | |
42 | - <?php if ( $email_from = wpinv_mail_get_from_address() ) { ?> |
|
42 | + <?php if ($email_from = wpinv_mail_get_from_address()) { ?> |
|
43 | 43 | <div class="email_from"> |
44 | - <?php echo wp_sprintf( __( 'Email: %s', 'invoicing' ), $email_from );?> |
|
44 | + <?php echo wp_sprintf(__('Email: %s', 'invoicing'), $email_from); ?> |
|
45 | 45 | </div> |
46 | 46 | <?php } ?> |
47 | 47 | |
48 | - <?php do_action( 'getpaid_company_address_bottom' ); ?> |
|
48 | + <?php do_action('getpaid_company_address_bottom'); ?> |
|
49 | 49 | |
50 | 50 | </div> |
51 | 51 |
@@ -1,6 +1,6 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | if ( ! defined( 'ABSPATH' ) ) { |
3 | - exit; |
|
3 | + exit; |
|
4 | 4 | } |
5 | 5 | |
6 | 6 | /** |
@@ -10,187 +10,187 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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,122 +420,122 @@ discard block |
||
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 | - // Abort if the country is not taxable. |
|
447 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
448 | - return; |
|
449 | - } |
|
450 | - |
|
451 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
452 | - |
|
453 | - foreach ( $processor->taxes as $tax ) { |
|
454 | - $this->add_tax( $tax ); |
|
455 | - } |
|
456 | - |
|
457 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
458 | - } |
|
459 | - |
|
460 | - /** |
|
461 | - * Adds a tax to the submission. |
|
462 | - * |
|
463 | - * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
464 | - * @since 1.0.19 |
|
465 | - */ |
|
466 | - public function add_tax( $tax ) { |
|
467 | - |
|
468 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
469 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
470 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
471 | - } |
|
472 | - |
|
473 | - $this->taxes[ $tax['name'] ] = $tax; |
|
474 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
475 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
476 | - |
|
477 | - } |
|
478 | - |
|
479 | - /** |
|
480 | - * Removes a specific tax. |
|
481 | - * |
|
482 | - * @since 1.0.19 |
|
483 | - */ |
|
484 | - public function remove_tax( $tax_name ) { |
|
485 | - |
|
486 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
487 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
488 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
489 | - unset( $this->taxes[ $tax_name ] ); |
|
490 | - } |
|
491 | - |
|
492 | - } |
|
493 | - |
|
494 | - /** |
|
495 | - * Whether or not we'll use taxes for the submission. |
|
496 | - * |
|
497 | - * @since 1.0.19 |
|
498 | - */ |
|
499 | - public function use_taxes() { |
|
500 | - |
|
501 | - $use_taxes = wpinv_use_taxes(); |
|
502 | - |
|
503 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
504 | - $use_taxes = false; |
|
505 | - } |
|
506 | - |
|
507 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
508 | - |
|
509 | - } |
|
510 | - |
|
511 | - /** |
|
512 | - * Returns the tax. |
|
513 | - * |
|
514 | - * @since 1.0.19 |
|
515 | - */ |
|
516 | - public function get_tax() { |
|
517 | - return $this->totals['taxes']['initial']; |
|
518 | - } |
|
519 | - |
|
520 | - /** |
|
521 | - * Returns the recurring tax. |
|
522 | - * |
|
523 | - * @since 1.0.19 |
|
524 | - */ |
|
525 | - public function get_recurring_tax() { |
|
526 | - return $this->totals['taxes']['recurring']; |
|
527 | - } |
|
528 | - |
|
529 | - /** |
|
530 | - * Returns all taxes. |
|
531 | - * |
|
532 | - * @since 1.0.19 |
|
533 | - */ |
|
534 | - public function get_taxes() { |
|
535 | - return $this->taxes; |
|
536 | - } |
|
537 | - |
|
538 | - /* |
|
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 | + // Abort if the country is not taxable. |
|
447 | + if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
448 | + return; |
|
449 | + } |
|
450 | + |
|
451 | + $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
452 | + |
|
453 | + foreach ( $processor->taxes as $tax ) { |
|
454 | + $this->add_tax( $tax ); |
|
455 | + } |
|
456 | + |
|
457 | + do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
458 | + } |
|
459 | + |
|
460 | + /** |
|
461 | + * Adds a tax to the submission. |
|
462 | + * |
|
463 | + * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
|
464 | + * @since 1.0.19 |
|
465 | + */ |
|
466 | + public function add_tax( $tax ) { |
|
467 | + |
|
468 | + if ( wpinv_round_tax_per_tax_rate() ) { |
|
469 | + $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
470 | + $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
471 | + } |
|
472 | + |
|
473 | + $this->taxes[ $tax['name'] ] = $tax; |
|
474 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
475 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
476 | + |
|
477 | + } |
|
478 | + |
|
479 | + /** |
|
480 | + * Removes a specific tax. |
|
481 | + * |
|
482 | + * @since 1.0.19 |
|
483 | + */ |
|
484 | + public function remove_tax( $tax_name ) { |
|
485 | + |
|
486 | + if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
487 | + $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
488 | + $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
489 | + unset( $this->taxes[ $tax_name ] ); |
|
490 | + } |
|
491 | + |
|
492 | + } |
|
493 | + |
|
494 | + /** |
|
495 | + * Whether or not we'll use taxes for the submission. |
|
496 | + * |
|
497 | + * @since 1.0.19 |
|
498 | + */ |
|
499 | + public function use_taxes() { |
|
500 | + |
|
501 | + $use_taxes = wpinv_use_taxes(); |
|
502 | + |
|
503 | + if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
504 | + $use_taxes = false; |
|
505 | + } |
|
506 | + |
|
507 | + return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
508 | + |
|
509 | + } |
|
510 | + |
|
511 | + /** |
|
512 | + * Returns the tax. |
|
513 | + * |
|
514 | + * @since 1.0.19 |
|
515 | + */ |
|
516 | + public function get_tax() { |
|
517 | + return $this->totals['taxes']['initial']; |
|
518 | + } |
|
519 | + |
|
520 | + /** |
|
521 | + * Returns the recurring tax. |
|
522 | + * |
|
523 | + * @since 1.0.19 |
|
524 | + */ |
|
525 | + public function get_recurring_tax() { |
|
526 | + return $this->totals['taxes']['recurring']; |
|
527 | + } |
|
528 | + |
|
529 | + /** |
|
530 | + * Returns all taxes. |
|
531 | + * |
|
532 | + * @since 1.0.19 |
|
533 | + */ |
|
534 | + public function get_taxes() { |
|
535 | + return $this->taxes; |
|
536 | + } |
|
537 | + |
|
538 | + /* |
|
539 | 539 | |-------------------------------------------------------------------------- |
540 | 540 | | Discounts |
541 | 541 | |-------------------------------------------------------------------------- |
@@ -544,99 +544,99 @@ discard block |
||
544 | 544 | | or only one-time. They also do not have to come from a discount code. |
545 | 545 | */ |
546 | 546 | |
547 | - /** |
|
548 | - * Prepares the submission's discount. |
|
549 | - * |
|
550 | - * @since 1.0.19 |
|
551 | - */ |
|
552 | - public function process_discount() { |
|
553 | - |
|
554 | - $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
555 | - $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
556 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
557 | - |
|
558 | - foreach ( $processor->discounts as $discount ) { |
|
559 | - $this->add_discount( $discount ); |
|
560 | - } |
|
561 | - |
|
562 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
563 | - } |
|
564 | - |
|
565 | - /** |
|
566 | - * Adds a discount to the submission. |
|
567 | - * |
|
568 | - * @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. |
|
569 | - * @since 1.0.19 |
|
570 | - */ |
|
571 | - public function add_discount( $discount ) { |
|
572 | - $this->discounts[ $discount['name'] ] = $discount; |
|
573 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
574 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
575 | - } |
|
576 | - |
|
577 | - /** |
|
578 | - * Removes a discount from the submission. |
|
579 | - * |
|
580 | - * @since 1.0.19 |
|
581 | - */ |
|
582 | - public function remove_discount( $name ) { |
|
583 | - |
|
584 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
585 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
586 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
587 | - unset( $this->discounts[ $name ] ); |
|
588 | - } |
|
589 | - |
|
590 | - } |
|
591 | - |
|
592 | - /** |
|
593 | - * Checks whether there is a discount code associated with this submission. |
|
594 | - * |
|
595 | - * @since 1.0.19 |
|
596 | - * @return bool |
|
597 | - */ |
|
598 | - public function has_discount_code() { |
|
599 | - return ! empty( $this->discounts['discount_code'] ); |
|
600 | - } |
|
601 | - |
|
602 | - /** |
|
603 | - * Returns the discount code. |
|
604 | - * |
|
605 | - * @since 1.0.19 |
|
606 | - * @return string |
|
607 | - */ |
|
608 | - public function get_discount_code() { |
|
609 | - return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
610 | - } |
|
611 | - |
|
612 | - /** |
|
613 | - * Returns the discount. |
|
614 | - * |
|
615 | - * @since 1.0.19 |
|
616 | - */ |
|
617 | - public function get_discount() { |
|
618 | - return $this->totals['discount']['initial']; |
|
619 | - } |
|
620 | - |
|
621 | - /** |
|
622 | - * Returns the recurring discount. |
|
623 | - * |
|
624 | - * @since 1.0.19 |
|
625 | - */ |
|
626 | - public function get_recurring_discount() { |
|
627 | - return $this->totals['discount']['recurring']; |
|
628 | - } |
|
629 | - |
|
630 | - /** |
|
631 | - * Returns all discounts. |
|
632 | - * |
|
633 | - * @since 1.0.19 |
|
634 | - */ |
|
635 | - public function get_discounts() { |
|
636 | - return $this->discounts; |
|
637 | - } |
|
638 | - |
|
639 | - /* |
|
547 | + /** |
|
548 | + * Prepares the submission's discount. |
|
549 | + * |
|
550 | + * @since 1.0.19 |
|
551 | + */ |
|
552 | + public function process_discount() { |
|
553 | + |
|
554 | + $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
|
555 | + $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
|
556 | + $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
557 | + |
|
558 | + foreach ( $processor->discounts as $discount ) { |
|
559 | + $this->add_discount( $discount ); |
|
560 | + } |
|
561 | + |
|
562 | + do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
563 | + } |
|
564 | + |
|
565 | + /** |
|
566 | + * Adds a discount to the submission. |
|
567 | + * |
|
568 | + * @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. |
|
569 | + * @since 1.0.19 |
|
570 | + */ |
|
571 | + public function add_discount( $discount ) { |
|
572 | + $this->discounts[ $discount['name'] ] = $discount; |
|
573 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
574 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
575 | + } |
|
576 | + |
|
577 | + /** |
|
578 | + * Removes a discount from the submission. |
|
579 | + * |
|
580 | + * @since 1.0.19 |
|
581 | + */ |
|
582 | + public function remove_discount( $name ) { |
|
583 | + |
|
584 | + if ( isset( $this->discounts[ $name ] ) ) { |
|
585 | + $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
586 | + $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
587 | + unset( $this->discounts[ $name ] ); |
|
588 | + } |
|
589 | + |
|
590 | + } |
|
591 | + |
|
592 | + /** |
|
593 | + * Checks whether there is a discount code associated with this submission. |
|
594 | + * |
|
595 | + * @since 1.0.19 |
|
596 | + * @return bool |
|
597 | + */ |
|
598 | + public function has_discount_code() { |
|
599 | + return ! empty( $this->discounts['discount_code'] ); |
|
600 | + } |
|
601 | + |
|
602 | + /** |
|
603 | + * Returns the discount code. |
|
604 | + * |
|
605 | + * @since 1.0.19 |
|
606 | + * @return string |
|
607 | + */ |
|
608 | + public function get_discount_code() { |
|
609 | + return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : ''; |
|
610 | + } |
|
611 | + |
|
612 | + /** |
|
613 | + * Returns the discount. |
|
614 | + * |
|
615 | + * @since 1.0.19 |
|
616 | + */ |
|
617 | + public function get_discount() { |
|
618 | + return $this->totals['discount']['initial']; |
|
619 | + } |
|
620 | + |
|
621 | + /** |
|
622 | + * Returns the recurring discount. |
|
623 | + * |
|
624 | + * @since 1.0.19 |
|
625 | + */ |
|
626 | + public function get_recurring_discount() { |
|
627 | + return $this->totals['discount']['recurring']; |
|
628 | + } |
|
629 | + |
|
630 | + /** |
|
631 | + * Returns all discounts. |
|
632 | + * |
|
633 | + * @since 1.0.19 |
|
634 | + */ |
|
635 | + public function get_discounts() { |
|
636 | + return $this->discounts; |
|
637 | + } |
|
638 | + |
|
639 | + /* |
|
640 | 640 | |-------------------------------------------------------------------------- |
641 | 641 | | Fees |
642 | 642 | |-------------------------------------------------------------------------- |
@@ -646,89 +646,89 @@ discard block |
||
646 | 646 | | fees. |
647 | 647 | */ |
648 | 648 | |
649 | - /** |
|
650 | - * Prepares the submission's fees. |
|
651 | - * |
|
652 | - * @since 1.0.19 |
|
653 | - */ |
|
654 | - public function process_fees() { |
|
655 | - |
|
656 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
657 | - |
|
658 | - foreach ( $fees_processor->fees as $fee ) { |
|
659 | - $this->add_fee( $fee ); |
|
660 | - } |
|
661 | - |
|
662 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
663 | - } |
|
664 | - |
|
665 | - /** |
|
666 | - * Adds a fee to the submission. |
|
667 | - * |
|
668 | - * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
669 | - * @since 1.0.19 |
|
670 | - */ |
|
671 | - public function add_fee( $fee ) { |
|
672 | - |
|
673 | - $this->fees[ $fee['name'] ] = $fee; |
|
674 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
675 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
676 | - |
|
677 | - } |
|
678 | - |
|
679 | - /** |
|
680 | - * Removes a fee from the submission. |
|
681 | - * |
|
682 | - * @since 1.0.19 |
|
683 | - */ |
|
684 | - public function remove_fee( $name ) { |
|
685 | - |
|
686 | - if ( isset( $this->fees[ $name ] ) ) { |
|
687 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
688 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
689 | - unset( $this->fees[ $name ] ); |
|
690 | - } |
|
691 | - |
|
692 | - } |
|
693 | - |
|
694 | - /** |
|
695 | - * Returns the fees. |
|
696 | - * |
|
697 | - * @since 1.0.19 |
|
698 | - */ |
|
699 | - public function get_fee() { |
|
700 | - return $this->totals['fees']['initial']; |
|
701 | - } |
|
702 | - |
|
703 | - /** |
|
704 | - * Returns the recurring fees. |
|
705 | - * |
|
706 | - * @since 1.0.19 |
|
707 | - */ |
|
708 | - public function get_recurring_fee() { |
|
709 | - return $this->totals['fees']['recurring']; |
|
710 | - } |
|
711 | - |
|
712 | - /** |
|
713 | - * Returns all fees. |
|
714 | - * |
|
715 | - * @since 1.0.19 |
|
716 | - */ |
|
717 | - public function get_fees() { |
|
718 | - return $this->fees; |
|
719 | - } |
|
720 | - |
|
721 | - /** |
|
722 | - * Checks if there are any fees for the form. |
|
723 | - * |
|
724 | - * @return bool |
|
725 | - * @since 1.0.19 |
|
726 | - */ |
|
727 | - public function has_fees() { |
|
728 | - return count( $this->fees ) !== 0; |
|
729 | - } |
|
730 | - |
|
731 | - /* |
|
649 | + /** |
|
650 | + * Prepares the submission's fees. |
|
651 | + * |
|
652 | + * @since 1.0.19 |
|
653 | + */ |
|
654 | + public function process_fees() { |
|
655 | + |
|
656 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
657 | + |
|
658 | + foreach ( $fees_processor->fees as $fee ) { |
|
659 | + $this->add_fee( $fee ); |
|
660 | + } |
|
661 | + |
|
662 | + do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
663 | + } |
|
664 | + |
|
665 | + /** |
|
666 | + * Adds a fee to the submission. |
|
667 | + * |
|
668 | + * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
|
669 | + * @since 1.0.19 |
|
670 | + */ |
|
671 | + public function add_fee( $fee ) { |
|
672 | + |
|
673 | + $this->fees[ $fee['name'] ] = $fee; |
|
674 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
675 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
676 | + |
|
677 | + } |
|
678 | + |
|
679 | + /** |
|
680 | + * Removes a fee from the submission. |
|
681 | + * |
|
682 | + * @since 1.0.19 |
|
683 | + */ |
|
684 | + public function remove_fee( $name ) { |
|
685 | + |
|
686 | + if ( isset( $this->fees[ $name ] ) ) { |
|
687 | + $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
688 | + $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
689 | + unset( $this->fees[ $name ] ); |
|
690 | + } |
|
691 | + |
|
692 | + } |
|
693 | + |
|
694 | + /** |
|
695 | + * Returns the fees. |
|
696 | + * |
|
697 | + * @since 1.0.19 |
|
698 | + */ |
|
699 | + public function get_fee() { |
|
700 | + return $this->totals['fees']['initial']; |
|
701 | + } |
|
702 | + |
|
703 | + /** |
|
704 | + * Returns the recurring fees. |
|
705 | + * |
|
706 | + * @since 1.0.19 |
|
707 | + */ |
|
708 | + public function get_recurring_fee() { |
|
709 | + return $this->totals['fees']['recurring']; |
|
710 | + } |
|
711 | + |
|
712 | + /** |
|
713 | + * Returns all fees. |
|
714 | + * |
|
715 | + * @since 1.0.19 |
|
716 | + */ |
|
717 | + public function get_fees() { |
|
718 | + return $this->fees; |
|
719 | + } |
|
720 | + |
|
721 | + /** |
|
722 | + * Checks if there are any fees for the form. |
|
723 | + * |
|
724 | + * @return bool |
|
725 | + * @since 1.0.19 |
|
726 | + */ |
|
727 | + public function has_fees() { |
|
728 | + return count( $this->fees ) !== 0; |
|
729 | + } |
|
730 | + |
|
731 | + /* |
|
732 | 732 | |-------------------------------------------------------------------------- |
733 | 733 | | MISC |
734 | 734 | |-------------------------------------------------------------------------- |
@@ -736,109 +736,109 @@ discard block |
||
736 | 736 | | Extra submission functions. |
737 | 737 | */ |
738 | 738 | |
739 | - /** |
|
740 | - * Returns the total amount to collect for this submission. |
|
741 | - * |
|
742 | - * @since 1.0.19 |
|
743 | - */ |
|
744 | - public function get_total() { |
|
745 | - $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
746 | - return max( $total, 0 ); |
|
747 | - } |
|
748 | - |
|
749 | - /** |
|
750 | - * Returns the recurring total amount to collect for this submission. |
|
751 | - * |
|
752 | - * @since 1.0.19 |
|
753 | - */ |
|
754 | - public function get_recurring_total() { |
|
755 | - $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
756 | - return max( $total, 0 ); |
|
757 | - } |
|
758 | - |
|
759 | - /** |
|
760 | - * Whether payment details should be collected for this submission. |
|
761 | - * |
|
762 | - * @since 1.0.19 |
|
763 | - */ |
|
764 | - public function should_collect_payment_details() { |
|
765 | - $initial = $this->get_total(); |
|
766 | - $recurring = $this->get_recurring_total(); |
|
767 | - |
|
768 | - if ( $this->has_recurring == 0 ) { |
|
769 | - $recurring = 0; |
|
770 | - } |
|
771 | - |
|
772 | - $collect = $initial > 0 || $recurring > 0; |
|
773 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
774 | - } |
|
775 | - |
|
776 | - /** |
|
777 | - * Returns the billing email of the user. |
|
778 | - * |
|
779 | - * @since 1.0.19 |
|
780 | - */ |
|
781 | - public function get_billing_email() { |
|
782 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
783 | - } |
|
784 | - |
|
785 | - /** |
|
786 | - * Checks if the submitter has a billing email. |
|
787 | - * |
|
788 | - * @since 1.0.19 |
|
789 | - */ |
|
790 | - public function has_billing_email() { |
|
791 | - $billing_email = $this->get_billing_email(); |
|
792 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
793 | - } |
|
794 | - |
|
795 | - /** |
|
796 | - * Returns the appropriate currency for the submission. |
|
797 | - * |
|
798 | - * @since 1.0.19 |
|
799 | - * @return string |
|
800 | - */ |
|
801 | - public function get_currency() { |
|
802 | - return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
803 | - } |
|
804 | - |
|
805 | - /** |
|
806 | - * Returns the raw submission data. |
|
807 | - * |
|
808 | - * @since 1.0.19 |
|
809 | - * @return array |
|
810 | - */ |
|
811 | - public function get_data() { |
|
812 | - return $this->data; |
|
813 | - } |
|
814 | - |
|
815 | - /** |
|
816 | - * Returns a field from the submission data |
|
817 | - * |
|
818 | - * @param string $field |
|
819 | - * @since 1.0.19 |
|
820 | - * @return mixed|null |
|
821 | - */ |
|
822 | - public function get_field( $field, $sub_array_key = null ) { |
|
823 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
824 | - } |
|
825 | - |
|
826 | - /** |
|
827 | - * Checks if a required field is set. |
|
828 | - * |
|
829 | - * @since 1.0.19 |
|
830 | - */ |
|
831 | - public function is_required_field_set( $field ) { |
|
832 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
833 | - } |
|
834 | - |
|
835 | - /** |
|
836 | - * Formats an amount |
|
837 | - * |
|
838 | - * @since 1.0.19 |
|
839 | - */ |
|
840 | - public function format_amount( $amount ) { |
|
841 | - return wpinv_price( $amount, $this->get_currency() ); |
|
842 | - } |
|
739 | + /** |
|
740 | + * Returns the total amount to collect for this submission. |
|
741 | + * |
|
742 | + * @since 1.0.19 |
|
743 | + */ |
|
744 | + public function get_total() { |
|
745 | + $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
|
746 | + return max( $total, 0 ); |
|
747 | + } |
|
748 | + |
|
749 | + /** |
|
750 | + * Returns the recurring total amount to collect for this submission. |
|
751 | + * |
|
752 | + * @since 1.0.19 |
|
753 | + */ |
|
754 | + public function get_recurring_total() { |
|
755 | + $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
|
756 | + return max( $total, 0 ); |
|
757 | + } |
|
758 | + |
|
759 | + /** |
|
760 | + * Whether payment details should be collected for this submission. |
|
761 | + * |
|
762 | + * @since 1.0.19 |
|
763 | + */ |
|
764 | + public function should_collect_payment_details() { |
|
765 | + $initial = $this->get_total(); |
|
766 | + $recurring = $this->get_recurring_total(); |
|
767 | + |
|
768 | + if ( $this->has_recurring == 0 ) { |
|
769 | + $recurring = 0; |
|
770 | + } |
|
771 | + |
|
772 | + $collect = $initial > 0 || $recurring > 0; |
|
773 | + return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
774 | + } |
|
775 | + |
|
776 | + /** |
|
777 | + * Returns the billing email of the user. |
|
778 | + * |
|
779 | + * @since 1.0.19 |
|
780 | + */ |
|
781 | + public function get_billing_email() { |
|
782 | + return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
783 | + } |
|
784 | + |
|
785 | + /** |
|
786 | + * Checks if the submitter has a billing email. |
|
787 | + * |
|
788 | + * @since 1.0.19 |
|
789 | + */ |
|
790 | + public function has_billing_email() { |
|
791 | + $billing_email = $this->get_billing_email(); |
|
792 | + return ! empty( $billing_email ) && is_email( $billing_email ); |
|
793 | + } |
|
794 | + |
|
795 | + /** |
|
796 | + * Returns the appropriate currency for the submission. |
|
797 | + * |
|
798 | + * @since 1.0.19 |
|
799 | + * @return string |
|
800 | + */ |
|
801 | + public function get_currency() { |
|
802 | + return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency(); |
|
803 | + } |
|
804 | + |
|
805 | + /** |
|
806 | + * Returns the raw submission data. |
|
807 | + * |
|
808 | + * @since 1.0.19 |
|
809 | + * @return array |
|
810 | + */ |
|
811 | + public function get_data() { |
|
812 | + return $this->data; |
|
813 | + } |
|
814 | + |
|
815 | + /** |
|
816 | + * Returns a field from the submission data |
|
817 | + * |
|
818 | + * @param string $field |
|
819 | + * @since 1.0.19 |
|
820 | + * @return mixed|null |
|
821 | + */ |
|
822 | + public function get_field( $field, $sub_array_key = null ) { |
|
823 | + return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
824 | + } |
|
825 | + |
|
826 | + /** |
|
827 | + * Checks if a required field is set. |
|
828 | + * |
|
829 | + * @since 1.0.19 |
|
830 | + */ |
|
831 | + public function is_required_field_set( $field ) { |
|
832 | + return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
833 | + } |
|
834 | + |
|
835 | + /** |
|
836 | + * Formats an amount |
|
837 | + * |
|
838 | + * @since 1.0.19 |
|
839 | + */ |
|
840 | + public function format_amount( $amount ) { |
|
841 | + return wpinv_price( $amount, $this->get_currency() ); |
|
842 | + } |
|
843 | 843 | |
844 | 844 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -134,8 +134,8 @@ discard block |
||
134 | 134 | $this->state = wpinv_get_default_state(); |
135 | 135 | |
136 | 136 | // Do we have an actual submission? |
137 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
138 | - $this->load_data( $_POST ); |
|
137 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
138 | + $this->load_data($_POST); |
|
139 | 139 | } |
140 | 140 | |
141 | 141 | } |
@@ -145,19 +145,19 @@ discard block |
||
145 | 145 | * |
146 | 146 | * @param array $data |
147 | 147 | */ |
148 | - public function load_data( $data ) { |
|
148 | + public function load_data($data) { |
|
149 | 149 | |
150 | 150 | // Remove slashes from the submitted data... |
151 | - $data = wp_unslash( $data ); |
|
151 | + $data = wp_unslash($data); |
|
152 | 152 | |
153 | 153 | // Allow plugins to filter the data. |
154 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
154 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
155 | 155 | |
156 | 156 | // Cache it... |
157 | 157 | $this->data = $data; |
158 | 158 | |
159 | 159 | // Then generate a unique id from the data. |
160 | - $this->id = md5( wp_json_encode( $data ) ); |
|
160 | + $this->id = md5(wp_json_encode($data)); |
|
161 | 161 | |
162 | 162 | // Finally, process the submission. |
163 | 163 | try { |
@@ -167,26 +167,26 @@ discard block |
||
167 | 167 | $processors = apply_filters( |
168 | 168 | 'getpaid_payment_form_submission_processors', |
169 | 169 | array( |
170 | - array( $this, 'process_payment_form' ), |
|
171 | - array( $this, 'process_invoice' ), |
|
172 | - array( $this, 'process_fees' ), |
|
173 | - array( $this, 'process_items' ), |
|
174 | - array( $this, 'process_taxes' ), |
|
175 | - array( $this, 'process_discount' ), |
|
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 | 176 | ), |
177 | 177 | $this |
178 | 178 | ); |
179 | 179 | |
180 | - foreach ( $processors as $processor ) { |
|
181 | - call_user_func_array( $processor, array( &$this ) ); |
|
180 | + foreach ($processors as $processor) { |
|
181 | + call_user_func_array($processor, array(&$this)); |
|
182 | 182 | } |
183 | 183 | |
184 | - } catch ( Exception $e ) { |
|
184 | + } catch (Exception $e) { |
|
185 | 185 | $this->last_error = $e->getMessage(); |
186 | 186 | } |
187 | 187 | |
188 | 188 | // Fired when we are done processing a submission. |
189 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
189 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
190 | 190 | |
191 | 191 | } |
192 | 192 | |
@@ -207,18 +207,18 @@ discard block |
||
207 | 207 | public function process_payment_form() { |
208 | 208 | |
209 | 209 | // Every submission needs an active payment form. |
210 | - if ( empty( $this->data['form_id'] ) ) { |
|
211 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
210 | + if (empty($this->data['form_id'])) { |
|
211 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
212 | 212 | } |
213 | 213 | |
214 | 214 | // Fetch the payment form. |
215 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
215 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
216 | 216 | |
217 | - if ( ! $this->payment_form->is_active() ) { |
|
218 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
217 | + if (!$this->payment_form->is_active()) { |
|
218 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
219 | 219 | } |
220 | 220 | |
221 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
221 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
222 | 222 | } |
223 | 223 | |
224 | 224 | /** |
@@ -248,30 +248,30 @@ discard block |
||
248 | 248 | public function process_invoice() { |
249 | 249 | |
250 | 250 | // Abort if there is no invoice. |
251 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
251 | + if (empty($this->data['invoice_id'])) { |
|
252 | 252 | return; |
253 | 253 | } |
254 | 254 | |
255 | 255 | // If the submission is for an existing invoice, ensure that it exists |
256 | 256 | // and that it is not paid for. |
257 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
257 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
258 | 258 | |
259 | - if ( empty( $invoice ) ) { |
|
260 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
259 | + if (empty($invoice)) { |
|
260 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
261 | 261 | } |
262 | 262 | |
263 | - if ( $invoice->is_paid() ) { |
|
264 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
263 | + if ($invoice->is_paid()) { |
|
264 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
265 | 265 | } |
266 | 266 | |
267 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
267 | + $this->payment_form->set_items($invoice->get_items()); |
|
268 | 268 | $this->payment_form->invoice = $invoice; |
269 | 269 | |
270 | 270 | $this->country = $invoice->get_country(); |
271 | 271 | $this->state = $invoice->get_state(); |
272 | 272 | $this->invoice = $invoice; |
273 | 273 | |
274 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
274 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /** |
@@ -291,7 +291,7 @@ discard block |
||
291 | 291 | * @return bool |
292 | 292 | */ |
293 | 293 | public function has_invoice() { |
294 | - return ! empty( $this->invoice ); |
|
294 | + return !empty($this->invoice); |
|
295 | 295 | } |
296 | 296 | |
297 | 297 | /* |
@@ -310,13 +310,13 @@ discard block |
||
310 | 310 | */ |
311 | 311 | public function process_items() { |
312 | 312 | |
313 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
313 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
314 | 314 | |
315 | - foreach ( $processor->items as $item ) { |
|
316 | - $this->add_item( $item ); |
|
315 | + foreach ($processor->items as $item) { |
|
316 | + $this->add_item($item); |
|
317 | 317 | } |
318 | 318 | |
319 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
319 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
320 | 320 | } |
321 | 321 | |
322 | 322 | /** |
@@ -325,18 +325,18 @@ discard block |
||
325 | 325 | * @since 1.0.19 |
326 | 326 | * @param GetPaid_Form_Item $item |
327 | 327 | */ |
328 | - public function add_item( $item ) { |
|
328 | + public function add_item($item) { |
|
329 | 329 | |
330 | 330 | // Make sure that it is available for purchase. |
331 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
331 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
332 | 332 | return; |
333 | 333 | } |
334 | 334 | |
335 | 335 | // Each submission can only contain one recurring item. |
336 | - if ( $item->is_recurring() ) { |
|
336 | + if ($item->is_recurring()) { |
|
337 | 337 | |
338 | - if ( $this->has_recurring != 0 ) { |
|
339 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
338 | + if ($this->has_recurring != 0) { |
|
339 | + throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing')); |
|
340 | 340 | } |
341 | 341 | |
342 | 342 | $this->has_recurring = $item->get_id(); |
@@ -344,7 +344,7 @@ discard block |
||
344 | 344 | } |
345 | 345 | |
346 | 346 | // Update the items and totals. |
347 | - $this->items[ $item->get_id() ] = $item; |
|
347 | + $this->items[$item->get_id()] = $item; |
|
348 | 348 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
349 | 349 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
350 | 350 | |
@@ -358,17 +358,17 @@ discard block |
||
358 | 358 | * |
359 | 359 | * @since 1.0.19 |
360 | 360 | */ |
361 | - public function remove_item( $item_id ) { |
|
361 | + public function remove_item($item_id) { |
|
362 | 362 | |
363 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
364 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
365 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
363 | + if (isset($this->items[$item_id])) { |
|
364 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
365 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
366 | 366 | |
367 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
367 | + if ($this->items[$item_id]->is_recurring()) { |
|
368 | 368 | $this->has_recurring = 0; |
369 | 369 | } |
370 | 370 | |
371 | - unset( $this->items[ $item_id ] ); |
|
371 | + unset($this->items[$item_id]); |
|
372 | 372 | } |
373 | 373 | |
374 | 374 | } |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | */ |
381 | 381 | public function get_subtotal() { |
382 | 382 | |
383 | - if ( wpinv_prices_include_tax() ) { |
|
383 | + if (wpinv_prices_include_tax()) { |
|
384 | 384 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
385 | 385 | } |
386 | 386 | |
@@ -394,7 +394,7 @@ discard block |
||
394 | 394 | */ |
395 | 395 | public function get_recurring_subtotal() { |
396 | 396 | |
397 | - if ( wpinv_prices_include_tax() ) { |
|
397 | + if (wpinv_prices_include_tax()) { |
|
398 | 398 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
399 | 399 | } |
400 | 400 | |
@@ -428,33 +428,33 @@ discard block |
||
428 | 428 | public function process_taxes() { |
429 | 429 | |
430 | 430 | // Abort if we're not using taxes. |
431 | - if ( ! $this->use_taxes() ) { |
|
431 | + if (!$this->use_taxes()) { |
|
432 | 432 | return; |
433 | 433 | } |
434 | 434 | |
435 | 435 | // If a custom country && state has been passed in, use it to calculate taxes. |
436 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
437 | - if ( ! empty( $country ) ) { |
|
436 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
437 | + if (!empty($country)) { |
|
438 | 438 | $this->country = $country; |
439 | 439 | } |
440 | 440 | |
441 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
442 | - if ( ! empty( $state ) ) { |
|
441 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
442 | + if (!empty($state)) { |
|
443 | 443 | $this->state = $state; |
444 | 444 | } |
445 | 445 | |
446 | 446 | // Abort if the country is not taxable. |
447 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
447 | + if (!wpinv_is_country_taxable($this->country)) { |
|
448 | 448 | return; |
449 | 449 | } |
450 | 450 | |
451 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
451 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
452 | 452 | |
453 | - foreach ( $processor->taxes as $tax ) { |
|
454 | - $this->add_tax( $tax ); |
|
453 | + foreach ($processor->taxes as $tax) { |
|
454 | + $this->add_tax($tax); |
|
455 | 455 | } |
456 | 456 | |
457 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
457 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
458 | 458 | } |
459 | 459 | |
460 | 460 | /** |
@@ -463,16 +463,16 @@ discard block |
||
463 | 463 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
464 | 464 | * @since 1.0.19 |
465 | 465 | */ |
466 | - public function add_tax( $tax ) { |
|
466 | + public function add_tax($tax) { |
|
467 | 467 | |
468 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
469 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
470 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
468 | + if (wpinv_round_tax_per_tax_rate()) { |
|
469 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
470 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
471 | 471 | } |
472 | 472 | |
473 | - $this->taxes[ $tax['name'] ] = $tax; |
|
474 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
475 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
473 | + $this->taxes[$tax['name']] = $tax; |
|
474 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
475 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
476 | 476 | |
477 | 477 | } |
478 | 478 | |
@@ -481,12 +481,12 @@ discard block |
||
481 | 481 | * |
482 | 482 | * @since 1.0.19 |
483 | 483 | */ |
484 | - public function remove_tax( $tax_name ) { |
|
484 | + public function remove_tax($tax_name) { |
|
485 | 485 | |
486 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
487 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
488 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
489 | - unset( $this->taxes[ $tax_name ] ); |
|
486 | + if (isset($this->taxes[$tax_name])) { |
|
487 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
488 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
489 | + unset($this->taxes[$tax_name]); |
|
490 | 490 | } |
491 | 491 | |
492 | 492 | } |
@@ -500,11 +500,11 @@ discard block |
||
500 | 500 | |
501 | 501 | $use_taxes = wpinv_use_taxes(); |
502 | 502 | |
503 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
503 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
504 | 504 | $use_taxes = false; |
505 | 505 | } |
506 | 506 | |
507 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
507 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
508 | 508 | |
509 | 509 | } |
510 | 510 | |
@@ -553,13 +553,13 @@ discard block |
||
553 | 553 | |
554 | 554 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
555 | 555 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
556 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
556 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
557 | 557 | |
558 | - foreach ( $processor->discounts as $discount ) { |
|
559 | - $this->add_discount( $discount ); |
|
558 | + foreach ($processor->discounts as $discount) { |
|
559 | + $this->add_discount($discount); |
|
560 | 560 | } |
561 | 561 | |
562 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
562 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
563 | 563 | } |
564 | 564 | |
565 | 565 | /** |
@@ -568,10 +568,10 @@ discard block |
||
568 | 568 | * @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. |
569 | 569 | * @since 1.0.19 |
570 | 570 | */ |
571 | - public function add_discount( $discount ) { |
|
572 | - $this->discounts[ $discount['name'] ] = $discount; |
|
573 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
574 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
571 | + public function add_discount($discount) { |
|
572 | + $this->discounts[$discount['name']] = $discount; |
|
573 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
574 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
575 | 575 | } |
576 | 576 | |
577 | 577 | /** |
@@ -579,12 +579,12 @@ discard block |
||
579 | 579 | * |
580 | 580 | * @since 1.0.19 |
581 | 581 | */ |
582 | - public function remove_discount( $name ) { |
|
582 | + public function remove_discount($name) { |
|
583 | 583 | |
584 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
585 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
586 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
587 | - unset( $this->discounts[ $name ] ); |
|
584 | + if (isset($this->discounts[$name])) { |
|
585 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
586 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
587 | + unset($this->discounts[$name]); |
|
588 | 588 | } |
589 | 589 | |
590 | 590 | } |
@@ -596,7 +596,7 @@ discard block |
||
596 | 596 | * @return bool |
597 | 597 | */ |
598 | 598 | public function has_discount_code() { |
599 | - return ! empty( $this->discounts['discount_code'] ); |
|
599 | + return !empty($this->discounts['discount_code']); |
|
600 | 600 | } |
601 | 601 | |
602 | 602 | /** |
@@ -653,13 +653,13 @@ discard block |
||
653 | 653 | */ |
654 | 654 | public function process_fees() { |
655 | 655 | |
656 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
656 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
657 | 657 | |
658 | - foreach ( $fees_processor->fees as $fee ) { |
|
659 | - $this->add_fee( $fee ); |
|
658 | + foreach ($fees_processor->fees as $fee) { |
|
659 | + $this->add_fee($fee); |
|
660 | 660 | } |
661 | 661 | |
662 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
662 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
663 | 663 | } |
664 | 664 | |
665 | 665 | /** |
@@ -668,11 +668,11 @@ discard block |
||
668 | 668 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
669 | 669 | * @since 1.0.19 |
670 | 670 | */ |
671 | - public function add_fee( $fee ) { |
|
671 | + public function add_fee($fee) { |
|
672 | 672 | |
673 | - $this->fees[ $fee['name'] ] = $fee; |
|
674 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
675 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
673 | + $this->fees[$fee['name']] = $fee; |
|
674 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
675 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
676 | 676 | |
677 | 677 | } |
678 | 678 | |
@@ -681,12 +681,12 @@ discard block |
||
681 | 681 | * |
682 | 682 | * @since 1.0.19 |
683 | 683 | */ |
684 | - public function remove_fee( $name ) { |
|
684 | + public function remove_fee($name) { |
|
685 | 685 | |
686 | - if ( isset( $this->fees[ $name ] ) ) { |
|
687 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
688 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
689 | - unset( $this->fees[ $name ] ); |
|
686 | + if (isset($this->fees[$name])) { |
|
687 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
688 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
689 | + unset($this->fees[$name]); |
|
690 | 690 | } |
691 | 691 | |
692 | 692 | } |
@@ -725,7 +725,7 @@ discard block |
||
725 | 725 | * @since 1.0.19 |
726 | 726 | */ |
727 | 727 | public function has_fees() { |
728 | - return count( $this->fees ) !== 0; |
|
728 | + return count($this->fees) !== 0; |
|
729 | 729 | } |
730 | 730 | |
731 | 731 | /* |
@@ -743,7 +743,7 @@ discard block |
||
743 | 743 | */ |
744 | 744 | public function get_total() { |
745 | 745 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
746 | - return max( $total, 0 ); |
|
746 | + return max($total, 0); |
|
747 | 747 | } |
748 | 748 | |
749 | 749 | /** |
@@ -753,7 +753,7 @@ discard block |
||
753 | 753 | */ |
754 | 754 | public function get_recurring_total() { |
755 | 755 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
756 | - return max( $total, 0 ); |
|
756 | + return max($total, 0); |
|
757 | 757 | } |
758 | 758 | |
759 | 759 | /** |
@@ -765,12 +765,12 @@ discard block |
||
765 | 765 | $initial = $this->get_total(); |
766 | 766 | $recurring = $this->get_recurring_total(); |
767 | 767 | |
768 | - if ( $this->has_recurring == 0 ) { |
|
768 | + if ($this->has_recurring == 0) { |
|
769 | 769 | $recurring = 0; |
770 | 770 | } |
771 | 771 | |
772 | 772 | $collect = $initial > 0 || $recurring > 0; |
773 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
773 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
774 | 774 | } |
775 | 775 | |
776 | 776 | /** |
@@ -779,7 +779,7 @@ discard block |
||
779 | 779 | * @since 1.0.19 |
780 | 780 | */ |
781 | 781 | public function get_billing_email() { |
782 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
782 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
783 | 783 | } |
784 | 784 | |
785 | 785 | /** |
@@ -789,7 +789,7 @@ discard block |
||
789 | 789 | */ |
790 | 790 | public function has_billing_email() { |
791 | 791 | $billing_email = $this->get_billing_email(); |
792 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
792 | + return !empty($billing_email) && is_email($billing_email); |
|
793 | 793 | } |
794 | 794 | |
795 | 795 | /** |
@@ -819,8 +819,8 @@ discard block |
||
819 | 819 | * @since 1.0.19 |
820 | 820 | * @return mixed|null |
821 | 821 | */ |
822 | - public function get_field( $field, $sub_array_key = null ) { |
|
823 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
822 | + public function get_field($field, $sub_array_key = null) { |
|
823 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
824 | 824 | } |
825 | 825 | |
826 | 826 | /** |
@@ -828,8 +828,8 @@ discard block |
||
828 | 828 | * |
829 | 829 | * @since 1.0.19 |
830 | 830 | */ |
831 | - public function is_required_field_set( $field ) { |
|
832 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
831 | + public function is_required_field_set($field) { |
|
832 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
@@ -837,8 +837,8 @@ discard block |
||
837 | 837 | * |
838 | 838 | * @since 1.0.19 |
839 | 839 | */ |
840 | - public function format_amount( $amount ) { |
|
841 | - return wpinv_price( $amount, $this->get_currency() ); |
|
840 | + public function format_amount($amount) { |
|
841 | + return wpinv_price($amount, $this->get_currency()); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | } |
@@ -1,7 +1,7 @@ discard block |
||
1 | 1 | <?php |
2 | 2 | // MUST have WordPress. |
3 | -if ( !defined( 'WPINC' ) ) { |
|
4 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
3 | +if (!defined('WPINC')) { |
|
4 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
5 | 5 | } |
6 | 6 | |
7 | 7 | class WPInv_Meta_Box_Payment_Form { |
@@ -11,23 +11,23 @@ discard block |
||
11 | 11 | * |
12 | 12 | * @param WP_Post $post |
13 | 13 | */ |
14 | - public static function output_details( $post ) { |
|
15 | - $details = get_post_meta( $post->ID, 'payment_form_data', true ); |
|
14 | + public static function output_details($post) { |
|
15 | + $details = get_post_meta($post->ID, 'payment_form_data', true); |
|
16 | 16 | |
17 | - if ( ! is_array( $details ) ) { |
|
17 | + if (!is_array($details)) { |
|
18 | 18 | return; |
19 | 19 | } |
20 | 20 | |
21 | 21 | echo '<div class="bsui"> <div class="form-row">'; |
22 | 22 | |
23 | - foreach ( $details as $key => $value ) { |
|
24 | - $key = sanitize_text_field( $key ); |
|
23 | + foreach ($details as $key => $value) { |
|
24 | + $key = sanitize_text_field($key); |
|
25 | 25 | |
26 | - if ( is_array( $value ) ) { |
|
27 | - $value = implode( ',', $value ); |
|
26 | + if (is_array($value)) { |
|
27 | + $value = implode(',', $value); |
|
28 | 28 | } |
29 | 29 | |
30 | - $value = esc_html( $value ); |
|
30 | + $value = esc_html($value); |
|
31 | 31 | echo "<div class='col-6 form-group'><strong>$key:</strong></div><div class='col-6 form-group'>$value</div>"; |
32 | 32 | } |
33 | 33 | |
@@ -40,13 +40,13 @@ discard block |
||
40 | 40 | * |
41 | 41 | * @param WP_Post $post |
42 | 42 | */ |
43 | - public static function output_shortcode( $post ) { |
|
43 | + public static function output_shortcode($post) { |
|
44 | 44 | |
45 | - if ( ! is_numeric( $post ) ) { |
|
45 | + if (!is_numeric($post)) { |
|
46 | 46 | $post = $post->ID; |
47 | 47 | } |
48 | 48 | |
49 | - if ( $post == wpinv_get_default_payment_form() ) { |
|
49 | + if ($post == wpinv_get_default_payment_form()) { |
|
50 | 50 | echo '—'; |
51 | 51 | return; |
52 | 52 | } |
@@ -55,27 +55,27 @@ |
||
55 | 55 | public static function vat_rates_settings() {} |
56 | 56 | |
57 | 57 | /** |
58 | - * |
|
59 | - * @deprecated |
|
60 | - */ |
|
58 | + * |
|
59 | + * @deprecated |
|
60 | + */ |
|
61 | 61 | public static function vat_settings() {} |
62 | 62 | |
63 | 63 | /** |
64 | - * |
|
65 | - * @deprecated |
|
66 | - */ |
|
64 | + * |
|
65 | + * @deprecated |
|
66 | + */ |
|
67 | 67 | public static function maxmind_folder() {} |
68 | 68 | |
69 | 69 | /** |
70 | - * |
|
71 | - * @deprecated |
|
72 | - */ |
|
70 | + * |
|
71 | + * @deprecated |
|
72 | + */ |
|
73 | 73 | public static function geoip2_download_database() {} |
74 | 74 | |
75 | 75 | /** |
76 | - * |
|
77 | - * @deprecated |
|
78 | - */ |
|
76 | + * |
|
77 | + * @deprecated |
|
78 | + */ |
|
79 | 79 | public static function geoip2_download_file() {} |
80 | 80 | |
81 | 81 | /** |
@@ -4,7 +4,7 @@ discard block |
||
4 | 4 | * |
5 | 5 | */ |
6 | 6 | |
7 | -defined( 'ABSPATH' ) || exit; |
|
7 | +defined('ABSPATH') || exit; |
|
8 | 8 | |
9 | 9 | /** |
10 | 10 | * @deprecated |
@@ -38,15 +38,15 @@ discard block |
||
38 | 38 | /** |
39 | 39 | * @deprecated |
40 | 40 | */ |
41 | - public static function is_eu_state( $country_code ) { |
|
42 | - return getpaid_is_eu_state( $country_code ); |
|
41 | + public static function is_eu_state($country_code) { |
|
42 | + return getpaid_is_eu_state($country_code); |
|
43 | 43 | } |
44 | 44 | |
45 | 45 | /** |
46 | 46 | * @deprecated |
47 | 47 | */ |
48 | - public static function is_gst_country( $country_code ) { |
|
49 | - return getpaid_is_gst_country( $country_code ); |
|
48 | + public static function is_gst_country($country_code) { |
|
49 | + return getpaid_is_gst_country($country_code); |
|
50 | 50 | } |
51 | 51 | |
52 | 52 | /** |