@@ -15,26 +15,26 @@ discard block |
||
15 | 15 | * |
16 | 16 | * @return int|array|WPInv_Subscription[]|GetPaid_Subscriptions_Query |
17 | 17 | */ |
18 | -function getpaid_get_subscriptions( $args = array(), $return = 'results' ) { |
|
18 | +function getpaid_get_subscriptions($args = array(), $return = 'results') { |
|
19 | 19 | |
20 | 20 | // Do not retrieve all fields if we just want the count. |
21 | - if ( 'count' == $return ) { |
|
21 | + if ('count' == $return) { |
|
22 | 22 | $args['fields'] = 'id'; |
23 | 23 | $args['number'] = 1; |
24 | 24 | } |
25 | 25 | |
26 | 26 | // Do not count all matches if we just want the results. |
27 | - if ( 'results' == $return ) { |
|
27 | + if ('results' == $return) { |
|
28 | 28 | $args['count_total'] = false; |
29 | 29 | } |
30 | 30 | |
31 | - $query = new GetPaid_Subscriptions_Query( $args ); |
|
31 | + $query = new GetPaid_Subscriptions_Query($args); |
|
32 | 32 | |
33 | - if ( 'results' == $return ) { |
|
33 | + if ('results' == $return) { |
|
34 | 34 | return $query->get_results(); |
35 | 35 | } |
36 | 36 | |
37 | - if ( 'count' == $return ) { |
|
37 | + if ('count' == $return) { |
|
38 | 38 | return $query->get_total(); |
39 | 39 | } |
40 | 40 | |
@@ -51,13 +51,13 @@ discard block |
||
51 | 51 | return apply_filters( |
52 | 52 | 'getpaid_get_subscription_statuses', |
53 | 53 | array( |
54 | - 'pending' => __( 'Pending', 'invoicing' ), |
|
55 | - 'trialling' => __( 'Trialing', 'invoicing' ), |
|
56 | - 'active' => __( 'Active', 'invoicing' ), |
|
57 | - 'failing' => __( 'Failing', 'invoicing' ), |
|
58 | - 'expired' => __( 'Expired', 'invoicing' ), |
|
59 | - 'completed' => __( 'Complete', 'invoicing' ), |
|
60 | - 'cancelled' => __( 'Cancelled', 'invoicing' ), |
|
54 | + 'pending' => __('Pending', 'invoicing'), |
|
55 | + 'trialling' => __('Trialing', 'invoicing'), |
|
56 | + 'active' => __('Active', 'invoicing'), |
|
57 | + 'failing' => __('Failing', 'invoicing'), |
|
58 | + 'expired' => __('Expired', 'invoicing'), |
|
59 | + 'completed' => __('Complete', 'invoicing'), |
|
60 | + 'cancelled' => __('Cancelled', 'invoicing'), |
|
61 | 61 | ) |
62 | 62 | ); |
63 | 63 | |
@@ -68,9 +68,9 @@ discard block |
||
68 | 68 | * |
69 | 69 | * @return string |
70 | 70 | */ |
71 | -function getpaid_get_subscription_status_label( $status ) { |
|
71 | +function getpaid_get_subscription_status_label($status) { |
|
72 | 72 | $statuses = getpaid_get_subscription_statuses(); |
73 | - return isset( $statuses[ $status ] ) ? $statuses[ $status ] : ucfirst( sanitize_text_field( $status ) ); |
|
73 | + return isset($statuses[$status]) ? $statuses[$status] : ucfirst(sanitize_text_field($status)); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | /** |
@@ -100,14 +100,14 @@ discard block |
||
100 | 100 | * |
101 | 101 | * @return array |
102 | 102 | */ |
103 | -function getpaid_get_subscription_status_counts( $args = array() ) { |
|
103 | +function getpaid_get_subscription_status_counts($args = array()) { |
|
104 | 104 | |
105 | - $statuses = array_keys( getpaid_get_subscription_statuses() ); |
|
105 | + $statuses = array_keys(getpaid_get_subscription_statuses()); |
|
106 | 106 | $counts = array(); |
107 | 107 | |
108 | - foreach ( $statuses as $status ) { |
|
109 | - $_args = wp_parse_args( "status=$status", $args ); |
|
110 | - $counts[ $status ] = getpaid_get_subscriptions( $_args, 'count' ); |
|
108 | + foreach ($statuses as $status) { |
|
109 | + $_args = wp_parse_args("status=$status", $args); |
|
110 | + $counts[$status] = getpaid_get_subscriptions($_args, 'count'); |
|
111 | 111 | } |
112 | 112 | |
113 | 113 | return $counts; |
@@ -126,23 +126,23 @@ discard block |
||
126 | 126 | array( |
127 | 127 | |
128 | 128 | 'day' => array( |
129 | - 'singular' => __( '%s day', 'invoicing' ), |
|
130 | - 'plural' => __( '%d days', 'invoicing' ), |
|
129 | + 'singular' => __('%s day', 'invoicing'), |
|
130 | + 'plural' => __('%d days', 'invoicing'), |
|
131 | 131 | ), |
132 | 132 | |
133 | 133 | 'week' => array( |
134 | - 'singular' => __( '%s week', 'invoicing' ), |
|
135 | - 'plural' => __( '%d weeks', 'invoicing' ), |
|
134 | + 'singular' => __('%s week', 'invoicing'), |
|
135 | + 'plural' => __('%d weeks', 'invoicing'), |
|
136 | 136 | ), |
137 | 137 | |
138 | 138 | 'month' => array( |
139 | - 'singular' => __( '%s month', 'invoicing' ), |
|
140 | - 'plural' => __( '%d months', 'invoicing' ), |
|
139 | + 'singular' => __('%s month', 'invoicing'), |
|
140 | + 'plural' => __('%d months', 'invoicing'), |
|
141 | 141 | ), |
142 | 142 | |
143 | 143 | 'year' => array( |
144 | - 'singular' => __( '%s year', 'invoicing' ), |
|
145 | - 'plural' => __( '%d years', 'invoicing' ), |
|
144 | + 'singular' => __('%s year', 'invoicing'), |
|
145 | + 'plural' => __('%d years', 'invoicing'), |
|
146 | 146 | ), |
147 | 147 | |
148 | 148 | ) |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | * @param string $trial_period |
157 | 157 | * @return int |
158 | 158 | */ |
159 | -function getpaid_get_subscription_trial_period_interval( $trial_period ) { |
|
160 | - return (int) preg_replace( '/[^0-9]/', '', $trial_period ); |
|
159 | +function getpaid_get_subscription_trial_period_interval($trial_period) { |
|
160 | + return (int) preg_replace('/[^0-9]/', '', $trial_period); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -166,8 +166,8 @@ discard block |
||
166 | 166 | * @param string $trial_period |
167 | 167 | * @return string |
168 | 168 | */ |
169 | -function getpaid_get_subscription_trial_period_period( $trial_period ) { |
|
170 | - return preg_replace( '/[^a-z]/', '', strtolower( $trial_period ) ); |
|
169 | +function getpaid_get_subscription_trial_period_period($trial_period) { |
|
170 | + return preg_replace('/[^a-z]/', '', strtolower($trial_period)); |
|
171 | 171 | } |
172 | 172 | |
173 | 173 | /** |
@@ -177,9 +177,9 @@ discard block |
||
177 | 177 | * @param int $interval |
178 | 178 | * @return string |
179 | 179 | */ |
180 | -function getpaid_get_subscription_period_label( $period, $interval = 1, $singular_prefix = '1' ) { |
|
181 | - $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label( $period, $interval ) : getpaid_get_singular_subscription_period_label( $period, $singular_prefix ); |
|
182 | - return strtolower( sanitize_text_field( $label ) ); |
|
180 | +function getpaid_get_subscription_period_label($period, $interval = 1, $singular_prefix = '1') { |
|
181 | + $label = (int) $interval > 1 ? getpaid_get_plural_subscription_period_label($period, $interval) : getpaid_get_singular_subscription_period_label($period, $singular_prefix); |
|
182 | + return strtolower(sanitize_text_field($label)); |
|
183 | 183 | } |
184 | 184 | |
185 | 185 | /** |
@@ -188,19 +188,19 @@ discard block |
||
188 | 188 | * @param string $period |
189 | 189 | * @return string |
190 | 190 | */ |
191 | -function getpaid_get_singular_subscription_period_label( $period, $singular_prefix = '1' ) { |
|
191 | +function getpaid_get_singular_subscription_period_label($period, $singular_prefix = '1') { |
|
192 | 192 | |
193 | 193 | $periods = getpaid_get_subscription_periods(); |
194 | - $period = strtolower( $period ); |
|
194 | + $period = strtolower($period); |
|
195 | 195 | |
196 | - if ( isset( $periods[ $period ] ) ) { |
|
197 | - return sprintf( $periods[ $period ]['singular'], $singular_prefix ); |
|
196 | + if (isset($periods[$period])) { |
|
197 | + return sprintf($periods[$period]['singular'], $singular_prefix); |
|
198 | 198 | } |
199 | 199 | |
200 | 200 | // Backwards compatibility. |
201 | - foreach ( $periods as $key => $data ) { |
|
202 | - if ( strpos( $key, $period ) === 0 ) { |
|
203 | - return sprintf( $data['singular'], $singular_prefix ); |
|
201 | + foreach ($periods as $key => $data) { |
|
202 | + if (strpos($key, $period) === 0) { |
|
203 | + return sprintf($data['singular'], $singular_prefix); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 | |
@@ -215,19 +215,19 @@ discard block |
||
215 | 215 | * @param int $interval |
216 | 216 | * @return string |
217 | 217 | */ |
218 | -function getpaid_get_plural_subscription_period_label( $period, $interval ) { |
|
218 | +function getpaid_get_plural_subscription_period_label($period, $interval) { |
|
219 | 219 | |
220 | 220 | $periods = getpaid_get_subscription_periods(); |
221 | - $period = strtolower( $period ); |
|
221 | + $period = strtolower($period); |
|
222 | 222 | |
223 | - if ( isset( $periods[ $period ] ) ) { |
|
224 | - return sprintf( $periods[ $period ]['plural'], $interval ); |
|
223 | + if (isset($periods[$period])) { |
|
224 | + return sprintf($periods[$period]['plural'], $interval); |
|
225 | 225 | } |
226 | 226 | |
227 | 227 | // Backwards compatibility. |
228 | - foreach ( $periods as $key => $data ) { |
|
229 | - if ( strpos( $key, $period ) === 0 ) { |
|
230 | - return sprintf( $data['plural'], $interval ); |
|
228 | + foreach ($periods as $key => $data) { |
|
229 | + if (strpos($key, $period) === 0) { |
|
230 | + return sprintf($data['plural'], $interval); |
|
231 | 231 | } |
232 | 232 | } |
233 | 233 | |
@@ -241,32 +241,32 @@ discard block |
||
241 | 241 | * @param WPInv_Subscription $subscription |
242 | 242 | * @return string |
243 | 243 | */ |
244 | -function getpaid_get_formatted_subscription_amount( $subscription ) { |
|
244 | +function getpaid_get_formatted_subscription_amount($subscription) { |
|
245 | 245 | |
246 | - $initial = wpinv_price( $subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
247 | - $recurring = wpinv_price( $subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency() ); |
|
248 | - $period = getpaid_get_subscription_period_label( $subscription->get_period(), $subscription->get_frequency(), '' ); |
|
246 | + $initial = wpinv_price($subscription->get_initial_amount(), $subscription->get_parent_payment()->get_currency()); |
|
247 | + $recurring = wpinv_price($subscription->get_recurring_amount(), $subscription->get_parent_payment()->get_currency()); |
|
248 | + $period = getpaid_get_subscription_period_label($subscription->get_period(), $subscription->get_frequency(), ''); |
|
249 | 249 | $bill_times = $subscription->get_bill_times(); |
250 | 250 | |
251 | - if ( ! empty( $bill_times ) ) { |
|
251 | + if (!empty($bill_times)) { |
|
252 | 252 | $bill_times = $subscription->get_frequency() * $bill_times; |
253 | - $bill_times = getpaid_get_subscription_period_label( $subscription->get_period(), $bill_times ); |
|
253 | + $bill_times = getpaid_get_subscription_period_label($subscription->get_period(), $bill_times); |
|
254 | 254 | } |
255 | 255 | |
256 | 256 | // Trial periods. |
257 | - if ( $subscription->has_trial_period() ) { |
|
257 | + if ($subscription->has_trial_period()) { |
|
258 | 258 | |
259 | - $trial_period = getpaid_get_subscription_trial_period_period( $subscription->get_trial_period() ); |
|
260 | - $trial_interval = getpaid_get_subscription_trial_period_interval( $subscription->get_trial_period() ); |
|
259 | + $trial_period = getpaid_get_subscription_trial_period_period($subscription->get_trial_period()); |
|
260 | + $trial_interval = getpaid_get_subscription_trial_period_interval($subscription->get_trial_period()); |
|
261 | 261 | |
262 | - if ( empty( $bill_times ) ) { |
|
262 | + if (empty($bill_times)) { |
|
263 | 263 | |
264 | 264 | return sprintf( |
265 | 265 | |
266 | 266 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period |
267 | - _x( '%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing' ), |
|
267 | + _x('%1$s trial for %2$s then %3$s / %4$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year)', 'invoicing'), |
|
268 | 268 | $initial, |
269 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
269 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
270 | 270 | $recurring, |
271 | 271 | $period |
272 | 272 | |
@@ -277,9 +277,9 @@ discard block |
||
277 | 277 | return sprintf( |
278 | 278 | |
279 | 279 | // translators: $1: is the initial amount, $2: is the trial period, $3: is the recurring amount, $4: is the recurring period, $5: is the bill times |
280 | - _x( '%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing' ), |
|
280 | + _x('%1$s trial for %2$s then %3$s / %4$s for %5$s', 'Subscription amount. (e.g.: $10 trial for 1 month then $120 / year for 4 years)', 'invoicing'), |
|
281 | 281 | $initial, |
282 | - getpaid_get_subscription_period_label( $trial_period, $trial_interval ), |
|
282 | + getpaid_get_subscription_period_label($trial_period, $trial_interval), |
|
283 | 283 | $recurring, |
284 | 284 | $period, |
285 | 285 | $bill_times |
@@ -287,14 +287,14 @@ discard block |
||
287 | 287 | |
288 | 288 | } |
289 | 289 | |
290 | - if ( $initial != $recurring ) { |
|
290 | + if ($initial != $recurring) { |
|
291 | 291 | |
292 | - if ( empty( $bill_times ) ) { |
|
292 | + if (empty($bill_times)) { |
|
293 | 293 | |
294 | 294 | return sprintf( |
295 | 295 | |
296 | 296 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period |
297 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing' ), |
|
297 | + _x('Initial payment of %1$s which renews at %2$s / %3$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year)', 'invoicing'), |
|
298 | 298 | $initial, |
299 | 299 | $recurring, |
300 | 300 | $period |
@@ -306,7 +306,7 @@ discard block |
||
306 | 306 | return sprintf( |
307 | 307 | |
308 | 308 | // translators: $1: is the initial amount, $2: is the recurring amount, $3: is the recurring period, $4: is the bill times |
309 | - _x( 'Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing' ), |
|
309 | + _x('Initial payment of %1$s which renews at %2$s / %3$s for %4$s', 'Subscription amount. (e.g.:Initial payment of $100 which renews at $120 / year for 5 years)', 'invoicing'), |
|
310 | 310 | $initial, |
311 | 311 | $recurring, |
312 | 312 | $period, |
@@ -316,12 +316,12 @@ discard block |
||
316 | 316 | |
317 | 317 | } |
318 | 318 | |
319 | - if ( empty( $bill_times ) ) { |
|
319 | + if (empty($bill_times)) { |
|
320 | 320 | |
321 | 321 | return sprintf( |
322 | 322 | |
323 | 323 | // translators: $1: is the recurring amount, $2: is the recurring period |
324 | - _x( '%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing' ), |
|
324 | + _x('%1$s / %2$s', 'Subscription amount. (e.g.: $120 / year)', 'invoicing'), |
|
325 | 325 | $initial, |
326 | 326 | $period |
327 | 327 | |
@@ -332,7 +332,7 @@ discard block |
||
332 | 332 | return sprintf( |
333 | 333 | |
334 | 334 | // translators: $1: is the bill times, $2: is the recurring amount, $3: is the recurring period |
335 | - _x( '%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing' ), |
|
335 | + _x('%2$s / %3$s for %1$s', 'Subscription amount. (e.g.: $120 / year for 5 years)', 'invoicing'), |
|
336 | 336 | $bill_times, |
337 | 337 | $initial, |
338 | 338 | $period |
@@ -347,8 +347,8 @@ discard block |
||
347 | 347 | * @param WPInv_Invoice $invoice |
348 | 348 | * @return WPInv_Subscription|bool |
349 | 349 | */ |
350 | -function getpaid_get_invoice_subscription( $invoice ) { |
|
351 | - return getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
350 | +function getpaid_get_invoice_subscription($invoice) { |
|
351 | + return getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
352 | 352 | } |
353 | 353 | |
354 | 354 | /** |
@@ -356,9 +356,9 @@ discard block |
||
356 | 356 | * |
357 | 357 | * @param WPInv_Invoice $invoice |
358 | 358 | */ |
359 | -function getpaid_activate_invoice_subscription( $invoice ) { |
|
360 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
361 | - if ( is_a( $subscription, 'WPInv_Subscription' ) ) { |
|
359 | +function getpaid_activate_invoice_subscription($invoice) { |
|
360 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
361 | + if (is_a($subscription, 'WPInv_Subscription')) { |
|
362 | 362 | $subscription->activate(); |
363 | 363 | } |
364 | 364 | } |
@@ -369,7 +369,7 @@ discard block |
||
369 | 369 | * @return WPInv_Subscriptions |
370 | 370 | */ |
371 | 371 | function getpaid_subscriptions() { |
372 | - return getpaid()->get( 'subscriptions' ); |
|
372 | + return getpaid()->get('subscriptions'); |
|
373 | 373 | } |
374 | 374 | |
375 | 375 | /** |
@@ -377,13 +377,13 @@ discard block |
||
377 | 377 | * |
378 | 378 | * @return WPInv_Subscription|bool |
379 | 379 | */ |
380 | -function wpinv_get_subscription( $invoice ) { |
|
380 | +function wpinv_get_subscription($invoice) { |
|
381 | 381 | |
382 | 382 | // Retrieve the invoice. |
383 | - $invoice = new WPInv_Invoice( $invoice ); |
|
383 | + $invoice = new WPInv_Invoice($invoice); |
|
384 | 384 | |
385 | 385 | // Ensure it is a recurring invoice. |
386 | - if ( ! $invoice->is_recurring() ) { |
|
386 | + if (!$invoice->is_recurring()) { |
|
387 | 387 | return false; |
388 | 388 | } |
389 | 389 | |
@@ -395,7 +395,7 @@ discard block |
||
395 | 395 | ) |
396 | 396 | ); |
397 | 397 | |
398 | - return empty( $subscription ) ? false : $subscription[0]; |
|
398 | + return empty($subscription) ? false : $subscription[0]; |
|
399 | 399 | |
400 | 400 | } |
401 | 401 | |
@@ -410,50 +410,50 @@ discard block |
||
410 | 410 | * @param GetPaid_Form_Item|WPInv_Item $cart_item |
411 | 411 | * @return string |
412 | 412 | */ |
413 | -function getpaid_get_recurring_item_key( $cart_item ) { |
|
413 | +function getpaid_get_recurring_item_key($cart_item) { |
|
414 | 414 | |
415 | 415 | $cart_key = 'renews_'; |
416 | 416 | $interval = $cart_item->get_recurring_interval(); |
417 | - $period = $cart_item->get_recurring_period( true ); |
|
417 | + $period = $cart_item->get_recurring_period(true); |
|
418 | 418 | $length = $cart_item->get_recurring_limit() * $interval; |
419 | - $trial_period = $cart_item->get_trial_period( true ); |
|
419 | + $trial_period = $cart_item->get_trial_period(true); |
|
420 | 420 | $trial_length = $cart_item->get_trial_interval(); |
421 | 421 | |
422 | 422 | // First start with the billing interval and period |
423 | - switch ( $interval ) { |
|
423 | + switch ($interval) { |
|
424 | 424 | case 1 : |
425 | - if ( 'day' == $period ) { |
|
425 | + if ('day' == $period) { |
|
426 | 426 | $cart_key .= 'daily'; |
427 | 427 | } else { |
428 | - $cart_key .= sprintf( '%sly', $period ); |
|
428 | + $cart_key .= sprintf('%sly', $period); |
|
429 | 429 | } |
430 | 430 | break; |
431 | 431 | case 2 : |
432 | - $cart_key .= sprintf( 'every_2nd_%s', $period ); |
|
432 | + $cart_key .= sprintf('every_2nd_%s', $period); |
|
433 | 433 | break; |
434 | 434 | case 3 : |
435 | - $cart_key .= sprintf( 'every_3rd_%s', $period ); |
|
435 | + $cart_key .= sprintf('every_3rd_%s', $period); |
|
436 | 436 | break; |
437 | 437 | default: |
438 | - $cart_key .= sprintf( 'every_%dth_%s', $interval, $period ); |
|
438 | + $cart_key .= sprintf('every_%dth_%s', $interval, $period); |
|
439 | 439 | break; |
440 | 440 | } |
441 | 441 | |
442 | 442 | // Maybe add the optional maximum billing periods... |
443 | - if ( $length > 0 ) { |
|
443 | + if ($length > 0) { |
|
444 | 444 | $cart_key .= '_for_'; |
445 | - $cart_key .= sprintf( '%d_%s', $length, $period ); |
|
446 | - if ( $length > 1 ) { |
|
445 | + $cart_key .= sprintf('%d_%s', $length, $period); |
|
446 | + if ($length > 1) { |
|
447 | 447 | $cart_key .= 's'; |
448 | 448 | } |
449 | 449 | } |
450 | 450 | |
451 | 451 | // And an optional free trial. |
452 | - if ( $cart_item->has_free_trial() ) { |
|
453 | - $cart_key .= sprintf( '_after_a_%d_%s_trial', $trial_length, $trial_period ); |
|
452 | + if ($cart_item->has_free_trial()) { |
|
453 | + $cart_key .= sprintf('_after_a_%d_%s_trial', $trial_length, $trial_period); |
|
454 | 454 | } |
455 | 455 | |
456 | - return apply_filters( 'getpaid_get_recurring_item_key', $cart_key, $cart_item ); |
|
456 | + return apply_filters('getpaid_get_recurring_item_key', $cart_key, $cart_item); |
|
457 | 457 | } |
458 | 458 | |
459 | 459 | /** |
@@ -462,14 +462,14 @@ discard block |
||
462 | 462 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
463 | 463 | * @return array |
464 | 464 | */ |
465 | -function getpaid_get_subscription_groups( $invoice ) { |
|
465 | +function getpaid_get_subscription_groups($invoice) { |
|
466 | 466 | |
467 | 467 | // Generate subscription groups. |
468 | 468 | $subscription_groups = array(); |
469 | - foreach ( $invoice->get_items() as $item ) { |
|
469 | + foreach ($invoice->get_items() as $item) { |
|
470 | 470 | |
471 | - if ( $item->is_recurring() ) { |
|
472 | - $subscription_groups[ getpaid_get_recurring_item_key( $item ) ][] = $item; |
|
471 | + if ($item->is_recurring()) { |
|
472 | + $subscription_groups[getpaid_get_recurring_item_key($item)][] = $item; |
|
473 | 473 | } |
474 | 474 | |
475 | 475 | } |
@@ -486,19 +486,19 @@ discard block |
||
486 | 486 | * @param WPInv_Invoice|GetPaid_Payment_Form_Submission|GetPaid_Payment_Form $invoice |
487 | 487 | * @return array |
488 | 488 | */ |
489 | -function getpaid_calculate_subscription_totals( $invoice ) { |
|
489 | +function getpaid_calculate_subscription_totals($invoice) { |
|
490 | 490 | |
491 | 491 | // Generate subscription groups. |
492 | - $subscription_groups = getpaid_get_subscription_groups( $invoice ); |
|
492 | + $subscription_groups = getpaid_get_subscription_groups($invoice); |
|
493 | 493 | |
494 | 494 | // Now let's calculate the totals for each group of subscriptions |
495 | 495 | $subscription_totals = array(); |
496 | 496 | |
497 | - foreach ( $subscription_groups as $subscription_key => $items ) { |
|
497 | + foreach ($subscription_groups as $subscription_key => $items) { |
|
498 | 498 | |
499 | - if ( empty( $subscription_totals[ $subscription_key ] ) ) { |
|
499 | + if (empty($subscription_totals[$subscription_key])) { |
|
500 | 500 | |
501 | - $subscription_totals[ $subscription_key ] = array( |
|
501 | + $subscription_totals[$subscription_key] = array( |
|
502 | 502 | 'initial_total' => 0, |
503 | 503 | 'recurring_total' => 0, |
504 | 504 | 'items' => array(), |
@@ -508,31 +508,31 @@ discard block |
||
508 | 508 | } |
509 | 509 | |
510 | 510 | // Get the totals of the group. |
511 | - foreach ( $items as $item ) { |
|
511 | + foreach ($items as $item) { |
|
512 | 512 | |
513 | - $subscription_totals[ $subscription_key ]['items'][] = $item->get_id(); |
|
514 | - $subscription_totals[ $subscription_key ]['item_id'] = $item->get_id(); |
|
515 | - $subscription_totals[ $subscription_key ]['period'] = $item->get_recurring_period( true ); |
|
516 | - $subscription_totals[ $subscription_key ]['interval'] = $item->get_recurring_interval(); |
|
517 | - $subscription_totals[ $subscription_key ]['initial_total'] += $item->get_sub_total(); |
|
518 | - $subscription_totals[ $subscription_key ]['recurring_total'] += $item->get_recurring_sub_total(); |
|
513 | + $subscription_totals[$subscription_key]['items'][] = $item->get_id(); |
|
514 | + $subscription_totals[$subscription_key]['item_id'] = $item->get_id(); |
|
515 | + $subscription_totals[$subscription_key]['period'] = $item->get_recurring_period(true); |
|
516 | + $subscription_totals[$subscription_key]['interval'] = $item->get_recurring_interval(); |
|
517 | + $subscription_totals[$subscription_key]['initial_total'] += $item->get_sub_total(); |
|
518 | + $subscription_totals[$subscription_key]['recurring_total'] += $item->get_recurring_sub_total(); |
|
519 | 519 | |
520 | 520 | // Calculate the next renewal date. |
521 | - $period = $item->get_recurring_period( true ); |
|
521 | + $period = $item->get_recurring_period(true); |
|
522 | 522 | $interval = $item->get_recurring_interval(); |
523 | 523 | |
524 | 524 | // If the subscription item has a trial period... |
525 | - if ( $item->has_free_trial() ) { |
|
526 | - $period = $item->get_trial_period( true ); |
|
525 | + if ($item->has_free_trial()) { |
|
526 | + $period = $item->get_trial_period(true); |
|
527 | 527 | $interval = $item->get_trial_interval(); |
528 | - $subscription_totals[ $subscription_key ]['trialling'] = $interval . ' ' . $period; |
|
528 | + $subscription_totals[$subscription_key]['trialling'] = $interval . ' ' . $period; |
|
529 | 529 | } |
530 | 530 | |
531 | - $subscription_totals[ $subscription_key ]['renews_on'] = date( 'Y-m-d H:i:s', strtotime( "+$interval $period", current_time( 'timestamp' ) ) ); |
|
531 | + $subscription_totals[$subscription_key]['renews_on'] = date('Y-m-d H:i:s', strtotime("+$interval $period", current_time('timestamp'))); |
|
532 | 532 | |
533 | 533 | } |
534 | 534 | |
535 | 535 | } |
536 | 536 | |
537 | - return apply_filters( 'getpaid_calculate_subscription_totals', $subscription_totals, $invoice ); |
|
537 | + return apply_filters('getpaid_calculate_subscription_totals', $subscription_totals, $invoice); |
|
538 | 538 | } |
@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -149,8 +149,8 @@ discard block |
||
149 | 149 | $this->state = wpinv_get_default_state(); |
150 | 150 | |
151 | 151 | // Do we have an actual submission? |
152 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
153 | - $this->load_data( $_POST ); |
|
152 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
153 | + $this->load_data($_POST); |
|
154 | 154 | } |
155 | 155 | |
156 | 156 | } |
@@ -160,19 +160,19 @@ discard block |
||
160 | 160 | * |
161 | 161 | * @param array $data |
162 | 162 | */ |
163 | - public function load_data( $data ) { |
|
163 | + public function load_data($data) { |
|
164 | 164 | |
165 | 165 | // Remove slashes from the submitted data... |
166 | - $data = wp_unslash( $data ); |
|
166 | + $data = wp_unslash($data); |
|
167 | 167 | |
168 | 168 | // Allow plugins to filter the data. |
169 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
169 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
170 | 170 | |
171 | 171 | // Cache it... |
172 | 172 | $this->data = $data; |
173 | 173 | |
174 | 174 | // Then generate a unique id from the data. |
175 | - $this->id = md5( wp_json_encode( $data ) ); |
|
175 | + $this->id = md5(wp_json_encode($data)); |
|
176 | 176 | |
177 | 177 | // Finally, process the submission. |
178 | 178 | try { |
@@ -182,30 +182,30 @@ discard block |
||
182 | 182 | $processors = apply_filters( |
183 | 183 | 'getpaid_payment_form_submission_processors', |
184 | 184 | array( |
185 | - array( $this, 'process_payment_form' ), |
|
186 | - array( $this, 'process_invoice' ), |
|
187 | - array( $this, 'process_fees' ), |
|
188 | - array( $this, 'process_items' ), |
|
189 | - array( $this, 'process_discount' ), |
|
190 | - array( $this, 'process_taxes' ), |
|
185 | + array($this, 'process_payment_form'), |
|
186 | + array($this, 'process_invoice'), |
|
187 | + array($this, 'process_fees'), |
|
188 | + array($this, 'process_items'), |
|
189 | + array($this, 'process_discount'), |
|
190 | + array($this, 'process_taxes'), |
|
191 | 191 | ), |
192 | 192 | $this |
193 | 193 | ); |
194 | 194 | |
195 | - foreach ( $processors as $processor ) { |
|
196 | - call_user_func_array( $processor, array( &$this ) ); |
|
195 | + foreach ($processors as $processor) { |
|
196 | + call_user_func_array($processor, array(&$this)); |
|
197 | 197 | } |
198 | 198 | |
199 | - } catch( GetPaid_Payment_Exception $e ) { |
|
199 | + } catch (GetPaid_Payment_Exception $e) { |
|
200 | 200 | $this->last_error = $e->getMessage(); |
201 | 201 | $this->last_error_code = $e->getErrorCode(); |
202 | - } catch ( Exception $e ) { |
|
202 | + } catch (Exception $e) { |
|
203 | 203 | $this->last_error = $e->getMessage(); |
204 | 204 | $this->last_error_code = $e->getCode(); |
205 | 205 | } |
206 | 206 | |
207 | 207 | // Fired when we are done processing a submission. |
208 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
208 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
209 | 209 | |
210 | 210 | } |
211 | 211 | |
@@ -226,18 +226,18 @@ discard block |
||
226 | 226 | public function process_payment_form() { |
227 | 227 | |
228 | 228 | // Every submission needs an active payment form. |
229 | - if ( empty( $this->data['form_id'] ) ) { |
|
230 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
229 | + if (empty($this->data['form_id'])) { |
|
230 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
231 | 231 | } |
232 | 232 | |
233 | 233 | // Fetch the payment form. |
234 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
234 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
235 | 235 | |
236 | - if ( ! $this->payment_form->is_active() ) { |
|
237 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
236 | + if (!$this->payment_form->is_active()) { |
|
237 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
238 | 238 | } |
239 | 239 | |
240 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
240 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
241 | 241 | } |
242 | 242 | |
243 | 243 | /** |
@@ -267,53 +267,53 @@ discard block |
||
267 | 267 | public function process_invoice() { |
268 | 268 | |
269 | 269 | // Abort if there is no invoice. |
270 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
270 | + if (empty($this->data['invoice_id'])) { |
|
271 | 271 | return; |
272 | 272 | } |
273 | 273 | |
274 | 274 | // If the submission is for an existing invoice, ensure that it exists |
275 | 275 | // and that it is not paid for. |
276 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
276 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
277 | 277 | |
278 | - if ( empty( $invoice ) ) { |
|
279 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
278 | + if (empty($invoice)) { |
|
279 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
280 | 280 | } |
281 | 281 | |
282 | - if ( $invoice->is_paid() ) { |
|
283 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
282 | + if ($invoice->is_paid()) { |
|
283 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
284 | 284 | } |
285 | 285 | |
286 | 286 | $this->payment_form->invoice = $invoice; |
287 | - if ( ! $this->payment_form->is_default() ) { |
|
287 | + if (!$this->payment_form->is_default()) { |
|
288 | 288 | |
289 | 289 | $items = array(); |
290 | 290 | $item_ids = array(); |
291 | 291 | |
292 | - foreach ( $invoice->get_items() as $item ) { |
|
293 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
292 | + foreach ($invoice->get_items() as $item) { |
|
293 | + if (!in_array($item->get_id(), $item_ids)) { |
|
294 | 294 | $item_ids[] = $item->get_id(); |
295 | 295 | $items[] = $item; |
296 | 296 | } |
297 | 297 | } |
298 | 298 | |
299 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
300 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
299 | + foreach ($this->payment_form->get_items() as $item) { |
|
300 | + if (!in_array($item->get_id(), $item_ids)) { |
|
301 | 301 | $item_ids[] = $item->get_id(); |
302 | 302 | $items[] = $item; |
303 | 303 | } |
304 | 304 | } |
305 | 305 | |
306 | - $this->payment_form->set_items( $items ); |
|
306 | + $this->payment_form->set_items($items); |
|
307 | 307 | |
308 | 308 | } else { |
309 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
309 | + $this->payment_form->set_items($invoice->get_items()); |
|
310 | 310 | } |
311 | 311 | |
312 | 312 | $this->country = $invoice->get_country(); |
313 | 313 | $this->state = $invoice->get_state(); |
314 | 314 | $this->invoice = $invoice; |
315 | 315 | |
316 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
316 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
317 | 317 | } |
318 | 318 | |
319 | 319 | /** |
@@ -333,7 +333,7 @@ discard block |
||
333 | 333 | * @return bool |
334 | 334 | */ |
335 | 335 | public function has_invoice() { |
336 | - return ! empty( $this->invoice ); |
|
336 | + return !empty($this->invoice); |
|
337 | 337 | } |
338 | 338 | |
339 | 339 | /* |
@@ -352,13 +352,13 @@ discard block |
||
352 | 352 | */ |
353 | 353 | public function process_items() { |
354 | 354 | |
355 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
355 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
356 | 356 | |
357 | - foreach ( $processor->items as $item ) { |
|
358 | - $this->add_item( $item ); |
|
357 | + foreach ($processor->items as $item) { |
|
358 | + $this->add_item($item); |
|
359 | 359 | } |
360 | 360 | |
361 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
361 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
362 | 362 | } |
363 | 363 | |
364 | 364 | /** |
@@ -367,18 +367,18 @@ discard block |
||
367 | 367 | * @since 1.0.19 |
368 | 368 | * @param GetPaid_Form_Item $item |
369 | 369 | */ |
370 | - public function add_item( $item ) { |
|
370 | + public function add_item($item) { |
|
371 | 371 | |
372 | 372 | // Make sure that it is available for purchase. |
373 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
373 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
374 | 374 | return; |
375 | 375 | } |
376 | 376 | |
377 | 377 | // Each submission can only contain one recurring item. |
378 | - if ( $item->is_recurring() ) { |
|
378 | + if ($item->is_recurring()) { |
|
379 | 379 | |
380 | - if ( $this->has_recurring != 0 ) { |
|
381 | - throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) ); |
|
380 | + if ($this->has_recurring != 0) { |
|
381 | + throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing')); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | $this->has_recurring = $item->get_id(); |
@@ -386,11 +386,11 @@ discard block |
||
386 | 386 | } |
387 | 387 | |
388 | 388 | // Update the items and totals. |
389 | - $this->items[ $item->get_id() ] = $item; |
|
389 | + $this->items[$item->get_id()] = $item; |
|
390 | 390 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
391 | 391 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
392 | 392 | |
393 | - $this->subscription_groups = getpaid_calculate_subscription_totals( $this ); |
|
393 | + $this->subscription_groups = getpaid_calculate_subscription_totals($this); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -401,17 +401,17 @@ discard block |
||
401 | 401 | * |
402 | 402 | * @since 1.0.19 |
403 | 403 | */ |
404 | - public function remove_item( $item_id ) { |
|
404 | + public function remove_item($item_id) { |
|
405 | 405 | |
406 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
407 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
408 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
406 | + if (isset($this->items[$item_id])) { |
|
407 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
408 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
409 | 409 | |
410 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
410 | + if ($this->items[$item_id]->is_recurring()) { |
|
411 | 411 | $this->has_recurring = 0; |
412 | 412 | } |
413 | 413 | |
414 | - unset( $this->items[ $item_id ] ); |
|
414 | + unset($this->items[$item_id]); |
|
415 | 415 | } |
416 | 416 | |
417 | 417 | } |
@@ -423,7 +423,7 @@ discard block |
||
423 | 423 | */ |
424 | 424 | public function get_subtotal() { |
425 | 425 | |
426 | - if ( wpinv_prices_include_tax() ) { |
|
426 | + if (wpinv_prices_include_tax()) { |
|
427 | 427 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
428 | 428 | } |
429 | 429 | |
@@ -437,7 +437,7 @@ discard block |
||
437 | 437 | */ |
438 | 438 | public function get_recurring_subtotal() { |
439 | 439 | |
440 | - if ( wpinv_prices_include_tax() ) { |
|
440 | + if (wpinv_prices_include_tax()) { |
|
441 | 441 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
442 | 442 | } |
443 | 443 | |
@@ -471,39 +471,39 @@ discard block |
||
471 | 471 | public function process_taxes() { |
472 | 472 | |
473 | 473 | // Abort if we're not using taxes. |
474 | - if ( ! $this->use_taxes() ) { |
|
474 | + if (!$this->use_taxes()) { |
|
475 | 475 | return; |
476 | 476 | } |
477 | 477 | |
478 | 478 | // If a custom country && state has been passed in, use it to calculate taxes. |
479 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
480 | - if ( ! empty( $country ) ) { |
|
479 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
480 | + if (!empty($country)) { |
|
481 | 481 | $this->country = $country; |
482 | 482 | } |
483 | 483 | |
484 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
485 | - if ( ! empty( $state ) ) { |
|
484 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
485 | + if (!empty($state)) { |
|
486 | 486 | $this->state = $state; |
487 | 487 | } |
488 | 488 | |
489 | 489 | // Confirm if the provided country and the ip country are similar. |
490 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
491 | - if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
492 | - throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) ); |
|
490 | + $address_confirmed = $this->get_field('confirm-address'); |
|
491 | + if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
492 | + throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing')); |
|
493 | 493 | } |
494 | 494 | |
495 | 495 | // Abort if the country is not taxable. |
496 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
496 | + if (!wpinv_is_country_taxable($this->country)) { |
|
497 | 497 | return; |
498 | 498 | } |
499 | 499 | |
500 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
500 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
501 | 501 | |
502 | - foreach ( $processor->taxes as $tax ) { |
|
503 | - $this->add_tax( $tax ); |
|
502 | + foreach ($processor->taxes as $tax) { |
|
503 | + $this->add_tax($tax); |
|
504 | 504 | } |
505 | 505 | |
506 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
506 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
507 | 507 | } |
508 | 508 | |
509 | 509 | /** |
@@ -512,16 +512,16 @@ discard block |
||
512 | 512 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
513 | 513 | * @since 1.0.19 |
514 | 514 | */ |
515 | - public function add_tax( $tax ) { |
|
515 | + public function add_tax($tax) { |
|
516 | 516 | |
517 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
518 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
519 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
517 | + if (wpinv_round_tax_per_tax_rate()) { |
|
518 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
519 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
520 | 520 | } |
521 | 521 | |
522 | - $this->taxes[ $tax['name'] ] = $tax; |
|
523 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
524 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
522 | + $this->taxes[$tax['name']] = $tax; |
|
523 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
524 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
525 | 525 | |
526 | 526 | } |
527 | 527 | |
@@ -530,12 +530,12 @@ discard block |
||
530 | 530 | * |
531 | 531 | * @since 1.0.19 |
532 | 532 | */ |
533 | - public function remove_tax( $tax_name ) { |
|
533 | + public function remove_tax($tax_name) { |
|
534 | 534 | |
535 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
536 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
537 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
538 | - unset( $this->taxes[ $tax_name ] ); |
|
535 | + if (isset($this->taxes[$tax_name])) { |
|
536 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
537 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
538 | + unset($this->taxes[$tax_name]); |
|
539 | 539 | } |
540 | 540 | |
541 | 541 | } |
@@ -549,11 +549,11 @@ discard block |
||
549 | 549 | |
550 | 550 | $use_taxes = wpinv_use_taxes(); |
551 | 551 | |
552 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
552 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
553 | 553 | $use_taxes = false; |
554 | 554 | } |
555 | 555 | |
556 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
556 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
557 | 557 | |
558 | 558 | } |
559 | 559 | |
@@ -602,13 +602,13 @@ discard block |
||
602 | 602 | |
603 | 603 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
604 | 604 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
605 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
605 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
606 | 606 | |
607 | - foreach ( $processor->discounts as $discount ) { |
|
608 | - $this->add_discount( $discount ); |
|
607 | + foreach ($processor->discounts as $discount) { |
|
608 | + $this->add_discount($discount); |
|
609 | 609 | } |
610 | 610 | |
611 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
611 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
612 | 612 | } |
613 | 613 | |
614 | 614 | /** |
@@ -617,10 +617,10 @@ discard block |
||
617 | 617 | * @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. |
618 | 618 | * @since 1.0.19 |
619 | 619 | */ |
620 | - public function add_discount( $discount ) { |
|
621 | - $this->discounts[ $discount['name'] ] = $discount; |
|
622 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
623 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
620 | + public function add_discount($discount) { |
|
621 | + $this->discounts[$discount['name']] = $discount; |
|
622 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
623 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
624 | 624 | } |
625 | 625 | |
626 | 626 | /** |
@@ -628,12 +628,12 @@ discard block |
||
628 | 628 | * |
629 | 629 | * @since 1.0.19 |
630 | 630 | */ |
631 | - public function remove_discount( $name ) { |
|
631 | + public function remove_discount($name) { |
|
632 | 632 | |
633 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
634 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
635 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
636 | - unset( $this->discounts[ $name ] ); |
|
633 | + if (isset($this->discounts[$name])) { |
|
634 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
635 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
636 | + unset($this->discounts[$name]); |
|
637 | 637 | } |
638 | 638 | |
639 | 639 | } |
@@ -645,7 +645,7 @@ discard block |
||
645 | 645 | * @return bool |
646 | 646 | */ |
647 | 647 | public function has_discount_code() { |
648 | - return ! empty( $this->discounts['discount_code'] ); |
|
648 | + return !empty($this->discounts['discount_code']); |
|
649 | 649 | } |
650 | 650 | |
651 | 651 | /** |
@@ -702,13 +702,13 @@ discard block |
||
702 | 702 | */ |
703 | 703 | public function process_fees() { |
704 | 704 | |
705 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
705 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
706 | 706 | |
707 | - foreach ( $fees_processor->fees as $fee ) { |
|
708 | - $this->add_fee( $fee ); |
|
707 | + foreach ($fees_processor->fees as $fee) { |
|
708 | + $this->add_fee($fee); |
|
709 | 709 | } |
710 | 710 | |
711 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
711 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
712 | 712 | } |
713 | 713 | |
714 | 714 | /** |
@@ -717,11 +717,11 @@ discard block |
||
717 | 717 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
718 | 718 | * @since 1.0.19 |
719 | 719 | */ |
720 | - public function add_fee( $fee ) { |
|
720 | + public function add_fee($fee) { |
|
721 | 721 | |
722 | - $this->fees[ $fee['name'] ] = $fee; |
|
723 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
724 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
722 | + $this->fees[$fee['name']] = $fee; |
|
723 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
724 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
725 | 725 | |
726 | 726 | } |
727 | 727 | |
@@ -730,12 +730,12 @@ discard block |
||
730 | 730 | * |
731 | 731 | * @since 1.0.19 |
732 | 732 | */ |
733 | - public function remove_fee( $name ) { |
|
733 | + public function remove_fee($name) { |
|
734 | 734 | |
735 | - if ( isset( $this->fees[ $name ] ) ) { |
|
736 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
737 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
738 | - unset( $this->fees[ $name ] ); |
|
735 | + if (isset($this->fees[$name])) { |
|
736 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
737 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
738 | + unset($this->fees[$name]); |
|
739 | 739 | } |
740 | 740 | |
741 | 741 | } |
@@ -774,7 +774,7 @@ discard block |
||
774 | 774 | * @since 1.0.19 |
775 | 775 | */ |
776 | 776 | public function has_fees() { |
777 | - return count( $this->fees ) !== 0; |
|
777 | + return count($this->fees) !== 0; |
|
778 | 778 | } |
779 | 779 | |
780 | 780 | /* |
@@ -792,7 +792,7 @@ discard block |
||
792 | 792 | * @since 1.0.19 |
793 | 793 | */ |
794 | 794 | public function is_initial_fetch() { |
795 | - return empty( $this->data['initial_state'] ); |
|
795 | + return empty($this->data['initial_state']); |
|
796 | 796 | } |
797 | 797 | |
798 | 798 | /** |
@@ -802,7 +802,7 @@ discard block |
||
802 | 802 | */ |
803 | 803 | public function get_total() { |
804 | 804 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount(); |
805 | - return max( $total, 0 ); |
|
805 | + return max($total, 0); |
|
806 | 806 | } |
807 | 807 | |
808 | 808 | /** |
@@ -812,7 +812,7 @@ discard block |
||
812 | 812 | */ |
813 | 813 | public function get_recurring_total() { |
814 | 814 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount(); |
815 | - return max( $total, 0 ); |
|
815 | + return max($total, 0); |
|
816 | 816 | } |
817 | 817 | |
818 | 818 | /** |
@@ -824,12 +824,12 @@ discard block |
||
824 | 824 | $initial = $this->get_total(); |
825 | 825 | $recurring = $this->get_recurring_total(); |
826 | 826 | |
827 | - if ( $this->has_recurring == 0 ) { |
|
827 | + if ($this->has_recurring == 0) { |
|
828 | 828 | $recurring = 0; |
829 | 829 | } |
830 | 830 | |
831 | 831 | $collect = $initial > 0 || $recurring > 0; |
832 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
832 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
833 | 833 | } |
834 | 834 | |
835 | 835 | /** |
@@ -838,7 +838,7 @@ discard block |
||
838 | 838 | * @since 1.0.19 |
839 | 839 | */ |
840 | 840 | public function get_billing_email() { |
841 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
841 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
842 | 842 | } |
843 | 843 | |
844 | 844 | /** |
@@ -848,7 +848,7 @@ discard block |
||
848 | 848 | */ |
849 | 849 | public function has_billing_email() { |
850 | 850 | $billing_email = $this->get_billing_email(); |
851 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
851 | + return !empty($billing_email) && is_email($billing_email); |
|
852 | 852 | } |
853 | 853 | |
854 | 854 | /** |
@@ -878,8 +878,8 @@ discard block |
||
878 | 878 | * @since 1.0.19 |
879 | 879 | * @return mixed|null |
880 | 880 | */ |
881 | - public function get_field( $field, $sub_array_key = null ) { |
|
882 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
881 | + public function get_field($field, $sub_array_key = null) { |
|
882 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
883 | 883 | } |
884 | 884 | |
885 | 885 | /** |
@@ -887,8 +887,8 @@ discard block |
||
887 | 887 | * |
888 | 888 | * @since 1.0.19 |
889 | 889 | */ |
890 | - public function is_required_field_set( $field ) { |
|
891 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
890 | + public function is_required_field_set($field) { |
|
891 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
892 | 892 | } |
893 | 893 | |
894 | 894 | /** |
@@ -896,8 +896,8 @@ discard block |
||
896 | 896 | * |
897 | 897 | * @since 1.0.19 |
898 | 898 | */ |
899 | - public function format_amount( $amount ) { |
|
900 | - return wpinv_price( $amount, $this->get_currency() ); |
|
899 | + public function format_amount($amount) { |
|
900 | + return wpinv_price($amount, $this->get_currency()); |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | } |