@@ -1,5 +1,5 @@ discard block |
||
1 | 1 | <?php |
2 | -if ( ! defined( 'ABSPATH' ) ) { |
|
2 | +if (!defined('ABSPATH')) { |
|
3 | 3 | exit; |
4 | 4 | } |
5 | 5 | |
@@ -146,8 +146,8 @@ discard block |
||
146 | 146 | $this->state = wpinv_get_default_state(); |
147 | 147 | |
148 | 148 | // Do we have an actual submission? |
149 | - if ( isset( $_POST['getpaid_payment_form_submission'] ) ) { |
|
150 | - $this->load_data( $_POST ); |
|
149 | + if (isset($_POST['getpaid_payment_form_submission'])) { |
|
150 | + $this->load_data($_POST); |
|
151 | 151 | } |
152 | 152 | |
153 | 153 | } |
@@ -157,19 +157,19 @@ discard block |
||
157 | 157 | * |
158 | 158 | * @param array $data |
159 | 159 | */ |
160 | - public function load_data( $data ) { |
|
160 | + public function load_data($data) { |
|
161 | 161 | |
162 | 162 | // Remove slashes from the submitted data... |
163 | - $data = wp_kses_post_deep( wp_unslash( $data ) ); |
|
163 | + $data = wp_kses_post_deep(wp_unslash($data)); |
|
164 | 164 | |
165 | 165 | // Allow plugins to filter the data. |
166 | - $data = apply_filters( 'getpaid_submission_data', $data, $this ); |
|
166 | + $data = apply_filters('getpaid_submission_data', $data, $this); |
|
167 | 167 | |
168 | 168 | // Cache it... |
169 | 169 | $this->data = $data; |
170 | 170 | |
171 | 171 | // Then generate a unique id from the data. |
172 | - $this->id = md5( wp_json_encode( $data ) ); |
|
172 | + $this->id = md5(wp_json_encode($data)); |
|
173 | 173 | |
174 | 174 | // Finally, process the submission. |
175 | 175 | try { |
@@ -179,30 +179,30 @@ discard block |
||
179 | 179 | $processors = apply_filters( |
180 | 180 | 'getpaid_payment_form_submission_processors', |
181 | 181 | array( |
182 | - array( $this, 'process_payment_form' ), |
|
183 | - array( $this, 'process_invoice' ), |
|
184 | - array( $this, 'process_fees' ), |
|
185 | - array( $this, 'process_items' ), |
|
186 | - array( $this, 'process_discount' ), |
|
187 | - array( $this, 'process_taxes' ), |
|
182 | + array($this, 'process_payment_form'), |
|
183 | + array($this, 'process_invoice'), |
|
184 | + array($this, 'process_fees'), |
|
185 | + array($this, 'process_items'), |
|
186 | + array($this, 'process_discount'), |
|
187 | + array($this, 'process_taxes'), |
|
188 | 188 | ), |
189 | 189 | $this |
190 | 190 | ); |
191 | 191 | |
192 | - foreach ( $processors as $processor ) { |
|
193 | - call_user_func_array( $processor, array( &$this ) ); |
|
192 | + foreach ($processors as $processor) { |
|
193 | + call_user_func_array($processor, array(&$this)); |
|
194 | 194 | } |
195 | 195 | |
196 | - } catch( GetPaid_Payment_Exception $e ) { |
|
196 | + } catch (GetPaid_Payment_Exception $e) { |
|
197 | 197 | $this->last_error = $e->getMessage(); |
198 | 198 | $this->last_error_code = $e->getErrorCode(); |
199 | - } catch ( Exception $e ) { |
|
199 | + } catch (Exception $e) { |
|
200 | 200 | $this->last_error = $e->getMessage(); |
201 | 201 | $this->last_error_code = $e->getCode(); |
202 | 202 | } |
203 | 203 | |
204 | 204 | // Fired when we are done processing a submission. |
205 | - do_action_ref_array( 'getpaid_process_submission', array( &$this ) ); |
|
205 | + do_action_ref_array('getpaid_process_submission', array(&$this)); |
|
206 | 206 | |
207 | 207 | } |
208 | 208 | |
@@ -223,18 +223,18 @@ discard block |
||
223 | 223 | public function process_payment_form() { |
224 | 224 | |
225 | 225 | // Every submission needs an active payment form. |
226 | - if ( empty( $this->data['form_id'] ) ) { |
|
227 | - throw new Exception( __( 'Missing payment form', 'invoicing' ) ); |
|
226 | + if (empty($this->data['form_id'])) { |
|
227 | + throw new Exception(__('Missing payment form', 'invoicing')); |
|
228 | 228 | } |
229 | 229 | |
230 | 230 | // Fetch the payment form. |
231 | - $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] ); |
|
231 | + $this->payment_form = new GetPaid_Payment_Form($this->data['form_id']); |
|
232 | 232 | |
233 | - if ( ! $this->payment_form->is_active() ) { |
|
234 | - throw new Exception( __( 'Payment form not active', 'invoicing' ) ); |
|
233 | + if (!$this->payment_form->is_active()) { |
|
234 | + throw new Exception(__('Payment form not active', 'invoicing')); |
|
235 | 235 | } |
236 | 236 | |
237 | - do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) ); |
|
237 | + do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this)); |
|
238 | 238 | } |
239 | 239 | |
240 | 240 | /** |
@@ -264,53 +264,53 @@ discard block |
||
264 | 264 | public function process_invoice() { |
265 | 265 | |
266 | 266 | // Abort if there is no invoice. |
267 | - if ( empty( $this->data['invoice_id'] ) ) { |
|
267 | + if (empty($this->data['invoice_id'])) { |
|
268 | 268 | return; |
269 | 269 | } |
270 | 270 | |
271 | 271 | // If the submission is for an existing invoice, ensure that it exists |
272 | 272 | // and that it is not paid for. |
273 | - $invoice = wpinv_get_invoice( $this->data['invoice_id'] ); |
|
273 | + $invoice = wpinv_get_invoice($this->data['invoice_id']); |
|
274 | 274 | |
275 | - if ( empty( $invoice ) ) { |
|
276 | - throw new Exception( __( 'Invalid invoice', 'invoicing' ) ); |
|
275 | + if (empty($invoice)) { |
|
276 | + throw new Exception(__('Invalid invoice', 'invoicing')); |
|
277 | 277 | } |
278 | 278 | |
279 | - if ( $invoice->is_paid() ) { |
|
280 | - throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) ); |
|
279 | + if ($invoice->is_paid()) { |
|
280 | + throw new Exception(__('This invoice is already paid for.', 'invoicing')); |
|
281 | 281 | } |
282 | 282 | |
283 | 283 | $this->payment_form->invoice = $invoice; |
284 | - if ( ! $this->payment_form->is_default() ) { |
|
284 | + if (!$this->payment_form->is_default()) { |
|
285 | 285 | |
286 | 286 | $items = array(); |
287 | 287 | $item_ids = array(); |
288 | 288 | |
289 | - foreach ( $invoice->get_items() as $item ) { |
|
290 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
289 | + foreach ($invoice->get_items() as $item) { |
|
290 | + if (!in_array($item->get_id(), $item_ids)) { |
|
291 | 291 | $item_ids[] = $item->get_id(); |
292 | 292 | $items[] = $item; |
293 | 293 | } |
294 | 294 | } |
295 | 295 | |
296 | - foreach ( $this->payment_form->get_items() as $item ) { |
|
297 | - if ( ! in_array( $item->get_id(), $item_ids ) ) { |
|
296 | + foreach ($this->payment_form->get_items() as $item) { |
|
297 | + if (!in_array($item->get_id(), $item_ids)) { |
|
298 | 298 | $item_ids[] = $item->get_id(); |
299 | 299 | $items[] = $item; |
300 | 300 | } |
301 | 301 | } |
302 | 302 | |
303 | - $this->payment_form->set_items( $items ); |
|
303 | + $this->payment_form->set_items($items); |
|
304 | 304 | |
305 | 305 | } else { |
306 | - $this->payment_form->set_items( $invoice->get_items() ); |
|
306 | + $this->payment_form->set_items($invoice->get_items()); |
|
307 | 307 | } |
308 | 308 | |
309 | 309 | $this->country = $invoice->get_country(); |
310 | 310 | $this->state = $invoice->get_state(); |
311 | 311 | $this->invoice = $invoice; |
312 | 312 | |
313 | - do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) ); |
|
313 | + do_action_ref_array('getpaid_submissions_process_invoice', array(&$this)); |
|
314 | 314 | } |
315 | 315 | |
316 | 316 | /** |
@@ -330,7 +330,7 @@ discard block |
||
330 | 330 | * @return bool |
331 | 331 | */ |
332 | 332 | public function has_invoice() { |
333 | - return ! empty( $this->invoice ); |
|
333 | + return !empty($this->invoice); |
|
334 | 334 | } |
335 | 335 | |
336 | 336 | /* |
@@ -349,13 +349,13 @@ discard block |
||
349 | 349 | */ |
350 | 350 | public function process_items() { |
351 | 351 | |
352 | - $processor = new GetPaid_Payment_Form_Submission_Items( $this ); |
|
352 | + $processor = new GetPaid_Payment_Form_Submission_Items($this); |
|
353 | 353 | |
354 | - foreach ( $processor->items as $item ) { |
|
355 | - $this->add_item( $item ); |
|
354 | + foreach ($processor->items as $item) { |
|
355 | + $this->add_item($item); |
|
356 | 356 | } |
357 | 357 | |
358 | - do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) ); |
|
358 | + do_action_ref_array('getpaid_submissions_process_items', array(&$this)); |
|
359 | 359 | } |
360 | 360 | |
361 | 361 | /** |
@@ -364,20 +364,20 @@ discard block |
||
364 | 364 | * @since 1.0.19 |
365 | 365 | * @param GetPaid_Form_Item $item |
366 | 366 | */ |
367 | - public function add_item( $item ) { |
|
367 | + public function add_item($item) { |
|
368 | 368 | |
369 | 369 | // Make sure that it is available for purchase. |
370 | - if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) { |
|
370 | + if (!$item->can_purchase() || isset($this->items[$item->get_id()])) { |
|
371 | 371 | return; |
372 | 372 | } |
373 | 373 | |
374 | 374 | // Each submission can only contain one recurring item. |
375 | - if ( $item->is_recurring() ) { |
|
375 | + if ($item->is_recurring()) { |
|
376 | 376 | $this->has_recurring = $item->get_id(); |
377 | 377 | } |
378 | 378 | |
379 | 379 | // Update the items and totals. |
380 | - $this->items[ $item->get_id() ] = $item; |
|
380 | + $this->items[$item->get_id()] = $item; |
|
381 | 381 | $this->totals['subtotal']['initial'] += $item->get_sub_total(); |
382 | 382 | $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total(); |
383 | 383 | |
@@ -391,17 +391,17 @@ discard block |
||
391 | 391 | * |
392 | 392 | * @since 1.0.19 |
393 | 393 | */ |
394 | - public function remove_item( $item_id ) { |
|
394 | + public function remove_item($item_id) { |
|
395 | 395 | |
396 | - if ( isset( $this->items[ $item_id ] ) ) { |
|
397 | - $this->totals['subtotal']['initial'] -= $this->items[ $item_id ]->get_sub_total(); |
|
398 | - $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total(); |
|
396 | + if (isset($this->items[$item_id])) { |
|
397 | + $this->totals['subtotal']['initial'] -= $this->items[$item_id]->get_sub_total(); |
|
398 | + $this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total(); |
|
399 | 399 | |
400 | - if ( $this->items[ $item_id ]->is_recurring() ) { |
|
400 | + if ($this->items[$item_id]->is_recurring()) { |
|
401 | 401 | $this->has_recurring = 0; |
402 | 402 | } |
403 | 403 | |
404 | - unset( $this->items[ $item_id ] ); |
|
404 | + unset($this->items[$item_id]); |
|
405 | 405 | } |
406 | 406 | |
407 | 407 | } |
@@ -413,7 +413,7 @@ discard block |
||
413 | 413 | */ |
414 | 414 | public function get_subtotal() { |
415 | 415 | |
416 | - if ( wpinv_prices_include_tax() ) { |
|
416 | + if (wpinv_prices_include_tax()) { |
|
417 | 417 | return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial']; |
418 | 418 | } |
419 | 419 | |
@@ -427,7 +427,7 @@ discard block |
||
427 | 427 | */ |
428 | 428 | public function get_recurring_subtotal() { |
429 | 429 | |
430 | - if ( wpinv_prices_include_tax() ) { |
|
430 | + if (wpinv_prices_include_tax()) { |
|
431 | 431 | return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring']; |
432 | 432 | } |
433 | 433 | |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | * @return bool |
452 | 452 | */ |
453 | 453 | public function has_subscription_group() { |
454 | - return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) ); |
|
454 | + return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this)); |
|
455 | 455 | } |
456 | 456 | |
457 | 457 | /** |
@@ -461,7 +461,7 @@ discard block |
||
461 | 461 | * @return bool |
462 | 462 | */ |
463 | 463 | public function has_multiple_subscription_groups() { |
464 | - return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) ); |
|
464 | + return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this)); |
|
465 | 465 | } |
466 | 466 | |
467 | 467 | /* |
@@ -481,39 +481,39 @@ discard block |
||
481 | 481 | public function process_taxes() { |
482 | 482 | |
483 | 483 | // Abort if we're not using taxes. |
484 | - if ( ! $this->use_taxes() ) { |
|
484 | + if (!$this->use_taxes()) { |
|
485 | 485 | return; |
486 | 486 | } |
487 | 487 | |
488 | 488 | // If a custom country && state has been passed in, use it to calculate taxes. |
489 | - $country = $this->get_field( 'wpinv_country', 'billing' ); |
|
490 | - if ( ! empty( $country ) ) { |
|
489 | + $country = $this->get_field('wpinv_country', 'billing'); |
|
490 | + if (!empty($country)) { |
|
491 | 491 | $this->country = $country; |
492 | 492 | } |
493 | 493 | |
494 | - $state = $this->get_field( 'wpinv_state', 'billing' ); |
|
495 | - if ( ! empty( $state ) ) { |
|
494 | + $state = $this->get_field('wpinv_state', 'billing'); |
|
495 | + if (!empty($state)) { |
|
496 | 496 | $this->state = $state; |
497 | 497 | } |
498 | 498 | |
499 | 499 | // Confirm if the provided country and the ip country are similar. |
500 | - $address_confirmed = $this->get_field( 'confirm-address' ); |
|
501 | - if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) { |
|
502 | - 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' ) ); |
|
500 | + $address_confirmed = $this->get_field('confirm-address'); |
|
501 | + if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) { |
|
502 | + 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')); |
|
503 | 503 | } |
504 | 504 | |
505 | 505 | // Abort if the country is not taxable. |
506 | - if ( ! wpinv_is_country_taxable( $this->country ) ) { |
|
506 | + if (!wpinv_is_country_taxable($this->country)) { |
|
507 | 507 | return; |
508 | 508 | } |
509 | 509 | |
510 | - $processor = new GetPaid_Payment_Form_Submission_Taxes( $this ); |
|
510 | + $processor = new GetPaid_Payment_Form_Submission_Taxes($this); |
|
511 | 511 | |
512 | - foreach ( $processor->taxes as $tax ) { |
|
513 | - $this->add_tax( $tax ); |
|
512 | + foreach ($processor->taxes as $tax) { |
|
513 | + $this->add_tax($tax); |
|
514 | 514 | } |
515 | 515 | |
516 | - do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) ); |
|
516 | + do_action_ref_array('getpaid_submissions_process_taxes', array(&$this)); |
|
517 | 517 | } |
518 | 518 | |
519 | 519 | /** |
@@ -522,16 +522,16 @@ discard block |
||
522 | 522 | * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required. |
523 | 523 | * @since 1.0.19 |
524 | 524 | */ |
525 | - public function add_tax( $tax ) { |
|
525 | + public function add_tax($tax) { |
|
526 | 526 | |
527 | - if ( wpinv_round_tax_per_tax_rate() ) { |
|
528 | - $tax['initial_tax'] = wpinv_round_amount( $tax['initial_tax'] ); |
|
529 | - $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] ); |
|
527 | + if (wpinv_round_tax_per_tax_rate()) { |
|
528 | + $tax['initial_tax'] = wpinv_round_amount($tax['initial_tax']); |
|
529 | + $tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']); |
|
530 | 530 | } |
531 | 531 | |
532 | - $this->taxes[ $tax['name'] ] = $tax; |
|
533 | - $this->totals['taxes']['initial'] += wpinv_sanitize_amount( $tax['initial_tax'] ); |
|
534 | - $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] ); |
|
532 | + $this->taxes[$tax['name']] = $tax; |
|
533 | + $this->totals['taxes']['initial'] += wpinv_sanitize_amount($tax['initial_tax']); |
|
534 | + $this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']); |
|
535 | 535 | |
536 | 536 | } |
537 | 537 | |
@@ -540,12 +540,12 @@ discard block |
||
540 | 540 | * |
541 | 541 | * @since 1.0.19 |
542 | 542 | */ |
543 | - public function remove_tax( $tax_name ) { |
|
543 | + public function remove_tax($tax_name) { |
|
544 | 544 | |
545 | - if ( isset( $this->taxes[ $tax_name ] ) ) { |
|
546 | - $this->totals['taxes']['initial'] -= $this->taxes[ $tax_name ]['initial_tax']; |
|
547 | - $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax']; |
|
548 | - unset( $this->taxes[ $tax_name ] ); |
|
545 | + if (isset($this->taxes[$tax_name])) { |
|
546 | + $this->totals['taxes']['initial'] -= $this->taxes[$tax_name]['initial_tax']; |
|
547 | + $this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax']; |
|
548 | + unset($this->taxes[$tax_name]); |
|
549 | 549 | } |
550 | 550 | |
551 | 551 | } |
@@ -559,11 +559,11 @@ discard block |
||
559 | 559 | |
560 | 560 | $use_taxes = wpinv_use_taxes(); |
561 | 561 | |
562 | - if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) { |
|
562 | + if ($this->has_invoice() && !$this->invoice->is_taxable()) { |
|
563 | 563 | $use_taxes = false; |
564 | 564 | } |
565 | 565 | |
566 | - return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this ); |
|
566 | + return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this); |
|
567 | 567 | |
568 | 568 | } |
569 | 569 | |
@@ -612,13 +612,13 @@ discard block |
||
612 | 612 | |
613 | 613 | $initial_total = $this->get_subtotal() + $this->get_fee() + $this->get_tax(); |
614 | 614 | $recurring_total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax(); |
615 | - $processor = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total ); |
|
615 | + $processor = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total); |
|
616 | 616 | |
617 | - foreach ( $processor->discounts as $discount ) { |
|
618 | - $this->add_discount( $discount ); |
|
617 | + foreach ($processor->discounts as $discount) { |
|
618 | + $this->add_discount($discount); |
|
619 | 619 | } |
620 | 620 | |
621 | - do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) ); |
|
621 | + do_action_ref_array('getpaid_submissions_process_discounts', array(&$this)); |
|
622 | 622 | } |
623 | 623 | |
624 | 624 | /** |
@@ -627,10 +627,10 @@ discard block |
||
627 | 627 | * @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. |
628 | 628 | * @since 1.0.19 |
629 | 629 | */ |
630 | - public function add_discount( $discount ) { |
|
631 | - $this->discounts[ $discount['name'] ] = $discount; |
|
632 | - $this->totals['discount']['initial'] += wpinv_sanitize_amount( $discount['initial_discount'] ); |
|
633 | - $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] ); |
|
630 | + public function add_discount($discount) { |
|
631 | + $this->discounts[$discount['name']] = $discount; |
|
632 | + $this->totals['discount']['initial'] += wpinv_sanitize_amount($discount['initial_discount']); |
|
633 | + $this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']); |
|
634 | 634 | } |
635 | 635 | |
636 | 636 | /** |
@@ -638,12 +638,12 @@ discard block |
||
638 | 638 | * |
639 | 639 | * @since 1.0.19 |
640 | 640 | */ |
641 | - public function remove_discount( $name ) { |
|
641 | + public function remove_discount($name) { |
|
642 | 642 | |
643 | - if ( isset( $this->discounts[ $name ] ) ) { |
|
644 | - $this->totals['discount']['initial'] -= $this->discounts[ $name ]['initial_discount']; |
|
645 | - $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount']; |
|
646 | - unset( $this->discounts[ $name ] ); |
|
643 | + if (isset($this->discounts[$name])) { |
|
644 | + $this->totals['discount']['initial'] -= $this->discounts[$name]['initial_discount']; |
|
645 | + $this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount']; |
|
646 | + unset($this->discounts[$name]); |
|
647 | 647 | } |
648 | 648 | |
649 | 649 | } |
@@ -655,7 +655,7 @@ discard block |
||
655 | 655 | * @return bool |
656 | 656 | */ |
657 | 657 | public function has_discount_code() { |
658 | - return ! empty( $this->discounts['discount_code'] ); |
|
658 | + return !empty($this->discounts['discount_code']); |
|
659 | 659 | } |
660 | 660 | |
661 | 661 | /** |
@@ -712,13 +712,13 @@ discard block |
||
712 | 712 | */ |
713 | 713 | public function process_fees() { |
714 | 714 | |
715 | - $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this ); |
|
715 | + $fees_processor = new GetPaid_Payment_Form_Submission_Fees($this); |
|
716 | 716 | |
717 | - foreach ( $fees_processor->fees as $fee ) { |
|
718 | - $this->add_fee( $fee ); |
|
717 | + foreach ($fees_processor->fees as $fee) { |
|
718 | + $this->add_fee($fee); |
|
719 | 719 | } |
720 | 720 | |
721 | - do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) ); |
|
721 | + do_action_ref_array('getpaid_submissions_process_fees', array(&$this)); |
|
722 | 722 | } |
723 | 723 | |
724 | 724 | /** |
@@ -727,17 +727,17 @@ discard block |
||
727 | 727 | * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required. |
728 | 728 | * @since 1.0.19 |
729 | 729 | */ |
730 | - public function add_fee( $fee ) { |
|
730 | + public function add_fee($fee) { |
|
731 | 731 | |
732 | - if ( $fee['name'] == 'shipping' ) { |
|
733 | - $this->totals['shipping']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
734 | - $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
732 | + if ($fee['name'] == 'shipping') { |
|
733 | + $this->totals['shipping']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
734 | + $this->totals['shipping']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
735 | 735 | return; |
736 | 736 | } |
737 | 737 | |
738 | - $this->fees[ $fee['name'] ] = $fee; |
|
739 | - $this->totals['fees']['initial'] += wpinv_sanitize_amount( $fee['initial_fee'] ); |
|
740 | - $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] ); |
|
738 | + $this->fees[$fee['name']] = $fee; |
|
739 | + $this->totals['fees']['initial'] += wpinv_sanitize_amount($fee['initial_fee']); |
|
740 | + $this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']); |
|
741 | 741 | |
742 | 742 | } |
743 | 743 | |
@@ -746,15 +746,15 @@ discard block |
||
746 | 746 | * |
747 | 747 | * @since 1.0.19 |
748 | 748 | */ |
749 | - public function remove_fee( $name ) { |
|
749 | + public function remove_fee($name) { |
|
750 | 750 | |
751 | - if ( isset( $this->fees[ $name ] ) ) { |
|
752 | - $this->totals['fees']['initial'] -= $this->fees[ $name ]['initial_fee']; |
|
753 | - $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee']; |
|
754 | - unset( $this->fees[ $name ] ); |
|
751 | + if (isset($this->fees[$name])) { |
|
752 | + $this->totals['fees']['initial'] -= $this->fees[$name]['initial_fee']; |
|
753 | + $this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee']; |
|
754 | + unset($this->fees[$name]); |
|
755 | 755 | } |
756 | 756 | |
757 | - if ( 'shipping' == $name ) { |
|
757 | + if ('shipping' == $name) { |
|
758 | 758 | $this->totals['shipping']['initial'] = 0; |
759 | 759 | $this->totals['shipping']['recurring'] = 0; |
760 | 760 | } |
@@ -795,7 +795,7 @@ discard block |
||
795 | 795 | * @since 1.0.19 |
796 | 796 | */ |
797 | 797 | public function has_fees() { |
798 | - return count( $this->fees ) !== 0; |
|
798 | + return count($this->fees) !== 0; |
|
799 | 799 | } |
800 | 800 | |
801 | 801 | /* |
@@ -831,7 +831,7 @@ discard block |
||
831 | 831 | * @since 1.0.19 |
832 | 832 | */ |
833 | 833 | public function has_shipping() { |
834 | - return apply_filters( 'getpaid_payment_form_has_shipping', false, $this ); |
|
834 | + return apply_filters('getpaid_payment_form_has_shipping', false, $this); |
|
835 | 835 | } |
836 | 836 | |
837 | 837 | /** |
@@ -841,7 +841,7 @@ discard block |
||
841 | 841 | * @since 1.0.19 |
842 | 842 | */ |
843 | 843 | public function is_initial_fetch() { |
844 | - return empty( $this->data['initial_state'] ); |
|
844 | + return empty($this->data['initial_state']); |
|
845 | 845 | } |
846 | 846 | |
847 | 847 | /** |
@@ -851,7 +851,7 @@ discard block |
||
851 | 851 | */ |
852 | 852 | public function get_total() { |
853 | 853 | $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount(); |
854 | - return max( $total, 0 ); |
|
854 | + return max($total, 0); |
|
855 | 855 | } |
856 | 856 | |
857 | 857 | /** |
@@ -861,7 +861,7 @@ discard block |
||
861 | 861 | */ |
862 | 862 | public function get_recurring_total() { |
863 | 863 | $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount(); |
864 | - return max( $total, 0 ); |
|
864 | + return max($total, 0); |
|
865 | 865 | } |
866 | 866 | |
867 | 867 | /** |
@@ -873,12 +873,12 @@ discard block |
||
873 | 873 | $initial = $this->get_total(); |
874 | 874 | $recurring = $this->get_recurring_total(); |
875 | 875 | |
876 | - if ( $this->has_recurring == 0 ) { |
|
876 | + if ($this->has_recurring == 0) { |
|
877 | 877 | $recurring = 0; |
878 | 878 | } |
879 | 879 | |
880 | 880 | $collect = $initial > 0 || $recurring > 0; |
881 | - return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this ); |
|
881 | + return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this); |
|
882 | 882 | } |
883 | 883 | |
884 | 884 | /** |
@@ -887,7 +887,7 @@ discard block |
||
887 | 887 | * @since 1.0.19 |
888 | 888 | */ |
889 | 889 | public function get_billing_email() { |
890 | - return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this ); |
|
890 | + return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this); |
|
891 | 891 | } |
892 | 892 | |
893 | 893 | /** |
@@ -897,7 +897,7 @@ discard block |
||
897 | 897 | */ |
898 | 898 | public function has_billing_email() { |
899 | 899 | $billing_email = $this->get_billing_email(); |
900 | - return ! empty( $billing_email ) && is_email( $billing_email ); |
|
900 | + return !empty($billing_email) && is_email($billing_email); |
|
901 | 901 | } |
902 | 902 | |
903 | 903 | /** |
@@ -927,8 +927,8 @@ discard block |
||
927 | 927 | * @since 1.0.19 |
928 | 928 | * @return mixed|null |
929 | 929 | */ |
930 | - public function get_field( $field, $sub_array_key = null ) { |
|
931 | - return getpaid_get_array_field( $this->data, $field, $sub_array_key ); |
|
930 | + public function get_field($field, $sub_array_key = null) { |
|
931 | + return getpaid_get_array_field($this->data, $field, $sub_array_key); |
|
932 | 932 | } |
933 | 933 | |
934 | 934 | /** |
@@ -936,8 +936,8 @@ discard block |
||
936 | 936 | * |
937 | 937 | * @since 1.0.19 |
938 | 938 | */ |
939 | - public function is_required_field_set( $field ) { |
|
940 | - return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] ); |
|
939 | + public function is_required_field_set($field) { |
|
940 | + return empty($field['required']) || !empty($this->data[$field['id']]); |
|
941 | 941 | } |
942 | 942 | |
943 | 943 | /** |
@@ -945,8 +945,8 @@ discard block |
||
945 | 945 | * |
946 | 946 | * @since 1.0.19 |
947 | 947 | */ |
948 | - public function format_amount( $amount ) { |
|
949 | - return wpinv_price( $amount, $this->get_currency() ); |
|
948 | + public function format_amount($amount) { |
|
949 | + return wpinv_price($amount, $this->get_currency()); |
|
950 | 950 | } |
951 | 951 | |
952 | 952 | } |
@@ -6,7 +6,7 @@ discard block |
||
6 | 6 | * |
7 | 7 | */ |
8 | 8 | |
9 | -if ( ! defined( 'ABSPATH' ) ) { |
|
9 | +if (!defined('ABSPATH')) { |
|
10 | 10 | exit; // Exit if accessed directly |
11 | 11 | } |
12 | 12 | |
@@ -20,13 +20,13 @@ discard block |
||
20 | 20 | * |
21 | 21 | * @param WP_Post $post |
22 | 22 | */ |
23 | - public static function output( $post ) { |
|
23 | + public static function output($post) { |
|
24 | 24 | |
25 | 25 | // Retrieve shipping address. |
26 | - $shipping_address = get_post_meta( $post->ID, 'shipping_address', true ); |
|
26 | + $shipping_address = get_post_meta($post->ID, 'shipping_address', true); |
|
27 | 27 | |
28 | 28 | // Abort if it is invalid. |
29 | - if ( ! is_array( $shipping_address ) ) { |
|
29 | + if (!is_array($shipping_address)) { |
|
30 | 30 | return; |
31 | 31 | } |
32 | 32 | |
@@ -34,29 +34,29 @@ discard block |
||
34 | 34 | |
35 | 35 | <div class="bsui"> |
36 | 36 | |
37 | - <?php if ( ! empty( $shipping_address['method'] ) ) : ?> |
|
37 | + <?php if (!empty($shipping_address['method'])) : ?> |
|
38 | 38 | |
39 | 39 | <div class="form-group form-row" style="color: green;"> |
40 | 40 | <div class="col"> |
41 | - <span style="font-weight: 600"><?php esc_html_e( 'Shipping Method', 'invoicing' ); ?>:</span> |
|
41 | + <span style="font-weight: 600"><?php esc_html_e('Shipping Method', 'invoicing'); ?>:</span> |
|
42 | 42 | </div> |
43 | 43 | <div class="col"> |
44 | - <?php echo wp_kses_post( $shipping_address['method'] ); ?> |
|
44 | + <?php echo wp_kses_post($shipping_address['method']); ?> |
|
45 | 45 | </div> |
46 | 46 | </div> |
47 | 47 | |
48 | 48 | <?php endif; ?> |
49 | 49 | |
50 | - <?php foreach ( getpaid_user_address_fields() as $key => $label ) : ?> |
|
50 | + <?php foreach (getpaid_user_address_fields() as $key => $label) : ?> |
|
51 | 51 | |
52 | - <?php if ( ! empty( $shipping_address[ $key ] ) ) : ?> |
|
52 | + <?php if (!empty($shipping_address[$key])) : ?> |
|
53 | 53 | |
54 | 54 | <div class="form-group form-row"> |
55 | 55 | <div class="col"> |
56 | - <span style="font-weight: 600"><?php echo esc_html( $label ); ?>:</span> |
|
56 | + <span style="font-weight: 600"><?php echo esc_html($label); ?>:</span> |
|
57 | 57 | </div> |
58 | 58 | <div class="col"> |
59 | - <?php echo self::prepare_for_display( $shipping_address, $key ); ?> |
|
59 | + <?php echo self::prepare_for_display($shipping_address, $key); ?> |
|
60 | 60 | </div> |
61 | 61 | </div> |
62 | 62 | |
@@ -77,21 +77,21 @@ discard block |
||
77 | 77 | * @param string $key |
78 | 78 | * @return string |
79 | 79 | */ |
80 | - public static function prepare_for_display( $address, $key ) { |
|
80 | + public static function prepare_for_display($address, $key) { |
|
81 | 81 | |
82 | 82 | // Prepare the value. |
83 | - $value = $address[ $key ]; |
|
83 | + $value = $address[$key]; |
|
84 | 84 | |
85 | - if ( $key == 'country' ) { |
|
86 | - $value = wpinv_country_name( $value ); |
|
85 | + if ($key == 'country') { |
|
86 | + $value = wpinv_country_name($value); |
|
87 | 87 | } |
88 | 88 | |
89 | - if ( $key == 'state' ) { |
|
90 | - $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country(); |
|
91 | - $value = wpinv_state_name( $value, $country ); |
|
89 | + if ($key == 'state') { |
|
90 | + $country = isset($address['country']) ? $address['country'] : wpinv_get_default_country(); |
|
91 | + $value = wpinv_state_name($value, $country); |
|
92 | 92 | } |
93 | 93 | |
94 | - return esc_html( $value ); |
|
94 | + return esc_html($value); |
|
95 | 95 | |
96 | 96 | } |
97 | 97 |
@@ -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 | * Main Checkout Class. |
@@ -22,7 +22,7 @@ discard block |
||
22 | 22 | * |
23 | 23 | * @param GetPaid_Payment_Form_Submission $submission |
24 | 24 | */ |
25 | - public function __construct( $submission ) { |
|
25 | + public function __construct($submission) { |
|
26 | 26 | $this->payment_form_submission = $submission; |
27 | 27 | } |
28 | 28 | |
@@ -38,22 +38,22 @@ discard block |
||
38 | 38 | // Prepare the invoice. |
39 | 39 | $items = $this->get_submission_items(); |
40 | 40 | $invoice = $this->get_submission_invoice(); |
41 | - $invoice = $this->process_submission_invoice( $invoice, $items ); |
|
41 | + $invoice = $this->process_submission_invoice($invoice, $items); |
|
42 | 42 | $prepared = $this->prepare_submission_data_for_saving(); |
43 | 43 | |
44 | - $this->prepare_billing_info( $invoice ); |
|
44 | + $this->prepare_billing_info($invoice); |
|
45 | 45 | |
46 | - $shipping = $this->prepare_shipping_info( $invoice ); |
|
46 | + $shipping = $this->prepare_shipping_info($invoice); |
|
47 | 47 | |
48 | 48 | // Save the invoice. |
49 | - $invoice->set_is_viewed( true ); |
|
49 | + $invoice->set_is_viewed(true); |
|
50 | 50 | $invoice->recalculate_total(); |
51 | 51 | $invoice->save(); |
52 | 52 | |
53 | - do_action( 'getpaid_checkout_invoice_updated', $invoice ); |
|
53 | + do_action('getpaid_checkout_invoice_updated', $invoice); |
|
54 | 54 | |
55 | 55 | // Send to the gateway. |
56 | - $this->post_process_submission( $invoice, $prepared, $shipping ); |
|
56 | + $this->post_process_submission($invoice, $prepared, $shipping); |
|
57 | 57 | } |
58 | 58 | |
59 | 59 | /** |
@@ -66,34 +66,34 @@ discard block |
||
66 | 66 | $data = $submission->get_data(); |
67 | 67 | |
68 | 68 | // Do we have an error? |
69 | - if ( ! empty( $submission->last_error ) ) { |
|
70 | - wp_send_json_error( $submission->last_error ); |
|
69 | + if (!empty($submission->last_error)) { |
|
70 | + wp_send_json_error($submission->last_error); |
|
71 | 71 | } |
72 | 72 | |
73 | 73 | // We need a billing email. |
74 | - if ( ! $submission->has_billing_email() ) { |
|
75 | - wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) ); |
|
74 | + if (!$submission->has_billing_email()) { |
|
75 | + wp_send_json_error(__('Provide a valid billing email.', 'invoicing')); |
|
76 | 76 | } |
77 | 77 | |
78 | 78 | // Non-recurring gateways should not be allowed to process recurring invoices. |
79 | - if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) { |
|
80 | - wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) ); |
|
79 | + if ($submission->should_collect_payment_details() && $submission->has_recurring && !wpinv_gateway_support_subscription($data['wpi-gateway'])) { |
|
80 | + wp_send_json_error(__('The selected payment gateway does not support subscription payments.', 'invoicing')); |
|
81 | 81 | } |
82 | 82 | |
83 | 83 | // Ensure the gateway is active. |
84 | - if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) { |
|
85 | - wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) ); |
|
84 | + if ($submission->should_collect_payment_details() && !wpinv_is_gateway_active($data['wpi-gateway'])) { |
|
85 | + wp_send_json_error(__('The selected payment gateway is not active', 'invoicing')); |
|
86 | 86 | } |
87 | 87 | |
88 | 88 | // Clear any existing errors. |
89 | 89 | wpinv_clear_errors(); |
90 | 90 | |
91 | 91 | // Allow themes and plugins to hook to errors |
92 | - do_action( 'getpaid_checkout_error_checks', $submission ); |
|
92 | + do_action('getpaid_checkout_error_checks', $submission); |
|
93 | 93 | |
94 | 94 | // Do we have any errors? |
95 | - if ( wpinv_get_errors() ) { |
|
96 | - wp_send_json_error( getpaid_get_errors_html() ); |
|
95 | + if (wpinv_get_errors()) { |
|
96 | + wp_send_json_error(getpaid_get_errors_html()); |
|
97 | 97 | } |
98 | 98 | |
99 | 99 | } |
@@ -108,8 +108,8 @@ discard block |
||
108 | 108 | $items = $this->payment_form_submission->get_items(); |
109 | 109 | |
110 | 110 | // Ensure that we have items. |
111 | - if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) { |
|
112 | - wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) ); |
|
111 | + if (empty($items) && !$this->payment_form_submission->has_fees()) { |
|
112 | + wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing')); |
|
113 | 113 | } |
114 | 114 | |
115 | 115 | return $items; |
@@ -123,17 +123,17 @@ discard block |
||
123 | 123 | protected function get_submission_invoice() { |
124 | 124 | $submission = $this->payment_form_submission; |
125 | 125 | |
126 | - if ( ! $submission->has_invoice() ) { |
|
126 | + if (!$submission->has_invoice()) { |
|
127 | 127 | $invoice = new WPInv_Invoice(); |
128 | - $invoice->set_created_via( 'payment_form' ); |
|
128 | + $invoice->set_created_via('payment_form'); |
|
129 | 129 | return $invoice; |
130 | 130 | } |
131 | 131 | |
132 | 132 | $invoice = $submission->get_invoice(); |
133 | 133 | |
134 | 134 | // Make sure that it is neither paid or refunded. |
135 | - if ( $invoice->is_paid() || $invoice->is_refunded() ) { |
|
136 | - wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) ); |
|
135 | + if ($invoice->is_paid() || $invoice->is_refunded()) { |
|
136 | + wp_send_json_error(__('This invoice has already been paid for.', 'invoicing')); |
|
137 | 137 | } |
138 | 138 | |
139 | 139 | return $invoice; |
@@ -146,33 +146,33 @@ discard block |
||
146 | 146 | * @param GetPaid_Form_Item[] $items |
147 | 147 | * @return WPInv_Invoice |
148 | 148 | */ |
149 | - protected function process_submission_invoice( $invoice, $items ) { |
|
149 | + protected function process_submission_invoice($invoice, $items) { |
|
150 | 150 | |
151 | 151 | $submission = $this->payment_form_submission; |
152 | 152 | |
153 | 153 | // Set-up the invoice details. |
154 | - $invoice->set_email( sanitize_email( $submission->get_billing_email() ) ); |
|
155 | - $invoice->set_user_id( $this->get_submission_customer() ); |
|
156 | - $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) ); |
|
157 | - $invoice->set_items( $items ); |
|
158 | - $invoice->set_fees( $submission->get_fees() ); |
|
159 | - $invoice->set_taxes( $submission->get_taxes() ); |
|
160 | - $invoice->set_discounts( $submission->get_discounts() ); |
|
161 | - $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) ); |
|
162 | - $invoice->set_currency( $submission->get_currency() ); |
|
163 | - |
|
164 | - if ( $submission->has_shipping() ) { |
|
165 | - $invoice->set_shipping( $submission->get_shipping() ); |
|
154 | + $invoice->set_email(sanitize_email($submission->get_billing_email())); |
|
155 | + $invoice->set_user_id($this->get_submission_customer()); |
|
156 | + $invoice->set_payment_form(absint($submission->get_payment_form()->get_id())); |
|
157 | + $invoice->set_items($items); |
|
158 | + $invoice->set_fees($submission->get_fees()); |
|
159 | + $invoice->set_taxes($submission->get_taxes()); |
|
160 | + $invoice->set_discounts($submission->get_discounts()); |
|
161 | + $invoice->set_gateway($submission->get_field('wpi-gateway')); |
|
162 | + $invoice->set_currency($submission->get_currency()); |
|
163 | + |
|
164 | + if ($submission->has_shipping()) { |
|
165 | + $invoice->set_shipping($submission->get_shipping()); |
|
166 | 166 | } |
167 | 167 | |
168 | - $address_confirmed = $submission->get_field( 'confirm-address' ); |
|
169 | - $invoice->set_address_confirmed( ! empty( $address_confirmed ) ); |
|
168 | + $address_confirmed = $submission->get_field('confirm-address'); |
|
169 | + $invoice->set_address_confirmed(!empty($address_confirmed)); |
|
170 | 170 | |
171 | - if ( $submission->has_discount_code() ) { |
|
172 | - $invoice->set_discount_code( $submission->get_discount_code() ); |
|
171 | + if ($submission->has_discount_code()) { |
|
172 | + $invoice->set_discount_code($submission->get_discount_code()); |
|
173 | 173 | } |
174 | 174 | |
175 | - getpaid_maybe_add_default_address( $invoice ); |
|
175 | + getpaid_maybe_add_default_address($invoice); |
|
176 | 176 | return $invoice; |
177 | 177 | } |
178 | 178 | |
@@ -185,33 +185,33 @@ discard block |
||
185 | 185 | $submission = $this->payment_form_submission; |
186 | 186 | |
187 | 187 | // If this is an existing invoice... |
188 | - if ( $submission->has_invoice() ) { |
|
188 | + if ($submission->has_invoice()) { |
|
189 | 189 | return $submission->get_invoice()->get_user_id(); |
190 | 190 | } |
191 | 191 | |
192 | 192 | // (Maybe) create the user. |
193 | 193 | $user = get_current_user_id(); |
194 | 194 | |
195 | - if ( empty( $user ) ) { |
|
196 | - $user = get_user_by( 'email', $submission->get_billing_email() ); |
|
195 | + if (empty($user)) { |
|
196 | + $user = get_user_by('email', $submission->get_billing_email()); |
|
197 | 197 | } |
198 | 198 | |
199 | - if ( empty( $user ) ) { |
|
200 | - $user = wpinv_create_user( $submission->get_billing_email() ); |
|
199 | + if (empty($user)) { |
|
200 | + $user = wpinv_create_user($submission->get_billing_email()); |
|
201 | 201 | |
202 | 202 | // (Maybe) send new user notification. |
203 | - $should_send_notification = wpinv_get_option( 'disable_new_user_emails' ); |
|
204 | - if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) { |
|
205 | - wp_send_new_user_notifications( $user, 'user' ); |
|
203 | + $should_send_notification = wpinv_get_option('disable_new_user_emails'); |
|
204 | + if (!empty($user) && is_numeric($user) && apply_filters('getpaid_send_new_user_notification', empty($should_send_notification), $user)) { |
|
205 | + wp_send_new_user_notifications($user, 'user'); |
|
206 | 206 | } |
207 | 207 | |
208 | 208 | } |
209 | 209 | |
210 | - if ( is_wp_error( $user ) ) { |
|
211 | - wp_send_json_error( $user->get_error_message() ); |
|
210 | + if (is_wp_error($user)) { |
|
211 | + wp_send_json_error($user->get_error_message()); |
|
212 | 212 | } |
213 | 213 | |
214 | - if ( is_numeric( $user ) ) { |
|
214 | + if (is_numeric($user)) { |
|
215 | 215 | return $user; |
216 | 216 | } |
217 | 217 | |
@@ -235,24 +235,24 @@ discard block |
||
235 | 235 | ); |
236 | 236 | |
237 | 237 | // Raw submission details. |
238 | - $data = $submission->get_data(); |
|
238 | + $data = $submission->get_data(); |
|
239 | 239 | |
240 | 240 | // Loop through the submitted details. |
241 | - foreach ( $submission->get_payment_form()->get_elements() as $field ) { |
|
241 | + foreach ($submission->get_payment_form()->get_elements() as $field) { |
|
242 | 242 | |
243 | 243 | // Skip premade fields. |
244 | - if ( ! empty( $field['premade'] ) ) { |
|
244 | + if (!empty($field['premade'])) { |
|
245 | 245 | continue; |
246 | 246 | } |
247 | 247 | |
248 | 248 | // Ensure address is provided. |
249 | - if ( $field['type'] == 'address' ) { |
|
250 | - $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
249 | + if ($field['type'] == 'address') { |
|
250 | + $address_type = isset($field['address_type']) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing'; |
|
251 | 251 | |
252 | - foreach ( $field['fields'] as $address_field ) { |
|
252 | + foreach ($field['fields'] as $address_field) { |
|
253 | 253 | |
254 | - if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { |
|
255 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
254 | + if (!empty($address_field['visible']) && !empty($address_field['required']) && '' === trim($_POST[$address_type][$address_field['name']])) { |
|
255 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
256 | 256 | } |
257 | 257 | |
258 | 258 | } |
@@ -260,49 +260,49 @@ discard block |
||
260 | 260 | } |
261 | 261 | |
262 | 262 | // If it is required and not set, abort. |
263 | - if ( ! $submission->is_required_field_set( $field ) ) { |
|
264 | - wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) ); |
|
263 | + if (!$submission->is_required_field_set($field)) { |
|
264 | + wp_send_json_error(__('Please fill all required fields.', 'invoicing')); |
|
265 | 265 | } |
266 | 266 | |
267 | 267 | // Handle misc fields. |
268 | - if ( isset( $data[ $field['id'] ] ) ) { |
|
268 | + if (isset($data[$field['id']])) { |
|
269 | 269 | |
270 | 270 | // Uploads. |
271 | - if ( $field['type'] == 'file_upload' ) { |
|
272 | - $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] ); |
|
271 | + if ($field['type'] == 'file_upload') { |
|
272 | + $max_file_num = empty($field['max_file_num']) ? 1 : absint($field['max_file_num']); |
|
273 | 273 | |
274 | - if ( count( $data[ $field['id'] ] ) > $max_file_num ) { |
|
275 | - wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) ); |
|
274 | + if (count($data[$field['id']]) > $max_file_num) { |
|
275 | + wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing')); |
|
276 | 276 | } |
277 | 277 | |
278 | 278 | $value = array(); |
279 | 279 | |
280 | - foreach ( $data[ $field['id'] ] as $url => $name ) { |
|
280 | + foreach ($data[$field['id']] as $url => $name) { |
|
281 | 281 | $value[] = sprintf( |
282 | 282 | '<a href="%s" target="_blank">%s</a>', |
283 | - esc_url_raw( $url ), |
|
284 | - esc_html( $name ) |
|
283 | + esc_url_raw($url), |
|
284 | + esc_html($name) |
|
285 | 285 | ); |
286 | 286 | } |
287 | 287 | |
288 | - $value = implode( ' | ', $value ); |
|
288 | + $value = implode(' | ', $value); |
|
289 | 289 | |
290 | - } else if ( $field['type'] == 'checkbox' ) { |
|
291 | - $value = isset( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' ); |
|
290 | + } else if ($field['type'] == 'checkbox') { |
|
291 | + $value = isset($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing'); |
|
292 | 292 | } else { |
293 | - $value = wp_kses_post( $data[ $field['id'] ] ); |
|
293 | + $value = wp_kses_post($data[$field['id']]); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | $label = $field['id']; |
297 | 297 | |
298 | - if ( isset( $field['label'] ) ) { |
|
298 | + if (isset($field['label'])) { |
|
299 | 299 | $label = $field['label']; |
300 | 300 | } |
301 | 301 | |
302 | - if ( ! empty( $field['add_meta'] ) ) { |
|
303 | - $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
302 | + if (!empty($field['add_meta'])) { |
|
303 | + $prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
304 | 304 | } |
305 | - $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value ); |
|
305 | + $prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value); |
|
306 | 306 | |
307 | 307 | } |
308 | 308 | |
@@ -319,30 +319,30 @@ discard block |
||
319 | 319 | * @param WPInv_Invoice $invoice |
320 | 320 | * @param string $type |
321 | 321 | */ |
322 | - public function prepare_address_details( $invoice, $type = 'billing' ) { |
|
322 | + public function prepare_address_details($invoice, $type = 'billing') { |
|
323 | 323 | |
324 | 324 | $data = $this->payment_form_submission->get_data(); |
325 | - $type = sanitize_key( $type ); |
|
325 | + $type = sanitize_key($type); |
|
326 | 326 | $address = array(); |
327 | 327 | $prepared = array(); |
328 | 328 | |
329 | - if ( ! empty( $data[ $type ] ) ) { |
|
330 | - $address = $data[ $type ]; |
|
329 | + if (!empty($data[$type])) { |
|
330 | + $address = $data[$type]; |
|
331 | 331 | } |
332 | 332 | |
333 | 333 | // Clean address details. |
334 | - foreach ( $address as $key => $value ) { |
|
335 | - $key = sanitize_key( $key ); |
|
336 | - $key = str_replace( 'wpinv_', '', $key ); |
|
337 | - $value = wpinv_clean( $value ); |
|
338 | - $prepared[ $key] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice ); |
|
334 | + foreach ($address as $key => $value) { |
|
335 | + $key = sanitize_key($key); |
|
336 | + $key = str_replace('wpinv_', '', $key); |
|
337 | + $value = wpinv_clean($value); |
|
338 | + $prepared[$key] = apply_filters("getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice); |
|
339 | 339 | } |
340 | 340 | |
341 | 341 | // Filter address details. |
342 | - $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice ); |
|
342 | + $prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice); |
|
343 | 343 | |
344 | 344 | // Remove non-whitelisted values. |
345 | - return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY ); |
|
345 | + return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY); |
|
346 | 346 | |
347 | 347 | } |
348 | 348 | |
@@ -352,12 +352,12 @@ discard block |
||
352 | 352 | * @return array |
353 | 353 | * @param WPInv_Invoice $invoice |
354 | 354 | */ |
355 | - protected function prepare_billing_info( &$invoice ) { |
|
355 | + protected function prepare_billing_info(&$invoice) { |
|
356 | 356 | |
357 | - $billing_address = $this->prepare_address_details( $invoice, 'billing' ); |
|
357 | + $billing_address = $this->prepare_address_details($invoice, 'billing'); |
|
358 | 358 | |
359 | 359 | // Update the invoice with the billing details. |
360 | - $invoice->set_props( $billing_address ); |
|
360 | + $invoice->set_props($billing_address); |
|
361 | 361 | |
362 | 362 | } |
363 | 363 | |
@@ -367,15 +367,15 @@ discard block |
||
367 | 367 | * @return array |
368 | 368 | * @param WPInv_Invoice $invoice |
369 | 369 | */ |
370 | - protected function prepare_shipping_info( $invoice ) { |
|
370 | + protected function prepare_shipping_info($invoice) { |
|
371 | 371 | |
372 | 372 | $data = $this->payment_form_submission->get_data(); |
373 | 373 | |
374 | - if ( empty( $data['same-shipping-address'] ) ) { |
|
375 | - return $this->prepare_address_details( $invoice, 'shipping' ); |
|
374 | + if (empty($data['same-shipping-address'])) { |
|
375 | + return $this->prepare_address_details($invoice, 'shipping'); |
|
376 | 376 | } |
377 | 377 | |
378 | - return $this->prepare_address_details( $invoice, 'billing' ); |
|
378 | + return $this->prepare_address_details($invoice, 'billing'); |
|
379 | 379 | |
380 | 380 | } |
381 | 381 | |
@@ -386,42 +386,42 @@ discard block |
||
386 | 386 | * @param array $prepared_payment_form_data |
387 | 387 | * @param array $shipping |
388 | 388 | */ |
389 | - protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) { |
|
389 | + protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) { |
|
390 | 390 | |
391 | 391 | // Ensure the invoice exists. |
392 | - if ( ! $invoice->exists() ) { |
|
393 | - wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) ); |
|
392 | + if (!$invoice->exists()) { |
|
393 | + wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing')); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | // Save payment form data. |
397 | - $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice ); |
|
398 | - delete_post_meta( $invoice->get_id(), 'payment_form_data' ); |
|
399 | - delete_post_meta( $invoice->get_id(), 'additional_meta_data' ); |
|
400 | - if ( ! empty( $prepared_payment_form_data ) ) { |
|
397 | + $prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice); |
|
398 | + delete_post_meta($invoice->get_id(), 'payment_form_data'); |
|
399 | + delete_post_meta($invoice->get_id(), 'additional_meta_data'); |
|
400 | + if (!empty($prepared_payment_form_data)) { |
|
401 | 401 | |
402 | - if ( ! empty( $prepared_payment_form_data['all'] ) ) { |
|
403 | - update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] ); |
|
402 | + if (!empty($prepared_payment_form_data['all'])) { |
|
403 | + update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']); |
|
404 | 404 | } |
405 | 405 | |
406 | - if ( ! empty( $prepared_payment_form_data['meta'] ) ) { |
|
407 | - update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] ); |
|
406 | + if (!empty($prepared_payment_form_data['meta'])) { |
|
407 | + update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']); |
|
408 | 408 | } |
409 | 409 | |
410 | 410 | } |
411 | 411 | |
412 | 412 | // Save payment form data. |
413 | - $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission ); |
|
414 | - if ( ! empty( $shipping ) ) { |
|
415 | - update_post_meta( $invoice->get_id(), 'shipping_address', $shipping ); |
|
413 | + $shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission); |
|
414 | + if (!empty($shipping)) { |
|
415 | + update_post_meta($invoice->get_id(), 'shipping_address', $shipping); |
|
416 | 416 | } |
417 | 417 | |
418 | 418 | // Backwards compatibility. |
419 | - add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) ); |
|
419 | + add_filter('wp_redirect', array($this, 'send_redirect_response')); |
|
420 | 420 | |
421 | - $this->process_payment( $invoice ); |
|
421 | + $this->process_payment($invoice); |
|
422 | 422 | |
423 | 423 | // If we are here, there was an error. |
424 | - wpinv_send_back_to_checkout( $invoice ); |
|
424 | + wpinv_send_back_to_checkout($invoice); |
|
425 | 425 | |
426 | 426 | } |
427 | 427 | |
@@ -430,41 +430,41 @@ discard block |
||
430 | 430 | * |
431 | 431 | * @param WPInv_Invoice $invoice |
432 | 432 | */ |
433 | - protected function process_payment( $invoice ) { |
|
433 | + protected function process_payment($invoice) { |
|
434 | 434 | |
435 | 435 | // Clear any checkout errors. |
436 | 436 | wpinv_clear_errors(); |
437 | 437 | |
438 | 438 | // No need to send free invoices to the gateway. |
439 | - if ( $invoice->is_free() ) { |
|
440 | - $this->process_free_payment( $invoice ); |
|
439 | + if ($invoice->is_free()) { |
|
440 | + $this->process_free_payment($invoice); |
|
441 | 441 | } |
442 | 442 | |
443 | 443 | $submission = $this->payment_form_submission; |
444 | 444 | |
445 | 445 | // Fires before sending to the gateway. |
446 | - do_action( 'getpaid_checkout_before_gateway', $invoice, $submission ); |
|
446 | + do_action('getpaid_checkout_before_gateway', $invoice, $submission); |
|
447 | 447 | |
448 | 448 | // Allow the sumission data to be modified before it is sent to the gateway. |
449 | 449 | $submission_data = $submission->get_data(); |
450 | - $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice ); |
|
451 | - $submission_data = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice ); |
|
450 | + $submission_gateway = apply_filters('getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice); |
|
451 | + $submission_data = apply_filters('getpaid_gateway_submission_data', $submission_data, $submission, $invoice); |
|
452 | 452 | |
453 | 453 | // Validate the currency. |
454 | - if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) { |
|
455 | - wpinv_set_error( 'invalid_currency', __( 'The chosen payment gateway does not support this currency', 'invoicing' ) ); |
|
454 | + if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) { |
|
455 | + wpinv_set_error('invalid_currency', __('The chosen payment gateway does not support this currency', 'invoicing')); |
|
456 | 456 | } |
457 | 457 | |
458 | 458 | // Check to see if we have any errors. |
459 | - if ( wpinv_get_errors() ) { |
|
460 | - wpinv_send_back_to_checkout( $invoice ); |
|
459 | + if (wpinv_get_errors()) { |
|
460 | + wpinv_send_back_to_checkout($invoice); |
|
461 | 461 | } |
462 | 462 | |
463 | 463 | // Send info to the gateway for payment processing |
464 | - do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission ); |
|
464 | + do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission); |
|
465 | 465 | |
466 | 466 | // Backwards compatibility. |
467 | - wpinv_send_to_gateway( $submission_gateway, $invoice ); |
|
467 | + wpinv_send_to_gateway($submission_gateway, $invoice); |
|
468 | 468 | |
469 | 469 | } |
470 | 470 | |
@@ -473,12 +473,12 @@ discard block |
||
473 | 473 | * |
474 | 474 | * @param WPInv_Invoice $invoice |
475 | 475 | */ |
476 | - protected function process_free_payment( $invoice ) { |
|
476 | + protected function process_free_payment($invoice) { |
|
477 | 477 | |
478 | - $invoice->set_gateway( 'none' ); |
|
479 | - $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true ); |
|
478 | + $invoice->set_gateway('none'); |
|
479 | + $invoice->add_note(__("This is a free invoice and won't be sent to the payment gateway", 'invoicing'), false, false, true); |
|
480 | 480 | $invoice->mark_paid(); |
481 | - wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) ); |
|
481 | + wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key())); |
|
482 | 482 | |
483 | 483 | } |
484 | 484 | |
@@ -486,9 +486,9 @@ discard block |
||
486 | 486 | * Sends a redrect response to payment details. |
487 | 487 | * |
488 | 488 | */ |
489 | - public function send_redirect_response( $url ) { |
|
490 | - $url = urlencode( $url ); |
|
491 | - wp_send_json_success( $url ); |
|
489 | + public function send_redirect_response($url) { |
|
490 | + $url = urlencode($url); |
|
491 | + wp_send_json_success($url); |
|
492 | 492 | } |
493 | 493 | |
494 | 494 | } |
@@ -7,15 +7,15 @@ discard block |
||
7 | 7 | */ |
8 | 8 | |
9 | 9 | // MUST have WordPress. |
10 | -if ( !defined( 'WPINC' ) ) { |
|
11 | - exit( 'Do NOT access this file directly: ' . basename( __FILE__ ) ); |
|
10 | +if (!defined('WPINC')) { |
|
11 | + exit('Do NOT access this file directly: ' . basename(__FILE__)); |
|
12 | 12 | } |
13 | 13 | |
14 | 14 | |
15 | 15 | function wpinv_get_default_country() { |
16 | - $country = wpinv_get_option( 'default_country', 'UK' ); |
|
16 | + $country = wpinv_get_option('default_country', 'UK'); |
|
17 | 17 | |
18 | - return apply_filters( 'wpinv_default_country', $country ); |
|
18 | + return apply_filters('wpinv_default_country', $country); |
|
19 | 19 | } |
20 | 20 | |
21 | 21 | /** |
@@ -23,8 +23,8 @@ discard block |
||
23 | 23 | * |
24 | 24 | * @return string |
25 | 25 | */ |
26 | -function getpaid_get_ip_country( $ip_address = '' ) { |
|
27 | - $country = GetPaid_Geolocation::geolocate_ip( $ip_address, true ); |
|
26 | +function getpaid_get_ip_country($ip_address = '') { |
|
27 | + $country = GetPaid_Geolocation::geolocate_ip($ip_address, true); |
|
28 | 28 | return $country['country']; |
29 | 29 | } |
30 | 30 | |
@@ -34,59 +34,59 @@ discard block |
||
34 | 34 | * @param string $country The country code to sanitize |
35 | 35 | * @return array |
36 | 36 | */ |
37 | -function wpinv_sanitize_country( $country ) { |
|
37 | +function wpinv_sanitize_country($country) { |
|
38 | 38 | |
39 | 39 | // Enure the country is specified |
40 | - if ( empty( $country ) ) { |
|
40 | + if (empty($country)) { |
|
41 | 41 | $country = wpinv_get_default_country(); |
42 | 42 | } |
43 | - return trim( wpinv_utf8_strtoupper( $country ) ); |
|
43 | + return trim(wpinv_utf8_strtoupper($country)); |
|
44 | 44 | |
45 | 45 | } |
46 | 46 | |
47 | -function wpinv_is_base_country( $country ) { |
|
47 | +function wpinv_is_base_country($country) { |
|
48 | 48 | $base_country = wpinv_get_default_country(); |
49 | 49 | |
50 | - if ( $base_country === 'UK' ) { |
|
50 | + if ($base_country === 'UK') { |
|
51 | 51 | $base_country = 'GB'; |
52 | 52 | } |
53 | - if ( $country == 'UK' ) { |
|
53 | + if ($country == 'UK') { |
|
54 | 54 | $country = 'GB'; |
55 | 55 | } |
56 | 56 | |
57 | - return ( $country && $country === $base_country ) ? true : false; |
|
57 | + return ($country && $country === $base_country) ? true : false; |
|
58 | 58 | } |
59 | 59 | |
60 | -function wpinv_country_name( $country_code = '' ) { |
|
60 | +function wpinv_country_name($country_code = '') { |
|
61 | 61 | $countries = wpinv_get_country_list(); |
62 | 62 | $country_code = $country_code == 'UK' ? 'GB' : $country_code; |
63 | - $country = isset( $countries[$country_code] ) ? $countries[$country_code] : $country_code; |
|
63 | + $country = isset($countries[$country_code]) ? $countries[$country_code] : $country_code; |
|
64 | 64 | |
65 | - return apply_filters( 'wpinv_country_name', $country, $country_code ); |
|
65 | + return apply_filters('wpinv_country_name', $country, $country_code); |
|
66 | 66 | } |
67 | 67 | |
68 | 68 | function wpinv_get_default_state() { |
69 | - $state = wpinv_get_option( 'default_state', '' ); |
|
69 | + $state = wpinv_get_option('default_state', ''); |
|
70 | 70 | |
71 | - return apply_filters( 'wpinv_default_state', $state ); |
|
71 | + return apply_filters('wpinv_default_state', $state); |
|
72 | 72 | } |
73 | 73 | |
74 | -function wpinv_state_name( $state_code = '', $country_code = '' ) { |
|
74 | +function wpinv_state_name($state_code = '', $country_code = '') { |
|
75 | 75 | $state = $state_code; |
76 | 76 | |
77 | - if ( !empty( $country_code ) ) { |
|
78 | - $states = wpinv_get_country_states( $country_code ); |
|
77 | + if (!empty($country_code)) { |
|
78 | + $states = wpinv_get_country_states($country_code); |
|
79 | 79 | |
80 | - $state = !empty( $states ) && isset( $states[$state_code] ) ? $states[$state_code] : $state; |
|
80 | + $state = !empty($states) && isset($states[$state_code]) ? $states[$state_code] : $state; |
|
81 | 81 | } |
82 | 82 | |
83 | - return apply_filters( 'wpinv_state_name', $state, $state_code, $country_code ); |
|
83 | + return apply_filters('wpinv_state_name', $state, $state_code, $country_code); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | function wpinv_store_address() { |
87 | - $address = wpinv_get_option( 'store_address', '' ); |
|
87 | + $address = wpinv_get_option('store_address', ''); |
|
88 | 88 | |
89 | - return apply_filters( 'wpinv_store_address', $address ); |
|
89 | + return apply_filters('wpinv_store_address', $address); |
|
90 | 90 | } |
91 | 91 | |
92 | 92 | /** |
@@ -94,24 +94,24 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param WPInv_Invoice $invoice |
96 | 96 | */ |
97 | -function getpaid_maybe_add_default_address( &$invoice ) { |
|
97 | +function getpaid_maybe_add_default_address(&$invoice) { |
|
98 | 98 | |
99 | 99 | $user_id = $invoice->get_user_id(); |
100 | 100 | |
101 | 101 | // Abort if the invoice belongs to no one. |
102 | - if ( empty( $user_id ) ) { |
|
102 | + if (empty($user_id)) { |
|
103 | 103 | return; |
104 | 104 | } |
105 | 105 | |
106 | 106 | // Fill in defaults whenever necessary. |
107 | - foreach ( wpinv_get_user_address( $user_id ) as $key => $value ) { |
|
107 | + foreach (wpinv_get_user_address($user_id) as $key => $value) { |
|
108 | 108 | |
109 | - if ( is_callable( $invoice, "get_$key" ) ) { |
|
110 | - $current = call_user_func( array( $invoice, "get_$key" ) ); |
|
109 | + if (is_callable($invoice, "get_$key")) { |
|
110 | + $current = call_user_func(array($invoice, "get_$key")); |
|
111 | 111 | |
112 | - if ( empty( $current ) ) { |
|
112 | + if (empty($current)) { |
|
113 | 113 | $method = "set_$key"; |
114 | - $invoice->$method( $value ); |
|
114 | + $invoice->$method($value); |
|
115 | 115 | } |
116 | 116 | |
117 | 117 | } |
@@ -130,22 +130,22 @@ discard block |
||
130 | 130 | $address_fields = apply_filters( |
131 | 131 | 'getpaid_user_address_fields', |
132 | 132 | array( |
133 | - 'first_name' => __( 'First Name', 'invoicing' ), |
|
134 | - 'last_name' => __( 'Last Name', 'invoicing' ), |
|
135 | - 'address' => __( 'Address', 'invoicing' ), |
|
136 | - 'city' => __( 'City', 'invoicing' ), |
|
137 | - 'country' => __( 'Country', 'invoicing' ), |
|
138 | - 'state' => __( 'State', 'invoicing' ), |
|
139 | - 'zip' => __( 'Zip/Postal Code', 'invoicing' ), |
|
140 | - 'phone' => __( 'Phone Number', 'invoicing' ), |
|
141 | - 'company' => __( 'Company', 'invoicing' ), |
|
142 | - 'company_id' => __( 'Company ID', 'invoicing' ), |
|
143 | - 'vat_number' => __( 'VAT Number', 'invoicing' ), |
|
133 | + 'first_name' => __('First Name', 'invoicing'), |
|
134 | + 'last_name' => __('Last Name', 'invoicing'), |
|
135 | + 'address' => __('Address', 'invoicing'), |
|
136 | + 'city' => __('City', 'invoicing'), |
|
137 | + 'country' => __('Country', 'invoicing'), |
|
138 | + 'state' => __('State', 'invoicing'), |
|
139 | + 'zip' => __('Zip/Postal Code', 'invoicing'), |
|
140 | + 'phone' => __('Phone Number', 'invoicing'), |
|
141 | + 'company' => __('Company', 'invoicing'), |
|
142 | + 'company_id' => __('Company ID', 'invoicing'), |
|
143 | + 'vat_number' => __('VAT Number', 'invoicing'), |
|
144 | 144 | ) |
145 | 145 | ); |
146 | 146 | |
147 | - if ( ! wpinv_use_taxes() && isset( $address_fields['vat_number'] ) ) { |
|
148 | - unset( $address_fields['vat_number'] ); |
|
147 | + if (!wpinv_use_taxes() && isset($address_fields['vat_number'])) { |
|
148 | + unset($address_fields['vat_number']); |
|
149 | 149 | } |
150 | 150 | |
151 | 151 | return $address_fields; |
@@ -156,8 +156,8 @@ discard block |
||
156 | 156 | * |
157 | 157 | * @return bool |
158 | 158 | */ |
159 | -function getpaid_is_address_field_whitelisted( $key ) { |
|
160 | - return array_key_exists( $key, getpaid_user_address_fields() ); |
|
159 | +function getpaid_is_address_field_whitelisted($key) { |
|
160 | + return array_key_exists($key, getpaid_user_address_fields()); |
|
161 | 161 | } |
162 | 162 | |
163 | 163 | /** |
@@ -167,24 +167,24 @@ discard block |
||
167 | 167 | * |
168 | 168 | * @param WPInv_Invoice $invoice |
169 | 169 | */ |
170 | -function getpaid_save_invoice_user_address( $invoice ) { |
|
170 | +function getpaid_save_invoice_user_address($invoice) { |
|
171 | 171 | |
172 | 172 | // Retrieve the invoice. |
173 | - $invoice = wpinv_get_invoice( $invoice ); |
|
173 | + $invoice = wpinv_get_invoice($invoice); |
|
174 | 174 | |
175 | 175 | // Abort if it does not exist. |
176 | - if ( empty( $invoice ) || $invoice->is_renewal() ) { |
|
176 | + if (empty($invoice) || $invoice->is_renewal()) { |
|
177 | 177 | return; |
178 | 178 | } |
179 | 179 | |
180 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
180 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
181 | 181 | |
182 | - if ( is_callable( array( $invoice, "get_$field" ) ) ) { |
|
183 | - $value = call_user_func( array( $invoice, "get_$field" ) ); |
|
182 | + if (is_callable(array($invoice, "get_$field"))) { |
|
183 | + $value = call_user_func(array($invoice, "get_$field")); |
|
184 | 184 | |
185 | 185 | // Only save if it is not empty. |
186 | - if ( ! empty( $value ) ) { |
|
187 | - update_user_meta( $invoice->get_user_id(), '_wpinv_' . $field, $value ); |
|
186 | + if (!empty($value)) { |
|
187 | + update_user_meta($invoice->get_user_id(), '_wpinv_' . $field, $value); |
|
188 | 188 | } |
189 | 189 | |
190 | 190 | } |
@@ -192,7 +192,7 @@ discard block |
||
192 | 192 | } |
193 | 193 | |
194 | 194 | } |
195 | -add_action( 'getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address' ); |
|
195 | +add_action('getpaid_checkout_invoice_updated', 'getpaid_save_invoice_user_address'); |
|
196 | 196 | |
197 | 197 | /** |
198 | 198 | * Retrieves a saved user address. |
@@ -201,14 +201,14 @@ discard block |
||
201 | 201 | * @param bool $with_default Whether or not we should use the default country and state. |
202 | 202 | * @return array |
203 | 203 | */ |
204 | -function wpinv_get_user_address( $user_id = 0, $with_default = true ) { |
|
204 | +function wpinv_get_user_address($user_id = 0, $with_default = true) { |
|
205 | 205 | |
206 | 206 | // Prepare the user id. |
207 | - $user_id = empty( $user_id ) ? get_current_user_id() : $user_id; |
|
208 | - $user_info = get_userdata( $user_id ); |
|
207 | + $user_id = empty($user_id) ? get_current_user_id() : $user_id; |
|
208 | + $user_info = get_userdata($user_id); |
|
209 | 209 | |
210 | 210 | // Abort if non exists. |
211 | - if ( empty( $user_info ) ) { |
|
211 | + if (empty($user_info)) { |
|
212 | 212 | return array(); |
213 | 213 | } |
214 | 214 | |
@@ -218,13 +218,13 @@ discard block |
||
218 | 218 | 'email' => $user_info->user_email, |
219 | 219 | ); |
220 | 220 | |
221 | - foreach ( array_keys( getpaid_user_address_fields() ) as $field ) { |
|
222 | - $address[$field] = getpaid_get_user_address_field( $user_id, $field ); |
|
221 | + foreach (array_keys(getpaid_user_address_fields()) as $field) { |
|
222 | + $address[$field] = getpaid_get_user_address_field($user_id, $field); |
|
223 | 223 | } |
224 | 224 | |
225 | - $address = array_filter( $address ); |
|
225 | + $address = array_filter($address); |
|
226 | 226 | |
227 | - if ( ! $with_default ) { |
|
227 | + if (!$with_default) { |
|
228 | 228 | return $address; |
229 | 229 | } |
230 | 230 | |
@@ -235,7 +235,7 @@ discard block |
||
235 | 235 | 'country' => wpinv_get_default_country(), |
236 | 236 | ); |
237 | 237 | |
238 | - return getpaid_array_merge_if_empty( $address, $defaults ); |
|
238 | + return getpaid_array_merge_if_empty($address, $defaults); |
|
239 | 239 | |
240 | 240 | } |
241 | 241 | |
@@ -246,7 +246,7 @@ discard block |
||
246 | 246 | * @param string $field The field to use. |
247 | 247 | * @return string|null |
248 | 248 | */ |
249 | -function getpaid_get_user_address_field( $user_id, $field ) { |
|
249 | +function getpaid_get_user_address_field($user_id, $field) { |
|
250 | 250 | |
251 | 251 | $prefixes = array( |
252 | 252 | '_wpinv_', |
@@ -254,15 +254,15 @@ discard block |
||
254 | 254 | '' |
255 | 255 | ); |
256 | 256 | |
257 | - foreach ( $prefixes as $prefix ) { |
|
257 | + foreach ($prefixes as $prefix) { |
|
258 | 258 | |
259 | 259 | // Meta table. |
260 | - $value = get_user_meta( $user_id, $prefix . $field, true ); |
|
260 | + $value = get_user_meta($user_id, $prefix . $field, true); |
|
261 | 261 | |
262 | 262 | // UWP table. |
263 | - $value = ( empty( $value ) && function_exists( 'uwp_get_usermeta' ) ) ? uwp_get_usermeta( $user_id, $prefix . $field ) : $value; |
|
263 | + $value = (empty($value) && function_exists('uwp_get_usermeta')) ? uwp_get_usermeta($user_id, $prefix . $field) : $value; |
|
264 | 264 | |
265 | - if ( ! empty( $value ) ) { |
|
265 | + if (!empty($value)) { |
|
266 | 266 | return $value; |
267 | 267 | } |
268 | 268 | |
@@ -279,16 +279,16 @@ discard block |
||
279 | 279 | * @param string $return What to return. |
280 | 280 | * @return array |
281 | 281 | */ |
282 | -function wpinv_get_continents( $return = 'all' ) { |
|
282 | +function wpinv_get_continents($return = 'all') { |
|
283 | 283 | |
284 | - $continents = wpinv_get_data( 'continents' ); |
|
284 | + $continents = wpinv_get_data('continents'); |
|
285 | 285 | |
286 | - switch( $return ) { |
|
286 | + switch ($return) { |
|
287 | 287 | case 'name' : |
288 | - return wp_list_pluck( $continents, 'name' ); |
|
288 | + return wp_list_pluck($continents, 'name'); |
|
289 | 289 | break; |
290 | 290 | case 'countries' : |
291 | - return wp_list_pluck( $continents, 'countries' ); |
|
291 | + return wp_list_pluck($continents, 'countries'); |
|
292 | 292 | break; |
293 | 293 | default : |
294 | 294 | return $continents; |
@@ -304,12 +304,12 @@ discard block |
||
304 | 304 | * @param string $country Country code. If no code is specified, defaults to the default country. |
305 | 305 | * @return string |
306 | 306 | */ |
307 | -function wpinv_get_continent_code_for_country( $country = false ) { |
|
307 | +function wpinv_get_continent_code_for_country($country = false) { |
|
308 | 308 | |
309 | - $country = wpinv_sanitize_country( $country ); |
|
309 | + $country = wpinv_sanitize_country($country); |
|
310 | 310 | |
311 | - foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) { |
|
312 | - if ( false !== array_search( $country, $countries, true ) ) { |
|
311 | + foreach (wpinv_get_continents('countries') as $continent_code => $countries) { |
|
312 | + if (false !== array_search($country, $countries, true)) { |
|
313 | 313 | return $continent_code; |
314 | 314 | } |
315 | 315 | } |
@@ -325,13 +325,13 @@ discard block |
||
325 | 325 | * @param string $country Country code. If no code is specified, defaults to the default country. |
326 | 326 | * @return array |
327 | 327 | */ |
328 | -function wpinv_get_country_calling_code( $country = null) { |
|
328 | +function wpinv_get_country_calling_code($country = null) { |
|
329 | 329 | |
330 | - $country = wpinv_sanitize_country( $country ); |
|
331 | - $codes = wpinv_get_data( 'phone-codes' ); |
|
332 | - $code = isset( $codes[ $country ] ) ? $codes[ $country ] : ''; |
|
330 | + $country = wpinv_sanitize_country($country); |
|
331 | + $codes = wpinv_get_data('phone-codes'); |
|
332 | + $code = isset($codes[$country]) ? $codes[$country] : ''; |
|
333 | 333 | |
334 | - if ( is_array( $code ) ) { |
|
334 | + if (is_array($code)) { |
|
335 | 335 | return $code[0]; |
336 | 336 | } |
337 | 337 | return $code; |
@@ -344,8 +344,8 @@ discard block |
||
344 | 344 | * @param bool $first_empty Whether or not the first item in the list should be empty |
345 | 345 | * @return array |
346 | 346 | */ |
347 | -function wpinv_get_country_list( $first_empty = false ) { |
|
348 | - return wpinv_maybe_add_empty_option( apply_filters( 'wpinv_countries', wpinv_get_data( 'countries' ) ), $first_empty ); |
|
347 | +function wpinv_get_country_list($first_empty = false) { |
|
348 | + return wpinv_maybe_add_empty_option(apply_filters('wpinv_countries', wpinv_get_data('countries')), $first_empty); |
|
349 | 349 | } |
350 | 350 | |
351 | 351 | /** |
@@ -355,22 +355,22 @@ discard block |
||
355 | 355 | * @param bool $first_empty Whether or not the first item in the list should be empty |
356 | 356 | * @return array |
357 | 357 | */ |
358 | -function wpinv_get_country_states( $country = null, $first_empty = false ) { |
|
358 | +function wpinv_get_country_states($country = null, $first_empty = false) { |
|
359 | 359 | |
360 | 360 | // Prepare the country. |
361 | - $country = wpinv_sanitize_country( $country ); |
|
361 | + $country = wpinv_sanitize_country($country); |
|
362 | 362 | |
363 | 363 | // Fetch all states. |
364 | - $all_states = wpinv_get_data( 'states' ); |
|
364 | + $all_states = wpinv_get_data('states'); |
|
365 | 365 | |
366 | 366 | // Fetch the specified country's states. |
367 | - $states = isset( $all_states[ $country ] ) ? $all_states[ $country ] : array() ; |
|
368 | - $states = apply_filters( "wpinv_{$country}_states", $states ); |
|
369 | - $states = apply_filters( 'wpinv_country_states', $states, $country ); |
|
367 | + $states = isset($all_states[$country]) ? $all_states[$country] : array(); |
|
368 | + $states = apply_filters("wpinv_{$country}_states", $states); |
|
369 | + $states = apply_filters('wpinv_country_states', $states, $country); |
|
370 | 370 | |
371 | - asort( $states ); |
|
371 | + asort($states); |
|
372 | 372 | |
373 | - return wpinv_maybe_add_empty_option( $states, $first_empty ); |
|
373 | + return wpinv_maybe_add_empty_option($states, $first_empty); |
|
374 | 374 | } |
375 | 375 | |
376 | 376 | /** |
@@ -380,7 +380,7 @@ discard block |
||
380 | 380 | * @return array |
381 | 381 | */ |
382 | 382 | function wpinv_get_us_states_list() { |
383 | - return apply_filters( 'wpinv_usa_states', wpinv_get_country_states( 'US' ) ); |
|
383 | + return apply_filters('wpinv_usa_states', wpinv_get_country_states('US')); |
|
384 | 384 | } |
385 | 385 | |
386 | 386 | /** |
@@ -390,7 +390,7 @@ discard block |
||
390 | 390 | * @return array |
391 | 391 | */ |
392 | 392 | function wpinv_get_canada_states_list() { |
393 | - return apply_filters( 'wpinv_canada_provinces', wpinv_get_country_states( 'CA' ) ); |
|
393 | + return apply_filters('wpinv_canada_provinces', wpinv_get_country_states('CA')); |
|
394 | 394 | } |
395 | 395 | |
396 | 396 | /** |
@@ -400,7 +400,7 @@ discard block |
||
400 | 400 | * @return array |
401 | 401 | */ |
402 | 402 | function wpinv_get_australia_states_list() { |
403 | - return apply_filters( 'wpinv_australia_states', wpinv_get_country_states( 'AU' ) ); |
|
403 | + return apply_filters('wpinv_australia_states', wpinv_get_country_states('AU')); |
|
404 | 404 | } |
405 | 405 | |
406 | 406 | /** |
@@ -410,7 +410,7 @@ discard block |
||
410 | 410 | * @return array |
411 | 411 | */ |
412 | 412 | function wpinv_get_bangladesh_states_list() { |
413 | - return apply_filters( 'wpinv_bangladesh_states', wpinv_get_country_states( 'BD' ) ); |
|
413 | + return apply_filters('wpinv_bangladesh_states', wpinv_get_country_states('BD')); |
|
414 | 414 | } |
415 | 415 | |
416 | 416 | /** |
@@ -420,7 +420,7 @@ discard block |
||
420 | 420 | * @return array |
421 | 421 | */ |
422 | 422 | function wpinv_get_brazil_states_list() { |
423 | - return apply_filters( 'wpinv_brazil_states', wpinv_get_country_states( 'BR' ) ); |
|
423 | + return apply_filters('wpinv_brazil_states', wpinv_get_country_states('BR')); |
|
424 | 424 | } |
425 | 425 | |
426 | 426 | /** |
@@ -430,7 +430,7 @@ discard block |
||
430 | 430 | * @return array |
431 | 431 | */ |
432 | 432 | function wpinv_get_bulgaria_states_list() { |
433 | - return apply_filters( 'wpinv_bulgaria_states', wpinv_get_country_states( 'BG' ) ); |
|
433 | + return apply_filters('wpinv_bulgaria_states', wpinv_get_country_states('BG')); |
|
434 | 434 | } |
435 | 435 | |
436 | 436 | /** |
@@ -440,7 +440,7 @@ discard block |
||
440 | 440 | * @return array |
441 | 441 | */ |
442 | 442 | function wpinv_get_hong_kong_states_list() { |
443 | - return apply_filters( 'wpinv_hong_kong_states', wpinv_get_country_states( 'HK' ) ); |
|
443 | + return apply_filters('wpinv_hong_kong_states', wpinv_get_country_states('HK')); |
|
444 | 444 | } |
445 | 445 | |
446 | 446 | /** |
@@ -450,7 +450,7 @@ discard block |
||
450 | 450 | * @return array |
451 | 451 | */ |
452 | 452 | function wpinv_get_hungary_states_list() { |
453 | - return apply_filters( 'wpinv_hungary_states', wpinv_get_country_states( 'HU' ) ); |
|
453 | + return apply_filters('wpinv_hungary_states', wpinv_get_country_states('HU')); |
|
454 | 454 | } |
455 | 455 | |
456 | 456 | /** |
@@ -460,7 +460,7 @@ discard block |
||
460 | 460 | * @return array |
461 | 461 | */ |
462 | 462 | function wpinv_get_japan_states_list() { |
463 | - return apply_filters( 'wpinv_japan_states', wpinv_get_country_states( 'JP' ) ); |
|
463 | + return apply_filters('wpinv_japan_states', wpinv_get_country_states('JP')); |
|
464 | 464 | } |
465 | 465 | |
466 | 466 | /** |
@@ -470,7 +470,7 @@ discard block |
||
470 | 470 | * @return array |
471 | 471 | */ |
472 | 472 | function wpinv_get_china_states_list() { |
473 | - return apply_filters( 'wpinv_china_states', wpinv_get_country_states( 'CN' ) ); |
|
473 | + return apply_filters('wpinv_china_states', wpinv_get_country_states('CN')); |
|
474 | 474 | } |
475 | 475 | |
476 | 476 | /** |
@@ -480,7 +480,7 @@ discard block |
||
480 | 480 | * @return array |
481 | 481 | */ |
482 | 482 | function wpinv_get_new_zealand_states_list() { |
483 | - return apply_filters( 'wpinv_new_zealand_states', wpinv_get_country_states( 'NZ' ) ); |
|
483 | + return apply_filters('wpinv_new_zealand_states', wpinv_get_country_states('NZ')); |
|
484 | 484 | } |
485 | 485 | |
486 | 486 | /** |
@@ -490,7 +490,7 @@ discard block |
||
490 | 490 | * @return array |
491 | 491 | */ |
492 | 492 | function wpinv_get_peru_states_list() { |
493 | - return apply_filters( 'wpinv_peru_states', wpinv_get_country_states( 'PE' ) ); |
|
493 | + return apply_filters('wpinv_peru_states', wpinv_get_country_states('PE')); |
|
494 | 494 | } |
495 | 495 | |
496 | 496 | /** |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | * @return array |
501 | 501 | */ |
502 | 502 | function wpinv_get_indonesia_states_list() { |
503 | - return apply_filters( 'wpinv_indonesia_states', wpinv_get_country_states( 'ID' ) ); |
|
503 | + return apply_filters('wpinv_indonesia_states', wpinv_get_country_states('ID')); |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | /** |
@@ -510,7 +510,7 @@ discard block |
||
510 | 510 | * @return array |
511 | 511 | */ |
512 | 512 | function wpinv_get_india_states_list() { |
513 | - return apply_filters( 'wpinv_india_states', wpinv_get_country_states( 'IN' ) ); |
|
513 | + return apply_filters('wpinv_india_states', wpinv_get_country_states('IN')); |
|
514 | 514 | } |
515 | 515 | |
516 | 516 | /** |
@@ -520,7 +520,7 @@ discard block |
||
520 | 520 | * @return array |
521 | 521 | */ |
522 | 522 | function wpinv_get_iran_states_list() { |
523 | - return apply_filters( 'wpinv_iran_states', wpinv_get_country_states( 'IR' ) ); |
|
523 | + return apply_filters('wpinv_iran_states', wpinv_get_country_states('IR')); |
|
524 | 524 | } |
525 | 525 | |
526 | 526 | /** |
@@ -530,7 +530,7 @@ discard block |
||
530 | 530 | * @return array |
531 | 531 | */ |
532 | 532 | function wpinv_get_italy_states_list() { |
533 | - return apply_filters( 'wpinv_italy_states', wpinv_get_country_states( 'IT' ) ); |
|
533 | + return apply_filters('wpinv_italy_states', wpinv_get_country_states('IT')); |
|
534 | 534 | } |
535 | 535 | |
536 | 536 | /** |
@@ -540,7 +540,7 @@ discard block |
||
540 | 540 | * @return array |
541 | 541 | */ |
542 | 542 | function wpinv_get_malaysia_states_list() { |
543 | - return apply_filters( 'wpinv_malaysia_states', wpinv_get_country_states( 'MY' ) ); |
|
543 | + return apply_filters('wpinv_malaysia_states', wpinv_get_country_states('MY')); |
|
544 | 544 | } |
545 | 545 | |
546 | 546 | /** |
@@ -550,7 +550,7 @@ discard block |
||
550 | 550 | * @return array |
551 | 551 | */ |
552 | 552 | function wpinv_get_mexico_states_list() { |
553 | - return apply_filters( 'wpinv_mexico_states', wpinv_get_country_states( 'MX' ) ); |
|
553 | + return apply_filters('wpinv_mexico_states', wpinv_get_country_states('MX')); |
|
554 | 554 | } |
555 | 555 | |
556 | 556 | /** |
@@ -560,7 +560,7 @@ discard block |
||
560 | 560 | * @return array |
561 | 561 | */ |
562 | 562 | function wpinv_get_nepal_states_list() { |
563 | - return apply_filters( 'wpinv_nepal_states', wpinv_get_country_states( 'NP' ) ); |
|
563 | + return apply_filters('wpinv_nepal_states', wpinv_get_country_states('NP')); |
|
564 | 564 | } |
565 | 565 | |
566 | 566 | /** |
@@ -570,7 +570,7 @@ discard block |
||
570 | 570 | * @return array |
571 | 571 | */ |
572 | 572 | function wpinv_get_south_africa_states_list() { |
573 | - return apply_filters( 'wpinv_south_africa_states', wpinv_get_country_states( 'ZA' ) ); |
|
573 | + return apply_filters('wpinv_south_africa_states', wpinv_get_country_states('ZA')); |
|
574 | 574 | } |
575 | 575 | |
576 | 576 | /** |
@@ -580,7 +580,7 @@ discard block |
||
580 | 580 | * @return array |
581 | 581 | */ |
582 | 582 | function wpinv_get_thailand_states_list() { |
583 | - return apply_filters( 'wpinv_thailand_states', wpinv_get_country_states( 'TH' ) ); |
|
583 | + return apply_filters('wpinv_thailand_states', wpinv_get_country_states('TH')); |
|
584 | 584 | } |
585 | 585 | |
586 | 586 | /** |
@@ -590,7 +590,7 @@ discard block |
||
590 | 590 | * @return array |
591 | 591 | */ |
592 | 592 | function wpinv_get_turkey_states_list() { |
593 | - return apply_filters( 'wpinv_turkey_states', wpinv_get_country_states( 'TR' ) ); |
|
593 | + return apply_filters('wpinv_turkey_states', wpinv_get_country_states('TR')); |
|
594 | 594 | } |
595 | 595 | |
596 | 596 | /** |
@@ -600,31 +600,31 @@ discard block |
||
600 | 600 | * @return array |
601 | 601 | */ |
602 | 602 | function wpinv_get_spain_states_list() { |
603 | - return apply_filters( 'wpinv_spain_states', wpinv_get_country_states( 'ES' ) ); |
|
603 | + return apply_filters('wpinv_spain_states', wpinv_get_country_states('ES')); |
|
604 | 604 | } |
605 | 605 | |
606 | 606 | function wpinv_get_states_field() { |
607 | - if( empty( $_POST['country'] ) ) { |
|
607 | + if (empty($_POST['country'])) { |
|
608 | 608 | $_POST['country'] = wpinv_get_default_country(); |
609 | 609 | } |
610 | - $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) ); |
|
610 | + $states = wpinv_get_country_states(sanitize_text_field($_POST['country'])); |
|
611 | 611 | |
612 | - if( !empty( $states ) ) { |
|
613 | - $sanitized_field_name = sanitize_text_field( $_POST['field_name'] ); |
|
612 | + if (!empty($states)) { |
|
613 | + $sanitized_field_name = sanitize_text_field($_POST['field_name']); |
|
614 | 614 | |
615 | - $class = isset( $_POST['class'] ) ? esc_attr( $_POST['class'] ) : ''; |
|
615 | + $class = isset($_POST['class']) ? esc_attr($_POST['class']) : ''; |
|
616 | 616 | $class .= " $sanitized_field_name getpaid_js_field-state custom-select wpinv-select wpi_select2"; |
617 | 617 | |
618 | - $args = array( |
|
618 | + $args = array( |
|
619 | 619 | 'name' => $sanitized_field_name, |
620 | 620 | 'id' => $sanitized_field_name, |
621 | - 'class' => implode( ' ', array_unique( explode( ' ', $class ) ) ), |
|
622 | - 'options' => array_merge( array( '' => '' ), $states ), |
|
621 | + 'class' => implode(' ', array_unique(explode(' ', $class))), |
|
622 | + 'options' => array_merge(array('' => ''), $states), |
|
623 | 623 | 'show_option_all' => false, |
624 | 624 | 'show_option_none' => false |
625 | 625 | ); |
626 | 626 | |
627 | - $response = wpinv_html_select( $args ); |
|
627 | + $response = wpinv_html_select($args); |
|
628 | 628 | |
629 | 629 | } else { |
630 | 630 | $response = 'nostates'; |
@@ -633,10 +633,10 @@ discard block |
||
633 | 633 | return $response; |
634 | 634 | } |
635 | 635 | |
636 | -function wpinv_default_billing_country( $country = '', $user_id = 0 ) { |
|
637 | - $country = !empty( $country ) ? $country : wpinv_get_default_country(); |
|
636 | +function wpinv_default_billing_country($country = '', $user_id = 0) { |
|
637 | + $country = !empty($country) ? $country : wpinv_get_default_country(); |
|
638 | 638 | |
639 | - return apply_filters( 'wpinv_default_billing_country', $country, $user_id ); |
|
639 | + return apply_filters('wpinv_default_billing_country', $country, $user_id); |
|
640 | 640 | } |
641 | 641 | |
642 | 642 | /** |
@@ -648,7 +648,7 @@ discard block |
||
648 | 648 | */ |
649 | 649 | function wpinv_get_address_formats() { |
650 | 650 | |
651 | - return apply_filters( 'wpinv_localisation_address_formats', |
|
651 | + return apply_filters('wpinv_localisation_address_formats', |
|
652 | 652 | array( |
653 | 653 | 'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}", |
654 | 654 | 'AU' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}", |
@@ -697,9 +697,9 @@ discard block |
||
697 | 697 | * @see `wpinv_get_invoice_address_replacements` |
698 | 698 | * @return string |
699 | 699 | */ |
700 | -function wpinv_get_full_address_format( $country = false) { |
|
700 | +function wpinv_get_full_address_format($country = false) { |
|
701 | 701 | |
702 | - if( empty( $country ) ) { |
|
702 | + if (empty($country)) { |
|
703 | 703 | $country = wpinv_get_default_country(); |
704 | 704 | } |
705 | 705 | |
@@ -707,7 +707,7 @@ discard block |
||
707 | 707 | $formats = wpinv_get_address_formats(); |
708 | 708 | |
709 | 709 | // Get format for the specified country. |
710 | - $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default']; |
|
710 | + $format = ($country && isset($formats[$country])) ? $formats[$country] : $formats['default']; |
|
711 | 711 | |
712 | 712 | /** |
713 | 713 | * Filters the address format to use on Invoices. |
@@ -719,7 +719,7 @@ discard block |
||
719 | 719 | * @param string $format The address format to use. |
720 | 720 | * @param string $country The country who's address format is being retrieved. |
721 | 721 | */ |
722 | - return apply_filters( 'wpinv_get_full_address_format', $format, $country ); |
|
722 | + return apply_filters('wpinv_get_full_address_format', $format, $country); |
|
723 | 723 | } |
724 | 724 | |
725 | 725 | /** |
@@ -730,7 +730,7 @@ discard block |
||
730 | 730 | * @param array $billing_details customer's billing details |
731 | 731 | * @return array |
732 | 732 | */ |
733 | -function wpinv_get_invoice_address_replacements( $billing_details ) { |
|
733 | +function wpinv_get_invoice_address_replacements($billing_details) { |
|
734 | 734 | |
735 | 735 | $default_args = array( |
736 | 736 | 'address' => '', |
@@ -743,22 +743,22 @@ discard block |
||
743 | 743 | 'company' => '', |
744 | 744 | ); |
745 | 745 | |
746 | - $args = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' ); |
|
746 | + $args = map_deep(wp_parse_args($billing_details, $default_args), 'trim'); |
|
747 | 747 | $state = $args['state']; |
748 | 748 | $country = $args['country']; |
749 | 749 | |
750 | 750 | // Handle full country name. |
751 | - $full_country = empty( $country ) ? $country : wpinv_country_name( $country ); |
|
751 | + $full_country = empty($country) ? $country : wpinv_country_name($country); |
|
752 | 752 | |
753 | 753 | // Handle full state name. |
754 | - $full_state = ( $country && $state ) ? wpinv_state_name( $state, $country ) : $state; |
|
754 | + $full_state = ($country && $state) ? wpinv_state_name($state, $country) : $state; |
|
755 | 755 | |
756 | 756 | $args['postcode'] = $args['zip']; |
757 | 757 | $args['name'] = $args['first_name'] . ' ' . $args['last_name']; |
758 | 758 | $args['state'] = $full_state; |
759 | 759 | $args['state_code'] = $state; |
760 | 760 | $args['country'] = $full_country; |
761 | - $args['country_code']= $country; |
|
761 | + $args['country_code'] = $country; |
|
762 | 762 | |
763 | 763 | /** |
764 | 764 | * Filters the address format replacements to use on Invoices. |
@@ -769,14 +769,14 @@ discard block |
||
769 | 769 | * @param array $replacements The address replacements to use. |
770 | 770 | * @param array $billing_details The billing details to use. |
771 | 771 | */ |
772 | - $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details ); |
|
772 | + $replacements = apply_filters('wpinv_get_invoice_address_replacements', $args, $billing_details); |
|
773 | 773 | |
774 | 774 | $return = array(); |
775 | 775 | |
776 | - foreach( $replacements as $key => $value ) { |
|
777 | - $value = is_scalar( $value ) ? trim( sanitize_text_field( $value ) ) : ''; |
|
776 | + foreach ($replacements as $key => $value) { |
|
777 | + $value = is_scalar($value) ? trim(sanitize_text_field($value)) : ''; |
|
778 | 778 | $return['{{' . $key . '}}'] = $value; |
779 | - $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper( $value ); |
|
779 | + $return['{{' . $key . '_upper}}'] = wpinv_utf8_strtoupper($value); |
|
780 | 780 | } |
781 | 781 | |
782 | 782 | return $return; |
@@ -790,6 +790,6 @@ discard block |
||
790 | 790 | * @since 1.0.14 |
791 | 791 | * @return string |
792 | 792 | */ |
793 | -function wpinv_trim_formatted_address_line( $line ) { |
|
794 | - return trim( $line, ', ' ); |
|
793 | +function wpinv_trim_formatted_address_line($line) { |
|
794 | + return trim($line, ', '); |
|
795 | 795 | } |
796 | 796 | \ No newline at end of file |
@@ -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 | * Paypal Payment Gateway IPN handler class. |
@@ -31,7 +31,7 @@ discard block |
||
31 | 31 | * |
32 | 32 | * @param GetPaid_Paypal_Gateway $gateway |
33 | 33 | */ |
34 | - public function __construct( $gateway ) { |
|
34 | + public function __construct($gateway) { |
|
35 | 35 | $this->gateway = $gateway; |
36 | 36 | $this->verify_ipn(); |
37 | 37 | } |
@@ -43,37 +43,37 @@ discard block |
||
43 | 43 | */ |
44 | 44 | public function verify_ipn() { |
45 | 45 | |
46 | - wpinv_error_log( 'GetPaid PayPal IPN Handler', false ); |
|
46 | + wpinv_error_log('GetPaid PayPal IPN Handler', false); |
|
47 | 47 | |
48 | 48 | // Validate the IPN. |
49 | - if ( empty( $_POST ) || ! $this->validate_ipn() ) { |
|
50 | - wp_die( 'PayPal IPN Request Failure', 500 ); |
|
49 | + if (empty($_POST) || !$this->validate_ipn()) { |
|
50 | + wp_die('PayPal IPN Request Failure', 500); |
|
51 | 51 | } |
52 | 52 | |
53 | 53 | // Process the IPN. |
54 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
55 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
54 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
55 | + $invoice = $this->get_ipn_invoice($posted); |
|
56 | 56 | |
57 | 57 | // Abort if it was not paid by our gateway. |
58 | - if ( $this->id != $invoice->get_gateway() ) { |
|
59 | - wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false ); |
|
60 | - wp_die( 'Invoice not paid via PayPal', 200 ); |
|
58 | + if ($this->id != $invoice->get_gateway()) { |
|
59 | + wpinv_error_log('Aborting, Invoice was not paid via PayPal', false); |
|
60 | + wp_die('Invoice not paid via PayPal', 200); |
|
61 | 61 | } |
62 | 62 | |
63 | - $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : ''; |
|
64 | - $posted['txn_type'] = sanitize_key( strtolower( $posted['txn_type'] ) ); |
|
63 | + $posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : ''; |
|
64 | + $posted['txn_type'] = sanitize_key(strtolower($posted['txn_type'])); |
|
65 | 65 | |
66 | - wpinv_error_log( 'Payment status:' . $posted['payment_status'], false ); |
|
67 | - wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false ); |
|
66 | + wpinv_error_log('Payment status:' . $posted['payment_status'], false); |
|
67 | + wpinv_error_log('IPN Type:' . $posted['txn_type'], false); |
|
68 | 68 | |
69 | - if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) { |
|
70 | - call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted ); |
|
71 | - wpinv_error_log( 'Done processing IPN', false ); |
|
72 | - wp_die( 'Processed', 200 ); |
|
69 | + if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) { |
|
70 | + call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted); |
|
71 | + wpinv_error_log('Done processing IPN', false); |
|
72 | + wp_die('Processed', 200); |
|
73 | 73 | } |
74 | 74 | |
75 | - wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false ); |
|
76 | - wp_die( 'Unsupported IPN type', 200 ); |
|
75 | + wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false); |
|
76 | + wp_die('Unsupported IPN type', 200); |
|
77 | 77 | |
78 | 78 | } |
79 | 79 | |
@@ -83,22 +83,22 @@ discard block |
||
83 | 83 | * @param array $posted |
84 | 84 | * @return WPInv_Invoice |
85 | 85 | */ |
86 | - protected function get_ipn_invoice( $posted ) { |
|
86 | + protected function get_ipn_invoice($posted) { |
|
87 | 87 | |
88 | - wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false ); |
|
88 | + wpinv_error_log('Retrieving PayPal IPN Response Invoice', false); |
|
89 | 89 | |
90 | - if ( ! empty( $posted['custom'] ) ) { |
|
91 | - $invoice = new WPInv_Invoice( $posted['custom'] ); |
|
90 | + if (!empty($posted['custom'])) { |
|
91 | + $invoice = new WPInv_Invoice($posted['custom']); |
|
92 | 92 | |
93 | - if ( $invoice->exists() ) { |
|
94 | - wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false ); |
|
93 | + if ($invoice->exists()) { |
|
94 | + wpinv_error_log('Found invoice #' . $invoice->get_number(), false); |
|
95 | 95 | return $invoice; |
96 | 96 | } |
97 | 97 | |
98 | 98 | } |
99 | 99 | |
100 | - wpinv_error_log( 'Could not retrieve the associated invoice.', false ); |
|
101 | - wp_die( 'Could not retrieve the associated invoice.', 200 ); |
|
100 | + wpinv_error_log('Could not retrieve the associated invoice.', false); |
|
101 | + wp_die('Could not retrieve the associated invoice.', 200); |
|
102 | 102 | } |
103 | 103 | |
104 | 104 | /** |
@@ -106,14 +106,14 @@ discard block |
||
106 | 106 | */ |
107 | 107 | protected function validate_ipn() { |
108 | 108 | |
109 | - wpinv_error_log( 'Validating PayPal IPN response', false ); |
|
109 | + wpinv_error_log('Validating PayPal IPN response', false); |
|
110 | 110 | |
111 | 111 | // Retrieve the associated invoice. |
112 | - $posted = wp_kses_post_deep( wp_unslash( $_POST ) ); |
|
113 | - $invoice = $this->get_ipn_invoice( $posted ); |
|
112 | + $posted = wp_kses_post_deep(wp_unslash($_POST)); |
|
113 | + $invoice = $this->get_ipn_invoice($posted); |
|
114 | 114 | |
115 | - if ( $this->gateway->is_sandbox( $invoice ) ) { |
|
116 | - wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false ); |
|
115 | + if ($this->gateway->is_sandbox($invoice)) { |
|
116 | + wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false); |
|
117 | 117 | } |
118 | 118 | |
119 | 119 | // Validate the IPN. |
@@ -130,20 +130,20 @@ discard block |
||
130 | 130 | ); |
131 | 131 | |
132 | 132 | // Post back to get a response. |
133 | - $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params ); |
|
133 | + $response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params); |
|
134 | 134 | |
135 | 135 | // Check to see if the request was valid. |
136 | - if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) { |
|
137 | - wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false ); |
|
136 | + if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) { |
|
137 | + wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false); |
|
138 | 138 | return true; |
139 | 139 | } |
140 | 140 | |
141 | - if ( is_wp_error( $response ) ) { |
|
142 | - wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' ); |
|
141 | + if (is_wp_error($response)) { |
|
142 | + wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN'); |
|
143 | 143 | return false; |
144 | 144 | } |
145 | 145 | |
146 | - wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' ); |
|
146 | + wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN'); |
|
147 | 147 | return false; |
148 | 148 | |
149 | 149 | } |
@@ -154,17 +154,17 @@ discard block |
||
154 | 154 | * @param WPInv_Invoice $invoice Invoice object. |
155 | 155 | * @param string $currency currency to validate. |
156 | 156 | */ |
157 | - protected function validate_ipn_currency( $invoice, $currency ) { |
|
157 | + protected function validate_ipn_currency($invoice, $currency) { |
|
158 | 158 | |
159 | - if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) { |
|
159 | + if (strtolower($invoice->get_currency()) !== strtolower($currency)) { |
|
160 | 160 | |
161 | 161 | /* translators: %s: currency code. */ |
162 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) ); |
|
162 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency)); |
|
163 | 163 | |
164 | - wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
164 | + wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true); |
|
165 | 165 | } |
166 | 166 | |
167 | - wpinv_error_log( $currency, 'Validated IPN Currency', false ); |
|
167 | + wpinv_error_log($currency, 'Validated IPN Currency', false); |
|
168 | 168 | } |
169 | 169 | |
170 | 170 | /** |
@@ -173,16 +173,16 @@ discard block |
||
173 | 173 | * @param WPInv_Invoice $invoice Invoice object. |
174 | 174 | * @param float $amount amount to validate. |
175 | 175 | */ |
176 | - protected function validate_ipn_amount( $invoice, $amount ) { |
|
177 | - if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) { |
|
176 | + protected function validate_ipn_amount($invoice, $amount) { |
|
177 | + if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) { |
|
178 | 178 | |
179 | 179 | /* translators: %s: Amount. */ |
180 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) ); |
|
180 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount)); |
|
181 | 181 | |
182 | - wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true ); |
|
182 | + wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true); |
|
183 | 183 | } |
184 | 184 | |
185 | - wpinv_error_log( $amount, 'Validated IPN Amount', false ); |
|
185 | + wpinv_error_log($amount, 'Validated IPN Amount', false); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | /** |
@@ -191,19 +191,19 @@ discard block |
||
191 | 191 | * @param WPInv_Invoice $invoice Invoice object. |
192 | 192 | * @param string $receiver_email Email to validate. |
193 | 193 | */ |
194 | - protected function validate_ipn_receiver_email( $invoice, $receiver_email ) { |
|
195 | - $paypal_email = wpinv_get_option( 'paypal_email' ); |
|
194 | + protected function validate_ipn_receiver_email($invoice, $receiver_email) { |
|
195 | + $paypal_email = wpinv_get_option('paypal_email'); |
|
196 | 196 | |
197 | - if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) { |
|
198 | - wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" ); |
|
197 | + if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) { |
|
198 | + wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}"); |
|
199 | 199 | |
200 | 200 | /* translators: %s: email address . */ |
201 | - $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) ); |
|
201 | + $invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email)); |
|
202 | 202 | |
203 | - return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true ); |
|
203 | + return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true); |
|
204 | 204 | } |
205 | 205 | |
206 | - wpinv_error_log( 'Validated PayPal Email', false ); |
|
206 | + wpinv_error_log('Validated PayPal Email', false); |
|
207 | 207 | } |
208 | 208 | |
209 | 209 | /** |
@@ -212,70 +212,70 @@ discard block |
||
212 | 212 | * @param WPInv_Invoice $invoice Invoice object. |
213 | 213 | * @param array $posted Posted data. |
214 | 214 | */ |
215 | - protected function ipn_txn_web_accept( $invoice, $posted ) { |
|
215 | + protected function ipn_txn_web_accept($invoice, $posted) { |
|
216 | 216 | |
217 | 217 | // Collect payment details |
218 | - $payment_status = strtolower( $posted['payment_status'] ); |
|
219 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
218 | + $payment_status = strtolower($posted['payment_status']); |
|
219 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
220 | 220 | |
221 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
222 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
221 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
222 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
223 | 223 | |
224 | 224 | // Update the transaction id. |
225 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
226 | - $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) ); |
|
225 | + if (!empty($posted['txn_id'])) { |
|
226 | + $invoice->set_transaction_id(wpinv_clean($posted['txn_id'])); |
|
227 | 227 | $invoice->save(); |
228 | 228 | } |
229 | 229 | |
230 | - $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) ); |
|
230 | + $invoice->add_system_note(__('Processing invoice IPN', 'invoicing')); |
|
231 | 231 | |
232 | 232 | // Process a refund. |
233 | - if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) { |
|
233 | + if ($payment_status == 'refunded' || $payment_status == 'reversed') { |
|
234 | 234 | |
235 | - update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 ); |
|
235 | + update_post_meta($invoice->get_id(), 'refunded_remotely', 1); |
|
236 | 236 | |
237 | - if ( ! $invoice->is_refunded() ) { |
|
238 | - $invoice->update_status( 'wpi-refunded', $posted['reason_code'] ); |
|
237 | + if (!$invoice->is_refunded()) { |
|
238 | + $invoice->update_status('wpi-refunded', $posted['reason_code']); |
|
239 | 239 | } |
240 | 240 | |
241 | - return wpinv_error_log( $posted['reason_code'], false ); |
|
241 | + return wpinv_error_log($posted['reason_code'], false); |
|
242 | 242 | } |
243 | 243 | |
244 | 244 | // Process payments. |
245 | - if ( $payment_status == 'completed' ) { |
|
245 | + if ($payment_status == 'completed') { |
|
246 | 246 | |
247 | - if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) { |
|
248 | - return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false ); |
|
247 | + if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) { |
|
248 | + return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false); |
|
249 | 249 | } |
250 | 250 | |
251 | - $this->validate_ipn_amount( $invoice, $posted['mc_gross'] ); |
|
251 | + $this->validate_ipn_amount($invoice, $posted['mc_gross']); |
|
252 | 252 | |
253 | 253 | $note = ''; |
254 | 254 | |
255 | - if ( ! empty( $posted['mc_fee'] ) ) { |
|
256 | - $note = sprintf( __( 'PayPal Transaction Fee %s.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) ); |
|
255 | + if (!empty($posted['mc_fee'])) { |
|
256 | + $note = sprintf(__('PayPal Transaction Fee %s.', 'invoicing'), sanitize_text_field($posted['mc_fee'])); |
|
257 | 257 | } |
258 | 258 | |
259 | - if ( ! empty( $posted['payer_status'] ) ) { |
|
260 | - $note = ' ' . sprintf( __( 'Buyer status %s.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) ); |
|
259 | + if (!empty($posted['payer_status'])) { |
|
260 | + $note = ' ' . sprintf(__('Buyer status %s.', 'invoicing'), sanitize_text_field($posted['payer_status'])); |
|
261 | 261 | } |
262 | 262 | |
263 | - $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) ); |
|
264 | - return wpinv_error_log( 'Invoice marked as paid.', false ); |
|
263 | + $invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note)); |
|
264 | + return wpinv_error_log('Invoice marked as paid.', false); |
|
265 | 265 | |
266 | 266 | } |
267 | 267 | |
268 | 268 | // Pending payments. |
269 | - if ( $payment_status == 'pending' ) { |
|
269 | + if ($payment_status == 'pending') { |
|
270 | 270 | |
271 | 271 | /* translators: %s: pending reason. */ |
272 | - $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) ); |
|
272 | + $invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason'])); |
|
273 | 273 | |
274 | - return wpinv_error_log( 'Invoice marked as "payment held".', false ); |
|
274 | + return wpinv_error_log('Invoice marked as "payment held".', false); |
|
275 | 275 | } |
276 | 276 | |
277 | 277 | /* translators: %s: payment status. */ |
278 | - $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) ); |
|
278 | + $invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status']))); |
|
279 | 279 | |
280 | 280 | } |
281 | 281 | |
@@ -285,8 +285,8 @@ discard block |
||
285 | 285 | * @param WPInv_Invoice $invoice Invoice object. |
286 | 286 | * @param array $posted Posted data. |
287 | 287 | */ |
288 | - protected function ipn_txn_cart( $invoice, $posted ) { |
|
289 | - $this->ipn_txn_web_accept( $invoice, $posted ); |
|
288 | + protected function ipn_txn_cart($invoice, $posted) { |
|
289 | + $this->ipn_txn_web_accept($invoice, $posted); |
|
290 | 290 | } |
291 | 291 | |
292 | 292 | /** |
@@ -295,43 +295,43 @@ discard block |
||
295 | 295 | * @param WPInv_Invoice $invoice Invoice object. |
296 | 296 | * @param array $posted Posted data. |
297 | 297 | */ |
298 | - protected function ipn_txn_subscr_signup( $invoice, $posted ) { |
|
298 | + protected function ipn_txn_subscr_signup($invoice, $posted) { |
|
299 | 299 | |
300 | - wpinv_error_log( 'Processing subscription signup', false ); |
|
300 | + wpinv_error_log('Processing subscription signup', false); |
|
301 | 301 | |
302 | 302 | // Make sure the invoice has a subscription. |
303 | - $subscription = getpaid_get_invoice_subscription( $invoice ); |
|
303 | + $subscription = getpaid_get_invoice_subscription($invoice); |
|
304 | 304 | |
305 | - if ( empty( $subscription ) ) { |
|
306 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
305 | + if (empty($subscription)) { |
|
306 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
307 | 307 | } |
308 | 308 | |
309 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
309 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
310 | 310 | |
311 | 311 | // Validate the IPN. |
312 | - $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] ); |
|
313 | - $this->validate_ipn_receiver_email( $invoice, $business_email ); |
|
314 | - $this->validate_ipn_currency( $invoice, $posted['mc_currency'] ); |
|
312 | + $business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']); |
|
313 | + $this->validate_ipn_receiver_email($invoice, $business_email); |
|
314 | + $this->validate_ipn_currency($invoice, $posted['mc_currency']); |
|
315 | 315 | |
316 | 316 | // Activate the subscription. |
317 | - $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() ); |
|
318 | - $subscription->set_date_created( current_time( 'mysql' ) ); |
|
319 | - $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) ); |
|
320 | - $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) ); |
|
317 | + $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created()); |
|
318 | + $subscription->set_date_created(current_time('mysql')); |
|
319 | + $subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration))); |
|
320 | + $subscription->set_profile_id(sanitize_text_field($posted['subscr_id'])); |
|
321 | 321 | $subscription->activate(); |
322 | 322 | |
323 | 323 | // Set the transaction id. |
324 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
325 | - $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
326 | - $invoice->set_transaction_id( $posted['txn_id'] ); |
|
324 | + if (!empty($posted['txn_id'])) { |
|
325 | + $invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
326 | + $invoice->set_transaction_id($posted['txn_id']); |
|
327 | 327 | } |
328 | 328 | |
329 | 329 | // Update the payment status. |
330 | 330 | $invoice->mark_paid(); |
331 | 331 | |
332 | - $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
332 | + $invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
333 | 333 | |
334 | - wpinv_error_log( 'Subscription started.', false ); |
|
334 | + wpinv_error_log('Subscription started.', false); |
|
335 | 335 | } |
336 | 336 | |
337 | 337 | /** |
@@ -340,45 +340,45 @@ discard block |
||
340 | 340 | * @param WPInv_Invoice $invoice Invoice object. |
341 | 341 | * @param array $posted Posted data. |
342 | 342 | */ |
343 | - protected function ipn_txn_subscr_payment( $invoice, $posted ) { |
|
343 | + protected function ipn_txn_subscr_payment($invoice, $posted) { |
|
344 | 344 | |
345 | 345 | // Make sure the invoice has a subscription. |
346 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
346 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
347 | 347 | |
348 | - if ( empty( $subscription ) ) { |
|
349 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
348 | + if (empty($subscription)) { |
|
349 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
350 | 350 | } |
351 | 351 | |
352 | - wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false ); |
|
352 | + wpinv_error_log('Found subscription #' . $subscription->get_id(), false); |
|
353 | 353 | |
354 | 354 | // PayPal sends a subscr_payment for the first payment too. |
355 | - $date_completed = getpaid_format_date( $invoice->get_date_completed() ); |
|
356 | - $date_created = getpaid_format_date( $invoice->get_date_created() ); |
|
357 | - $today_date = getpaid_format_date( current_time( 'mysql' ) ); |
|
358 | - $payment_date = getpaid_format_date( $posted['payment_date'] ); |
|
359 | - $subscribe_date = getpaid_format_date( $subscription->get_date_created() ); |
|
360 | - $dates = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) ); |
|
355 | + $date_completed = getpaid_format_date($invoice->get_date_completed()); |
|
356 | + $date_created = getpaid_format_date($invoice->get_date_created()); |
|
357 | + $today_date = getpaid_format_date(current_time('mysql')); |
|
358 | + $payment_date = getpaid_format_date($posted['payment_date']); |
|
359 | + $subscribe_date = getpaid_format_date($subscription->get_date_created()); |
|
360 | + $dates = array_filter(compact('date_completed', 'date_created', 'subscribe_date')); |
|
361 | 361 | |
362 | - foreach( $dates as $date ) { |
|
362 | + foreach ($dates as $date) { |
|
363 | 363 | |
364 | - if ( $date !== $today_date && $date !== $payment_date ) { |
|
364 | + if ($date !== $today_date && $date !== $payment_date) { |
|
365 | 365 | continue; |
366 | 366 | } |
367 | 367 | |
368 | - if ( ! empty( $posted['txn_id'] ) ) { |
|
369 | - $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) ); |
|
370 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true ); |
|
368 | + if (!empty($posted['txn_id'])) { |
|
369 | + $invoice->set_transaction_id(sanitize_text_field($posted['txn_id'])); |
|
370 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true); |
|
371 | 371 | } |
372 | 372 | |
373 | 373 | return $invoice->mark_paid(); |
374 | 374 | |
375 | 375 | } |
376 | 376 | |
377 | - wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false ); |
|
377 | + wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false); |
|
378 | 378 | |
379 | 379 | // Abort if the payment is already recorded. |
380 | - if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) { |
|
381 | - return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false ); |
|
380 | + if (wpinv_get_id_by_transaction_id($posted['txn_id'])) { |
|
381 | + return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false); |
|
382 | 382 | } |
383 | 383 | |
384 | 384 | $args = array( |
@@ -386,17 +386,17 @@ discard block |
||
386 | 386 | 'gateway' => $this->id, |
387 | 387 | ); |
388 | 388 | |
389 | - $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) ); |
|
389 | + $invoice = wpinv_get_invoice($subscription->add_payment($args)); |
|
390 | 390 | |
391 | - if ( empty( $invoice ) ) { |
|
391 | + if (empty($invoice)) { |
|
392 | 392 | return; |
393 | 393 | } |
394 | 394 | |
395 | - $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true ); |
|
396 | - $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true ); |
|
395 | + $invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true); |
|
396 | + $invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true); |
|
397 | 397 | |
398 | 398 | $subscription->renew(); |
399 | - wpinv_error_log( 'Subscription renewed.', false ); |
|
399 | + wpinv_error_log('Subscription renewed.', false); |
|
400 | 400 | |
401 | 401 | } |
402 | 402 | |
@@ -405,18 +405,18 @@ discard block |
||
405 | 405 | * |
406 | 406 | * @param WPInv_Invoice $invoice Invoice object. |
407 | 407 | */ |
408 | - protected function ipn_txn_subscr_cancel( $invoice ) { |
|
408 | + protected function ipn_txn_subscr_cancel($invoice) { |
|
409 | 409 | |
410 | 410 | // Make sure the invoice has a subscription. |
411 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
411 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
412 | 412 | |
413 | - if ( empty( $subscription ) ) { |
|
414 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
413 | + if (empty($subscription)) { |
|
414 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
415 | 415 | } |
416 | 416 | |
417 | - wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false ); |
|
417 | + wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false); |
|
418 | 418 | $subscription->cancel(); |
419 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
419 | + wpinv_error_log('Subscription cancelled.', false); |
|
420 | 420 | |
421 | 421 | } |
422 | 422 | |
@@ -426,18 +426,18 @@ discard block |
||
426 | 426 | * @param WPInv_Invoice $invoice Invoice object. |
427 | 427 | * @param array $posted Posted data. |
428 | 428 | */ |
429 | - protected function ipn_txn_subscr_eot( $invoice ) { |
|
429 | + protected function ipn_txn_subscr_eot($invoice) { |
|
430 | 430 | |
431 | 431 | // Make sure the invoice has a subscription. |
432 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
432 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
433 | 433 | |
434 | - if ( empty( $subscription ) ) { |
|
435 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
434 | + if (empty($subscription)) { |
|
435 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
436 | 436 | } |
437 | 437 | |
438 | - wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false ); |
|
438 | + wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false); |
|
439 | 439 | $subscription->complete(); |
440 | - wpinv_error_log( 'Subscription completed.', false ); |
|
440 | + wpinv_error_log('Subscription completed.', false); |
|
441 | 441 | |
442 | 442 | } |
443 | 443 | |
@@ -447,18 +447,18 @@ discard block |
||
447 | 447 | * @param WPInv_Invoice $invoice Invoice object. |
448 | 448 | * @param array $posted Posted data. |
449 | 449 | */ |
450 | - protected function ipn_txn_subscr_failed( $invoice ) { |
|
450 | + protected function ipn_txn_subscr_failed($invoice) { |
|
451 | 451 | |
452 | 452 | // Make sure the invoice has a subscription. |
453 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
453 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
454 | 454 | |
455 | - if ( empty( $subscription ) ) { |
|
456 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
455 | + if (empty($subscription)) { |
|
456 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
457 | 457 | } |
458 | 458 | |
459 | - wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false ); |
|
459 | + wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false); |
|
460 | 460 | $subscription->failing(); |
461 | - wpinv_error_log( 'Subscription marked as failing.', false ); |
|
461 | + wpinv_error_log('Subscription marked as failing.', false); |
|
462 | 462 | |
463 | 463 | } |
464 | 464 | |
@@ -468,18 +468,18 @@ discard block |
||
468 | 468 | * @param WPInv_Invoice $invoice Invoice object. |
469 | 469 | * @param array $posted Posted data. |
470 | 470 | */ |
471 | - protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) { |
|
471 | + protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) { |
|
472 | 472 | |
473 | 473 | // Make sure the invoice has a subscription. |
474 | - $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice ); |
|
474 | + $subscription = getpaid_subscriptions()->get_invoice_subscription($invoice); |
|
475 | 475 | |
476 | - if ( empty( $subscription ) ) { |
|
477 | - return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false ); |
|
476 | + if (empty($subscription)) { |
|
477 | + return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false); |
|
478 | 478 | } |
479 | 479 | |
480 | - wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false ); |
|
480 | + wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false); |
|
481 | 481 | $subscription->cancel(); |
482 | - wpinv_error_log( 'Subscription cancelled.', false ); |
|
482 | + wpinv_error_log('Subscription cancelled.', false); |
|
483 | 483 | } |
484 | 484 | |
485 | 485 | } |
@@ -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 | |
@@ -12,54 +12,54 @@ discard block |
||
12 | 12 | |
13 | 13 | <form method="post" class="text-center card-body"> |
14 | 14 | <div class="gp-wizard-payments"> |
15 | - <h2 class="gd-settings-title h3 "><?php _e( 'Gateway Setup', 'invoicing' ); ?></h2> |
|
16 | - <p><?php _e( 'Below are a few gateways that can be setup in a few seconds.', 'invoicing' ); ?> |
|
15 | + <h2 class="gd-settings-title h3 "><?php _e('Gateway Setup', 'invoicing'); ?></h2> |
|
16 | + <p><?php _e('Below are a few gateways that can be setup in a few seconds.', 'invoicing'); ?> |
|
17 | 17 | <br> |
18 | - <?php _e( 'We have 20+ Gateways that can be setup later.', 'invoicing' ); ?> |
|
18 | + <?php _e('We have 20+ Gateways that can be setup later.', 'invoicing'); ?> |
|
19 | 19 | </p> |
20 | 20 | |
21 | 21 | <ul class="list-group"> |
22 | 22 | |
23 | 23 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
24 | - <span class="mr-auto"><img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg' );?>" class="ml-n2" alt="Stripe"></span> |
|
25 | - <?php if ( false === wpinv_get_option( 'stripe_live_connect_account_id' ) ) : ?> |
|
24 | + <span class="mr-auto"><img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/stripe-verified.svg'); ?>" class="ml-n2" alt="Stripe"></span> |
|
25 | + <?php if (false === wpinv_get_option('stripe_live_connect_account_id')) : ?> |
|
26 | 26 | <a href="<?php echo wp_nonce_url( |
27 | 27 | add_query_arg( |
28 | 28 | array( |
29 | 29 | 'getpaid-admin-action' => 'connect_gateway', |
30 | 30 | 'plugin' => 'stripe', |
31 | - 'redirect' => urlencode( add_query_arg( 'step', 'payments' ) ), |
|
31 | + 'redirect' => urlencode(add_query_arg('step', 'payments')), |
|
32 | 32 | ), |
33 | 33 | admin_url() |
34 | 34 | ), |
35 | 35 | 'getpaid-nonce', |
36 | 36 | 'getpaid-nonce' |
37 | 37 | ); ?>" |
38 | - class="btn btn-sm btn-outline-primary"><?php _e( 'Connect', 'invoicing' ); ?></a> |
|
38 | + class="btn btn-sm btn-outline-primary"><?php _e('Connect', 'invoicing'); ?></a> |
|
39 | 39 | <?php else: ?> |
40 | - <span class="btn btn-sm btn-success"><?php _e( 'Connected', 'invoicing' ); ?></span> |
|
40 | + <span class="btn btn-sm btn-success"><?php _e('Connected', 'invoicing'); ?></span> |
|
41 | 41 | <?php endif; ?> |
42 | 42 | </li> |
43 | 43 | |
44 | 44 | <li class="list-group-item"> |
45 | 45 | <div class="d-flex justify-content-between align-items-center"> |
46 | 46 | <span class="mr-auto"> |
47 | - <img src="<?php echo esc_url( WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp' );?>" class="" alt="PayPal" height="25"> |
|
47 | + <img src="<?php echo esc_url(WPINV_PLUGIN_URL . 'assets/images/pp-logo-150px.webp'); ?>" class="" alt="PayPal" height="25"> |
|
48 | 48 | </span> |
49 | 49 | <a |
50 | 50 | href="#" |
51 | 51 | onclick="jQuery('.getpaid-setup-paypal-input').toggleClass('d-none'); return false;" |
52 | - class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php _e( 'Set-up', 'invoicing' ); ?></a> |
|
52 | + class="getpaid-setup-paypal btn btn-sm btn-outline-primary"><?php _e('Set-up', 'invoicing'); ?></a> |
|
53 | 53 | </div> |
54 | 54 | <div class="mt-4 getpaid-setup-paypal-input d-none"> |
55 | - <input type="text" placeholder="<?php esc_attr_e( 'PayPal Email', 'invoicing' ); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr( wpinv_get_option( 'paypal_email' ) ); ?>"> |
|
55 | + <input type="text" placeholder="<?php esc_attr_e('PayPal Email', 'invoicing'); ?>" name="paypal-email" class="form-control" value="<?php echo esc_attr(wpinv_get_option('paypal_email')); ?>"> |
|
56 | 56 | </div> |
57 | 57 | </li> |
58 | 58 | |
59 | 59 | <li class="list-group-item d-flex justify-content-between align-items-center"> |
60 | - <span class="mr-auto"><?php _e( 'Test Gateway', 'invoicing' ); ?></span> |
|
60 | + <span class="mr-auto"><?php _e('Test Gateway', 'invoicing'); ?></span> |
|
61 | 61 | <div class="custom-control custom-switch"> |
62 | - <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked( wpinv_is_gateway_active( 'manual' ) ); ?>> |
|
62 | + <input type="checkbox" name="enable-manual-gateway" class="custom-control-input" id="enable-manual-gateway" <?php checked(wpinv_is_gateway_active('manual')); ?>> |
|
63 | 63 | <label class="custom-control-label" for="enable-manual-gateway"></label> |
64 | 64 | </div> |
65 | 65 | </li> |
@@ -68,10 +68,10 @@ discard block |
||
68 | 68 | </div> |
69 | 69 | |
70 | 70 | <p class="gp-setup-actions step text-center mt-4"> |
71 | - <input type="submit" class="btn btn-primary" value="<?php esc_attr_e( 'Continue', 'invoicing' ); ?>" /> |
|
71 | + <input type="submit" class="btn btn-primary" value="<?php esc_attr_e('Continue', 'invoicing'); ?>" /> |
|
72 | 72 | </p> |
73 | 73 | |
74 | - <?php getpaid_hidden_field( 'save_step', 1 ); ?> |
|
75 | - <?php wp_nonce_field( 'getpaid-setup-wizard', 'getpaid-setup-wizard' ); ?> |
|
74 | + <?php getpaid_hidden_field('save_step', 1); ?> |
|
75 | + <?php wp_nonce_field('getpaid-setup-wizard', 'getpaid-setup-wizard'); ?> |
|
76 | 76 | </form> |
77 | 77 | </div> |
@@ -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 | * GetPaid_Reports_Export Class. |
@@ -19,8 +19,8 @@ discard block |
||
19 | 19 | public function display() { |
20 | 20 | |
21 | 21 | echo "<div class='row mt-4' style='max-width: 920px;' >"; |
22 | - foreach ( array_keys( getpaid_get_invoice_post_types() ) as $post_type ) { |
|
23 | - $this->display_post_type_export( $post_type ); |
|
22 | + foreach (array_keys(getpaid_get_invoice_post_types()) as $post_type) { |
|
23 | + $this->display_post_type_export($post_type); |
|
24 | 24 | } |
25 | 25 | $this->display_subscription_export(); |
26 | 26 | echo "</div>"; |
@@ -31,13 +31,13 @@ discard block |
||
31 | 31 | * Retrieves the download url. |
32 | 32 | * |
33 | 33 | */ |
34 | - public function get_download_url( $post_type ) { |
|
34 | + public function get_download_url($post_type) { |
|
35 | 35 | |
36 | 36 | return wp_nonce_url( |
37 | 37 | add_query_arg( |
38 | 38 | array( |
39 | 39 | 'getpaid-admin-action' => 'export_invoices', |
40 | - 'post_type' => urlencode( $post_type ), |
|
40 | + 'post_type' => urlencode($post_type), |
|
41 | 41 | ) |
42 | 42 | ), |
43 | 43 | 'getpaid-nonce', |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | * Displays a single post type export card. |
51 | 51 | * |
52 | 52 | */ |
53 | - public function display_post_type_export( $post_type ) { |
|
53 | + public function display_post_type_export($post_type) { |
|
54 | 54 | |
55 | 55 | ?> |
56 | 56 | |
@@ -61,8 +61,8 @@ discard block |
||
61 | 61 | <strong> |
62 | 62 | <?php |
63 | 63 | printf( |
64 | - __( 'Export %s', 'invoicing' ), |
|
65 | - sanitize_text_field( getpaid_get_post_type_label( $post_type ) ) |
|
64 | + __('Export %s', 'invoicing'), |
|
65 | + sanitize_text_field(getpaid_get_post_type_label($post_type)) |
|
66 | 66 | ); |
67 | 67 | ?> |
68 | 68 | </strong> |
@@ -70,14 +70,14 @@ discard block |
||
70 | 70 | |
71 | 71 | <div class="card-body"> |
72 | 72 | |
73 | - <form method="post" action="<?php echo esc_url( $this->get_download_url( $post_type ) ); ?>"> |
|
73 | + <form method="post" action="<?php echo esc_url($this->get_download_url($post_type)); ?>"> |
|
74 | 74 | |
75 | 75 | <?php |
76 | - $this->display_markup( $this->generate_from_date( $post_type ) ); |
|
77 | - $this->display_markup( $this->generate_to_date( $post_type ) ); |
|
78 | - $this->display_markup( $this->generate_post_status_select( $post_type ) ); |
|
79 | - $this->display_markup( $this->generate_file_type_select( $post_type ) ); |
|
80 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
76 | + $this->display_markup($this->generate_from_date($post_type)); |
|
77 | + $this->display_markup($this->generate_to_date($post_type)); |
|
78 | + $this->display_markup($this->generate_post_status_select($post_type)); |
|
79 | + $this->display_markup($this->generate_file_type_select($post_type)); |
|
80 | + submit_button(__('Download', 'invoicing')); |
|
81 | 81 | ?> |
82 | 82 | |
83 | 83 | </form> |
@@ -95,14 +95,14 @@ discard block |
||
95 | 95 | * Generates the from date input field. |
96 | 96 | * |
97 | 97 | */ |
98 | - public function generate_from_date( $post_type ) { |
|
98 | + public function generate_from_date($post_type) { |
|
99 | 99 | |
100 | 100 | return aui()->input( |
101 | 101 | array( |
102 | 102 | 'name' => 'from_date', |
103 | - 'id' => esc_attr( "$post_type-from_date" ), |
|
103 | + 'id' => esc_attr("$post_type-from_date"), |
|
104 | 104 | 'placeholder'=> 'yy-mm-dd', |
105 | - 'label' => __( 'From Date', 'invoicing' ), |
|
105 | + 'label' => __('From Date', 'invoicing'), |
|
106 | 106 | 'label_type' => 'vertical', |
107 | 107 | 'label_class' => 'd-block', |
108 | 108 | 'type' => 'datepicker', |
@@ -115,14 +115,14 @@ discard block |
||
115 | 115 | * Generates the to date input field. |
116 | 116 | * |
117 | 117 | */ |
118 | - public function generate_to_date( $post_type ) { |
|
118 | + public function generate_to_date($post_type) { |
|
119 | 119 | |
120 | 120 | return aui()->input( |
121 | 121 | array( |
122 | 122 | 'name' => 'to_date', |
123 | - 'id' => esc_attr( "$post_type-to_date" ), |
|
123 | + 'id' => esc_attr("$post_type-to_date"), |
|
124 | 124 | 'placeholder'=> 'yy-mm-dd', |
125 | - 'label' => __( 'To Date', 'invoicing' ), |
|
125 | + 'label' => __('To Date', 'invoicing'), |
|
126 | 126 | 'label_type' => 'vertical', |
127 | 127 | 'label_class' => 'd-block', |
128 | 128 | 'type' => 'datepicker', |
@@ -135,20 +135,20 @@ discard block |
||
135 | 135 | * Generates the to post status select field. |
136 | 136 | * |
137 | 137 | */ |
138 | - public function generate_post_status_select( $post_type ) { |
|
138 | + public function generate_post_status_select($post_type) { |
|
139 | 139 | |
140 | - if ( 'subscriptions' === $post_type ) { |
|
140 | + if ('subscriptions' === $post_type) { |
|
141 | 141 | $options = getpaid_get_subscription_statuses(); |
142 | 142 | } else { |
143 | - $options = wpinv_get_invoice_statuses( true, false, $post_type ); |
|
143 | + $options = wpinv_get_invoice_statuses(true, false, $post_type); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | return aui()->select( |
147 | 147 | array( |
148 | 148 | 'name' => 'status', |
149 | - 'id' => esc_attr( "$post_type-status" ), |
|
150 | - 'placeholder' => __( 'All Statuses', 'invoicing' ), |
|
151 | - 'label' => __( 'Status', 'invoicing' ), |
|
149 | + 'id' => esc_attr("$post_type-status"), |
|
150 | + 'placeholder' => __('All Statuses', 'invoicing'), |
|
151 | + 'label' => __('Status', 'invoicing'), |
|
152 | 152 | 'label_type' => 'vertical', |
153 | 153 | 'label_class' => 'd-block', |
154 | 154 | 'options' => $options, |
@@ -161,20 +161,20 @@ discard block |
||
161 | 161 | * Generates the to file type select field. |
162 | 162 | * |
163 | 163 | */ |
164 | - public function generate_file_type_select( $post_type ) { |
|
164 | + public function generate_file_type_select($post_type) { |
|
165 | 165 | |
166 | 166 | return aui()->select( |
167 | 167 | array( |
168 | 168 | 'name' => 'file_type', |
169 | - 'id' => esc_attr( "$post_type-file_type" ), |
|
170 | - 'placeholder' => __( 'Select File Type', 'invoicing' ), |
|
171 | - 'label' => __( 'Export File', 'invoicing' ), |
|
169 | + 'id' => esc_attr("$post_type-file_type"), |
|
170 | + 'placeholder' => __('Select File Type', 'invoicing'), |
|
171 | + 'label' => __('Export File', 'invoicing'), |
|
172 | 172 | 'label_type' => 'vertical', |
173 | 173 | 'label_class' => 'd-block', |
174 | 174 | 'options' => array( |
175 | - 'csv' => __( 'CSV', 'invoicing' ), |
|
176 | - 'xml' => __( 'XML', 'invoicing' ), |
|
177 | - 'json' => __( 'JSON', 'invoicing' ), |
|
175 | + 'csv' => __('CSV', 'invoicing'), |
|
176 | + 'xml' => __('XML', 'invoicing'), |
|
177 | + 'json' => __('JSON', 'invoicing'), |
|
178 | 178 | ), |
179 | 179 | ) |
180 | 180 | ); |
@@ -185,7 +185,7 @@ discard block |
||
185 | 185 | * Displays a field's markup. |
186 | 186 | * |
187 | 187 | */ |
188 | - public function display_markup( $markup ) { |
|
188 | + public function display_markup($markup) { |
|
189 | 189 | |
190 | 190 | echo str_replace( |
191 | 191 | array( |
@@ -211,20 +211,20 @@ discard block |
||
211 | 211 | |
212 | 212 | <div class="card-header"> |
213 | 213 | <strong> |
214 | - <?php _e( 'Export Subscriptions', 'invoicing' ); ?> |
|
214 | + <?php _e('Export Subscriptions', 'invoicing'); ?> |
|
215 | 215 | </strong> |
216 | 216 | </div> |
217 | 217 | |
218 | 218 | <div class="card-body"> |
219 | 219 | |
220 | - <form method="post" action="<?php echo esc_url( $this->get_download_url( 'subscriptions' ) ); ?>"> |
|
220 | + <form method="post" action="<?php echo esc_url($this->get_download_url('subscriptions')); ?>"> |
|
221 | 221 | |
222 | 222 | <?php |
223 | - $this->display_markup( $this->generate_from_date( 'subscriptions' ) ); |
|
224 | - $this->display_markup( $this->generate_to_date( 'subscriptions' ) ); |
|
225 | - $this->display_markup( $this->generate_post_status_select( 'subscriptions' ) ); |
|
226 | - $this->display_markup( $this->generate_file_type_select( 'subscriptions' ) ); |
|
227 | - submit_button( __( 'Download', 'invoicing' ) ); |
|
223 | + $this->display_markup($this->generate_from_date('subscriptions')); |
|
224 | + $this->display_markup($this->generate_to_date('subscriptions')); |
|
225 | + $this->display_markup($this->generate_post_status_select('subscriptions')); |
|
226 | + $this->display_markup($this->generate_file_type_select('subscriptions')); |
|
227 | + submit_button(__('Download', 'invoicing')); |
|
228 | 228 | ?> |
229 | 229 | |
230 | 230 | </form> |
@@ -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 | * GetPaid_Subscription_Exporter Class. |
@@ -18,7 +18,7 @@ discard block |
||
18 | 18 | * @param array $args Args to search for. |
19 | 19 | * @return array |
20 | 20 | */ |
21 | - public function get_subscription_query_args( $args ) { |
|
21 | + public function get_subscription_query_args($args) { |
|
22 | 22 | |
23 | 23 | $query_args = array( |
24 | 24 | 'status' => 'all', |
@@ -27,22 +27,22 @@ discard block |
||
27 | 27 | 'fields' => 'all', |
28 | 28 | ); |
29 | 29 | |
30 | - if ( ! empty( $args['status'] ) && in_array( $args['status'], array_keys( getpaid_get_subscription_statuses() ), true ) ) { |
|
31 | - $query_args['status'] = wpinv_clean( wpinv_parse_list( $args['status'] ) ); |
|
30 | + if (!empty($args['status']) && in_array($args['status'], array_keys(getpaid_get_subscription_statuses()), true)) { |
|
31 | + $query_args['status'] = wpinv_clean(wpinv_parse_list($args['status'])); |
|
32 | 32 | } |
33 | 33 | |
34 | 34 | $date_query = array(); |
35 | - if ( ! empty( $args['to_date'] ) ) { |
|
36 | - $date_query['before'] = wpinv_clean( $args['to_date'] ); |
|
35 | + if (!empty($args['to_date'])) { |
|
36 | + $date_query['before'] = wpinv_clean($args['to_date']); |
|
37 | 37 | } |
38 | 38 | |
39 | - if ( ! empty( $args['from_date'] ) ) { |
|
40 | - $date_query['after'] = wpinv_clean( $args['from_date'] ); |
|
39 | + if (!empty($args['from_date'])) { |
|
40 | + $date_query['after'] = wpinv_clean($args['from_date']); |
|
41 | 41 | } |
42 | 42 | |
43 | - if ( ! empty( $date_query ) ) { |
|
43 | + if (!empty($date_query)) { |
|
44 | 44 | $date_query['inclusive'] = true; |
45 | - $query_args['date_created_query'] = array( $date_query ); |
|
45 | + $query_args['date_created_query'] = array($date_query); |
|
46 | 46 | } |
47 | 47 | |
48 | 48 | return $query_args; |
@@ -54,10 +54,10 @@ discard block |
||
54 | 54 | * @param array $query_args GetPaid_Subscriptions_Query args. |
55 | 55 | * @return WPInv_Subscription[] |
56 | 56 | */ |
57 | - public function get_subscriptions( $query_args ) { |
|
57 | + public function get_subscriptions($query_args) { |
|
58 | 58 | |
59 | 59 | // Get subscriptions. |
60 | - $subscriptions = new GetPaid_Subscriptions_Query( $query_args ); |
|
60 | + $subscriptions = new GetPaid_Subscriptions_Query($query_args); |
|
61 | 61 | |
62 | 62 | // Prepare the results. |
63 | 63 | return $subscriptions->get_results(); |
@@ -68,22 +68,22 @@ discard block |
||
68 | 68 | * Handles the actual download. |
69 | 69 | * |
70 | 70 | */ |
71 | - public function export( $post_type, $args ) { |
|
71 | + public function export($post_type, $args) { |
|
72 | 72 | |
73 | - $subscriptions = $this->get_subscriptions( $this->get_subscription_query_args( $args ) ); |
|
73 | + $subscriptions = $this->get_subscriptions($this->get_subscription_query_args($args)); |
|
74 | 74 | $stream = $this->prepare_output(); |
75 | 75 | $headers = $this->get_export_fields(); |
76 | - $file_type = $this->prepare_file_type( 'subscriptions' ); |
|
76 | + $file_type = $this->prepare_file_type('subscriptions'); |
|
77 | 77 | |
78 | - if ( 'csv' == $file_type ) { |
|
79 | - $this->download_csv( $subscriptions, $stream, $headers ); |
|
80 | - } else if( 'xml' == $file_type ) { |
|
81 | - $this->download_xml( $subscriptions, $stream, $headers ); |
|
78 | + if ('csv' == $file_type) { |
|
79 | + $this->download_csv($subscriptions, $stream, $headers); |
|
80 | + } else if ('xml' == $file_type) { |
|
81 | + $this->download_xml($subscriptions, $stream, $headers); |
|
82 | 82 | } else { |
83 | - $this->download_json( $subscriptions, $stream, $headers ); |
|
83 | + $this->download_json($subscriptions, $stream, $headers); |
|
84 | 84 | } |
85 | 85 | |
86 | - fclose( $stream ); |
|
86 | + fclose($stream); |
|
87 | 87 | exit; |
88 | 88 | } |
89 | 89 | |
@@ -95,32 +95,32 @@ discard block |
||
95 | 95 | * @since 1.0.19 |
96 | 96 | * @return array |
97 | 97 | */ |
98 | - public function prepare_row( $subscription, $fields ) { |
|
98 | + public function prepare_row($subscription, $fields) { |
|
99 | 99 | |
100 | 100 | $prepared = array(); |
101 | 101 | $amount_fields = $this->get_amount_fields(); |
102 | 102 | $invoice = $subscription->get_parent_payment(); |
103 | 103 | |
104 | - foreach ( $fields as $field ) { |
|
104 | + foreach ($fields as $field) { |
|
105 | 105 | |
106 | 106 | $value = ''; |
107 | 107 | $method = "get_$field"; |
108 | 108 | |
109 | - if ( 0 === stripos( $field, 'customer' ) || 'currency' === $field ) { |
|
109 | + if (0 === stripos($field, 'customer') || 'currency' === $field) { |
|
110 | 110 | |
111 | - if ( method_exists( $invoice, $method ) ) { |
|
112 | - $value = $invoice->$method(); |
|
111 | + if (method_exists($invoice, $method)) { |
|
112 | + $value = $invoice->$method(); |
|
113 | 113 | } |
114 | 114 | |
115 | - } else if ( method_exists( $subscription, $method ) ) { |
|
116 | - $value = $subscription->$method(); |
|
115 | + } else if (method_exists($subscription, $method)) { |
|
116 | + $value = $subscription->$method(); |
|
117 | 117 | } |
118 | 118 | |
119 | - if ( in_array( $field, $amount_fields ) ) { |
|
120 | - $value = wpinv_round_amount( wpinv_sanitize_amount( $value ) ); |
|
119 | + if (in_array($field, $amount_fields)) { |
|
120 | + $value = wpinv_round_amount(wpinv_sanitize_amount($value)); |
|
121 | 121 | } |
122 | 122 | |
123 | - $prepared[ $field ] = wpinv_clean( $value ); |
|
123 | + $prepared[$field] = wpinv_clean($value); |
|
124 | 124 | |
125 | 125 | } |
126 | 126 | |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | |
167 | 167 | ); |
168 | 168 | |
169 | - return apply_filters( 'getpaid_subscription_exporter_get_fields', $fields ); |
|
169 | + return apply_filters('getpaid_subscription_exporter_get_fields', $fields); |
|
170 | 170 | } |
171 | 171 | |
172 | 172 | /** |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | 'recurring_amount' |
183 | 183 | ); |
184 | 184 | |
185 | - return apply_filters( 'getpaid_subscription_exporter_get_amount_fields', $fields ); |
|
185 | + return apply_filters('getpaid_subscription_exporter_get_amount_fields', $fields); |
|
186 | 186 | } |
187 | 187 | |
188 | 188 | } |
@@ -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 | * GetPaid_Reports Class. |
@@ -17,11 +17,11 @@ discard block |
||
17 | 17 | * |
18 | 18 | */ |
19 | 19 | public function __construct() { |
20 | - add_action( 'admin_menu', array( $this, 'register_reports_page' ), 20 ); |
|
21 | - add_action( 'wpinv_reports_tab_reports', array( $this, 'display_reports_tab' ) ); |
|
22 | - add_action( 'wpinv_reports_tab_export', array( $this, 'display_exports_tab' ) ); |
|
23 | - add_action( 'getpaid_authenticated_admin_action_download_graph', array( $this, 'download_graph' ) ); |
|
24 | - add_action( 'getpaid_authenticated_admin_action_export_invoices', array( $this, 'export_invoices' ) ); |
|
20 | + add_action('admin_menu', array($this, 'register_reports_page'), 20); |
|
21 | + add_action('wpinv_reports_tab_reports', array($this, 'display_reports_tab')); |
|
22 | + add_action('wpinv_reports_tab_export', array($this, 'display_exports_tab')); |
|
23 | + add_action('getpaid_authenticated_admin_action_download_graph', array($this, 'download_graph')); |
|
24 | + add_action('getpaid_authenticated_admin_action_export_invoices', array($this, 'export_invoices')); |
|
25 | 25 | |
26 | 26 | } |
27 | 27 | |
@@ -33,11 +33,11 @@ discard block |
||
33 | 33 | |
34 | 34 | add_submenu_page( |
35 | 35 | 'wpinv', |
36 | - __( 'Reports', 'invoicing' ), |
|
37 | - __( 'Reports', 'invoicing' ), |
|
36 | + __('Reports', 'invoicing'), |
|
37 | + __('Reports', 'invoicing'), |
|
38 | 38 | wpinv_get_capability(), |
39 | 39 | 'wpinv-reports', |
40 | - array( $this, 'display_reports_page' ) |
|
40 | + array($this, 'display_reports_page') |
|
41 | 41 | ); |
42 | 42 | |
43 | 43 | } |
@@ -50,26 +50,26 @@ discard block |
||
50 | 50 | |
51 | 51 | // Prepare variables. |
52 | 52 | $tabs = $this->get_tabs(); |
53 | - $current_tab = isset( $_GET['tab'] ) ? sanitize_text_field( $_GET['tab'] ) : 'reports'; |
|
54 | - $current_tab = array_key_exists( $current_tab, $tabs ) ? $current_tab : 'reports'; |
|
53 | + $current_tab = isset($_GET['tab']) ? sanitize_text_field($_GET['tab']) : 'reports'; |
|
54 | + $current_tab = array_key_exists($current_tab, $tabs) ? $current_tab : 'reports'; |
|
55 | 55 | |
56 | 56 | // Display the current tab. |
57 | 57 | ?> |
58 | 58 | |
59 | 59 | <div class="wrap"> |
60 | 60 | |
61 | - <h1><?php echo sanitize_text_field( $tabs[ $current_tab ] ); ?></h1> |
|
61 | + <h1><?php echo sanitize_text_field($tabs[$current_tab]); ?></h1> |
|
62 | 62 | |
63 | 63 | <nav class="nav-tab-wrapper"> |
64 | 64 | |
65 | 65 | <?php |
66 | - foreach( $tabs as $key => $label ) { |
|
66 | + foreach ($tabs as $key => $label) { |
|
67 | 67 | |
68 | - $key = sanitize_text_field( $key ); |
|
69 | - $label = sanitize_text_field( $label ); |
|
68 | + $key = sanitize_text_field($key); |
|
69 | + $label = sanitize_text_field($label); |
|
70 | 70 | $class = $key == $current_tab ? 'nav-tab nav-tab-active' : 'nav-tab'; |
71 | 71 | $url = esc_url( |
72 | - add_query_arg( 'tab', $key, admin_url( 'admin.php?page=wpinv-reports' ) ) |
|
72 | + add_query_arg('tab', $key, admin_url('admin.php?page=wpinv-reports')) |
|
73 | 73 | ); |
74 | 74 | |
75 | 75 | echo "\n\t\t\t<a href='$url' class='$class'>$label</a>"; |
@@ -79,18 +79,18 @@ discard block |
||
79 | 79 | |
80 | 80 | </nav> |
81 | 81 | |
82 | - <div class="bsui <?php echo esc_attr( $current_tab ); ?>"> |
|
83 | - <?php do_action( "wpinv_reports_tab_{$current_tab}" ); ?> |
|
82 | + <div class="bsui <?php echo esc_attr($current_tab); ?>"> |
|
83 | + <?php do_action("wpinv_reports_tab_{$current_tab}"); ?> |
|
84 | 84 | </div> |
85 | 85 | |
86 | 86 | </div> |
87 | 87 | <?php |
88 | 88 | |
89 | 89 | // Wordfence loads an unsupported version of chart js on our page. |
90 | - wp_deregister_style( 'chart-js' ); |
|
91 | - wp_deregister_script( 'chart-js' ); |
|
92 | - wp_enqueue_script( 'chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array( 'jquery' ), '2.9.4', true ); |
|
93 | - wp_enqueue_style( 'chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4' ); |
|
90 | + wp_deregister_style('chart-js'); |
|
91 | + wp_deregister_script('chart-js'); |
|
92 | + wp_enqueue_script('chart-js', WPINV_PLUGIN_URL . 'assets/js/chart.bundle.min.js', array('jquery'), '2.9.4', true); |
|
93 | + wp_enqueue_style('chart-js', WPINV_PLUGIN_URL . 'assets/css/chart.min.css', array(), '2.9.4'); |
|
94 | 94 | |
95 | 95 | } |
96 | 96 | |
@@ -102,11 +102,11 @@ discard block |
||
102 | 102 | public function get_tabs() { |
103 | 103 | |
104 | 104 | $tabs = array( |
105 | - 'reports' => __( 'Reports', 'invoicing' ), |
|
106 | - 'export' => __( 'Export', 'invoicing' ), |
|
105 | + 'reports' => __('Reports', 'invoicing'), |
|
106 | + 'export' => __('Export', 'invoicing'), |
|
107 | 107 | ); |
108 | 108 | |
109 | - return apply_filters( 'getpaid_report_tabs', $tabs ); |
|
109 | + return apply_filters('getpaid_report_tabs', $tabs); |
|
110 | 110 | } |
111 | 111 | |
112 | 112 | /** |
@@ -136,11 +136,11 @@ discard block |
||
136 | 136 | * |
137 | 137 | * @param array $args |
138 | 138 | */ |
139 | - public function download_graph( $args ) { |
|
139 | + public function download_graph($args) { |
|
140 | 140 | |
141 | - if ( ! empty( $args['graph'] ) ) { |
|
141 | + if (!empty($args['graph'])) { |
|
142 | 142 | $downloader = new GetPaid_Graph_Downloader(); |
143 | - $downloader->download( $args['graph'] ); |
|
143 | + $downloader->download($args['graph']); |
|
144 | 144 | } |
145 | 145 | |
146 | 146 | } |
@@ -150,17 +150,17 @@ discard block |
||
150 | 150 | * |
151 | 151 | * @param array $args |
152 | 152 | */ |
153 | - public function export_invoices( $args ) { |
|
153 | + public function export_invoices($args) { |
|
154 | 154 | |
155 | - if ( ! empty( $args['post_type'] ) ) { |
|
155 | + if (!empty($args['post_type'])) { |
|
156 | 156 | |
157 | - if ( 'subscriptions' === $args['post_type'] ) { |
|
157 | + if ('subscriptions' === $args['post_type']) { |
|
158 | 158 | $downloader = new GetPaid_Subscription_Exporter(); |
159 | 159 | } else { |
160 | 160 | $downloader = new GetPaid_Invoice_Exporter(); |
161 | 161 | } |
162 | 162 | |
163 | - $downloader->export( $args['post_type'], $args ); |
|
163 | + $downloader->export($args['post_type'], $args); |
|
164 | 164 | } |
165 | 165 | |
166 | 166 | } |