Passed
Push — master ( 3a0618...5aee45 )
by Stiofan
05:13
created
includes/gateways/class-getpaid-authorize-net-gateway.php 2 patches
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 4;
35 35
 
36 36
     /**
37
-	 * Endpoint for requests from Authorize.net.
38
-	 *
39
-	 * @var string
40
-	 */
41
-	protected $notify_url;
42
-
43
-	/**
44
-	 * Endpoint for requests to Authorize.net.
45
-	 *
46
-	 * @var string
47
-	 */
37
+     * Endpoint for requests from Authorize.net.
38
+     *
39
+     * @var string
40
+     */
41
+    protected $notify_url;
42
+
43
+    /**
44
+     * Endpoint for requests to Authorize.net.
45
+     *
46
+     * @var string
47
+     */
48 48
     protected $endpoint;
49 49
 
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
56 56
 
57 57
     /**
58
-	 * URL to view a transaction.
59
-	 *
60
-	 * @var string
61
-	 */
58
+     * URL to view a transaction.
59
+     *
60
+     * @var string
61
+     */
62 62
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
63 63
 
64 64
     /**
65
-	 * Class constructor.
66
-	 */
67
-	public function __construct() {
65
+     * Class constructor.
66
+     */
67
+    public function __construct() {
68 68
 
69 69
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70 70
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
     }
77 77
 
78 78
     /**
79
-	 * Displays the payment method select field.
80
-	 *
81
-	 * @param int $invoice_id 0 or invoice id.
82
-	 * @param GetPaid_Payment_Form $form Current payment form.
83
-	 */
79
+     * Displays the payment method select field.
80
+     *
81
+     * @param int $invoice_id 0 or invoice id.
82
+     * @param GetPaid_Payment_Form $form Current payment form.
83
+     */
84 84
     public function payment_fields( $invoice_id, $form ) {
85 85
 
86 86
         // Let the user select a payment method.
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-	 * Creates a customer profile.
95
-	 *
96
-	 *
97
-	 * @param WPInv_Invoice $invoice Invoice.
94
+     * Creates a customer profile.
95
+     *
96
+     *
97
+     * @param WPInv_Invoice $invoice Invoice.
98 98
      * @param array $submission_data Posted checkout fields.
99 99
      * @param bool $save Whether or not to save the payment as a token.
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101
-	 * @return string|WP_Error Payment profile id.
102
-	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
101
+     * @return string|WP_Error Payment profile id.
102
+     */
103
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
104 104
 
105 105
         // Remove non-digits from the number
106 106
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
     }
168 168
 
169 169
     /**
170
-	 * Retrieves a customer profile.
171
-	 *
172
-	 *
173
-	 * @param string $profile_id profile id.
174
-	 * @return string|WP_Error Profile id.
170
+     * Retrieves a customer profile.
171
+     *
172
+     *
173
+     * @param string $profile_id profile id.
174
+     * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176
-	 */
177
-	public function get_customer_profile( $profile_id ) {
176
+     */
177
+    public function get_customer_profile( $profile_id ) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
     }
190 190
 
191 191
     /**
192
-	 * Creates a customer profile.
193
-	 *
194
-	 *
192
+     * Creates a customer profile.
193
+     *
194
+     *
195 195
      * @param string $profile_id profile id.
196
-	 * @param WPInv_Invoice $invoice Invoice.
196
+     * @param WPInv_Invoice $invoice Invoice.
197 197
      * @param array $submission_data Posted checkout fields.
198 198
      * @param bool $save Whether or not to save the payment as a token.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200
-	 * @return string|WP_Error Profile id.
201
-	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
200
+     * @return string|WP_Error Profile id.
201
+     */
202
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
203 203
 
204 204
         // Remove non-digits from the number
205 205
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -272,13 +272,13 @@  discard block
 block discarded – undo
272 272
     }
273 273
 
274 274
     /**
275
-	 * Retrieves payment details from cache.
276
-	 *
277
-	 *
275
+     * Retrieves payment details from cache.
276
+     *
277
+     *
278 278
      * @param array $payment_details.
279
-	 * @return array|false Profile id.
280
-	 */
281
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
279
+     * @return array|false Profile id.
280
+     */
281
+    public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
282 282
 
283 283
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
284 284
         $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
@@ -303,13 +303,13 @@  discard block
 block discarded – undo
303 303
     }
304 304
 
305 305
     /**
306
-	 * Securely adds payment details to cache.
307
-	 *
308
-	 *
306
+     * Securely adds payment details to cache.
307
+     *
308
+     *
309 309
      * @param array $payment_details.
310 310
      * @param string $payment_profile_id.
311
-	 */
312
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
311
+     */
312
+    public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
313 313
 
314 314
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
315 315
         $cached_information = is_array( $cached_information ) ? $cached_information : array();
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
     }
322 322
 
323 323
     /**
324
-	 * Retrieves a customer payment profile.
325
-	 *
326
-	 *
327
-	 * @param string $customer_profile_id customer profile id.
324
+     * Retrieves a customer payment profile.
325
+     *
326
+     *
327
+     * @param string $customer_profile_id customer profile id.
328 328
      * @param string $payment_profile_id payment profile id.
329
-	 * @return string|WP_Error Profile id.
329
+     * @return string|WP_Error Profile id.
330 330
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
331
-	 */
332
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
331
+     */
332
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
333 333
 
334 334
         // Generate args.
335 335
         $args = array(
@@ -345,15 +345,15 @@  discard block
 block discarded – undo
345 345
     }
346 346
 
347 347
     /**
348
-	 * Charges a customer payment profile.
349
-	 *
348
+     * Charges a customer payment profile.
349
+     *
350 350
      * @param string $customer_profile_id customer profile id.
351 351
      * @param string $payment_profile_id payment profile id.
352
-	 * @param WPInv_Invoice $invoice Invoice.
352
+     * @param WPInv_Invoice $invoice Invoice.
353 353
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
354
-	 * @return WP_Error|object
355
-	 */
356
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
354
+     * @return WP_Error|object
355
+     */
356
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
357 357
 
358 358
         // Generate args.
359 359
         $args = array(
@@ -399,41 +399,41 @@  discard block
 block discarded – undo
399 399
     }
400 400
 
401 401
     /**
402
-	 * Processes a customer charge.
403
-	 *
402
+     * Processes a customer charge.
403
+     *
404 404
      * @param stdClass $result Api response.
405
-	 * @param WPInv_Invoice $invoice Invoice.
406
-	 */
407
-	public function process_charge_response( $result, $invoice ) {
405
+     * @param WPInv_Invoice $invoice Invoice.
406
+     */
407
+    public function process_charge_response( $result, $invoice ) {
408 408
 
409 409
         wpinv_clear_errors();
410
-		$response_code = (int) $result->transactionResponse->responseCode;
410
+        $response_code = (int) $result->transactionResponse->responseCode;
411 411
 
412
-		// Succeeded.
413
-		if ( 1 == $response_code || 4 == $response_code ) {
412
+        // Succeeded.
413
+        if ( 1 == $response_code || 4 == $response_code ) {
414 414
 
415
-			// Maybe set a transaction id.
416
-			if ( ! empty( $result->transactionResponse->transId ) ) {
417
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
418
-			}
415
+            // Maybe set a transaction id.
416
+            if ( ! empty( $result->transactionResponse->transId ) ) {
417
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
418
+            }
419 419
 
420
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
420
+            $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
421 421
 
422
-			if ( 1 == $response_code ) {
423
-				return $invoice->mark_paid();
424
-			}
422
+            if ( 1 == $response_code ) {
423
+                return $invoice->mark_paid();
424
+            }
425 425
 
426
-			$invoice->set_status( 'wpi-onhold' );
427
-        	$invoice->add_note(
426
+            $invoice->set_status( 'wpi-onhold' );
427
+            $invoice->add_note(
428 428
                 sprintf(
429 429
                     __( 'Held for review: %s', 'invoicing' ),
430 430
                     $result->transactionResponse->messages->message[0]->description
431 431
                 )
432
-			);
432
+            );
433 433
 
434
-			return $invoice->save();
434
+            return $invoice->save();
435 435
 
436
-		}
436
+        }
437 437
 
438 438
         wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
439 439
 
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
     }
446 446
 
447 447
     /**
448
-	 * Returns payment information.
449
-	 *
450
-	 *
451
-	 * @param array $card Card details.
452
-	 * @return array
453
-	 */
454
-	public function get_payment_information( $card ) {
448
+     * Returns payment information.
449
+     *
450
+     *
451
+     * @param array $card Card details.
452
+     * @return array
453
+     */
454
+    public function get_payment_information( $card ) {
455 455
         return array(
456 456
 
457 457
             'creditCard'         => array (
@@ -464,25 +464,25 @@  discard block
 block discarded – undo
464 464
     }
465 465
 
466 466
     /**
467
-	 * Returns the customer profile meta name.
468
-	 *
469
-	 *
470
-	 * @param WPInv_Invoice $invoice Invoice.
471
-	 * @return string
472
-	 */
473
-	public function get_customer_profile_meta_name( $invoice ) {
467
+     * Returns the customer profile meta name.
468
+     *
469
+     *
470
+     * @param WPInv_Invoice $invoice Invoice.
471
+     * @return string
472
+     */
473
+    public function get_customer_profile_meta_name( $invoice ) {
474 474
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
475 475
     }
476 476
 
477 477
     /**
478
-	 * Validates the submitted data.
479
-	 *
480
-	 *
481
-	 * @param array $submission_data Posted checkout fields.
478
+     * Validates the submitted data.
479
+     *
480
+     *
481
+     * @param array $submission_data Posted checkout fields.
482 482
      * @param WPInv_Invoice $invoice
483
-	 * @return WP_Error|string The payment profile id
484
-	 */
485
-	public function validate_submission_data( $submission_data, $invoice ) {
483
+     * @return WP_Error|string The payment profile id
484
+     */
485
+    public function validate_submission_data( $submission_data, $invoice ) {
486 486
 
487 487
         // Validate authentication details.
488 488
         $auth = $this->get_auth_params();
@@ -514,13 +514,13 @@  discard block
 block discarded – undo
514 514
     }
515 515
 
516 516
     /**
517
-	 * Returns invoice line items.
518
-	 *
519
-	 *
520
-	 * @param WPInv_Invoice $invoice Invoice.
521
-	 * @return array
522
-	 */
523
-	public function get_line_items( $invoice ) {
517
+     * Returns invoice line items.
518
+     *
519
+     *
520
+     * @param WPInv_Invoice $invoice Invoice.
521
+     * @return array
522
+     */
523
+    public function get_line_items( $invoice ) {
524 524
         $items = array();
525 525
 
526 526
         foreach ( $invoice->get_items() as $item ) {
@@ -558,15 +558,15 @@  discard block
 block discarded – undo
558 558
     }
559 559
 
560 560
     /**
561
-	 * Process Payment.
562
-	 *
563
-	 *
564
-	 * @param WPInv_Invoice $invoice Invoice.
565
-	 * @param array $submission_data Posted checkout fields.
566
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
567
-	 * @return array
568
-	 */
569
-	public function process_payment( $invoice, $submission_data, $submission ) {
561
+     * Process Payment.
562
+     *
563
+     *
564
+     * @param WPInv_Invoice $invoice Invoice.
565
+     * @param array $submission_data Posted checkout fields.
566
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
567
+     * @return array
568
+     */
569
+    public function process_payment( $invoice, $submission_data, $submission ) {
570 570
 
571 571
         // Validate the submitted data.
572 572
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -599,45 +599,45 @@  discard block
 block discarded – undo
599 599
 
600 600
         exit;
601 601
 
602
-	}
602
+    }
603 603
 	
604
-	/**
605
-	 * Processes the initial payment.
606
-	 *
604
+    /**
605
+     * Processes the initial payment.
606
+     *
607 607
      * @param WPInv_Invoice $invoice Invoice.
608
-	 */
609
-	protected function process_initial_payment( $invoice ) {
608
+     */
609
+    protected function process_initial_payment( $invoice ) {
610 610
 
611
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
611
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
612 612
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
613
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
613
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
614 614
 
615
-		// Do we have an error?
616
-		if ( is_wp_error( $result ) ) {
617
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
618
-			wpinv_send_back_to_checkout( $invoice );
619
-		}
615
+        // Do we have an error?
616
+        if ( is_wp_error( $result ) ) {
617
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
618
+            wpinv_send_back_to_checkout( $invoice );
619
+        }
620 620
 
621
-		// Process the response.
622
-		$this->process_charge_response( $result, $invoice );
621
+        // Process the response.
622
+        $this->process_charge_response( $result, $invoice );
623 623
 
624
-		if ( wpinv_get_errors() ) {
625
-			wpinv_send_back_to_checkout( $invoice );
626
-		}
624
+        if ( wpinv_get_errors() ) {
625
+            wpinv_send_back_to_checkout( $invoice );
626
+        }
627 627
 
628
-	}
628
+    }
629 629
 
630 630
     /**
631
-	 * Processes recurring payments.
632
-	 *
631
+     * Processes recurring payments.
632
+     *
633 633
      * @param WPInv_Invoice $invoice Invoice.
634 634
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
635
-	 */
636
-	public function process_subscription( $invoice, $subscriptions ) {
635
+     */
636
+    public function process_subscription( $invoice, $subscriptions ) {
637 637
 
638 638
         // Check if there is an initial amount to charge.
639 639
         if ( (float) $invoice->get_total() > 0 ) {
640
-			$this->process_initial_payment( $invoice );
640
+            $this->process_initial_payment( $invoice );
641 641
         }
642 642
 
643 643
         // Activate the subscriptions.
@@ -655,19 +655,19 @@  discard block
 block discarded – undo
655 655
             }
656 656
         }
657 657
 
658
-		// Redirect to the success page.
658
+        // Redirect to the success page.
659 659
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
660 660
 
661 661
     }
662 662
 
663
-	/**
664
-	 * (Maybe) renews an authorize.net subscription profile.
665
-	 *
666
-	 *
667
-	 * @param bool $should_expire
663
+    /**
664
+     * (Maybe) renews an authorize.net subscription profile.
665
+     *
666
+     *
667
+     * @param bool $should_expire
668 668
      * @param WPInv_Subscription $subscription
669
-	 */
670
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
669
+     */
670
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
671 671
 
672 672
         // Ensure its our subscription && it's active.
673 673
         if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -684,18 +684,18 @@  discard block
 block discarded – undo
684 684
 
685 685
         return false;
686 686
 
687
-	}
687
+    }
688 688
 
689 689
     /**
690
-	 * Renews a subscription.
691
-	 *
690
+     * Renews a subscription.
691
+     *
692 692
      * @param WPInv_Subscription $subscription
693
-	 */
694
-	public function renew_subscription( $subscription ) {
693
+     */
694
+    public function renew_subscription( $subscription ) {
695 695
 
696
-		// Generate the renewal invoice.
697
-		$new_invoice = $subscription->create_payment();
698
-		$old_invoice = $subscription->get_parent_payment();
696
+        // Generate the renewal invoice.
697
+        $new_invoice = $subscription->create_payment();
698
+        $old_invoice = $subscription->get_parent_payment();
699 699
 
700 700
         if ( empty( $new_invoice ) ) {
701 701
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -704,37 +704,37 @@  discard block
 block discarded – undo
704 704
         }
705 705
 
706 706
         // Charge the payment method.
707
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
708
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
709
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
707
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
708
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
709
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
710 710
 
711
-		// Do we have an error?
712
-		if ( is_wp_error( $result ) ) {
711
+        // Do we have an error?
712
+        if ( is_wp_error( $result ) ) {
713 713
 
714
-			$old_invoice->add_note(
715
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
716
-				true,
717
-				false,
718
-				true
719
-			);
720
-			$subscription->failing();
721
-			return;
714
+            $old_invoice->add_note(
715
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
716
+                true,
717
+                false,
718
+                true
719
+            );
720
+            $subscription->failing();
721
+            return;
722 722
 
723
-		}
723
+        }
724 724
 
725
-		// Process the response.
726
-		$this->process_charge_response( $result, $new_invoice );
725
+        // Process the response.
726
+        $this->process_charge_response( $result, $new_invoice );
727 727
 
728
-		if ( wpinv_get_errors() ) {
728
+        if ( wpinv_get_errors() ) {
729 729
 
730
-			$old_invoice->add_note(
731
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
732
-				true,
733
-				false,
734
-				true
735
-			);
736
-			$subscription->failing();
737
-			return;
730
+            $old_invoice->add_note(
731
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
732
+                true,
733
+                false,
734
+                true
735
+            );
736
+            $subscription->failing();
737
+            return;
738 738
 
739 739
         }
740 740
 
@@ -743,13 +743,13 @@  discard block
 block discarded – undo
743 743
     }
744 744
 
745 745
     /**
746
-	 * Processes invoice addons.
747
-	 *
748
-	 * @param WPInv_Invoice $invoice
749
-	 * @param GetPaid_Form_Item[] $items
750
-	 * @return WPInv_Invoice
751
-	 */
752
-	public function process_addons( $invoice, $items ) {
746
+     * Processes invoice addons.
747
+     *
748
+     * @param WPInv_Invoice $invoice
749
+     * @param GetPaid_Form_Item[] $items
750
+     * @return WPInv_Invoice
751
+     */
752
+    public function process_addons( $invoice, $items ) {
753 753
 
754 754
         global $getpaid_authorize_addons;
755 755
 
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
         $invoice->recalculate_total();
770 770
 
771 771
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
772
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
772
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
773 773
 
774 774
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
775 775
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -784,11 +784,11 @@  discard block
 block discarded – undo
784 784
     }
785 785
 
786 786
     /**
787
-	 * Processes invoice addons.
788
-	 *
787
+     * Processes invoice addons.
788
+     *
789 789
      * @param array $args
790
-	 * @return array
791
-	 */
790
+     * @return array
791
+     */
792 792
     public function filter_addons_request( $args ) {
793 793
 
794 794
         global $getpaid_authorize_addons;
@@ -822,11 +822,11 @@  discard block
 block discarded – undo
822 822
     }
823 823
 
824 824
     /**
825
-	 * Filters the gateway settings.
826
-	 *
827
-	 * @param array $admin_settings
828
-	 */
829
-	public function admin_settings( $admin_settings ) {
825
+     * Filters the gateway settings.
826
+     *
827
+     * @param array $admin_settings
828
+     */
829
+    public function admin_settings( $admin_settings ) {
830 830
 
831 831
         $currencies = sprintf(
832 832
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
             'readonly' => true,
867 867
         );
868 868
 
869
-		return $admin_settings;
870
-	}
869
+        return $admin_settings;
870
+    }
871 871
 
872 872
 }
Please login to merge, or discard this patch.
Spacing   +198 added lines, -198 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Authorize.net Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = getpaid_get_non_query_string_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = getpaid_get_non_query_string_ipn_url($this->id);
72 72
 
73
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
74
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
73
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
74
+        add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice'));
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         echo $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        echo $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        echo $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,72 +100,72 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication'   => $this->get_auth_params(),
112 112
                 'profile'                  => array(
113
-                    'merchantCustomerId'   => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'          => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'                => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId'   => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'          => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'                => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'      => array(
117 117
                         'customerType'     => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'           => array(
121
-                            'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'      => getpaid_limit_length( $invoice->get_address(), 60 ),
124
-                            'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'      => getpaid_limit_length($invoice->get_address(), 60),
124
+                            'city'         => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'        => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'      => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'          => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'          => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     )
133 133
                 ),
134
-                'validationMode'           => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
134
+                'validationMode'           => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
135 135
             )
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
 
142 142
             // In case the customer profile already exists remotely.
143
-            if ( 'E00039' == $response->get_error_code() ) {
144
-                $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() );
145
-                $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id );
146
-                return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save );
143
+            if ('E00039' == $response->get_error_code()) {
144
+                $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message());
145
+                $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id);
146
+                return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save);
147 147
             }
148 148
 
149 149
             return $response;
150 150
         }
151 151
 
152
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
152
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
153 153
 
154 154
         // Save the payment token.
155
-        if ( $save ) {
155
+        if ($save) {
156 156
             $this->save_token(
157 157
                 array(
158 158
                     'id'      => $response->customerPaymentProfileIdList[0],
159
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
159
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4),
160 160
                     'default' => true,
161
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
161
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
162 162
                 )
163 163
             );
164 164
         }
165 165
 
166 166
         // Add a note about the validation response.
167 167
         $invoice->add_note(
168
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
168
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
169 169
             false,
170 170
             false,
171 171
             true
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @return string|WP_Error Profile id.
183 183
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
184 184
 	 */
185
-	public function get_customer_profile( $profile_id ) {
185
+	public function get_customer_profile($profile_id) {
186 186
 
187 187
         // Generate args.
188 188
         $args = array(
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
             )
193 193
         );
194 194
 
195
-        return $this->post( $args, false );
195
+        return $this->post($args, false);
196 196
 
197 197
     }
198 198
 
@@ -207,18 +207,18 @@  discard block
 block discarded – undo
207 207
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
208 208
 	 * @return string|WP_Error Profile id.
209 209
 	 */
210
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
210
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
211 211
 
212 212
         // Remove non-digits from the number
213
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
213
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
214 214
 
215 215
         // Prepare card details.
216
-        $payment_information                          = $this->get_payment_information( $submission_data['authorizenet'] );
216
+        $payment_information                          = $this->get_payment_information($submission_data['authorizenet']);
217 217
 
218 218
         // Authorize.NET does not support saving the same card twice.
219
-        $cached_information                           = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice );
219
+        $cached_information                           = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice);
220 220
 
221
-        if ( $cached_information ) {
221
+        if ($cached_information) {
222 222
             return $cached_information;
223 223
         }
224 224
 
@@ -231,52 +231,52 @@  discard block
 block discarded – undo
231 231
 
232 232
                     // Billing information.
233 233
                     'billTo'           => array(
234
-                        'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
235
-                        'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
236
-                        'address'      => getpaid_limit_length( $invoice->get_address(), 60 ),
237
-                        'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
238
-                        'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
239
-                        'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
240
-                        'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
234
+                        'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
235
+                        'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
236
+                        'address'      => getpaid_limit_length($invoice->get_address(), 60),
237
+                        'city'         => getpaid_limit_length($invoice->get_city(), 40),
238
+                        'state'        => getpaid_limit_length($invoice->get_state(), 40),
239
+                        'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
240
+                        'country'      => getpaid_limit_length($invoice->get_country(), 60),
241 241
                     ),
242 242
 
243 243
                     // Payment information.
244 244
                     'payment'          => $payment_information
245 245
                 ),
246
-                'validationMode'       => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
246
+                'validationMode'       => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
247 247
             )
248 248
         );
249 249
 
250
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
250
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
251 251
 
252
-        if ( is_wp_error( $response ) ) {
252
+        if (is_wp_error($response)) {
253 253
             return $response;
254 254
         }
255 255
 
256 256
         // Save the payment token.
257
-        if ( $save ) {
257
+        if ($save) {
258 258
             $this->save_token(
259 259
                 array(
260 260
                     'id'      => $response->customerPaymentProfileId,
261
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
261
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4),
262 262
                     'default' => true,
263
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
263
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
264 264
                 )
265 265
             );
266 266
         }
267 267
 
268 268
         // Cache payment profile id.
269
-        $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId );
269
+        $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId);
270 270
 
271 271
         // Add a note about the validation response.
272 272
         $invoice->add_note(
273
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
273
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
274 274
             false,
275 275
             false,
276 276
             true
277 277
         );
278 278
 
279
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile );
279
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile);
280 280
 
281 281
         return $response->customerPaymentProfileId;
282 282
     }
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
      * @param array $payment_details.
289 289
 	 * @return array|false Profile id.
290 290
 	 */
291
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
291
+	public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) {
292 292
 
293
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
294
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
293
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
294
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
295 295
 
296
-        if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) {
296
+        if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) {
297 297
             return false;
298 298
         }
299 299
 
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
             'getCustomerPaymentProfileRequest' => array(
303 303
                 'merchantAuthentication'   => $this->get_auth_params(),
304 304
                 'customerProfileId'        => $customer_profile,
305
-                'customerPaymentProfileId' => $cached_information[ $payment_details ],
305
+                'customerPaymentProfileId' => $cached_information[$payment_details],
306 306
             )
307 307
         );
308 308
 
309
-        $response = $this->post( $args, $invoice );
309
+        $response = $this->post($args, $invoice);
310 310
 
311
-        return is_wp_error( $response ) ? false : $cached_information[ $payment_details ];
311
+        return is_wp_error($response) ? false : $cached_information[$payment_details];
312 312
 
313 313
     }
314 314
 
@@ -319,14 +319,14 @@  discard block
 block discarded – undo
319 319
      * @param array $payment_details.
320 320
      * @param string $payment_profile_id.
321 321
 	 */
322
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
322
+	public function add_payment_profile_to_cache($payment_details, $payment_profile_id) {
323 323
 
324
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
325
-        $cached_information = is_array( $cached_information ) ? $cached_information : array();
326
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
324
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
325
+        $cached_information = is_array($cached_information) ? $cached_information : array();
326
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
327 327
 
328
-        $cached_information[ $payment_details ] = $payment_profile_id;
329
-        update_option( 'getpaid_authorize_net_cached_profiles', $cached_information );
328
+        $cached_information[$payment_details] = $payment_profile_id;
329
+        update_option('getpaid_authorize_net_cached_profiles', $cached_information);
330 330
 
331 331
     }
332 332
 
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 	 * @return string|WP_Error Profile id.
340 340
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
341 341
 	 */
342
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
342
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
343 343
 
344 344
         // Generate args.
345 345
         $args = array(
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             )
351 351
         );
352 352
 
353
-        return $this->post( $args, false );
353
+        return $this->post($args, false);
354 354
 
355 355
     }
356 356
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
364 364
 	 * @return WP_Error|object
365 365
 	 */
366
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
366
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
367 367
 
368 368
         // Generate args.
369 369
         $args = array(
@@ -383,28 +383,28 @@  discard block
 block discarded – undo
383 383
                         )
384 384
                     ),
385 385
                     'order'                    => array(
386
-                        'invoiceNumber'        => getpaid_limit_length( $invoice->get_number(), 20 ),
386
+                        'invoiceNumber'        => getpaid_limit_length($invoice->get_number(), 20),
387 387
                     ),
388
-                    'lineItems'                => array( 'lineItem' => $this->get_line_items( $invoice ) ),
388
+                    'lineItems'                => array('lineItem' => $this->get_line_items($invoice)),
389 389
                     'tax'                      => array(
390 390
                         'amount'               => $invoice->get_total_tax(),
391
-                        'name'                 => __( 'TAX', 'invoicing' ),
391
+                        'name'                 => __('TAX', 'invoicing'),
392 392
                     ),
393
-                    'poNumber'                 => getpaid_limit_length( $invoice->get_number(), 25 ),
393
+                    'poNumber'                 => getpaid_limit_length($invoice->get_number(), 25),
394 394
                     'customer'                 => array(
395
-                        'id'                   => getpaid_limit_length( $invoice->get_user_id(), 25 ),
396
-                        'email'                => getpaid_limit_length( $invoice->get_email(), 25 ),
395
+                        'id'                   => getpaid_limit_length($invoice->get_user_id(), 25),
396
+                        'email'                => getpaid_limit_length($invoice->get_email(), 25),
397 397
                     ),
398 398
                     'customerIP'               => $invoice->get_ip(),
399 399
                 )
400 400
             )
401 401
         );
402 402
 
403
-        if ( 0 == $invoice->get_total_tax() ) {
404
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
403
+        if (0 == $invoice->get_total_tax()) {
404
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
405 405
         }
406 406
 
407
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
407
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
408 408
 
409 409
     }
410 410
 
@@ -414,29 +414,29 @@  discard block
 block discarded – undo
414 414
      * @param stdClass $result Api response.
415 415
 	 * @param WPInv_Invoice $invoice Invoice.
416 416
 	 */
417
-	public function process_charge_response( $result, $invoice ) {
417
+	public function process_charge_response($result, $invoice) {
418 418
 
419 419
         wpinv_clear_errors();
420 420
 		$response_code = (int) $result->transactionResponse->responseCode;
421 421
 
422 422
 		// Succeeded.
423
-		if ( 1 == $response_code || 4 == $response_code ) {
423
+		if (1 == $response_code || 4 == $response_code) {
424 424
 
425 425
 			// Maybe set a transaction id.
426
-			if ( ! empty( $result->transactionResponse->transId ) ) {
427
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
426
+			if (!empty($result->transactionResponse->transId)) {
427
+				$invoice->set_transaction_id($result->transactionResponse->transId);
428 428
 			}
429 429
 
430
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
430
+			$invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
431 431
 
432
-			if ( 1 == $response_code ) {
432
+			if (1 == $response_code) {
433 433
 				return $invoice->mark_paid();
434 434
 			}
435 435
 
436
-			$invoice->set_status( 'wpi-onhold' );
436
+			$invoice->set_status('wpi-onhold');
437 437
         	$invoice->add_note(
438 438
                 sprintf(
439
-                    __( 'Held for review: %s', 'invoicing' ),
439
+                    __('Held for review: %s', 'invoicing'),
440 440
                     $result->transactionResponse->messages->message[0]->description
441 441
                 )
442 442
 			);
@@ -445,11 +445,11 @@  discard block
 block discarded – undo
445 445
 
446 446
 		}
447 447
 
448
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
448
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
449 449
 
450
-        if ( ! empty( $result->transactionResponse->errors ) ) {
450
+        if (!empty($result->transactionResponse->errors)) {
451 451
             $errors = (object) $result->transactionResponse->errors;
452
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
452
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
453 453
         }
454 454
 
455 455
     }
@@ -461,10 +461,10 @@  discard block
 block discarded – undo
461 461
 	 * @param array $card Card details.
462 462
 	 * @return array
463 463
 	 */
464
-	public function get_payment_information( $card ) {
464
+	public function get_payment_information($card) {
465 465
         return array(
466 466
 
467
-            'creditCard'         => array (
467
+            'creditCard'         => array(
468 468
                 'cardNumber'     => $card['cc_number'],
469 469
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
470 470
                 'cardCode'       => $card['cc_cvv2'],
@@ -480,8 +480,8 @@  discard block
 block discarded – undo
480 480
 	 * @param WPInv_Invoice $invoice Invoice.
481 481
 	 * @return string
482 482
 	 */
483
-	public function get_customer_profile_meta_name( $invoice ) {
484
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
483
+	public function get_customer_profile_meta_name($invoice) {
484
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
485 485
     }
486 486
 
487 487
     /**
@@ -492,34 +492,34 @@  discard block
 block discarded – undo
492 492
      * @param WPInv_Invoice $invoice
493 493
 	 * @return WP_Error|string The payment profile id
494 494
 	 */
495
-	public function validate_submission_data( $submission_data, $invoice ) {
495
+	public function validate_submission_data($submission_data, $invoice) {
496 496
 
497 497
         // Validate authentication details.
498 498
         $auth = $this->get_auth_params();
499 499
 
500
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
501
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') );
500
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
501
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
502 502
         }
503 503
 
504 504
         // Validate the payment method.
505
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
506
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
505
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
506
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
507 507
         }
508 508
 
509 509
         // Are we adding a new payment method?
510
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
510
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
511 511
             return $submission_data['getpaid-authorizenet-payment-method'];
512 512
         }
513 513
 
514 514
         // Retrieve the customer profile id.
515
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
515
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
516 516
 
517 517
         // Create payment method.
518
-        if ( empty( $profile_id ) ) {
519
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
518
+        if (empty($profile_id)) {
519
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
520 520
         }
521 521
 
522
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
522
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
523 523
 
524 524
     }
525 525
 
@@ -530,32 +530,32 @@  discard block
 block discarded – undo
530 530
 	 * @param WPInv_Invoice $invoice Invoice.
531 531
 	 * @return array
532 532
 	 */
533
-	public function get_line_items( $invoice ) {
533
+	public function get_line_items($invoice) {
534 534
         $items = array();
535 535
 
536
-        foreach ( $invoice->get_items() as $item ) {
536
+        foreach ($invoice->get_items() as $item) {
537 537
 
538 538
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
539 539
             $items[] = array(
540
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
541
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
542
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
543
-                'quantity'    => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ),
540
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
541
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
542
+                'description' => getpaid_limit_length($item->get_description(), 255),
543
+                'quantity'    => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()),
544 544
                 'unitPrice'   => (float) $amount,
545 545
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
546 546
             );
547 547
 
548 548
         }
549 549
 
550
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
550
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
551 551
 
552
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
552
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
553 553
 
554
-            if ( $amount > 0 ) {
554
+            if ($amount > 0) {
555 555
                 $items[] = array(
556
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
557
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
558
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
556
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
557
+                    'name'        => getpaid_limit_length($fee_name, 31),
558
+                    'description' => getpaid_limit_length($fee_name, 255),
559 559
                     'quantity'    => '1',
560 560
                     'unitPrice'   => (float) $amount,
561 561
                     'taxable'     => false,
@@ -576,36 +576,36 @@  discard block
 block discarded – undo
576 576
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
577 577
 	 * @return array
578 578
 	 */
579
-	public function process_payment( $invoice, $submission_data, $submission ) {
579
+	public function process_payment($invoice, $submission_data, $submission) {
580 580
 
581 581
         // Validate the submitted data.
582
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
582
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
583 583
 
584 584
         // Do we have an error?
585
-        if ( is_wp_error( $payment_profile_id ) ) {
586
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
587
-            wpinv_send_back_to_checkout( $invoice );
585
+        if (is_wp_error($payment_profile_id)) {
586
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
587
+            wpinv_send_back_to_checkout($invoice);
588 588
         }
589 589
 
590 590
         // Save the payment method to the order.
591
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
591
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
592 592
 
593 593
         // Check if this is a subscription or not.
594
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
595
-        if ( ! empty( $subscriptions ) ) {
596
-            $this->process_subscription( $invoice, $subscriptions );
594
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
595
+        if (!empty($subscriptions)) {
596
+            $this->process_subscription($invoice, $subscriptions);
597 597
         }
598 598
 
599 599
         // If it is free, send to the success page.
600
-        if ( ! $invoice->needs_payment() ) {
600
+        if (!$invoice->needs_payment()) {
601 601
             $invoice->mark_paid();
602
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
602
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
603 603
         }
604 604
 
605 605
         // Charge the payment profile.
606
-        $this->process_initial_payment( $invoice );
606
+        $this->process_initial_payment($invoice);
607 607
 
608
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
608
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
609 609
 
610 610
         exit;
611 611
 
@@ -616,23 +616,23 @@  discard block
 block discarded – undo
616 616
 	 *
617 617
      * @param WPInv_Invoice $invoice Invoice.
618 618
 	 */
619
-	protected function process_initial_payment( $invoice ) {
619
+	protected function process_initial_payment($invoice) {
620 620
 
621
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
622
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
623
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
621
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
622
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
623
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
624 624
 
625 625
 		// Do we have an error?
626
-		if ( is_wp_error( $result ) ) {
627
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
628
-			wpinv_send_back_to_checkout( $invoice );
626
+		if (is_wp_error($result)) {
627
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
628
+			wpinv_send_back_to_checkout($invoice);
629 629
 		}
630 630
 
631 631
 		// Process the response.
632
-		$this->process_charge_response( $result, $invoice );
632
+		$this->process_charge_response($result, $invoice);
633 633
 
634
-		if ( wpinv_get_errors() ) {
635
-			wpinv_send_back_to_checkout( $invoice );
634
+		if (wpinv_get_errors()) {
635
+			wpinv_send_back_to_checkout($invoice);
636 636
 		}
637 637
 
638 638
 	}
@@ -643,30 +643,30 @@  discard block
 block discarded – undo
643 643
      * @param WPInv_Invoice $invoice Invoice.
644 644
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
645 645
 	 */
646
-	public function process_subscription( $invoice, $subscriptions ) {
646
+	public function process_subscription($invoice, $subscriptions) {
647 647
 
648 648
         // Check if there is an initial amount to charge.
649
-        if ( (float) $invoice->get_total() > 0 ) {
650
-			$this->process_initial_payment( $invoice );
649
+        if ((float) $invoice->get_total() > 0) {
650
+			$this->process_initial_payment($invoice);
651 651
         }
652 652
 
653 653
         // Activate the subscriptions.
654
-        $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
654
+        $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
655 655
 
656
-        foreach ( $subscriptions as $subscription ) {
657
-            if ( $subscription->exists() ) {
658
-                $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
659
-                $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
656
+        foreach ($subscriptions as $subscription) {
657
+            if ($subscription->exists()) {
658
+                $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
659
+                $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
660 660
 
661
-                $subscription->set_next_renewal_date( $expiry );
662
-                $subscription->set_date_created( current_time( 'mysql' ) );
663
-                $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) );
661
+                $subscription->set_next_renewal_date($expiry);
662
+                $subscription->set_date_created(current_time('mysql'));
663
+                $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id()));
664 664
                 $subscription->activate();
665 665
             }
666 666
         }
667 667
 
668 668
 		// Redirect to the success page.
669
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
669
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
670 670
 
671 671
     }
672 672
 
@@ -677,20 +677,20 @@  discard block
 block discarded – undo
677 677
 	 * @param bool $should_expire
678 678
      * @param WPInv_Subscription $subscription
679 679
 	 */
680
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
680
+	public function maybe_renew_subscription($should_expire, $subscription) {
681 681
 
682 682
         // Ensure its our subscription && it's active.
683
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
683
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
684 684
             return $should_expire;
685 685
         }
686 686
 
687 687
         // If this is the last renewal, complete the subscription.
688
-        if ( $subscription->is_last_renewal() ) {
688
+        if ($subscription->is_last_renewal()) {
689 689
             $subscription->complete();
690 690
             return false;
691 691
         }
692 692
 
693
-        $this->renew_subscription( $subscription );
693
+        $this->renew_subscription($subscription);
694 694
 
695 695
         return false;
696 696
 
@@ -701,28 +701,28 @@  discard block
 block discarded – undo
701 701
 	 *
702 702
      * @param WPInv_Subscription $subscription
703 703
 	 */
704
-	public function renew_subscription( $subscription ) {
704
+	public function renew_subscription($subscription) {
705 705
 
706 706
 		// Generate the renewal invoice.
707 707
 		$new_invoice = $subscription->create_payment();
708 708
 		$old_invoice = $subscription->get_parent_payment();
709 709
 
710
-        if ( empty( $new_invoice ) ) {
711
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
710
+        if (empty($new_invoice)) {
711
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
712 712
             $subscription->failing();
713 713
             return;
714 714
         }
715 715
 
716 716
         // Charge the payment method.
717
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
718
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
719
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
717
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
718
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
719
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
720 720
 
721 721
 		// Do we have an error?
722
-		if ( is_wp_error( $result ) ) {
722
+		if (is_wp_error($result)) {
723 723
 
724 724
 			$old_invoice->add_note(
725
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
725
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
726 726
 				true,
727 727
 				false,
728 728
 				true
@@ -733,12 +733,12 @@  discard block
 block discarded – undo
733 733
 		}
734 734
 
735 735
 		// Process the response.
736
-		$this->process_charge_response( $result, $new_invoice );
736
+		$this->process_charge_response($result, $new_invoice);
737 737
 
738
-		if ( wpinv_get_errors() ) {
738
+		if (wpinv_get_errors()) {
739 739
 
740 740
 			$old_invoice->add_note(
741
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
741
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
742 742
 				true,
743 743
 				false,
744 744
 				true
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 
749 749
         }
750 750
 
751
-        $subscription->add_payment( array(), $new_invoice );
751
+        $subscription->add_payment(array(), $new_invoice);
752 752
         $subscription->renew();
753 753
     }
754 754
 
@@ -759,34 +759,34 @@  discard block
 block discarded – undo
759 759
 	 * @param GetPaid_Form_Item[] $items
760 760
 	 * @return WPInv_Invoice
761 761
 	 */
762
-	public function process_addons( $invoice, $items ) {
762
+	public function process_addons($invoice, $items) {
763 763
 
764 764
         global $getpaid_authorize_addons;
765 765
 
766 766
         $getpaid_authorize_addons = array();
767
-        foreach ( $items as $item ) {
767
+        foreach ($items as $item) {
768 768
 
769
-            if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) {
769
+            if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) {
770 770
                 $getpaid_authorize_addons[] = $item;
771 771
             }
772 772
 
773 773
         }
774 774
 
775
-        if ( empty( $getpaid_authorize_addons ) ) {
775
+        if (empty($getpaid_authorize_addons)) {
776 776
             return;
777 777
         }
778 778
 
779 779
         $invoice->recalculate_total();
780 780
 
781
-        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
782
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
781
+        $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
782
+		$customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
783 783
 
784
-        add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
785
-        $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
786
-        remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) );
784
+        add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2);
785
+        $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
786
+        remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'));
787 787
 
788
-        if ( is_wp_error( $result ) ) {
789
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
788
+        if (is_wp_error($result)) {
789
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
790 790
             return;
791 791
         }
792 792
 
@@ -799,19 +799,19 @@  discard block
 block discarded – undo
799 799
      * @param array $args
800 800
 	 * @return array
801 801
 	 */
802
-    public function filter_addons_request( $args ) {
802
+    public function filter_addons_request($args) {
803 803
 
804 804
         global $getpaid_authorize_addons;
805 805
         $total = 0;
806 806
 
807
-        foreach ( $getpaid_authorize_addons as $addon ) {
807
+        foreach ($getpaid_authorize_addons as $addon) {
808 808
             $total += $addon->get_sub_total();
809 809
         }
810 810
 
811 811
         $args['createTransactionRequest']['transactionRequest']['amount'] = $total;
812 812
 
813
-        if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) {
814
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
813
+        if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) {
814
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
815 815
         }
816 816
 
817 817
         return $args;
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
     public function sandbox_notice() {
825 825
 
826 826
         return sprintf(
827
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
827
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
828 828
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
829 829
             '</a>'
830 830
         );
@@ -836,42 +836,42 @@  discard block
 block discarded – undo
836 836
 	 *
837 837
 	 * @param array $admin_settings
838 838
 	 */
839
-	public function admin_settings( $admin_settings ) {
839
+	public function admin_settings($admin_settings) {
840 840
 
841 841
         $currencies = sprintf(
842
-            __( 'Supported Currencies: %s', 'invoicing' ),
843
-            implode( ', ', $this->currencies )
842
+            __('Supported Currencies: %s', 'invoicing'),
843
+            implode(', ', $this->currencies)
844 844
         );
845 845
 
846 846
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
847
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
847
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
848 848
 
849 849
         $admin_settings['authorizenet_login_id'] = array(
850 850
             'type' => 'text',
851 851
             'id'   => 'authorizenet_login_id',
852
-            'name' => __( 'API Login ID', 'invoicing' ),
853
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
852
+            'name' => __('API Login ID', 'invoicing'),
853
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
854 854
         );
855 855
 
856 856
         $admin_settings['authorizenet_transaction_key'] = array(
857 857
             'type' => 'text',
858 858
             'id'   => 'authorizenet_transaction_key',
859
-            'name' => __( 'Transaction Key', 'invoicing' ),
859
+            'name' => __('Transaction Key', 'invoicing'),
860 860
         );
861 861
 
862 862
         $admin_settings['authorizenet_signature_key'] = array(
863 863
             'type' => 'text',
864 864
             'id'   => 'authorizenet_signature_key',
865
-            'name' => __( 'Signature Key', 'invoicing' ),
866
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
865
+            'name' => __('Signature Key', 'invoicing'),
866
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
867 867
         );
868 868
 
869 869
         $admin_settings['authorizenet_ipn_url'] = array(
870 870
             'type'     => 'ipn_url',
871 871
             'id'       => 'authorizenet_ipn_url',
872
-            'name'     => __( 'Webhook URL', 'invoicing' ),
872
+            'name'     => __('Webhook URL', 'invoicing'),
873 873
             'std'      => $this->notify_url,
874
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
874
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
875 875
             'custom'   => 'authorizenet',
876 876
             'readonly' => true,
877 877
         );
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-manual-gateway.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'manual';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
34
-	public $order = 11;
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34
+    public $order = 11;
35 35
 
36 36
     /**
37
-	 * Class constructor.
38
-	 */
39
-	public function __construct() {
37
+     * Class constructor.
38
+     */
39
+    public function __construct() {
40 40
         parent::__construct();
41 41
 
42 42
         $this->title        = __( 'Test Gateway', 'invoicing' );
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
     }
47 47
 
48 48
     /**
49
-	 * Process Payment.
50
-	 *
51
-	 *
52
-	 * @param WPInv_Invoice $invoice Invoice.
53
-	 * @param array $submission_data Posted checkout fields.
54
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
-	 * @return array
56
-	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
49
+     * Process Payment.
50
+     *
51
+     *
52
+     * @param WPInv_Invoice $invoice Invoice.
53
+     * @param array $submission_data Posted checkout fields.
54
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
+     * @return array
56
+     */
57
+    public function process_payment( $invoice, $submission_data, $submission ) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     /**
88
-	 * (Maybe) renews a manual subscription profile.
89
-	 *
90
-	 *
91
-	 * @param bool $should_expire
88
+     * (Maybe) renews a manual subscription profile.
89
+     *
90
+     *
91
+     * @param bool $should_expire
92 92
      * @param WPInv_Subscription $subscription
93
-	 */
94
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
93
+     */
94
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
95 95
 
96 96
         // Ensure its our subscription && it's active.
97 97
         if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
     }
120 120
 
121 121
     /**
122
-	 * Processes invoice addons.
123
-	 *
124
-	 * @param WPInv_Invoice $invoice
125
-	 * @param GetPaid_Form_Item[] $items
126
-	 * @return WPInv_Invoice
127
-	 */
128
-	public function process_addons( $invoice, $items ) {
122
+     * Processes invoice addons.
123
+     *
124
+     * @param WPInv_Invoice $invoice
125
+     * @param GetPaid_Form_Item[] $items
126
+     * @return WPInv_Invoice
127
+     */
128
+    public function process_addons( $invoice, $items ) {
129 129
 
130 130
         foreach ( $items as $item ) {
131 131
             $invoice->add_item( $item );
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Manual Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
27
+    protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
 	public function __construct() {
40 40
         parent::__construct();
41 41
 
42
-        $this->title        = __( 'Test Gateway', 'invoicing' );
43
-        $this->method_title = __( 'Test Gateway', 'invoicing' );
42
+        $this->title        = __('Test Gateway', 'invoicing');
43
+        $this->method_title = __('Test Gateway', 'invoicing');
44 44
 
45
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
45
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
46 46
     }
47 47
 
48 48
     /**
@@ -54,25 +54,25 @@  discard block
 block discarded – undo
54 54
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55 55
 	 * @return array
56 56
 	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
57
+	public function process_payment($invoice, $submission_data, $submission) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
61 61
 
62 62
         // (Maybe) activate subscriptions.
63
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
63
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
64 64
 
65
-        if ( ! empty( $subscriptions ) ) {
66
-            $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
65
+        if (!empty($subscriptions)) {
66
+            $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
67 67
 
68
-            foreach ( $subscriptions as $subscription ) {
69
-                if ( $subscription->exists() ) {
70
-                    $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
71
-                    $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
68
+            foreach ($subscriptions as $subscription) {
69
+                if ($subscription->exists()) {
70
+                    $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
71
+                    $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
72 72
 
73
-                    $subscription->set_next_renewal_date( $expiry );
74
-                    $subscription->set_date_created( current_time( 'mysql' ) );
75
-                    $subscription->set_profile_id( $invoice->generate_key( 'manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) );
73
+                    $subscription->set_next_renewal_date($expiry);
74
+                    $subscription->set_date_created(current_time('mysql'));
75
+                    $subscription->set_profile_id($invoice->generate_key('manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id()));
76 76
                     $subscription->activate();
77 77
                 }
78 78
             }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         }
81 81
 
82 82
         // Send to the success page.
83
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
83
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
84 84
 
85 85
     }
86 86
 
@@ -91,15 +91,15 @@  discard block
 block discarded – undo
91 91
 	 * @param bool $should_expire
92 92
      * @param WPInv_Subscription $subscription
93 93
 	 */
94
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
94
+	public function maybe_renew_subscription($should_expire, $subscription) {
95 95
 
96 96
         // Ensure its our subscription && it's active.
97
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
97
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
98 98
             return $should_expire;
99 99
         }
100 100
 
101 101
         // If this is the last renewal, complete the subscription.
102
-        if ( $subscription->is_last_renewal() ) {
102
+        if ($subscription->is_last_renewal()) {
103 103
             $subscription->complete();
104 104
             return false;
105 105
         }
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 	 * @param GetPaid_Form_Item[] $items
126 126
 	 * @return WPInv_Invoice
127 127
 	 */
128
-	public function process_addons( $invoice, $items ) {
128
+	public function process_addons($invoice, $items) {
129 129
 
130
-        foreach ( $items as $item ) {
131
-            $invoice->add_item( $item );
130
+        foreach ($items as $item) {
131
+            $invoice->add_item($item);
132 132
         }
133 133
 
134 134
         $invoice->recalculate_total();
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 2 patches
Indentation   +732 added lines, -732 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 class WPInv_Item  extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'item';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'item';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'item';
25 25
 
26 26
     /**
27
-	 * Item Data array. This is the core item data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'parent_id'            => 0,
34
-		'status'               => 'draft',
35
-		'version'              => '',
36
-		'date_created'         => null,
27
+     * Item Data array. This is the core item data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'parent_id'            => 0,
34
+        'status'               => 'draft',
35
+        'version'              => '',
36
+        'date_created'         => null,
37 37
         'date_modified'        => null,
38 38
         'name'                 => '',
39 39
         'description'          => '',
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     );
59 59
 
60 60
     /**
61
-	 * Stores meta in cache for future reads.
62
-	 *
63
-	 * A group must be set to to enable caching.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	protected $cache_group = 'getpaid_items';
61
+     * Stores meta in cache for future reads.
62
+     *
63
+     * A group must be set to to enable caching.
64
+     *
65
+     * @var string
66
+     */
67
+    protected $cache_group = 'getpaid_items';
68 68
 
69 69
     /**
70 70
      * Stores a reference to the original WP_Post object
@@ -74,37 +74,37 @@  discard block
 block discarded – undo
74 74
     protected $post = null;
75 75
 
76 76
     /**
77
-	 * Get the item if ID is passed, otherwise the item is new and empty.
78
-	 *
79
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
-	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
94
-		} else {
95
-			$this->set_object_read( true );
96
-		}
77
+     * Get the item if ID is passed, otherwise the item is new and empty.
78
+     *
79
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
+     */
81
+    public function __construct( $item = 0 ) {
82
+        parent::__construct( $item );
83
+
84
+        if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
+            $this->set_id( $item );
86
+        } elseif ( $item instanceof self ) {
87
+            $this->set_id( $item->get_id() );
88
+        } elseif ( ! empty( $item->ID ) ) {
89
+            $this->set_id( $item->ID );
90
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
+            $this->set_id( $item_id );
92
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
+            $this->set_id( $item_id );
94
+        } else {
95
+            $this->set_object_read( true );
96
+        }
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
100 100
 
101
-		if ( $this->get_id() > 0 ) {
101
+        if ( $this->get_id() > 0 ) {
102 102
             $this->post = get_post( $this->get_id() );
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+            $this->data_store->read( $this );
105 105
         }
106 106
 
107
-	}
107
+    }
108 108
 
109 109
     /*
110 110
 	|--------------------------------------------------------------------------
@@ -122,401 +122,401 @@  discard block
 block discarded – undo
122 122
     */
123 123
 
124 124
     /**
125
-	 * Get parent item ID.
126
-	 *
127
-	 * @since 1.0.19
128
-	 * @param  string $context View or edit context.
129
-	 * @return int
130
-	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
125
+     * Get parent item ID.
126
+     *
127
+     * @since 1.0.19
128
+     * @param  string $context View or edit context.
129
+     * @return int
130
+     */
131
+    public function get_parent_id( $context = 'view' ) {
132
+        return (int) $this->get_prop( 'parent_id', $context );
133 133
     }
134 134
 
135 135
     /**
136
-	 * Get item status.
137
-	 *
138
-	 * @since 1.0.19
139
-	 * @param  string $context View or edit context.
140
-	 * @return string
141
-	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
136
+     * Get item status.
137
+     *
138
+     * @since 1.0.19
139
+     * @param  string $context View or edit context.
140
+     * @return string
141
+     */
142
+    public function get_status( $context = 'view' ) {
143
+        return $this->get_prop( 'status', $context );
144 144
     }
145 145
 
146 146
     /**
147
-	 * Get plugin version when the item was created.
148
-	 *
149
-	 * @since 1.0.19
150
-	 * @param  string $context View or edit context.
151
-	 * @return string
152
-	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
147
+     * Get plugin version when the item was created.
148
+     *
149
+     * @since 1.0.19
150
+     * @param  string $context View or edit context.
151
+     * @return string
152
+     */
153
+    public function get_version( $context = 'view' ) {
154
+        return $this->get_prop( 'version', $context );
155 155
     }
156 156
 
157 157
     /**
158
-	 * Get date when the item was created.
159
-	 *
160
-	 * @since 1.0.19
161
-	 * @param  string $context View or edit context.
162
-	 * @return string
163
-	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
158
+     * Get date when the item was created.
159
+     *
160
+     * @since 1.0.19
161
+     * @param  string $context View or edit context.
162
+     * @return string
163
+     */
164
+    public function get_date_created( $context = 'view' ) {
165
+        return $this->get_prop( 'date_created', $context );
166 166
     }
167 167
 
168 168
     /**
169
-	 * Get GMT date when the item was created.
170
-	 *
171
-	 * @since 1.0.19
172
-	 * @param  string $context View or edit context.
173
-	 * @return string
174
-	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
169
+     * Get GMT date when the item was created.
170
+     *
171
+     * @since 1.0.19
172
+     * @param  string $context View or edit context.
173
+     * @return string
174
+     */
175
+    public function get_date_created_gmt( $context = 'view' ) {
176 176
         $date = $this->get_date_created( $context );
177 177
 
178 178
         if ( $date ) {
179 179
             $date = get_gmt_from_date( $date );
180 180
         }
181
-		return $date;
181
+        return $date;
182 182
     }
183 183
 
184 184
     /**
185
-	 * Get date when the item was last modified.
186
-	 *
187
-	 * @since 1.0.19
188
-	 * @param  string $context View or edit context.
189
-	 * @return string
190
-	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
185
+     * Get date when the item was last modified.
186
+     *
187
+     * @since 1.0.19
188
+     * @param  string $context View or edit context.
189
+     * @return string
190
+     */
191
+    public function get_date_modified( $context = 'view' ) {
192
+        return $this->get_prop( 'date_modified', $context );
193 193
     }
194 194
 
195 195
     /**
196
-	 * Get GMT date when the item was last modified.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
196
+     * Get GMT date when the item was last modified.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_date_modified_gmt( $context = 'view' ) {
203 203
         $date = $this->get_date_modified( $context );
204 204
 
205 205
         if ( $date ) {
206 206
             $date = get_gmt_from_date( $date );
207 207
         }
208
-		return $date;
208
+        return $date;
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get the item name.
213
-	 *
214
-	 * @since 1.0.19
215
-	 * @param  string $context View or edit context.
216
-	 * @return string
217
-	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
212
+     * Get the item name.
213
+     *
214
+     * @since 1.0.19
215
+     * @param  string $context View or edit context.
216
+     * @return string
217
+     */
218
+    public function get_name( $context = 'view' ) {
219
+        return $this->get_prop( 'name', $context );
220 220
     }
221 221
 
222 222
     /**
223
-	 * Alias of self::get_name().
224
-	 *
225
-	 * @since 1.0.19
226
-	 * @param  string $context View or edit context.
227
-	 * @return string
228
-	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
223
+     * Alias of self::get_name().
224
+     *
225
+     * @since 1.0.19
226
+     * @param  string $context View or edit context.
227
+     * @return string
228
+     */
229
+    public function get_title( $context = 'view' ) {
230
+        return $this->get_name( $context );
231 231
     }
232 232
 
233 233
     /**
234
-	 * Get the item description.
235
-	 *
236
-	 * @since 1.0.19
237
-	 * @param  string $context View or edit context.
238
-	 * @return string
239
-	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
234
+     * Get the item description.
235
+     *
236
+     * @since 1.0.19
237
+     * @param  string $context View or edit context.
238
+     * @return string
239
+     */
240
+    public function get_description( $context = 'view' ) {
241
+        return $this->get_prop( 'description', $context );
242 242
     }
243 243
 
244 244
     /**
245
-	 * Alias of self::get_description().
246
-	 *
247
-	 * @since 1.0.19
248
-	 * @param  string $context View or edit context.
249
-	 * @return string
250
-	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
245
+     * Alias of self::get_description().
246
+     *
247
+     * @since 1.0.19
248
+     * @param  string $context View or edit context.
249
+     * @return string
250
+     */
251
+    public function get_excerpt( $context = 'view' ) {
252
+        return $this->get_description( $context );
253 253
     }
254 254
 
255 255
     /**
256
-	 * Alias of self::get_description().
257
-	 *
258
-	 * @since 1.0.19
259
-	 * @param  string $context View or edit context.
260
-	 * @return string
261
-	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
256
+     * Alias of self::get_description().
257
+     *
258
+     * @since 1.0.19
259
+     * @param  string $context View or edit context.
260
+     * @return string
261
+     */
262
+    public function get_summary( $context = 'view' ) {
263
+        return $this->get_description( $context );
264 264
     }
265 265
 
266 266
     /**
267
-	 * Get the owner of the item.
268
-	 *
269
-	 * @since 1.0.19
270
-	 * @param  string $context View or edit context.
271
-	 * @return int
272
-	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
275
-	}
267
+     * Get the owner of the item.
268
+     *
269
+     * @since 1.0.19
270
+     * @param  string $context View or edit context.
271
+     * @return int
272
+     */
273
+    public function get_author( $context = 'view' ) {
274
+        return (int) $this->get_prop( 'author', $context );
275
+    }
276 276
 	
277
-	/**
278
-	 * Alias of self::get_author().
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @param  string $context View or edit context.
282
-	 * @return int
283
-	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
286
-    }
287
-
288
-    /**
289
-	 * Get the price of the item.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return float
294
-	 */
295
-	public function get_price( $context = 'view' ) {
277
+    /**
278
+     * Alias of self::get_author().
279
+     *
280
+     * @since 1.0.19
281
+     * @param  string $context View or edit context.
282
+     * @return int
283
+     */
284
+    public function get_owner( $context = 'view' ) {
285
+        return $this->get_author( $context );
286
+    }
287
+
288
+    /**
289
+     * Get the price of the item.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return float
294
+     */
295
+    public function get_price( $context = 'view' ) {
296 296
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
297
-	}
297
+    }
298 298
 	
299
-	/**
300
-	 * Get the inital price of the item.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return float
305
-	 */
306
-	public function get_initial_price( $context = 'view' ) {
299
+    /**
300
+     * Get the inital price of the item.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return float
305
+     */
306
+    public function get_initial_price( $context = 'view' ) {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+        $price = (float) $this->get_price( $context );
309 309
 
310
-		if ( $this->has_free_trial() ) {
311
-			$price = 0;
312
-		}
310
+        if ( $this->has_free_trial() ) {
311
+            $price = 0;
312
+        }
313 313
 
314 314
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
315 315
     }
316 316
 
317 317
     /**
318
-	 * Returns a formated price.
319
-	 *
320
-	 * @since 1.0.19
321
-	 * @param  string $context View or edit context.
322
-	 * @return string
323
-	 */
318
+     * Returns a formated price.
319
+     *
320
+     * @since 1.0.19
321
+     * @param  string $context View or edit context.
322
+     * @return string
323
+     */
324 324
     public function get_the_price() {
325 325
         return wpinv_price( $this->get_price() );
326
-	}
327
-
328
-	/**
329
-	 * Returns the formated initial price.
330
-	 *
331
-	 * @since 1.0.19
332
-	 * @param  string $context View or edit context.
333
-	 * @return string
334
-	 */
326
+    }
327
+
328
+    /**
329
+     * Returns the formated initial price.
330
+     *
331
+     * @since 1.0.19
332
+     * @param  string $context View or edit context.
333
+     * @return string
334
+     */
335 335
     public function get_the_initial_price() {
336 336
         return wpinv_price( $this->get_initial_price() );
337 337
     }
338 338
 
339 339
     /**
340
-	 * Get the VAT rule of the item.
341
-	 *
342
-	 * @since 1.0.19
343
-	 * @param  string $context View or edit context.
344
-	 * @return string
345
-	 */
346
-	public function get_vat_rule( $context = 'view' ) {
340
+     * Get the VAT rule of the item.
341
+     *
342
+     * @since 1.0.19
343
+     * @param  string $context View or edit context.
344
+     * @return string
345
+     */
346
+    public function get_vat_rule( $context = 'view' ) {
347 347
         return $this->get_prop( 'vat_rule', $context );
348 348
     }
349 349
 
350 350
     /**
351
-	 * Get the VAT class of the item.
352
-	 *
353
-	 * @since 1.0.19
354
-	 * @param  string $context View or edit context.
355
-	 * @return string
356
-	 */
357
-	public function get_vat_class( $context = 'view' ) {
351
+     * Get the VAT class of the item.
352
+     *
353
+     * @since 1.0.19
354
+     * @param  string $context View or edit context.
355
+     * @return string
356
+     */
357
+    public function get_vat_class( $context = 'view' ) {
358 358
         return $this->get_prop( 'vat_class', $context );
359 359
     }
360 360
 
361 361
     /**
362
-	 * Get the type of the item.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param  string $context View or edit context.
366
-	 * @return string
367
-	 */
368
-	public function get_type( $context = 'view' ) {
362
+     * Get the type of the item.
363
+     *
364
+     * @since 1.0.19
365
+     * @param  string $context View or edit context.
366
+     * @return string
367
+     */
368
+    public function get_type( $context = 'view' ) {
369 369
         return $this->get_prop( 'type', $context );
370 370
     }
371 371
 
372 372
     /**
373
-	 * Get the custom id of the item.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $context View or edit context.
377
-	 * @return string
378
-	 */
379
-	public function get_custom_id( $context = 'view' ) {
373
+     * Get the custom id of the item.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $context View or edit context.
377
+     * @return string
378
+     */
379
+    public function get_custom_id( $context = 'view' ) {
380 380
         return $this->get_prop( 'custom_id', $context );
381 381
     }
382 382
 
383 383
     /**
384
-	 * Get the custom name of the item.
385
-	 *
386
-	 * @since 1.0.19
387
-	 * @param  string $context View or edit context.
388
-	 * @return string
389
-	 */
390
-	public function get_custom_name( $context = 'view' ) {
384
+     * Get the custom name of the item.
385
+     *
386
+     * @since 1.0.19
387
+     * @param  string $context View or edit context.
388
+     * @return string
389
+     */
390
+    public function get_custom_name( $context = 'view' ) {
391 391
         return $this->get_prop( 'custom_name', $context );
392 392
     }
393 393
 
394 394
     /**
395
-	 * Get the custom singular name of the item.
396
-	 *
397
-	 * @since 1.0.19
398
-	 * @param  string $context View or edit context.
399
-	 * @return string
400
-	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
395
+     * Get the custom singular name of the item.
396
+     *
397
+     * @since 1.0.19
398
+     * @param  string $context View or edit context.
399
+     * @return string
400
+     */
401
+    public function get_custom_singular_name( $context = 'view' ) {
402 402
         return $this->get_prop( 'custom_singular_name', $context );
403 403
     }
404 404
 
405 405
     /**
406
-	 * Checks if an item is editable..
407
-	 *
408
-	 * @since 1.0.19
409
-	 * @param  string $context View or edit context.
410
-	 * @return int
411
-	 */
412
-	public function get_is_editable( $context = 'view' ) {
406
+     * Checks if an item is editable..
407
+     *
408
+     * @since 1.0.19
409
+     * @param  string $context View or edit context.
410
+     * @return int
411
+     */
412
+    public function get_is_editable( $context = 'view' ) {
413 413
         return (int) $this->get_prop( 'is_editable', $context );
414 414
     }
415 415
 
416 416
     /**
417
-	 * Alias of self::get_is_editable().
418
-	 *
419
-	 * @since 1.0.19
420
-	 * @param  string $context View or edit context.
421
-	 * @return int
422
-	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
417
+     * Alias of self::get_is_editable().
418
+     *
419
+     * @since 1.0.19
420
+     * @param  string $context View or edit context.
421
+     * @return int
422
+     */
423
+    public function get_editable( $context = 'view' ) {
424
+        return $this->get_is_editable( $context );
425 425
     }
426 426
 
427 427
     /**
428
-	 * Checks if dynamic pricing is enabled.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $context View or edit context.
432
-	 * @return int
433
-	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
428
+     * Checks if dynamic pricing is enabled.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $context View or edit context.
432
+     * @return int
433
+     */
434
+    public function get_is_dynamic_pricing( $context = 'view' ) {
435 435
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
436 436
     }
437 437
 
438 438
     /**
439
-	 * Returns the minimum price if dynamic pricing is enabled.
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @param  string $context View or edit context.
443
-	 * @return float
444
-	 */
445
-	public function get_minimum_price( $context = 'view' ) {
439
+     * Returns the minimum price if dynamic pricing is enabled.
440
+     *
441
+     * @since 1.0.19
442
+     * @param  string $context View or edit context.
443
+     * @return float
444
+     */
445
+    public function get_minimum_price( $context = 'view' ) {
446 446
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
447 447
     }
448 448
 
449 449
     /**
450
-	 * Checks if this is a recurring item.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return int
455
-	 */
456
-	public function get_is_recurring( $context = 'view' ) {
450
+     * Checks if this is a recurring item.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return int
455
+     */
456
+    public function get_is_recurring( $context = 'view' ) {
457 457
         return (int) $this->get_prop( 'is_recurring', $context );
458
-	}
458
+    }
459 459
 	
460
-	/**
461
-	 * Get the recurring price of the item.
462
-	 *
463
-	 * @since 1.0.19
464
-	 * @param  string $context View or edit context.
465
-	 * @return float
466
-	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
460
+    /**
461
+     * Get the recurring price of the item.
462
+     *
463
+     * @since 1.0.19
464
+     * @param  string $context View or edit context.
465
+     * @return float
466
+     */
467
+    public function get_recurring_price( $context = 'view' ) {
468
+        $price = $this->get_price( $context );
469 469
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
470
-	}
471
-
472
-	/**
473
-	 * Get the formatted recurring price of the item.
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return string
478
-	 */
470
+    }
471
+
472
+    /**
473
+     * Get the formatted recurring price of the item.
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return string
478
+     */
479 479
     public function get_the_recurring_price() {
480 480
         return wpinv_price( $this->get_recurring_price() );
481
-	}
482
-
483
-	/**
484
-	 * Get the first renewal date (in timestamps) of the item.
485
-	 *
486
-	 * @since 1.0.19
487
-	 * @return int
488
-	 */
489
-	public function get_first_renewal_date() {
490
-
491
-		$periods = array(
492
-			'D' => 'days',
493
-			'W' => 'weeks',
494
-			'M' => 'months',
495
-			'Y' => 'years',
496
-		);
497
-
498
-		$period   = $this->get_recurring_period();
499
-		$interval = $this->get_recurring_interval();
500
-
501
-		if ( $this->has_free_trial() ) {
502
-			$period   = $this->get_trial_period();
503
-			$interval = $this->get_trial_interval();
504
-		}
505
-
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
481
+    }
482
+
483
+    /**
484
+     * Get the first renewal date (in timestamps) of the item.
485
+     *
486
+     * @since 1.0.19
487
+     * @return int
488
+     */
489
+    public function get_first_renewal_date() {
490
+
491
+        $periods = array(
492
+            'D' => 'days',
493
+            'W' => 'weeks',
494
+            'M' => 'months',
495
+            'Y' => 'years',
496
+        );
497
+
498
+        $period   = $this->get_recurring_period();
499
+        $interval = $this->get_recurring_interval();
500
+
501
+        if ( $this->has_free_trial() ) {
502
+            $period   = $this->get_trial_period();
503
+            $interval = $this->get_trial_interval();
504
+        }
505
+
506
+        $period       = $periods[ $period ];
507
+        $interval     = empty( $interval ) ? 1 : $interval;
508
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509 509
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
510 510
     }
511 511
 
512 512
     /**
513
-	 * Get the recurring period.
514
-	 *
515
-	 * @since 1.0.19
516
-	 * @param  bool $full Return abbreviation or in full.
517
-	 * @return string
518
-	 */
519
-	public function get_recurring_period( $full = false ) {
513
+     * Get the recurring period.
514
+     *
515
+     * @since 1.0.19
516
+     * @param  bool $full Return abbreviation or in full.
517
+     * @return string
518
+     */
519
+    public function get_recurring_period( $full = false ) {
520 520
         $period = $this->get_prop( 'recurring_period', 'view' );
521 521
 
522 522
         if ( $full && ! is_bool( $full ) ) {
@@ -527,58 +527,58 @@  discard block
 block discarded – undo
527 527
     }
528 528
 
529 529
     /**
530
-	 * Get the recurring interval.
531
-	 *
532
-	 * @since 1.0.19
533
-	 * @param  string $context View or edit context.
534
-	 * @return int
535
-	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
-		return max( 1, $interval );
530
+     * Get the recurring interval.
531
+     *
532
+     * @since 1.0.19
533
+     * @param  string $context View or edit context.
534
+     * @return int
535
+     */
536
+    public function get_recurring_interval( $context = 'view' ) {
537
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
+        return max( 1, $interval );
539 539
     }
540 540
 
541 541
     /**
542
-	 * Get the recurring limit.
543
-	 *
544
-	 * @since 1.0.19
545
-	 * @param  string $context View or edit context.
546
-	 * @return int
547
-	 */
548
-	public function get_recurring_limit( $context = 'view' ) {
542
+     * Get the recurring limit.
543
+     *
544
+     * @since 1.0.19
545
+     * @param  string $context View or edit context.
546
+     * @return int
547
+     */
548
+    public function get_recurring_limit( $context = 'view' ) {
549 549
         return (int) $this->get_prop( 'recurring_limit', $context );
550 550
     }
551 551
 
552 552
     /**
553
-	 * Checks if we have a free trial.
554
-	 *
555
-	 * @since 1.0.19
556
-	 * @param  string $context View or edit context.
557
-	 * @return int
558
-	 */
559
-	public function get_is_free_trial( $context = 'view' ) {
553
+     * Checks if we have a free trial.
554
+     *
555
+     * @since 1.0.19
556
+     * @param  string $context View or edit context.
557
+     * @return int
558
+     */
559
+    public function get_is_free_trial( $context = 'view' ) {
560 560
         return (int) $this->get_prop( 'is_free_trial', $context );
561 561
     }
562 562
 
563 563
     /**
564
-	 * Alias for self::get_is_free_trial().
565
-	 *
566
-	 * @since 1.0.19
567
-	 * @param  string $context View or edit context.
568
-	 * @return int
569
-	 */
570
-	public function get_free_trial( $context = 'view' ) {
564
+     * Alias for self::get_is_free_trial().
565
+     *
566
+     * @since 1.0.19
567
+     * @param  string $context View or edit context.
568
+     * @return int
569
+     */
570
+    public function get_free_trial( $context = 'view' ) {
571 571
         return $this->get_is_free_trial( $context );
572 572
     }
573 573
 
574 574
     /**
575
-	 * Get the trial period.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param  bool $full Return abbreviation or in full.
579
-	 * @return string
580
-	 */
581
-	public function get_trial_period( $full = false ) {
575
+     * Get the trial period.
576
+     *
577
+     * @since 1.0.19
578
+     * @param  bool $full Return abbreviation or in full.
579
+     * @return string
580
+     */
581
+    public function get_trial_period( $full = false ) {
582 582
         $period = $this->get_prop( 'trial_period', 'view' );
583 583
 
584 584
         if ( $full && ! is_bool( $full ) ) {
@@ -589,104 +589,104 @@  discard block
 block discarded – undo
589 589
     }
590 590
 
591 591
     /**
592
-	 * Get the trial interval.
593
-	 *
594
-	 * @since 1.0.19
595
-	 * @param  string $context View or edit context.
596
-	 * @return int
597
-	 */
598
-	public function get_trial_interval( $context = 'view' ) {
592
+     * Get the trial interval.
593
+     *
594
+     * @since 1.0.19
595
+     * @param  string $context View or edit context.
596
+     * @return int
597
+     */
598
+    public function get_trial_interval( $context = 'view' ) {
599 599
         return (int) $this->get_prop( 'trial_interval', $context );
600
-	}
600
+    }
601 601
 	
602
-	/**
603
-	 * Get the item's edit url.
604
-	 *
605
-	 * @since 1.0.19
606
-	 * @return string
607
-	 */
608
-	public function get_edit_url() {
602
+    /**
603
+     * Get the item's edit url.
604
+     *
605
+     * @since 1.0.19
606
+     * @return string
607
+     */
608
+    public function get_edit_url() {
609 609
         return get_edit_post_link( $this->get_id(), 'edit' );
610
-	}
611
-
612
-	/**
613
-	 * Given an item's name/custom id, it returns its id.
614
-	 *
615
-	 *
616
-	 * @static
617
-	 * @param string $value The item name or custom id.
618
-	 * @param string $field Either name or custom_id.
619
-	 * @param string $type in case you need to search for a given type.
620
-	 * @since 1.0.15
621
-	 * @return int
622
-	 */
623
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
624
-
625
-		// Trim the value.
626
-		$value = sanitize_text_field( $value );
627
-		if ( empty( $value ) ) {
628
-			return 0;
629
-		}
610
+    }
611
+
612
+    /**
613
+     * Given an item's name/custom id, it returns its id.
614
+     *
615
+     *
616
+     * @static
617
+     * @param string $value The item name or custom id.
618
+     * @param string $field Either name or custom_id.
619
+     * @param string $type in case you need to search for a given type.
620
+     * @since 1.0.15
621
+     * @return int
622
+     */
623
+    public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
624
+
625
+        // Trim the value.
626
+        $value = sanitize_text_field( $value );
627
+        if ( empty( $value ) ) {
628
+            return 0;
629
+        }
630 630
 
631 631
         // Valid fields.
632 632
         $fields = array( 'custom_id', 'name', 'slug' );
633 633
 
634
-		// Ensure a field has been passed.
635
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
636
-			return 0;
637
-		}
638
-
639
-		if ( $field == 'name' ) {
640
-			$field = 'slug';
641
-		}
642
-
643
-		// Maybe retrieve from the cache.
644
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
-		if ( ! empty( $item_id ) ) {
646
-			return $item_id;
647
-		}
648
-
649
-		// Fetch from the db.
650
-		$items = array();
651
-		if ( $field == 'slug' ) {
652
-			$items = get_posts(
653
-				array(
654
-					'post_type'      => 'wpi_item',
655
-					'name'           => $value,
656
-					'posts_per_page' => 1,
657
-					'post_status'    => 'any',
658
-				)
659
-			);
660
-		}
661
-
662
-		if ( $field =='custom_id' ) {
663
-			$items = get_posts(
664
-				array(
665
-					'post_type'      => 'wpi_item',
666
-					'posts_per_page' => 1,
667
-					'post_status'    => 'any',
668
-					'meta_query'     => array(
669
-						array(
670
-							'key'   => '_wpinv_type',
671
-                			'value' => $type,
672
-						),
673
-						array(
674
-							'key'   => '_wpinv_custom_id',
675
-                			'value' => $value,
676
-						)
677
-					)
678
-				)
679
-			);
680
-		}
681
-
682
-		if ( empty( $items ) ) {
683
-			return 0;
684
-		}
685
-
686
-		// Update the cache with our data
687
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
688
-
689
-		return $items[0]->ID;
634
+        // Ensure a field has been passed.
635
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
636
+            return 0;
637
+        }
638
+
639
+        if ( $field == 'name' ) {
640
+            $field = 'slug';
641
+        }
642
+
643
+        // Maybe retrieve from the cache.
644
+        $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
+        if ( ! empty( $item_id ) ) {
646
+            return $item_id;
647
+        }
648
+
649
+        // Fetch from the db.
650
+        $items = array();
651
+        if ( $field == 'slug' ) {
652
+            $items = get_posts(
653
+                array(
654
+                    'post_type'      => 'wpi_item',
655
+                    'name'           => $value,
656
+                    'posts_per_page' => 1,
657
+                    'post_status'    => 'any',
658
+                )
659
+            );
660
+        }
661
+
662
+        if ( $field =='custom_id' ) {
663
+            $items = get_posts(
664
+                array(
665
+                    'post_type'      => 'wpi_item',
666
+                    'posts_per_page' => 1,
667
+                    'post_status'    => 'any',
668
+                    'meta_query'     => array(
669
+                        array(
670
+                            'key'   => '_wpinv_type',
671
+                            'value' => $type,
672
+                        ),
673
+                        array(
674
+                            'key'   => '_wpinv_custom_id',
675
+                            'value' => $value,
676
+                        )
677
+                    )
678
+                )
679
+            );
680
+        }
681
+
682
+        if ( empty( $items ) ) {
683
+            return 0;
684
+        }
685
+
686
+        // Update the cache with our data
687
+        wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
688
+
689
+        return $items[0]->ID;
690 690
     }
691 691
 
692 692
     /**
@@ -719,52 +719,52 @@  discard block
 block discarded – undo
719 719
     */
720 720
 
721 721
     /**
722
-	 * Set parent order ID.
723
-	 *
724
-	 * @since 1.0.19
725
-	 */
726
-	public function set_parent_id( $value ) {
727
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
728
-			return;
729
-		}
730
-		$this->set_prop( 'parent_id', absint( $value ) );
731
-	}
732
-
733
-    /**
734
-	 * Sets item status.
735
-	 *
736
-	 * @since 1.0.19
737
-	 * @param  string $status New status.
738
-	 * @return array details of change.
739
-	 */
740
-	public function set_status( $status ) {
722
+     * Set parent order ID.
723
+     *
724
+     * @since 1.0.19
725
+     */
726
+    public function set_parent_id( $value ) {
727
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
728
+            return;
729
+        }
730
+        $this->set_prop( 'parent_id', absint( $value ) );
731
+    }
732
+
733
+    /**
734
+     * Sets item status.
735
+     *
736
+     * @since 1.0.19
737
+     * @param  string $status New status.
738
+     * @return array details of change.
739
+     */
740
+    public function set_status( $status ) {
741 741
         $old_status = $this->get_status();
742 742
 
743 743
         $this->set_prop( 'status', $status );
744 744
 
745
-		return array(
746
-			'from' => $old_status,
747
-			'to'   => $status,
748
-		);
745
+        return array(
746
+            'from' => $old_status,
747
+            'to'   => $status,
748
+        );
749 749
     }
750 750
 
751 751
     /**
752
-	 * Set plugin version when the item was created.
753
-	 *
754
-	 * @since 1.0.19
755
-	 */
756
-	public function set_version( $value ) {
757
-		$this->set_prop( 'version', $value );
752
+     * Set plugin version when the item was created.
753
+     *
754
+     * @since 1.0.19
755
+     */
756
+    public function set_version( $value ) {
757
+        $this->set_prop( 'version', $value );
758 758
     }
759 759
 
760 760
     /**
761
-	 * Set date when the item was created.
762
-	 *
763
-	 * @since 1.0.19
764
-	 * @param string $value Value to set.
761
+     * Set date when the item was created.
762
+     *
763
+     * @since 1.0.19
764
+     * @param string $value Value to set.
765 765
      * @return bool Whether or not the date was set.
766
-	 */
767
-	public function set_date_created( $value ) {
766
+     */
767
+    public function set_date_created( $value ) {
768 768
         $date = strtotime( $value );
769 769
 
770 770
         if ( $date ) {
@@ -777,13 +777,13 @@  discard block
 block discarded – undo
777 777
     }
778 778
 
779 779
     /**
780
-	 * Set date when the item was last modified.
781
-	 *
782
-	 * @since 1.0.19
783
-	 * @param string $value Value to set.
780
+     * Set date when the item was last modified.
781
+     *
782
+     * @since 1.0.19
783
+     * @param string $value Value to set.
784 784
      * @return bool Whether or not the date was set.
785
-	 */
786
-	public function set_date_modified( $value ) {
785
+     */
786
+    public function set_date_modified( $value ) {
787 787
         $date = strtotime( $value );
788 788
 
789 789
         if ( $date ) {
@@ -796,115 +796,115 @@  discard block
 block discarded – undo
796 796
     }
797 797
 
798 798
     /**
799
-	 * Set the item name.
800
-	 *
801
-	 * @since 1.0.19
802
-	 * @param  string $value New name.
803
-	 */
804
-	public function set_name( $value ) {
799
+     * Set the item name.
800
+     *
801
+     * @since 1.0.19
802
+     * @param  string $value New name.
803
+     */
804
+    public function set_name( $value ) {
805 805
         $name = sanitize_text_field( $value );
806
-		$this->set_prop( 'name', $name );
806
+        $this->set_prop( 'name', $name );
807 807
     }
808 808
 
809 809
     /**
810
-	 * Alias of self::set_name().
811
-	 *
812
-	 * @since 1.0.19
813
-	 * @param  string $value New name.
814
-	 */
815
-	public function set_title( $value ) {
816
-		$this->set_name( $value );
810
+     * Alias of self::set_name().
811
+     *
812
+     * @since 1.0.19
813
+     * @param  string $value New name.
814
+     */
815
+    public function set_title( $value ) {
816
+        $this->set_name( $value );
817 817
     }
818 818
 
819 819
     /**
820
-	 * Set the item description.
821
-	 *
822
-	 * @since 1.0.19
823
-	 * @param  string $value New description.
824
-	 */
825
-	public function set_description( $value ) {
826
-		$description = wp_kses_post( $value );
827
-		return $this->set_prop( 'description', $description );
820
+     * Set the item description.
821
+     *
822
+     * @since 1.0.19
823
+     * @param  string $value New description.
824
+     */
825
+    public function set_description( $value ) {
826
+        $description = wp_kses_post( $value );
827
+        return $this->set_prop( 'description', $description );
828 828
     }
829 829
 
830 830
     /**
831
-	 * Alias of self::set_description().
832
-	 *
833
-	 * @since 1.0.19
834
-	 * @param  string $value New description.
835
-	 */
836
-	public function set_excerpt( $value ) {
837
-		$this->set_description( $value );
831
+     * Alias of self::set_description().
832
+     *
833
+     * @since 1.0.19
834
+     * @param  string $value New description.
835
+     */
836
+    public function set_excerpt( $value ) {
837
+        $this->set_description( $value );
838 838
     }
839 839
 
840 840
     /**
841
-	 * Alias of self::set_description().
842
-	 *
843
-	 * @since 1.0.19
844
-	 * @param  string $value New description.
845
-	 */
846
-	public function set_summary( $value ) {
847
-		$this->set_description( $value );
841
+     * Alias of self::set_description().
842
+     *
843
+     * @since 1.0.19
844
+     * @param  string $value New description.
845
+     */
846
+    public function set_summary( $value ) {
847
+        $this->set_description( $value );
848 848
     }
849 849
 
850 850
     /**
851
-	 * Set the owner of the item.
852
-	 *
853
-	 * @since 1.0.19
854
-	 * @param  int $value New author.
855
-	 */
856
-	public function set_author( $value ) {
857
-		$this->set_prop( 'author', (int) $value );
858
-	}
851
+     * Set the owner of the item.
852
+     *
853
+     * @since 1.0.19
854
+     * @param  int $value New author.
855
+     */
856
+    public function set_author( $value ) {
857
+        $this->set_prop( 'author', (int) $value );
858
+    }
859 859
 	
860
-	/**
861
-	 * Alias of self::set_author().
862
-	 *
863
-	 * @since 1.0.19
864
-	 * @param  int $value New author.
865
-	 */
866
-	public function set_owner( $value ) {
867
-		$this->set_author( $value );
868
-    }
869
-
870
-    /**
871
-	 * Set the price of the item.
872
-	 *
873
-	 * @since 1.0.19
874
-	 * @param  float $value New price.
875
-	 */
876
-	public function set_price( $value ) {
860
+    /**
861
+     * Alias of self::set_author().
862
+     *
863
+     * @since 1.0.19
864
+     * @param  int $value New author.
865
+     */
866
+    public function set_owner( $value ) {
867
+        $this->set_author( $value );
868
+    }
869
+
870
+    /**
871
+     * Set the price of the item.
872
+     *
873
+     * @since 1.0.19
874
+     * @param  float $value New price.
875
+     */
876
+    public function set_price( $value ) {
877 877
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
878 878
     }
879 879
 
880 880
     /**
881
-	 * Set the VAT rule of the item.
882
-	 *
883
-	 * @since 1.0.19
884
-	 * @param  string $value new rule.
885
-	 */
886
-	public function set_vat_rule( $value ) {
881
+     * Set the VAT rule of the item.
882
+     *
883
+     * @since 1.0.19
884
+     * @param  string $value new rule.
885
+     */
886
+    public function set_vat_rule( $value ) {
887 887
         $this->set_prop( 'vat_rule', $value );
888 888
     }
889 889
 
890 890
     /**
891
-	 * Set the VAT class of the item.
892
-	 *
893
-	 * @since 1.0.19
894
-	 * @param  string $value new class.
895
-	 */
896
-	public function set_vat_class( $value ) {
891
+     * Set the VAT class of the item.
892
+     *
893
+     * @since 1.0.19
894
+     * @param  string $value new class.
895
+     */
896
+    public function set_vat_class( $value ) {
897 897
         $this->set_prop( 'vat_class', $value );
898 898
     }
899 899
 
900 900
     /**
901
-	 * Set the type of the item.
902
-	 *
903
-	 * @since 1.0.19
904
-	 * @param  string $value new item type.
905
-	 * @return string
906
-	 */
907
-	public function set_type( $value ) {
901
+     * Set the type of the item.
902
+     *
903
+     * @since 1.0.19
904
+     * @param  string $value new item type.
905
+     * @return string
906
+     */
907
+    public function set_type( $value ) {
908 908
 
909 909
         if ( empty( $value ) ) {
910 910
             $value = 'custom';
@@ -914,132 +914,132 @@  discard block
 block discarded – undo
914 914
     }
915 915
 
916 916
     /**
917
-	 * Set the custom id of the item.
918
-	 *
919
-	 * @since 1.0.19
920
-	 * @param  string $value new custom id.
921
-	 */
922
-	public function set_custom_id( $value ) {
917
+     * Set the custom id of the item.
918
+     *
919
+     * @since 1.0.19
920
+     * @param  string $value new custom id.
921
+     */
922
+    public function set_custom_id( $value ) {
923 923
         $this->set_prop( 'custom_id', $value );
924 924
     }
925 925
 
926 926
     /**
927
-	 * Set the custom name of the item.
928
-	 *
929
-	 * @since 1.0.19
930
-	 * @param  string $value new custom name.
931
-	 */
932
-	public function set_custom_name( $value ) {
927
+     * Set the custom name of the item.
928
+     *
929
+     * @since 1.0.19
930
+     * @param  string $value new custom name.
931
+     */
932
+    public function set_custom_name( $value ) {
933 933
         $this->set_prop( 'custom_name', $value );
934 934
     }
935 935
 
936 936
     /**
937
-	 * Set the custom singular name of the item.
938
-	 *
939
-	 * @since 1.0.19
940
-	 * @param  string $value new custom singular name.
941
-	 */
942
-	public function set_custom_singular_name( $value ) {
937
+     * Set the custom singular name of the item.
938
+     *
939
+     * @since 1.0.19
940
+     * @param  string $value new custom singular name.
941
+     */
942
+    public function set_custom_singular_name( $value ) {
943 943
         $this->set_prop( 'custom_singular_name', $value );
944 944
     }
945 945
 
946 946
     /**
947
-	 * Sets if an item is editable..
948
-	 *
949
-	 * @since 1.0.19
950
-	 * @param  int|bool $value whether or not the item is editable.
951
-	 */
952
-	public function set_is_editable( $value ) {
953
-		$this->set_prop( 'is_editable', (int) $value );
947
+     * Sets if an item is editable..
948
+     *
949
+     * @since 1.0.19
950
+     * @param  int|bool $value whether or not the item is editable.
951
+     */
952
+    public function set_is_editable( $value ) {
953
+        $this->set_prop( 'is_editable', (int) $value );
954 954
     }
955 955
 
956 956
     /**
957
-	 * Sets if dynamic pricing is enabled.
958
-	 *
959
-	 * @since 1.0.19
960
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
961
-	 */
962
-	public function set_is_dynamic_pricing( $value ) {
957
+     * Sets if dynamic pricing is enabled.
958
+     *
959
+     * @since 1.0.19
960
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
961
+     */
962
+    public function set_is_dynamic_pricing( $value ) {
963 963
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
964 964
     }
965 965
 
966 966
     /**
967
-	 * Sets the minimum price if dynamic pricing is enabled.
968
-	 *
969
-	 * @since 1.0.19
970
-	 * @param  float $value minimum price.
971
-	 */
972
-	public function set_minimum_price( $value ) {
967
+     * Sets the minimum price if dynamic pricing is enabled.
968
+     *
969
+     * @since 1.0.19
970
+     * @param  float $value minimum price.
971
+     */
972
+    public function set_minimum_price( $value ) {
973 973
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
974 974
     }
975 975
 
976 976
     /**
977
-	 * Sets if this is a recurring item.
978
-	 *
979
-	 * @since 1.0.19
980
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
981
-	 */
982
-	public function set_is_recurring( $value ) {
977
+     * Sets if this is a recurring item.
978
+     *
979
+     * @since 1.0.19
980
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
981
+     */
982
+    public function set_is_recurring( $value ) {
983 983
         $this->set_prop( 'is_recurring', (int) $value );
984 984
     }
985 985
 
986 986
     /**
987
-	 * Set the recurring period.
988
-	 *
989
-	 * @since 1.0.19
990
-	 * @param  string $value new period.
991
-	 */
992
-	public function set_recurring_period( $value ) {
987
+     * Set the recurring period.
988
+     *
989
+     * @since 1.0.19
990
+     * @param  string $value new period.
991
+     */
992
+    public function set_recurring_period( $value ) {
993 993
         $this->set_prop( 'recurring_period', $value );
994 994
     }
995 995
 
996 996
     /**
997
-	 * Set the recurring interval.
998
-	 *
999
-	 * @since 1.0.19
1000
-	 * @param  int $value recurring interval.
1001
-	 */
1002
-	public function set_recurring_interval( $value ) {
997
+     * Set the recurring interval.
998
+     *
999
+     * @since 1.0.19
1000
+     * @param  int $value recurring interval.
1001
+     */
1002
+    public function set_recurring_interval( $value ) {
1003 1003
         return $this->set_prop( 'recurring_interval', (int) $value );
1004 1004
     }
1005 1005
 
1006 1006
     /**
1007
-	 * Get the recurring limit.
1008
-	 * @since 1.0.19
1009
-	 * @param  int $value The recurring limit.
1010
-	 * @return int
1011
-	 */
1012
-	public function set_recurring_limit( $value ) {
1007
+     * Get the recurring limit.
1008
+     * @since 1.0.19
1009
+     * @param  int $value The recurring limit.
1010
+     * @return int
1011
+     */
1012
+    public function set_recurring_limit( $value ) {
1013 1013
         $this->set_prop( 'recurring_limit', (int) $value );
1014 1014
     }
1015 1015
 
1016 1016
     /**
1017
-	 * Checks if we have a free trial.
1018
-	 *
1019
-	 * @since 1.0.19
1020
-	 * @param  int|bool $value whether or not it has a free trial.
1021
-	 */
1022
-	public function set_is_free_trial( $value ) {
1017
+     * Checks if we have a free trial.
1018
+     *
1019
+     * @since 1.0.19
1020
+     * @param  int|bool $value whether or not it has a free trial.
1021
+     */
1022
+    public function set_is_free_trial( $value ) {
1023 1023
         $this->set_prop( 'is_free_trial', (int) $value );
1024 1024
     }
1025 1025
 
1026 1026
     /**
1027
-	 * Set the trial period.
1028
-	 *
1029
-	 * @since 1.0.19
1030
-	 * @param  string $value trial period.
1031
-	 */
1032
-	public function set_trial_period( $value ) {
1027
+     * Set the trial period.
1028
+     *
1029
+     * @since 1.0.19
1030
+     * @param  string $value trial period.
1031
+     */
1032
+    public function set_trial_period( $value ) {
1033 1033
         $this->set_prop( 'trial_period', $value );
1034 1034
     }
1035 1035
 
1036 1036
     /**
1037
-	 * Set the trial interval.
1038
-	 *
1039
-	 * @since 1.0.19
1040
-	 * @param  int $value trial interval.
1041
-	 */
1042
-	public function set_trial_interval( $value ) {
1037
+     * Set the trial interval.
1038
+     *
1039
+     * @since 1.0.19
1040
+     * @param  int $value trial interval.
1041
+     */
1042
+    public function set_trial_interval( $value ) {
1043 1043
         $this->set_prop( 'trial_interval', $value );
1044 1044
     }
1045 1045
 
@@ -1047,17 +1047,17 @@  discard block
 block discarded – undo
1047 1047
      * Create an item. For backwards compatibilty.
1048 1048
      * 
1049 1049
      * @deprecated
1050
-	 * @return int item id
1050
+     * @return int item id
1051 1051
      */
1052 1052
     public function create( $data = array() ) {
1053 1053
 
1054
-		// Set the properties.
1055
-		if ( is_array( $data ) ) {
1056
-			$this->set_props( $data );
1057
-		}
1054
+        // Set the properties.
1055
+        if ( is_array( $data ) ) {
1056
+            $this->set_props( $data );
1057
+        }
1058 1058
 
1059
-		// Save the item.
1060
-		return $this->save();
1059
+        // Save the item.
1060
+        return $this->save();
1061 1061
 
1062 1062
     }
1063 1063
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
      * Updates an item. For backwards compatibilty.
1066 1066
      * 
1067 1067
      * @deprecated
1068
-	 * @return int item id
1068
+     * @return int item id
1069 1069
      */
1070 1070
     public function update( $data = array() ) {
1071 1071
         return $this->create( $data );
@@ -1081,93 +1081,93 @@  discard block
 block discarded – undo
1081 1081
 	*/
1082 1082
 
1083 1083
     /**
1084
-	 * Checks whether the item has enabled dynamic pricing.
1085
-	 *
1086
-	 * @since 1.0.19
1087
-	 * @return bool
1088
-	 */
1089
-	public function user_can_set_their_price() {
1084
+     * Checks whether the item has enabled dynamic pricing.
1085
+     *
1086
+     * @since 1.0.19
1087
+     * @return bool
1088
+     */
1089
+    public function user_can_set_their_price() {
1090 1090
         return (bool) $this->get_is_dynamic_pricing();
1091
-	}
1091
+    }
1092 1092
 	
1093
-	/**
1094
-	 * Checks whether the item is recurring.
1095
-	 *
1096
-	 * @since 1.0.19
1097
-	 * @return bool
1098
-	 */
1099
-	public function is_recurring() {
1093
+    /**
1094
+     * Checks whether the item is recurring.
1095
+     *
1096
+     * @since 1.0.19
1097
+     * @return bool
1098
+     */
1099
+    public function is_recurring() {
1100 1100
         return (bool) $this->get_is_recurring();
1101 1101
     }
1102 1102
 
1103 1103
     /**
1104
-	 * Checks whether the item has a free trial.
1105
-	 *
1106
-	 * @since 1.0.19
1107
-	 * @return bool
1108
-	 */
1104
+     * Checks whether the item has a free trial.
1105
+     *
1106
+     * @since 1.0.19
1107
+     * @return bool
1108
+     */
1109 1109
     public function has_free_trial() {
1110 1110
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1111 1111
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1112 1112
     }
1113 1113
 
1114 1114
     /**
1115
-	 * Checks whether the item is free.
1116
-	 *
1117
-	 * @since 1.0.19
1118
-	 * @return bool
1119
-	 */
1115
+     * Checks whether the item is free.
1116
+     *
1117
+     * @since 1.0.19
1118
+     * @return bool
1119
+     */
1120 1120
     public function is_free() {
1121 1121
         $is_free   = $this->get_price() == 0;
1122 1122
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1123 1123
     }
1124 1124
 
1125 1125
     /**
1126
-	 * Checks the item status against a passed in status.
1127
-	 *
1128
-	 * @param array|string $status Status to check.
1129
-	 * @return bool
1130
-	 */
1131
-	public function has_status( $status ) {
1132
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1126
+     * Checks the item status against a passed in status.
1127
+     *
1128
+     * @param array|string $status Status to check.
1129
+     * @return bool
1130
+     */
1131
+    public function has_status( $status ) {
1132
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1134 1134
     }
1135 1135
 
1136 1136
     /**
1137
-	 * Checks the item type against a passed in types.
1138
-	 *
1139
-	 * @param array|string $type Type to check.
1140
-	 * @return bool
1141
-	 */
1142
-	public function is_type( $type ) {
1143
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1145
-	}
1137
+     * Checks the item type against a passed in types.
1138
+     *
1139
+     * @param array|string $type Type to check.
1140
+     * @return bool
1141
+     */
1142
+    public function is_type( $type ) {
1143
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1145
+    }
1146 1146
 
1147 1147
     /**
1148
-	 * Checks whether the item is editable.
1149
-	 *
1150
-	 * @since 1.0.19
1151
-	 * @return bool
1152
-	 */
1148
+     * Checks whether the item is editable.
1149
+     *
1150
+     * @since 1.0.19
1151
+     * @return bool
1152
+     */
1153 1153
     public function is_editable() {
1154 1154
         $is_editable = $this->get_is_editable();
1155 1155
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1156
-	}
1156
+    }
1157 1157
 
1158
-	/**
1159
-	 * Returns an array of cart fees.
1160
-	 */
1161
-	public function get_fees() {
1158
+    /**
1159
+     * Returns an array of cart fees.
1160
+     */
1161
+    public function get_fees() {
1162 1162
         return array();
1163 1163
     }
1164 1164
 
1165 1165
     /**
1166
-	 * Checks whether the item is purchasable.
1167
-	 *
1168
-	 * @since 1.0.19
1169
-	 * @return bool
1170
-	 */
1166
+     * Checks whether the item is purchasable.
1167
+     *
1168
+     * @since 1.0.19
1169
+     * @return bool
1170
+     */
1171 1171
     public function can_purchase() {
1172 1172
         $can_purchase = $this->exists();
1173 1173
 
@@ -1179,11 +1179,11 @@  discard block
 block discarded – undo
1179 1179
     }
1180 1180
 
1181 1181
     /**
1182
-	 * Checks whether the item supports dynamic pricing.
1183
-	 *
1184
-	 * @since 1.0.19
1185
-	 * @return bool
1186
-	 */
1182
+     * Checks whether the item supports dynamic pricing.
1183
+     *
1184
+     * @since 1.0.19
1185
+     * @return bool
1186
+     */
1187 1187
     public function supports_dynamic_pricing() {
1188 1188
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1189 1189
     }
Please login to merge, or discard this patch.
Spacing   +211 added lines, -211 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -78,30 +78,30 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80 80
 	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
81
+	public function __construct($item = 0) {
82
+		parent::__construct($item);
83
+
84
+		if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) {
85
+			$this->set_id($item);
86
+		} elseif ($item instanceof self) {
87
+			$this->set_id($item->get_id());
88
+		} elseif (!empty($item->ID)) {
89
+			$this->set_id($item->ID);
90
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) {
91
+			$this->set_id($item_id);
92
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) {
93
+			$this->set_id($item_id);
94 94
 		} else {
95
-			$this->set_object_read( true );
95
+			$this->set_object_read(true);
96 96
 		}
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
100 100
 
101
-		if ( $this->get_id() > 0 ) {
102
-            $this->post = get_post( $this->get_id() );
101
+		if ($this->get_id() > 0) {
102
+            $this->post = get_post($this->get_id());
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+			$this->data_store->read($this);
105 105
         }
106 106
 
107 107
 	}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * @param  string $context View or edit context.
129 129
 	 * @return int
130 130
 	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
131
+	public function get_parent_id($context = 'view') {
132
+		return (int) $this->get_prop('parent_id', $context);
133 133
     }
134 134
 
135 135
     /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	 * @param  string $context View or edit context.
140 140
 	 * @return string
141 141
 	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
142
+	public function get_status($context = 'view') {
143
+		return $this->get_prop('status', $context);
144 144
     }
145 145
 
146 146
     /**
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 	 * @param  string $context View or edit context.
151 151
 	 * @return string
152 152
 	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
153
+	public function get_version($context = 'view') {
154
+		return $this->get_prop('version', $context);
155 155
     }
156 156
 
157 157
     /**
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 	 * @param  string $context View or edit context.
162 162
 	 * @return string
163 163
 	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
164
+	public function get_date_created($context = 'view') {
165
+		return $this->get_prop('date_created', $context);
166 166
     }
167 167
 
168 168
     /**
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	 * @param  string $context View or edit context.
173 173
 	 * @return string
174 174
 	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
176
-        $date = $this->get_date_created( $context );
175
+	public function get_date_created_gmt($context = 'view') {
176
+        $date = $this->get_date_created($context);
177 177
 
178
-        if ( $date ) {
179
-            $date = get_gmt_from_date( $date );
178
+        if ($date) {
179
+            $date = get_gmt_from_date($date);
180 180
         }
181 181
 		return $date;
182 182
     }
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 	 * @param  string $context View or edit context.
189 189
 	 * @return string
190 190
 	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
191
+	public function get_date_modified($context = 'view') {
192
+		return $this->get_prop('date_modified', $context);
193 193
     }
194 194
 
195 195
     /**
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
203
-        $date = $this->get_date_modified( $context );
202
+	public function get_date_modified_gmt($context = 'view') {
203
+        $date = $this->get_date_modified($context);
204 204
 
205
-        if ( $date ) {
206
-            $date = get_gmt_from_date( $date );
205
+        if ($date) {
206
+            $date = get_gmt_from_date($date);
207 207
         }
208 208
 		return $date;
209 209
     }
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
 	 * @param  string $context View or edit context.
216 216
 	 * @return string
217 217
 	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
218
+	public function get_name($context = 'view') {
219
+		return $this->get_prop('name', $context);
220 220
     }
221 221
 
222 222
     /**
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 	 * @param  string $context View or edit context.
227 227
 	 * @return string
228 228
 	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
229
+	public function get_title($context = 'view') {
230
+		return $this->get_name($context);
231 231
     }
232 232
 
233 233
     /**
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 	 * @param  string $context View or edit context.
238 238
 	 * @return string
239 239
 	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
240
+	public function get_description($context = 'view') {
241
+		return $this->get_prop('description', $context);
242 242
     }
243 243
 
244 244
     /**
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 * @param  string $context View or edit context.
249 249
 	 * @return string
250 250
 	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
251
+	public function get_excerpt($context = 'view') {
252
+		return $this->get_description($context);
253 253
     }
254 254
 
255 255
     /**
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
 	 * @param  string $context View or edit context.
260 260
 	 * @return string
261 261
 	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
262
+	public function get_summary($context = 'view') {
263
+		return $this->get_description($context);
264 264
     }
265 265
 
266 266
     /**
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 	 * @param  string $context View or edit context.
271 271
 	 * @return int
272 272
 	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
273
+	public function get_author($context = 'view') {
274
+		return (int) $this->get_prop('author', $context);
275 275
 	}
276 276
 	
277 277
 	/**
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 * @param  string $context View or edit context.
282 282
 	 * @return int
283 283
 	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
284
+	public function get_owner($context = 'view') {
285
+		return $this->get_author($context);
286 286
     }
287 287
 
288 288
     /**
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	 * @param  string $context View or edit context.
293 293
 	 * @return float
294 294
 	 */
295
-	public function get_price( $context = 'view' ) {
296
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
295
+	public function get_price($context = 'view') {
296
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
297 297
 	}
298 298
 	
299 299
 	/**
@@ -303,15 +303,15 @@  discard block
 block discarded – undo
303 303
 	 * @param  string $context View or edit context.
304 304
 	 * @return float
305 305
 	 */
306
-	public function get_initial_price( $context = 'view' ) {
306
+	public function get_initial_price($context = 'view') {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+		$price = (float) $this->get_price($context);
309 309
 
310
-		if ( $this->has_free_trial() ) {
310
+		if ($this->has_free_trial()) {
311 311
 			$price = 0;
312 312
 		}
313 313
 
314
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
314
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this));
315 315
     }
316 316
 
317 317
     /**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @return string
323 323
 	 */
324 324
     public function get_the_price() {
325
-        return wpinv_price( $this->get_price() );
325
+        return wpinv_price($this->get_price());
326 326
 	}
327 327
 
328 328
 	/**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @return string
334 334
 	 */
335 335
     public function get_the_initial_price() {
336
-        return wpinv_price( $this->get_initial_price() );
336
+        return wpinv_price($this->get_initial_price());
337 337
     }
338 338
 
339 339
     /**
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
 	 * @param  string $context View or edit context.
344 344
 	 * @return string
345 345
 	 */
346
-	public function get_vat_rule( $context = 'view' ) {
347
-        return $this->get_prop( 'vat_rule', $context );
346
+	public function get_vat_rule($context = 'view') {
347
+        return $this->get_prop('vat_rule', $context);
348 348
     }
349 349
 
350 350
     /**
@@ -354,8 +354,8 @@  discard block
 block discarded – undo
354 354
 	 * @param  string $context View or edit context.
355 355
 	 * @return string
356 356
 	 */
357
-	public function get_vat_class( $context = 'view' ) {
358
-        return $this->get_prop( 'vat_class', $context );
357
+	public function get_vat_class($context = 'view') {
358
+        return $this->get_prop('vat_class', $context);
359 359
     }
360 360
 
361 361
     /**
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
 	 * @param  string $context View or edit context.
366 366
 	 * @return string
367 367
 	 */
368
-	public function get_type( $context = 'view' ) {
369
-        return $this->get_prop( 'type', $context );
368
+	public function get_type($context = 'view') {
369
+        return $this->get_prop('type', $context);
370 370
     }
371 371
 
372 372
     /**
@@ -376,8 +376,8 @@  discard block
 block discarded – undo
376 376
 	 * @param  string $context View or edit context.
377 377
 	 * @return string
378 378
 	 */
379
-	public function get_custom_id( $context = 'view' ) {
380
-        return $this->get_prop( 'custom_id', $context );
379
+	public function get_custom_id($context = 'view') {
380
+        return $this->get_prop('custom_id', $context);
381 381
     }
382 382
 
383 383
     /**
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 	 * @param  string $context View or edit context.
388 388
 	 * @return string
389 389
 	 */
390
-	public function get_custom_name( $context = 'view' ) {
391
-        return $this->get_prop( 'custom_name', $context );
390
+	public function get_custom_name($context = 'view') {
391
+        return $this->get_prop('custom_name', $context);
392 392
     }
393 393
 
394 394
     /**
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 	 * @param  string $context View or edit context.
399 399
 	 * @return string
400 400
 	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
402
-        return $this->get_prop( 'custom_singular_name', $context );
401
+	public function get_custom_singular_name($context = 'view') {
402
+        return $this->get_prop('custom_singular_name', $context);
403 403
     }
404 404
 
405 405
     /**
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 	 * @param  string $context View or edit context.
410 410
 	 * @return int
411 411
 	 */
412
-	public function get_is_editable( $context = 'view' ) {
413
-        return (int) $this->get_prop( 'is_editable', $context );
412
+	public function get_is_editable($context = 'view') {
413
+        return (int) $this->get_prop('is_editable', $context);
414 414
     }
415 415
 
416 416
     /**
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	 * @param  string $context View or edit context.
421 421
 	 * @return int
422 422
 	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
423
+	public function get_editable($context = 'view') {
424
+		return $this->get_is_editable($context);
425 425
     }
426 426
 
427 427
     /**
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @param  string $context View or edit context.
432 432
 	 * @return int
433 433
 	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
435
-        return (int) $this->get_prop( 'is_dynamic_pricing', $context );
434
+	public function get_is_dynamic_pricing($context = 'view') {
435
+        return (int) $this->get_prop('is_dynamic_pricing', $context);
436 436
     }
437 437
 
438 438
     /**
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 	 * @param  string $context View or edit context.
443 443
 	 * @return float
444 444
 	 */
445
-	public function get_minimum_price( $context = 'view' ) {
446
-        return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
445
+	public function get_minimum_price($context = 'view') {
446
+        return wpinv_sanitize_amount($this->get_prop('minimum_price', $context));
447 447
     }
448 448
 
449 449
     /**
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 	 * @param  string $context View or edit context.
454 454
 	 * @return int
455 455
 	 */
456
-	public function get_is_recurring( $context = 'view' ) {
457
-        return (int) $this->get_prop( 'is_recurring', $context );
456
+	public function get_is_recurring($context = 'view') {
457
+        return (int) $this->get_prop('is_recurring', $context);
458 458
 	}
459 459
 	
460 460
 	/**
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 	 * @param  string $context View or edit context.
465 465
 	 * @return float
466 466
 	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
469
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
467
+	public function get_recurring_price($context = 'view') {
468
+		$price = $this->get_price($context);
469
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID));
470 470
 	}
471 471
 
472 472
 	/**
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return string
478 478
 	 */
479 479
     public function get_the_recurring_price() {
480
-        return wpinv_price( $this->get_recurring_price() );
480
+        return wpinv_price($this->get_recurring_price());
481 481
 	}
482 482
 
483 483
 	/**
@@ -498,15 +498,15 @@  discard block
 block discarded – undo
498 498
 		$period   = $this->get_recurring_period();
499 499
 		$interval = $this->get_recurring_interval();
500 500
 
501
-		if ( $this->has_free_trial() ) {
501
+		if ($this->has_free_trial()) {
502 502
 			$period   = $this->get_trial_period();
503 503
 			$interval = $this->get_trial_interval();
504 504
 		}
505 505
 
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509
-        return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
506
+		$period       = $periods[$period];
507
+		$interval     = empty($interval) ? 1 : $interval;
508
+		$next_renewal = strtotime("+$interval $period", current_time('timestamp'));
509
+        return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this);
510 510
     }
511 511
 
512 512
     /**
@@ -516,14 +516,14 @@  discard block
 block discarded – undo
516 516
 	 * @param  bool $full Return abbreviation or in full.
517 517
 	 * @return string
518 518
 	 */
519
-	public function get_recurring_period( $full = false ) {
520
-        $period = $this->get_prop( 'recurring_period', 'view' );
519
+	public function get_recurring_period($full = false) {
520
+        $period = $this->get_prop('recurring_period', 'view');
521 521
 
522
-        if ( $full && ! is_bool( $full ) ) {
522
+        if ($full && !is_bool($full)) {
523 523
             $full = false;
524 524
         }
525 525
 
526
-        return getpaid_sanitize_recurring_period( $period, $full );
526
+        return getpaid_sanitize_recurring_period($period, $full);
527 527
     }
528 528
 
529 529
     /**
@@ -533,9 +533,9 @@  discard block
 block discarded – undo
533 533
 	 * @param  string $context View or edit context.
534 534
 	 * @return int
535 535
 	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
-		return max( 1, $interval );
536
+	public function get_recurring_interval($context = 'view') {
537
+		$interval = absint($this->get_prop('recurring_interval', $context));
538
+		return max(1, $interval);
539 539
     }
540 540
 
541 541
     /**
@@ -545,8 +545,8 @@  discard block
 block discarded – undo
545 545
 	 * @param  string $context View or edit context.
546 546
 	 * @return int
547 547
 	 */
548
-	public function get_recurring_limit( $context = 'view' ) {
549
-        return (int) $this->get_prop( 'recurring_limit', $context );
548
+	public function get_recurring_limit($context = 'view') {
549
+        return (int) $this->get_prop('recurring_limit', $context);
550 550
     }
551 551
 
552 552
     /**
@@ -556,8 +556,8 @@  discard block
 block discarded – undo
556 556
 	 * @param  string $context View or edit context.
557 557
 	 * @return int
558 558
 	 */
559
-	public function get_is_free_trial( $context = 'view' ) {
560
-        return (int) $this->get_prop( 'is_free_trial', $context );
559
+	public function get_is_free_trial($context = 'view') {
560
+        return (int) $this->get_prop('is_free_trial', $context);
561 561
     }
562 562
 
563 563
     /**
@@ -567,8 +567,8 @@  discard block
 block discarded – undo
567 567
 	 * @param  string $context View or edit context.
568 568
 	 * @return int
569 569
 	 */
570
-	public function get_free_trial( $context = 'view' ) {
571
-        return $this->get_is_free_trial( $context );
570
+	public function get_free_trial($context = 'view') {
571
+        return $this->get_is_free_trial($context);
572 572
     }
573 573
 
574 574
     /**
@@ -578,14 +578,14 @@  discard block
 block discarded – undo
578 578
 	 * @param  bool $full Return abbreviation or in full.
579 579
 	 * @return string
580 580
 	 */
581
-	public function get_trial_period( $full = false ) {
582
-        $period = $this->get_prop( 'trial_period', 'view' );
581
+	public function get_trial_period($full = false) {
582
+        $period = $this->get_prop('trial_period', 'view');
583 583
 
584
-        if ( $full && ! is_bool( $full ) ) {
584
+        if ($full && !is_bool($full)) {
585 585
             $full = false;
586 586
         }
587 587
 
588
-        return getpaid_sanitize_recurring_period( $period, $full );
588
+        return getpaid_sanitize_recurring_period($period, $full);
589 589
     }
590 590
 
591 591
     /**
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
 	 * @param  string $context View or edit context.
596 596
 	 * @return int
597 597
 	 */
598
-	public function get_trial_interval( $context = 'view' ) {
599
-        return (int) $this->get_prop( 'trial_interval', $context );
598
+	public function get_trial_interval($context = 'view') {
599
+        return (int) $this->get_prop('trial_interval', $context);
600 600
 	}
601 601
 	
602 602
 	/**
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 	 * @return string
607 607
 	 */
608 608
 	public function get_edit_url() {
609
-        return get_edit_post_link( $this->get_id(), 'edit' );
609
+        return get_edit_post_link($this->get_id(), 'edit');
610 610
 	}
611 611
 
612 612
 	/**
@@ -620,35 +620,35 @@  discard block
 block discarded – undo
620 620
 	 * @since 1.0.15
621 621
 	 * @return int
622 622
 	 */
623
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
623
+	public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') {
624 624
 
625 625
 		// Trim the value.
626
-		$value = sanitize_text_field( $value );
627
-		if ( empty( $value ) ) {
626
+		$value = sanitize_text_field($value);
627
+		if (empty($value)) {
628 628
 			return 0;
629 629
 		}
630 630
 
631 631
         // Valid fields.
632
-        $fields = array( 'custom_id', 'name', 'slug' );
632
+        $fields = array('custom_id', 'name', 'slug');
633 633
 
634 634
 		// Ensure a field has been passed.
635
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
635
+		if (empty($field) || !in_array($field, $fields)) {
636 636
 			return 0;
637 637
 		}
638 638
 
639
-		if ( $field == 'name' ) {
639
+		if ($field == 'name') {
640 640
 			$field = 'slug';
641 641
 		}
642 642
 
643 643
 		// Maybe retrieve from the cache.
644
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
-		if ( ! empty( $item_id ) ) {
644
+		$item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids");
645
+		if (!empty($item_id)) {
646 646
 			return $item_id;
647 647
 		}
648 648
 
649 649
 		// Fetch from the db.
650 650
 		$items = array();
651
-		if ( $field == 'slug' ) {
651
+		if ($field == 'slug') {
652 652
 			$items = get_posts(
653 653
 				array(
654 654
 					'post_type'      => 'wpi_item',
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 			);
660 660
 		}
661 661
 
662
-		if ( $field =='custom_id' ) {
662
+		if ($field == 'custom_id') {
663 663
 			$items = get_posts(
664 664
 				array(
665 665
 					'post_type'      => 'wpi_item',
@@ -679,12 +679,12 @@  discard block
 block discarded – undo
679 679
 			);
680 680
 		}
681 681
 
682
-		if ( empty( $items ) ) {
682
+		if (empty($items)) {
683 683
 			return 0;
684 684
 		}
685 685
 
686 686
 		// Update the cache with our data
687
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
687
+		wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids");
688 688
 
689 689
 		return $items[0]->ID;
690 690
     }
@@ -692,19 +692,19 @@  discard block
 block discarded – undo
692 692
     /**
693 693
      * Margic method for retrieving a property.
694 694
      */
695
-    public function __get( $key ) {
695
+    public function __get($key) {
696 696
 
697 697
         // Check if we have a helper method for that.
698
-        if ( method_exists( $this, 'get_' . $key ) ) {
699
-            return call_user_func( array( $this, 'get_' . $key ) );
698
+        if (method_exists($this, 'get_' . $key)) {
699
+            return call_user_func(array($this, 'get_' . $key));
700 700
         }
701 701
 
702 702
         // Check if the key is in the associated $post object.
703
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
703
+        if (!empty($this->post) && isset($this->post->$key)) {
704 704
             return $this->post->$key;
705 705
         }
706 706
 
707
-        return $this->get_prop( $key );
707
+        return $this->get_prop($key);
708 708
 
709 709
     }
710 710
 
@@ -723,11 +723,11 @@  discard block
 block discarded – undo
723 723
 	 *
724 724
 	 * @since 1.0.19
725 725
 	 */
726
-	public function set_parent_id( $value ) {
727
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
726
+	public function set_parent_id($value) {
727
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
728 728
 			return;
729 729
 		}
730
-		$this->set_prop( 'parent_id', absint( $value ) );
730
+		$this->set_prop('parent_id', absint($value));
731 731
 	}
732 732
 
733 733
     /**
@@ -737,10 +737,10 @@  discard block
 block discarded – undo
737 737
 	 * @param  string $status New status.
738 738
 	 * @return array details of change.
739 739
 	 */
740
-	public function set_status( $status ) {
740
+	public function set_status($status) {
741 741
         $old_status = $this->get_status();
742 742
 
743
-        $this->set_prop( 'status', $status );
743
+        $this->set_prop('status', $status);
744 744
 
745 745
 		return array(
746 746
 			'from' => $old_status,
@@ -753,8 +753,8 @@  discard block
 block discarded – undo
753 753
 	 *
754 754
 	 * @since 1.0.19
755 755
 	 */
756
-	public function set_version( $value ) {
757
-		$this->set_prop( 'version', $value );
756
+	public function set_version($value) {
757
+		$this->set_prop('version', $value);
758 758
     }
759 759
 
760 760
     /**
@@ -764,11 +764,11 @@  discard block
 block discarded – undo
764 764
 	 * @param string $value Value to set.
765 765
      * @return bool Whether or not the date was set.
766 766
 	 */
767
-	public function set_date_created( $value ) {
768
-        $date = strtotime( $value );
767
+	public function set_date_created($value) {
768
+        $date = strtotime($value);
769 769
 
770
-        if ( $date ) {
771
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
770
+        if ($date) {
771
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
772 772
             return true;
773 773
         }
774 774
 
@@ -783,11 +783,11 @@  discard block
 block discarded – undo
783 783
 	 * @param string $value Value to set.
784 784
      * @return bool Whether or not the date was set.
785 785
 	 */
786
-	public function set_date_modified( $value ) {
787
-        $date = strtotime( $value );
786
+	public function set_date_modified($value) {
787
+        $date = strtotime($value);
788 788
 
789
-        if ( $date ) {
790
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
789
+        if ($date) {
790
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
791 791
             return true;
792 792
         }
793 793
 
@@ -801,9 +801,9 @@  discard block
 block discarded – undo
801 801
 	 * @since 1.0.19
802 802
 	 * @param  string $value New name.
803 803
 	 */
804
-	public function set_name( $value ) {
805
-        $name = sanitize_text_field( $value );
806
-		$this->set_prop( 'name', $name );
804
+	public function set_name($value) {
805
+        $name = sanitize_text_field($value);
806
+		$this->set_prop('name', $name);
807 807
     }
808 808
 
809 809
     /**
@@ -812,8 +812,8 @@  discard block
 block discarded – undo
812 812
 	 * @since 1.0.19
813 813
 	 * @param  string $value New name.
814 814
 	 */
815
-	public function set_title( $value ) {
816
-		$this->set_name( $value );
815
+	public function set_title($value) {
816
+		$this->set_name($value);
817 817
     }
818 818
 
819 819
     /**
@@ -822,9 +822,9 @@  discard block
 block discarded – undo
822 822
 	 * @since 1.0.19
823 823
 	 * @param  string $value New description.
824 824
 	 */
825
-	public function set_description( $value ) {
826
-		$description = wp_kses_post( $value );
827
-		return $this->set_prop( 'description', $description );
825
+	public function set_description($value) {
826
+		$description = wp_kses_post($value);
827
+		return $this->set_prop('description', $description);
828 828
     }
829 829
 
830 830
     /**
@@ -833,8 +833,8 @@  discard block
 block discarded – undo
833 833
 	 * @since 1.0.19
834 834
 	 * @param  string $value New description.
835 835
 	 */
836
-	public function set_excerpt( $value ) {
837
-		$this->set_description( $value );
836
+	public function set_excerpt($value) {
837
+		$this->set_description($value);
838 838
     }
839 839
 
840 840
     /**
@@ -843,8 +843,8 @@  discard block
 block discarded – undo
843 843
 	 * @since 1.0.19
844 844
 	 * @param  string $value New description.
845 845
 	 */
846
-	public function set_summary( $value ) {
847
-		$this->set_description( $value );
846
+	public function set_summary($value) {
847
+		$this->set_description($value);
848 848
     }
849 849
 
850 850
     /**
@@ -853,8 +853,8 @@  discard block
 block discarded – undo
853 853
 	 * @since 1.0.19
854 854
 	 * @param  int $value New author.
855 855
 	 */
856
-	public function set_author( $value ) {
857
-		$this->set_prop( 'author', (int) $value );
856
+	public function set_author($value) {
857
+		$this->set_prop('author', (int) $value);
858 858
 	}
859 859
 	
860 860
 	/**
@@ -863,8 +863,8 @@  discard block
 block discarded – undo
863 863
 	 * @since 1.0.19
864 864
 	 * @param  int $value New author.
865 865
 	 */
866
-	public function set_owner( $value ) {
867
-		$this->set_author( $value );
866
+	public function set_owner($value) {
867
+		$this->set_author($value);
868 868
     }
869 869
 
870 870
     /**
@@ -873,8 +873,8 @@  discard block
 block discarded – undo
873 873
 	 * @since 1.0.19
874 874
 	 * @param  float $value New price.
875 875
 	 */
876
-	public function set_price( $value ) {
877
-        $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
876
+	public function set_price($value) {
877
+        $this->set_prop('price', (float) wpinv_sanitize_amount($value));
878 878
     }
879 879
 
880 880
     /**
@@ -883,8 +883,8 @@  discard block
 block discarded – undo
883 883
 	 * @since 1.0.19
884 884
 	 * @param  string $value new rule.
885 885
 	 */
886
-	public function set_vat_rule( $value ) {
887
-        $this->set_prop( 'vat_rule', $value );
886
+	public function set_vat_rule($value) {
887
+        $this->set_prop('vat_rule', $value);
888 888
     }
889 889
 
890 890
     /**
@@ -893,8 +893,8 @@  discard block
 block discarded – undo
893 893
 	 * @since 1.0.19
894 894
 	 * @param  string $value new class.
895 895
 	 */
896
-	public function set_vat_class( $value ) {
897
-        $this->set_prop( 'vat_class', $value );
896
+	public function set_vat_class($value) {
897
+        $this->set_prop('vat_class', $value);
898 898
     }
899 899
 
900 900
     /**
@@ -904,13 +904,13 @@  discard block
 block discarded – undo
904 904
 	 * @param  string $value new item type.
905 905
 	 * @return string
906 906
 	 */
907
-	public function set_type( $value ) {
907
+	public function set_type($value) {
908 908
 
909
-        if ( empty( $value ) ) {
909
+        if (empty($value)) {
910 910
             $value = 'custom';
911 911
         }
912 912
 
913
-        $this->set_prop( 'type', $value );
913
+        $this->set_prop('type', $value);
914 914
     }
915 915
 
916 916
     /**
@@ -919,8 +919,8 @@  discard block
 block discarded – undo
919 919
 	 * @since 1.0.19
920 920
 	 * @param  string $value new custom id.
921 921
 	 */
922
-	public function set_custom_id( $value ) {
923
-        $this->set_prop( 'custom_id', $value );
922
+	public function set_custom_id($value) {
923
+        $this->set_prop('custom_id', $value);
924 924
     }
925 925
 
926 926
     /**
@@ -929,8 +929,8 @@  discard block
 block discarded – undo
929 929
 	 * @since 1.0.19
930 930
 	 * @param  string $value new custom name.
931 931
 	 */
932
-	public function set_custom_name( $value ) {
933
-        $this->set_prop( 'custom_name', $value );
932
+	public function set_custom_name($value) {
933
+        $this->set_prop('custom_name', $value);
934 934
     }
935 935
 
936 936
     /**
@@ -939,8 +939,8 @@  discard block
 block discarded – undo
939 939
 	 * @since 1.0.19
940 940
 	 * @param  string $value new custom singular name.
941 941
 	 */
942
-	public function set_custom_singular_name( $value ) {
943
-        $this->set_prop( 'custom_singular_name', $value );
942
+	public function set_custom_singular_name($value) {
943
+        $this->set_prop('custom_singular_name', $value);
944 944
     }
945 945
 
946 946
     /**
@@ -949,8 +949,8 @@  discard block
 block discarded – undo
949 949
 	 * @since 1.0.19
950 950
 	 * @param  int|bool $value whether or not the item is editable.
951 951
 	 */
952
-	public function set_is_editable( $value ) {
953
-		$this->set_prop( 'is_editable', (int) $value );
952
+	public function set_is_editable($value) {
953
+		$this->set_prop('is_editable', (int) $value);
954 954
     }
955 955
 
956 956
     /**
@@ -959,8 +959,8 @@  discard block
 block discarded – undo
959 959
 	 * @since 1.0.19
960 960
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
961 961
 	 */
962
-	public function set_is_dynamic_pricing( $value ) {
963
-        $this->set_prop( 'is_dynamic_pricing', (int) $value );
962
+	public function set_is_dynamic_pricing($value) {
963
+        $this->set_prop('is_dynamic_pricing', (int) $value);
964 964
     }
965 965
 
966 966
     /**
@@ -969,8 +969,8 @@  discard block
 block discarded – undo
969 969
 	 * @since 1.0.19
970 970
 	 * @param  float $value minimum price.
971 971
 	 */
972
-	public function set_minimum_price( $value ) {
973
-        $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
972
+	public function set_minimum_price($value) {
973
+        $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value));
974 974
     }
975 975
 
976 976
     /**
@@ -979,8 +979,8 @@  discard block
 block discarded – undo
979 979
 	 * @since 1.0.19
980 980
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
981 981
 	 */
982
-	public function set_is_recurring( $value ) {
983
-        $this->set_prop( 'is_recurring', (int) $value );
982
+	public function set_is_recurring($value) {
983
+        $this->set_prop('is_recurring', (int) $value);
984 984
     }
985 985
 
986 986
     /**
@@ -989,8 +989,8 @@  discard block
 block discarded – undo
989 989
 	 * @since 1.0.19
990 990
 	 * @param  string $value new period.
991 991
 	 */
992
-	public function set_recurring_period( $value ) {
993
-        $this->set_prop( 'recurring_period', $value );
992
+	public function set_recurring_period($value) {
993
+        $this->set_prop('recurring_period', $value);
994 994
     }
995 995
 
996 996
     /**
@@ -999,8 +999,8 @@  discard block
 block discarded – undo
999 999
 	 * @since 1.0.19
1000 1000
 	 * @param  int $value recurring interval.
1001 1001
 	 */
1002
-	public function set_recurring_interval( $value ) {
1003
-        return $this->set_prop( 'recurring_interval', (int) $value );
1002
+	public function set_recurring_interval($value) {
1003
+        return $this->set_prop('recurring_interval', (int) $value);
1004 1004
     }
1005 1005
 
1006 1006
     /**
@@ -1009,8 +1009,8 @@  discard block
 block discarded – undo
1009 1009
 	 * @param  int $value The recurring limit.
1010 1010
 	 * @return int
1011 1011
 	 */
1012
-	public function set_recurring_limit( $value ) {
1013
-        $this->set_prop( 'recurring_limit', (int) $value );
1012
+	public function set_recurring_limit($value) {
1013
+        $this->set_prop('recurring_limit', (int) $value);
1014 1014
     }
1015 1015
 
1016 1016
     /**
@@ -1019,8 +1019,8 @@  discard block
 block discarded – undo
1019 1019
 	 * @since 1.0.19
1020 1020
 	 * @param  int|bool $value whether or not it has a free trial.
1021 1021
 	 */
1022
-	public function set_is_free_trial( $value ) {
1023
-        $this->set_prop( 'is_free_trial', (int) $value );
1022
+	public function set_is_free_trial($value) {
1023
+        $this->set_prop('is_free_trial', (int) $value);
1024 1024
     }
1025 1025
 
1026 1026
     /**
@@ -1029,8 +1029,8 @@  discard block
 block discarded – undo
1029 1029
 	 * @since 1.0.19
1030 1030
 	 * @param  string $value trial period.
1031 1031
 	 */
1032
-	public function set_trial_period( $value ) {
1033
-        $this->set_prop( 'trial_period', $value );
1032
+	public function set_trial_period($value) {
1033
+        $this->set_prop('trial_period', $value);
1034 1034
     }
1035 1035
 
1036 1036
     /**
@@ -1039,8 +1039,8 @@  discard block
 block discarded – undo
1039 1039
 	 * @since 1.0.19
1040 1040
 	 * @param  int $value trial interval.
1041 1041
 	 */
1042
-	public function set_trial_interval( $value ) {
1043
-        $this->set_prop( 'trial_interval', $value );
1042
+	public function set_trial_interval($value) {
1043
+        $this->set_prop('trial_interval', $value);
1044 1044
     }
1045 1045
 
1046 1046
     /**
@@ -1049,11 +1049,11 @@  discard block
 block discarded – undo
1049 1049
      * @deprecated
1050 1050
 	 * @return int item id
1051 1051
      */
1052
-    public function create( $data = array() ) {
1052
+    public function create($data = array()) {
1053 1053
 
1054 1054
 		// Set the properties.
1055
-		if ( is_array( $data ) ) {
1056
-			$this->set_props( $data );
1055
+		if (is_array($data)) {
1056
+			$this->set_props($data);
1057 1057
 		}
1058 1058
 
1059 1059
 		// Save the item.
@@ -1067,8 +1067,8 @@  discard block
 block discarded – undo
1067 1067
      * @deprecated
1068 1068
 	 * @return int item id
1069 1069
      */
1070
-    public function update( $data = array() ) {
1071
-        return $this->create( $data );
1070
+    public function update($data = array()) {
1071
+        return $this->create($data);
1072 1072
     }
1073 1073
 
1074 1074
     /*
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
 	 */
1109 1109
     public function has_free_trial() {
1110 1110
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1111
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1111
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
1112 1112
     }
1113 1113
 
1114 1114
     /**
@@ -1118,8 +1118,8 @@  discard block
 block discarded – undo
1118 1118
 	 * @return bool
1119 1119
 	 */
1120 1120
     public function is_free() {
1121
-        $is_free   = $this->get_price() == 0;
1122
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1121
+        $is_free = $this->get_price() == 0;
1122
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this);
1123 1123
     }
1124 1124
 
1125 1125
     /**
@@ -1128,9 +1128,9 @@  discard block
 block discarded – undo
1128 1128
 	 * @param array|string $status Status to check.
1129 1129
 	 * @return bool
1130 1130
 	 */
1131
-	public function has_status( $status ) {
1132
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1131
+	public function has_status($status) {
1132
+		$has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status;
1133
+		return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status);
1134 1134
     }
1135 1135
 
1136 1136
     /**
@@ -1139,9 +1139,9 @@  discard block
 block discarded – undo
1139 1139
 	 * @param array|string $type Type to check.
1140 1140
 	 * @return bool
1141 1141
 	 */
1142
-	public function is_type( $type ) {
1143
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1142
+	public function is_type($type) {
1143
+		$is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type;
1144
+		return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type);
1145 1145
 	}
1146 1146
 
1147 1147
     /**
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
 	 */
1153 1153
     public function is_editable() {
1154 1154
         $is_editable = $this->get_is_editable();
1155
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1155
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this);
1156 1156
 	}
1157 1157
 
1158 1158
 	/**
@@ -1171,11 +1171,11 @@  discard block
 block discarded – undo
1171 1171
     public function can_purchase() {
1172 1172
         $can_purchase = $this->exists();
1173 1173
 
1174
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
1174
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
1175 1175
             $can_purchase = false;
1176 1176
         }
1177 1177
 
1178
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
1178
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
1179 1179
     }
1180 1180
 
1181 1181
     /**
@@ -1185,6 +1185,6 @@  discard block
 block discarded – undo
1185 1185
 	 * @return bool
1186 1186
 	 */
1187 1187
     public function supports_dynamic_pricing() {
1188
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1188
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
1189 1189
     }
1190 1190
 }
Please login to merge, or discard this patch.
includes/class-getpaid-daily-maintenance.php 2 patches
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -12,108 +12,108 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct(){
19
-
20
-		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
-
23
-		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
-
26
-		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
31
-
32
-	}
33
-
34
-	/**
35
-	 * Schedules a cron to run every day at 7 a.m
36
-	 *
37
-	 */
38
-	public function maybe_create_scheduled_event() {
39
-
40
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
43
-		}
44
-
45
-	}
46
-
47
-	/**
48
-	 * Clears deprecated events.
49
-	 *
50
-	 */
51
-	public function maybe_clear_deprecated_events() {
52
-
53
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
-			update_option( 'wpinv_cleared_old_events', 1 );
57
-		}
58
-
59
-	}
60
-
61
-	/**
62
-	 * Fires the old hook for backwards compatibility.
63
-	 *
64
-	 */
65
-	public function backwards_compat() {
66
-		do_action( 'wpinv_register_schedule_event_daily' );
67
-	}
68
-
69
-	/**
70
-	 * Expires expired subscriptions.
71
-	 *
72
-	 */
73
-	public function maybe_expire_subscriptions() {
74
-
75
-		// Fetch expired subscriptions (skips those that expire today).
76
-		$args  = array(
77
-			'number'             => -1,
78
-			'count_total'        => false,
79
-			'status'             => 'trialling active failing cancelled',
80
-			'date_expires_query' => array(
81
-				'before'    => 'today',
82
-				'inclusive' => false,
83
-			),
84
-		);
85
-
86
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
87
-
88
-		foreach ( $subscriptions->get_results() as $subscription ) {
89
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
-				$subscription->set_status( 'expired' );
91
-				$subscription->save();
92
-			}
93
-		}
94
-
95
-	}
96
-
97
-	/**
98
-	 * Logs cron runs.
99
-	 *
100
-	 */
101
-	public function log_cron_run() {
102
-		wpinv_error_log( 'GetPaid Daily Cron', false );
103
-	}
104
-
105
-	/**
106
-	 * Updates GeoIP databases.
107
-	 *
108
-	 */
109
-	public function maybe_update_geoip_databases() {
110
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
111
-
112
-		if ( false === $updated ) {
113
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
-			do_action( 'getpaid_update_geoip_databases' );
115
-		}
116
-
117
-	}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct(){
19
+
20
+        // Clear deprecated events.
21
+        add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
+
23
+        // (Maybe) schedule a cron that runs daily.
24
+        add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
+
26
+        // Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
+        add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
+        add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
31
+
32
+    }
33
+
34
+    /**
35
+     * Schedules a cron to run every day at 7 a.m
36
+     *
37
+     */
38
+    public function maybe_create_scheduled_event() {
39
+
40
+        if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
+            $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
+            wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
43
+        }
44
+
45
+    }
46
+
47
+    /**
48
+     * Clears deprecated events.
49
+     *
50
+     */
51
+    public function maybe_clear_deprecated_events() {
52
+
53
+        if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
+            update_option( 'wpinv_cleared_old_events', 1 );
57
+        }
58
+
59
+    }
60
+
61
+    /**
62
+     * Fires the old hook for backwards compatibility.
63
+     *
64
+     */
65
+    public function backwards_compat() {
66
+        do_action( 'wpinv_register_schedule_event_daily' );
67
+    }
68
+
69
+    /**
70
+     * Expires expired subscriptions.
71
+     *
72
+     */
73
+    public function maybe_expire_subscriptions() {
74
+
75
+        // Fetch expired subscriptions (skips those that expire today).
76
+        $args  = array(
77
+            'number'             => -1,
78
+            'count_total'        => false,
79
+            'status'             => 'trialling active failing cancelled',
80
+            'date_expires_query' => array(
81
+                'before'    => 'today',
82
+                'inclusive' => false,
83
+            ),
84
+        );
85
+
86
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
87
+
88
+        foreach ( $subscriptions->get_results() as $subscription ) {
89
+            if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
+                $subscription->set_status( 'expired' );
91
+                $subscription->save();
92
+            }
93
+        }
94
+
95
+    }
96
+
97
+    /**
98
+     * Logs cron runs.
99
+     *
100
+     */
101
+    public function log_cron_run() {
102
+        wpinv_error_log( 'GetPaid Daily Cron', false );
103
+    }
104
+
105
+    /**
106
+     * Updates GeoIP databases.
107
+     *
108
+     */
109
+    public function maybe_update_geoip_databases() {
110
+        $updated = get_transient( 'getpaid_updated_geoip_databases' );
111
+
112
+        if ( false === $updated ) {
113
+            set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
+            do_action( 'getpaid_update_geoip_databases' );
115
+        }
116
+
117
+    }
118 118
 
119 119
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Daily maintenance class.
@@ -15,19 +15,19 @@  discard block
 block discarded – undo
15 15
 	/**
16 16
 	 * Class constructor.
17 17
 	 */
18
-	public function __construct(){
18
+	public function __construct() {
19 19
 
20 20
 		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
21
+		add_action('wp', array($this, 'maybe_clear_deprecated_events'));
22 22
 
23 23
 		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
24
+		add_action('wp', array($this, 'maybe_create_scheduled_event'));
25 25
 
26 26
 		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
27
+		add_action('getpaid_daily_maintenance', array($this, 'log_cron_run'));
28
+		add_action('getpaid_daily_maintenance', array($this, 'backwards_compat'));
29
+		add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions'));
30
+		add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases'));
31 31
 
32 32
 	}
33 33
 
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
 	 */
38 38
 	public function maybe_create_scheduled_event() {
39 39
 
40
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
40
+		if (!wp_next_scheduled('getpaid_daily_maintenance')) {
41
+			$timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp'));
42
+			wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance');
43 43
 		}
44 44
 
45 45
 	}
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function maybe_clear_deprecated_events() {
52 52
 
53
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
-			update_option( 'wpinv_cleared_old_events', 1 );
53
+		if (!get_option('wpinv_cleared_old_events')) {
54
+			wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily');
55
+			wp_clear_scheduled_hook('wpinv_register_schedule_event_daily');
56
+			update_option('wpinv_cleared_old_events', 1);
57 57
 		}
58 58
 
59 59
 	}
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 *
64 64
 	 */
65 65
 	public function backwards_compat() {
66
-		do_action( 'wpinv_register_schedule_event_daily' );
66
+		do_action('wpinv_register_schedule_event_daily');
67 67
 	}
68 68
 
69 69
 	/**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	public function maybe_expire_subscriptions() {
74 74
 
75 75
 		// Fetch expired subscriptions (skips those that expire today).
76
-		$args  = array(
76
+		$args = array(
77 77
 			'number'             => -1,
78 78
 			'count_total'        => false,
79 79
 			'status'             => 'trialling active failing cancelled',
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 			),
84 84
 		);
85 85
 
86
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
86
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
87 87
 
88
-		foreach ( $subscriptions->get_results() as $subscription ) {
89
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
-				$subscription->set_status( 'expired' );
88
+		foreach ($subscriptions->get_results() as $subscription) {
89
+			if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', true, $subscription)) {
90
+				$subscription->set_status('expired');
91 91
 				$subscription->save();
92 92
 			}
93 93
 		}
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 */
101 101
 	public function log_cron_run() {
102
-		wpinv_error_log( 'GetPaid Daily Cron', false );
102
+		wpinv_error_log('GetPaid Daily Cron', false);
103 103
 	}
104 104
 
105 105
 	/**
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 	 *
108 108
 	 */
109 109
 	public function maybe_update_geoip_databases() {
110
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
110
+		$updated = get_transient('getpaid_updated_geoip_databases');
111 111
 
112
-		if ( false === $updated ) {
113
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
-			do_action( 'getpaid_update_geoip_databases' );
112
+		if (false === $updated) {
113
+			set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS);
114
+			do_action('getpaid_update_geoip_databases');
115 115
 		}
116 116
 
117 117
 	}
Please login to merge, or discard this patch.
templates/invoice-receipt.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -7,64 +7,64 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Fetch the invoice.
13
-$invoice = new WPInv_Invoice( $invoice );
13
+$invoice = new WPInv_Invoice($invoice);
14 14
 
15 15
 // @deprecated
16
-do_action( 'wpinv_success_content_before', $invoice );
17
-do_action( 'wpinv_before_receipt', $invoice );
16
+do_action('wpinv_success_content_before', $invoice);
17
+do_action('wpinv_before_receipt', $invoice);
18 18
 
19 19
 wpinv_print_errors();
20 20
 
21 21
 // Prepare header text.
22
-if ( $invoice->is_paid() ) {
22
+if ($invoice->is_paid()) {
23 23
 
24 24
     $alert = aui()->alert(
25 25
         array(
26 26
             'type'    => 'success',
27
-            'content' => __( 'Thank you for your payment!', 'invoicing' ),
27
+            'content' => __('Thank you for your payment!', 'invoicing'),
28 28
         )
29 29
     );
30 30
 
31
-} else if ( $invoice->is_refunded() ) {
31
+} else if ($invoice->is_refunded()) {
32 32
 
33 33
     $alert = aui()->alert(
34 34
         array(
35 35
             'type'    => 'info',
36
-            'content' => __( 'This invoice was refunded.', 'invoicing' ),
36
+            'content' => __('This invoice was refunded.', 'invoicing'),
37 37
         )
38 38
     );
39 39
 
40
-} else if ( $invoice->is_held() ) {
40
+} else if ($invoice->is_held()) {
41 41
 
42 42
     $alert = aui()->alert(
43 43
         array(
44 44
             'type'    => 'info',
45
-            'content' => __( 'This invoice will be processed as soon we verify your payment.', 'invoicing' ),
45
+            'content' => __('This invoice will be processed as soon we verify your payment.', 'invoicing'),
46 46
         )
47 47
     );
48 48
 
49
-} else if ( $invoice->needs_payment() ) {
49
+} else if ($invoice->needs_payment()) {
50 50
 
51
-    if ( ! empty( $_GET['token'] ) ) {
51
+    if (!empty($_GET['token'])) {
52 52
 
53 53
         $alert = aui()->alert(
54 54
             array(
55 55
                 'type'    => 'info',
56
-                'content' => __( "Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing' ),
56
+                'content' => __("Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing'),
57 57
             )
58 58
         );
59 59
 
60
-    } else if ( $invoice->is_due() ) {
60
+    } else if ($invoice->is_due()) {
61 61
 
62 62
         $alert = aui()->alert(
63 63
             array(
64 64
                 'type'    => 'danger',
65 65
                 'content' => sprintf(
66
-                    __( 'This invoice was due on %.', 'invoicing' ),
67
-                    getpaid_format_date_value( $invoice->get_due_date() )
66
+                    __('This invoice was due on %.', 'invoicing'),
67
+                    getpaid_format_date_value($invoice->get_due_date())
68 68
                 ),
69 69
             )
70 70
         );
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         $alert = aui()->alert(
75 75
             array(
76 76
                 'type'    => 'warning',
77
-                'content' => __( 'This invoice needs payment.', 'invoicing' ),
77
+                'content' => __('This invoice needs payment.', 'invoicing'),
78 78
             )
79 79
         );
80 80
 
@@ -89,19 +89,19 @@  discard block
 block discarded – undo
89 89
 
90 90
         'pay' => array(
91 91
             'url'   => $invoice->get_checkout_payment_url(),
92
-            'name'  => __( 'Pay For Invoice', 'invoicing' ),
92
+            'name'  => __('Pay For Invoice', 'invoicing'),
93 93
             'class' => 'btn-success',
94 94
         ),
95 95
 
96 96
         'view' => array(
97 97
             'url'   => $invoice->get_view_url(),
98
-            'name'  => __( 'View Invoice', 'invoicing' ),
98
+            'name'  => __('View Invoice', 'invoicing'),
99 99
             'class' => 'btn-primary',
100 100
         ),
101 101
 
102 102
         'history' => array(
103 103
             'url'   => wpinv_get_history_page_uri(),
104
-            'name'  => __( 'Invoice History', 'invoicing' ),
104
+            'name'  => __('Invoice History', 'invoicing'),
105 105
             'class' => 'btn-warning',
106 106
         ),
107 107
 
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 
111 111
 );
112 112
 
113
-if ( ( ! $invoice->needs_payment() || $invoice->is_held() ) && isset( $actions['pay'] ) ) {
114
-    unset( $actions['pay'] );
113
+if ((!$invoice->needs_payment() || $invoice->is_held()) && isset($actions['pay'])) {
114
+    unset($actions['pay']);
115 115
 }
116 116
 
117
-if ( ! is_user_logged_in() && isset( $actions['history'] ) ) {
118
-    unset( $actions['history'] );
117
+if (!is_user_logged_in() && isset($actions['history'])) {
118
+    unset($actions['history']);
119 119
 }
120 120
 
121 121
 ?>
@@ -124,19 +124,19 @@  discard block
 block discarded – undo
124 124
 
125 125
         <?php
126 126
         
127
-            do_action( 'wpinv_receipt_start', $invoice );
127
+            do_action('wpinv_receipt_start', $invoice);
128 128
 
129
-            if ( ! empty( $actions ) ) {
129
+            if (!empty($actions)) {
130 130
 
131 131
                 echo '<div class="wpinv-receipt-actions text-right mt-1 mb-4">';
132 132
 
133
-                foreach ( $actions as $key => $action ) {
133
+                foreach ($actions as $key => $action) {
134 134
 
135
-                    $key    = sanitize_html_class( $key );
136
-                    $class  = empty( $action['class'] ) ? 'btn-dark' : sanitize_html_class( $action['class'] );
137
-                    $url    = empty( $action['url'] ) ? '#' : esc_url( $action['url'] );
138
-                    $attrs  = empty( $action['attrs'] ) ? '' : $action['attrs'];
139
-                    $anchor = sanitize_text_field( $action['name'] );
135
+                    $key    = sanitize_html_class($key);
136
+                    $class  = empty($action['class']) ? 'btn-dark' : sanitize_html_class($action['class']);
137
+                    $url    = empty($action['url']) ? '#' : esc_url($action['url']);
138
+                    $attrs  = empty($action['attrs']) ? '' : $action['attrs'];
139
+                    $anchor = sanitize_text_field($action['name']);
140 140
 
141 141
                     echo "<a href='$url' class='btn btn-sm ml-1 $class $key' $attrs>$anchor</a>";
142 142
                 }
@@ -152,21 +152,21 @@  discard block
 block discarded – undo
152 152
         <div class="wpinv-receipt-details">
153 153
 
154 154
             <h4 class="wpinv-details-t mb-3 mt-3">
155
-                <?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ), $invoice ); ?>
155
+                <?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing'), $invoice); ?>
156 156
             </h4>
157 157
 
158
-            <?php getpaid_invoice_meta( $invoice ); ?>
158
+            <?php getpaid_invoice_meta($invoice); ?>
159 159
 
160 160
         </div>
161 161
 
162
-        <?php echo getpaid_display_invoice_subscriptions( $invoice ); ?>
162
+        <?php echo getpaid_display_invoice_subscriptions($invoice); ?>
163 163
 
164
-        <?php do_action( 'wpinv_receipt_end', $invoice ); ?>
164
+        <?php do_action('wpinv_receipt_end', $invoice); ?>
165 165
 
166 166
     </div>
167 167
 
168 168
 <?php
169 169
 
170 170
 // @deprecated
171
-do_action( 'wpinv_success_content_after', $invoice );
172
-do_action( 'wpinv_after_receipt', $invoice );
171
+do_action('wpinv_success_content_after', $invoice);
172
+do_action('wpinv_after_receipt', $invoice);
Please login to merge, or discard this patch.
templates/wpinv-payment-processing.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@  discard block
 block discarded – undo
4 4
         <?php 
5 5
             echo
6 6
             wp_sprintf(
7
-                __( 'Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing' ),
8
-                esc_url_raw( remove_query_arg( 'payment-confirm' ) )
7
+                __('Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing'),
8
+                esc_url_raw(remove_query_arg('payment-confirm'))
9 9
             );
10 10
         ?>
11 11
         <i class="fa fa-spin fa-refresh"></i>
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     <script type="text/javascript">
15 15
         setTimeout(
16 16
             function(){
17
-                window.location.href = '<?php echo esc_url_raw( remove_query_arg( 'payment-confirm' ) ) ;?>';
17
+                window.location.href = '<?php echo esc_url_raw(remove_query_arg('payment-confirm')); ?>';
18 18
             },
19 19
             10000
20 20
         );
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 2 patches
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -12,276 +12,276 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
21
-
22 15
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
39
-
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
44 21
 
45
-		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
47
-
48
-		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type );
50
-
51
-		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
53
-
54
-		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
-		}
58
-
59
-	}
22
+    /**
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
60 26
 
61
-	/**
62
-	 * Register core metaboxes.
63
-	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type ) {
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
65 29
 
66
-		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
68 32
 
69
-			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
71 35
 
72
-			// Payment form information.
73
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
74 39
 
75
-		}
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
76 44
 
77
-	}
45
+        // For invoices...
46
+        self::add_invoice_meta_boxes( $post_type, $post );
78 47
 
79
-	/**
80
-	 * Register core metaboxes.
81
-	 */
82
-	protected static function add_item_meta_boxes( $post_type ) {
48
+        // For payment forms.
49
+        self::add_payment_form_meta_boxes( $post_type );
83 50
 
84
-		if ( $post_type == 'wpi_item' ) {
51
+        // For invoice items.
52
+        self::add_item_meta_boxes( $post_type );
85 53
 
86
-			// Item details.
87
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
54
+        // For invoice discounts.
55
+        if ( $post_type == 'wpi_discount' ) {
56
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
+        }
88 58
 
89
-			// If taxes are enabled, register the tax metabox.
90
-			if ( wpinv_use_taxes() ) {
91
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
-			}
59
+    }
93 60
 
94
-			// Item info.
95
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
61
+    /**
62
+     * Register core metaboxes.
63
+     */
64
+    protected static function add_payment_form_meta_boxes( $post_type ) {
96 65
 
97
-		}
66
+        // For payment forms.
67
+        if ( $post_type == 'wpi_payment_form' ) {
98 68
 
99
-	}
69
+            // Design payment form.
70
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
100 71
 
101
-	/**
102
-	 * Register invoice metaboxes.
103
-	 */
104
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
72
+            // Payment form information.
73
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
105 74
 
106
-		// For invoices...
107
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
-			$invoice = new WPInv_Invoice( $post );
75
+        }
109 76
 
110
-			// Resend invoice.
111
-			if ( ! $invoice->is_draft() ) {
77
+    }
112 78
 
113
-				add_meta_box(
114
-					'wpinv-mb-resend-invoice',
115
-					sprintf(
116
-						__( 'Resend %s', 'invoicing' ),
117
-						ucfirst( $invoice->get_invoice_quote_type() )
118
-					),
119
-					'GetPaid_Meta_Box_Resend_Invoice::output',
120
-					$post_type,
121
-					'side',
122
-					'low'
123
-				);
79
+    /**
80
+     * Register core metaboxes.
81
+     */
82
+    protected static function add_item_meta_boxes( $post_type ) {
124 83
 
125
-			}
84
+        if ( $post_type == 'wpi_item' ) {
126 85
 
127
-			// Subscriptions.
128
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
129
-			if ( ! empty( $subscriptions ) ) {
86
+            // Item details.
87
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
130 88
 
131
-				if ( is_array( $subscriptions ) ) {
132
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
133
-				} else {
134
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
135
-				}
89
+            // If taxes are enabled, register the tax metabox.
90
+            if ( wpinv_use_taxes() ) {
91
+                add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
+            }
136 93
 
137
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
138
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
139
-				}
94
+            // Item info.
95
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
140 96
 
141
-			}
97
+        }
142 98
 
143
-			// Invoice details.
144
-			add_meta_box(
145
-				'wpinv-details',
146
-				sprintf(
147
-					__( '%s Details', 'invoicing' ),
148
-					ucfirst( $invoice->get_invoice_quote_type() )
149
-				),
150
-				'GetPaid_Meta_Box_Invoice_Details::output',
151
-				$post_type,
152
-				'side'
153
-			);
154
-
155
-			// Payment details.
156
-			if ( ! $invoice->is_draft() ) {
157
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
158
-			}
99
+    }
159 100
 
160
-			// Billing details.
161
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
101
+    /**
102
+     * Register invoice metaboxes.
103
+     */
104
+    protected static function add_invoice_meta_boxes( $post_type, $post ) {
105
+
106
+        // For invoices...
107
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
+            $invoice = new WPInv_Invoice( $post );
109
+
110
+            // Resend invoice.
111
+            if ( ! $invoice->is_draft() ) {
112
+
113
+                add_meta_box(
114
+                    'wpinv-mb-resend-invoice',
115
+                    sprintf(
116
+                        __( 'Resend %s', 'invoicing' ),
117
+                        ucfirst( $invoice->get_invoice_quote_type() )
118
+                    ),
119
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
120
+                    $post_type,
121
+                    'side',
122
+                    'low'
123
+                );
124
+
125
+            }
126
+
127
+            // Subscriptions.
128
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
129
+            if ( ! empty( $subscriptions ) ) {
130
+
131
+                if ( is_array( $subscriptions ) ) {
132
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
133
+                } else {
134
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
135
+                }
136
+
137
+                if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
138
+                    add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
139
+                }
140
+
141
+            }
142
+
143
+            // Invoice details.
144
+            add_meta_box(
145
+                'wpinv-details',
146
+                sprintf(
147
+                    __( '%s Details', 'invoicing' ),
148
+                    ucfirst( $invoice->get_invoice_quote_type() )
149
+                ),
150
+                'GetPaid_Meta_Box_Invoice_Details::output',
151
+                $post_type,
152
+                'side'
153
+            );
154
+
155
+            // Payment details.
156
+            if ( ! $invoice->is_draft() ) {
157
+                add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
158
+            }
159
+
160
+            // Billing details.
161
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
162 162
 			
163
-			// Invoice items.
164
-			add_meta_box(
165
-				'wpinv-items',
166
-				sprintf(
167
-					__( '%s Items', 'invoicing' ),
168
-					ucfirst( $invoice->get_invoice_quote_type() )
169
-				),
170
-				'GetPaid_Meta_Box_Invoice_Items::output',
171
-				$post_type,
172
-				'normal',
173
-				'high'
174
-			);
163
+            // Invoice items.
164
+            add_meta_box(
165
+                'wpinv-items',
166
+                sprintf(
167
+                    __( '%s Items', 'invoicing' ),
168
+                    ucfirst( $invoice->get_invoice_quote_type() )
169
+                ),
170
+                'GetPaid_Meta_Box_Invoice_Items::output',
171
+                $post_type,
172
+                'normal',
173
+                'high'
174
+            );
175 175
 			
176
-			// Invoice notes.
177
-			add_meta_box(
178
-				'wpinv-notes',
179
-				sprintf(
180
-					__( '%s Notes', 'invoicing' ),
181
-					ucfirst( $invoice->get_invoice_quote_type() )
182
-				),
183
-				'WPInv_Meta_Box_Notes::output',
184
-				$post_type,
185
-				'side',
186
-				'low'
187
-			);
188
-
189
-			// Shipping Address.
190
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
192
-			}
193
-
194
-			// Payment form information.
195
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
197
-			}
198
-
199
-		}
200
-
201
-	}
202
-
203
-	/**
204
-	 * Remove some metaboxes.
205
-	 */
206
-	public static function remove_meta_boxes() {
207
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
208
-	}
209
-
210
-	/**
211
-	 * Rename other metaboxes.
212
-	 */
213
-	public static function rename_meta_boxes() {
176
+            // Invoice notes.
177
+            add_meta_box(
178
+                'wpinv-notes',
179
+                sprintf(
180
+                    __( '%s Notes', 'invoicing' ),
181
+                    ucfirst( $invoice->get_invoice_quote_type() )
182
+                ),
183
+                'WPInv_Meta_Box_Notes::output',
184
+                $post_type,
185
+                'side',
186
+                'low'
187
+            );
188
+
189
+            // Shipping Address.
190
+            if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
192
+            }
193
+
194
+            // Payment form information.
195
+            if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
197
+            }
198
+
199
+        }
200
+
201
+    }
202
+
203
+    /**
204
+     * Remove some metaboxes.
205
+     */
206
+    public static function remove_meta_boxes() {
207
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
208
+    }
209
+
210
+    /**
211
+     * Rename other metaboxes.
212
+     */
213
+    public static function rename_meta_boxes() {
214 214
 		
215
-	}
216
-
217
-	/**
218
-	 * Check if we're saving, then trigger an action based on the post type.
219
-	 *
220
-	 * @param  int    $post_id Post ID.
221
-	 * @param  object $post Post object.
222
-	 */
223
-	public static function save_meta_boxes( $post_id, $post ) {
224
-		$post_id = absint( $post_id );
225
-		$data    = wp_unslash( $_POST );
226
-
227
-		// Do not save for ajax requests.
228
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
229
-			return;
230
-		}
231
-
232
-		// $post_id and $post are required
233
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
234
-			return;
235
-		}
236
-
237
-		// Dont' save meta boxes for revisions or autosaves.
238
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
239
-			return;
240
-		}
241
-
242
-		// Check the nonce.
243
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
244
-			return;
245
-		}
246
-
247
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
249
-			return;
250
-		}
251
-
252
-		// Check user has permission to edit.
253
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
254
-			return;
255
-		}
256
-
257
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
258
-
259
-			// We need this save event to run once to avoid potential endless loops.
260
-			self::$saved_meta_boxes = true;
261
-
262
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
263
-
264
-		}
265
-
266
-		// Ensure this is our post type.
267
-		$post_types_map = array(
268
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
269
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
270
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
271
-		);
272
-
273
-		// Is this our post type?
274
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
275
-			return;
276
-		}
277
-
278
-		// We need this save event to run once to avoid potential endless loops.
279
-		self::$saved_meta_boxes = true;
215
+    }
216
+
217
+    /**
218
+     * Check if we're saving, then trigger an action based on the post type.
219
+     *
220
+     * @param  int    $post_id Post ID.
221
+     * @param  object $post Post object.
222
+     */
223
+    public static function save_meta_boxes( $post_id, $post ) {
224
+        $post_id = absint( $post_id );
225
+        $data    = wp_unslash( $_POST );
226
+
227
+        // Do not save for ajax requests.
228
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
229
+            return;
230
+        }
231
+
232
+        // $post_id and $post are required
233
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
234
+            return;
235
+        }
236
+
237
+        // Dont' save meta boxes for revisions or autosaves.
238
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
239
+            return;
240
+        }
241
+
242
+        // Check the nonce.
243
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
244
+            return;
245
+        }
246
+
247
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
249
+            return;
250
+        }
251
+
252
+        // Check user has permission to edit.
253
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
254
+            return;
255
+        }
256
+
257
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
258
+
259
+            // We need this save event to run once to avoid potential endless loops.
260
+            self::$saved_meta_boxes = true;
261
+
262
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
263
+
264
+        }
265
+
266
+        // Ensure this is our post type.
267
+        $post_types_map = array(
268
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
269
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
270
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
271
+        );
272
+
273
+        // Is this our post type?
274
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
275
+            return;
276
+        }
277
+
278
+        // We need this save event to run once to avoid potential endless loops.
279
+        self::$saved_meta_boxes = true;
280 280
 		
281
-		// Save the post.
282
-		$class = $post_types_map[ $post->post_type ];
283
-		$class::save( $post_id, $_POST, $post );
281
+        // Save the post.
282
+        $class = $post_types_map[ $post->post_type ];
283
+        $class::save( $post_id, $_POST, $post );
284 284
 
285
-	}
285
+    }
286 286
 
287 287
 }
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Metaboxes Admin Class
@@ -25,35 +25,35 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 
45 45
 		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
46
+		self::add_invoice_meta_boxes($post_type, $post);
47 47
 
48 48
 		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type );
49
+		self::add_payment_form_meta_boxes($post_type);
50 50
 
51 51
 		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
52
+		self::add_item_meta_boxes($post_type);
53 53
 
54 54
 		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
55
+		if ($post_type == 'wpi_discount') {
56
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
57 57
 		}
58 58
 
59 59
 	}
@@ -61,16 +61,16 @@  discard block
 block discarded – undo
61 61
 	/**
62 62
 	 * Register core metaboxes.
63 63
 	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type ) {
64
+	protected static function add_payment_form_meta_boxes($post_type) {
65 65
 
66 66
 		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
67
+		if ($post_type == 'wpi_payment_form') {
68 68
 
69 69
 			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
70
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
71 71
 
72 72
 			// Payment form information.
73
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
73
+			add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
74 74
 
75 75
 		}
76 76
 
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
 	/**
80 80
 	 * Register core metaboxes.
81 81
 	 */
82
-	protected static function add_item_meta_boxes( $post_type ) {
82
+	protected static function add_item_meta_boxes($post_type) {
83 83
 
84
-		if ( $post_type == 'wpi_item' ) {
84
+		if ($post_type == 'wpi_item') {
85 85
 
86 86
 			// Item details.
87
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
87
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
88 88
 
89 89
 			// If taxes are enabled, register the tax metabox.
90
-			if ( wpinv_use_taxes() ) {
91
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
90
+			if (wpinv_use_taxes()) {
91
+				add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
92 92
 			}
93 93
 
94 94
 			// Item info.
95
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
95
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
96 96
 
97 97
 		}
98 98
 
@@ -101,20 +101,20 @@  discard block
 block discarded – undo
101 101
 	/**
102 102
 	 * Register invoice metaboxes.
103 103
 	 */
104
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
104
+	protected static function add_invoice_meta_boxes($post_type, $post) {
105 105
 
106 106
 		// For invoices...
107
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
-			$invoice = new WPInv_Invoice( $post );
107
+		if (getpaid_is_invoice_post_type($post_type)) {
108
+			$invoice = new WPInv_Invoice($post);
109 109
 
110 110
 			// Resend invoice.
111
-			if ( ! $invoice->is_draft() ) {
111
+			if (!$invoice->is_draft()) {
112 112
 
113 113
 				add_meta_box(
114 114
 					'wpinv-mb-resend-invoice',
115 115
 					sprintf(
116
-						__( 'Resend %s', 'invoicing' ),
117
-						ucfirst( $invoice->get_invoice_quote_type() )
116
+						__('Resend %s', 'invoicing'),
117
+						ucfirst($invoice->get_invoice_quote_type())
118 118
 					),
119 119
 					'GetPaid_Meta_Box_Resend_Invoice::output',
120 120
 					$post_type,
@@ -125,17 +125,17 @@  discard block
 block discarded – undo
125 125
 			}
126 126
 
127 127
 			// Subscriptions.
128
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
129
-			if ( ! empty( $subscriptions ) ) {
128
+			$subscriptions = getpaid_get_invoice_subscriptions($invoice);
129
+			if (!empty($subscriptions)) {
130 130
 
131
-				if ( is_array( $subscriptions ) ) {
132
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
131
+				if (is_array($subscriptions)) {
132
+					add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced');
133 133
 				} else {
134
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
134
+					add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced');
135 135
 				}
136 136
 
137
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
138
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
137
+				if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) {
138
+					add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced');
139 139
 				}
140 140
 
141 141
 			}
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 			add_meta_box(
145 145
 				'wpinv-details',
146 146
 				sprintf(
147
-					__( '%s Details', 'invoicing' ),
148
-					ucfirst( $invoice->get_invoice_quote_type() )
147
+					__('%s Details', 'invoicing'),
148
+					ucfirst($invoice->get_invoice_quote_type())
149 149
 				),
150 150
 				'GetPaid_Meta_Box_Invoice_Details::output',
151 151
 				$post_type,
@@ -153,19 +153,19 @@  discard block
 block discarded – undo
153 153
 			);
154 154
 
155 155
 			// Payment details.
156
-			if ( ! $invoice->is_draft() ) {
157
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
156
+			if (!$invoice->is_draft()) {
157
+				add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default');
158 158
 			}
159 159
 
160 160
 			// Billing details.
161
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
161
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high');
162 162
 			
163 163
 			// Invoice items.
164 164
 			add_meta_box(
165 165
 				'wpinv-items',
166 166
 				sprintf(
167
-					__( '%s Items', 'invoicing' ),
168
-					ucfirst( $invoice->get_invoice_quote_type() )
167
+					__('%s Items', 'invoicing'),
168
+					ucfirst($invoice->get_invoice_quote_type())
169 169
 				),
170 170
 				'GetPaid_Meta_Box_Invoice_Items::output',
171 171
 				$post_type,
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
 			add_meta_box(
178 178
 				'wpinv-notes',
179 179
 				sprintf(
180
-					__( '%s Notes', 'invoicing' ),
181
-					ucfirst( $invoice->get_invoice_quote_type() )
180
+					__('%s Notes', 'invoicing'),
181
+					ucfirst($invoice->get_invoice_quote_type())
182 182
 				),
183 183
 				'WPInv_Meta_Box_Notes::output',
184 184
 				$post_type,
@@ -187,13 +187,13 @@  discard block
 block discarded – undo
187 187
 			);
188 188
 
189 189
 			// Shipping Address.
190
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
190
+			if (get_post_meta($invoice->get_id(), 'shipping_address', true)) {
191
+				add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high');
192 192
 			}
193 193
 
194 194
 			// Payment form information.
195
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
195
+			if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) {
196
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high');
197 197
 			}
198 198
 
199 199
 		}
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * Remove some metaboxes.
205 205
 	 */
206 206
 	public static function remove_meta_boxes() {
207
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
207
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
208 208
 	}
209 209
 
210 210
 	/**
@@ -220,46 +220,46 @@  discard block
 block discarded – undo
220 220
 	 * @param  int    $post_id Post ID.
221 221
 	 * @param  object $post Post object.
222 222
 	 */
223
-	public static function save_meta_boxes( $post_id, $post ) {
224
-		$post_id = absint( $post_id );
225
-		$data    = wp_unslash( $_POST );
223
+	public static function save_meta_boxes($post_id, $post) {
224
+		$post_id = absint($post_id);
225
+		$data    = wp_unslash($_POST);
226 226
 
227 227
 		// Do not save for ajax requests.
228
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
228
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
229 229
 			return;
230 230
 		}
231 231
 
232 232
 		// $post_id and $post are required
233
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
233
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
234 234
 			return;
235 235
 		}
236 236
 
237 237
 		// Dont' save meta boxes for revisions or autosaves.
238
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
238
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
239 239
 			return;
240 240
 		}
241 241
 
242 242
 		// Check the nonce.
243
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
243
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
244 244
 			return;
245 245
 		}
246 246
 
247 247
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
248
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
249 249
 			return;
250 250
 		}
251 251
 
252 252
 		// Check user has permission to edit.
253
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
253
+		if (!current_user_can('edit_post', $post_id)) {
254 254
 			return;
255 255
 		}
256 256
 
257
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
257
+		if (getpaid_is_invoice_post_type($post->post_type)) {
258 258
 
259 259
 			// We need this save event to run once to avoid potential endless loops.
260 260
 			self::$saved_meta_boxes = true;
261 261
 
262
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
262
+			return GetPaid_Meta_Box_Invoice_Address::save($post_id);
263 263
 
264 264
 		}
265 265
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		);
272 272
 
273 273
 		// Is this our post type?
274
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
274
+		if (!isset($post_types_map[$post->post_type])) {
275 275
 			return;
276 276
 		}
277 277
 
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 		self::$saved_meta_boxes = true;
280 280
 		
281 281
 		// Save the post.
282
-		$class = $post_types_map[ $post->post_type ];
283
-		$class::save( $post_id, $_POST, $post );
282
+		$class = $post_types_map[$post->post_type];
283
+		$class::save($post_id, $_POST, $post);
284 284
 
285 285
 	}
286 286
 
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway-ipn-handler.php 2 patches
Indentation   +390 added lines, -390 removed lines patch added patch discarded remove patch
@@ -12,472 +12,472 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Paypal_Gateway_IPN_Handler {
14 14
 
15
-	/**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	protected $id = 'paypal';
21
-
22
-	/**
23
-	 * Payment method object.
24
-	 *
25
-	 * @var GetPaid_Paypal_Gateway
26
-	 */
27
-	protected $gateway;
28
-
29
-	/**
30
-	 * Class constructor.
31
-	 *
32
-	 * @param GetPaid_Paypal_Gateway $gateway
33
-	 */
34
-	public function __construct( $gateway ) {
35
-		$this->gateway = $gateway;
36
-		$this->verify_ipn();
37
-	}
38
-
39
-	/**
40
-	 * Processes ipns and marks payments as complete.
41
-	 *
42
-	 * @return void
43
-	 */
44
-	public function verify_ipn() {
45
-
46
-		wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
-
48
-		// Validate the IPN.
49
-		if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
-			wp_die( 'PayPal IPN Request Failure', 500 );
51
-		}
52
-
53
-		// Process the IPN.
54
-		$posted  = wp_unslash( $_POST );
55
-		$invoice = $this->get_ipn_invoice( $posted );
56
-
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 );
61
-		}
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'] ) );
65
-
66
-		wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
-		wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
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 );
73
-		}
74
-
75
-		wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
-		wp_die( 'Unsupported IPN type', 200 );
77
-
78
-	}
79
-
80
-	/**
81
-	 * Retrieves IPN Invoice.
82
-	 *
83
-	 * @param array $posted
84
-	 * @return WPInv_Invoice
85
-	 */
86
-	protected function get_ipn_invoice( $posted ) {
87
-
88
-		wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
-
90
-		if ( ! empty( $posted['custom'] ) ) {
91
-			$invoice = new WPInv_Invoice( $posted['custom'] );
92
-
93
-			if ( $invoice->exists() ) {
94
-				wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
-				return $invoice;
96
-			}
97
-
98
-		}
99
-
100
-		wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
-		wp_die( 'Could not retrieve the associated invoice.', 200 );
102
-	}
103
-
104
-	/**
105
-	 * Check PayPal IPN validity.
106
-	 */
107
-	protected function validate_ipn() {
108
-
109
-		wpinv_error_log( 'Validating PayPal IPN response', false );
110
-
111
-		// Retrieve the associated invoice.
112
-		$posted  = wp_unslash( $_POST );
113
-		$invoice = $this->get_ipn_invoice( $posted );
114
-
115
-		if ( $this->gateway->is_sandbox( $invoice ) ) {
116
-			wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
117
-		}
118
-
119
-		// Validate the IPN.
120
-		$posted['cmd'] = '_notify-validate';
121
-
122
-		// Send back post vars to paypal.
123
-		$params = array(
124
-			'body'        => $posted,
125
-			'timeout'     => 60,
126
-			'httpversion' => '1.1',
127
-			'compress'    => false,
128
-			'decompress'  => false,
129
-			'user-agent'  => 'GetPaid/' . WPINV_VERSION,
130
-		);
131
-
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 );
134
-
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 );
138
-			return true;
139
-		}
140
-
141
-		if ( is_wp_error( $response ) ) {
142
-			wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
143
-			return false;
144
-		}
15
+    /**
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20
+    protected $id = 'paypal';
21
+
22
+    /**
23
+     * Payment method object.
24
+     *
25
+     * @var GetPaid_Paypal_Gateway
26
+     */
27
+    protected $gateway;
28
+
29
+    /**
30
+     * Class constructor.
31
+     *
32
+     * @param GetPaid_Paypal_Gateway $gateway
33
+     */
34
+    public function __construct( $gateway ) {
35
+        $this->gateway = $gateway;
36
+        $this->verify_ipn();
37
+    }
38
+
39
+    /**
40
+     * Processes ipns and marks payments as complete.
41
+     *
42
+     * @return void
43
+     */
44
+    public function verify_ipn() {
45
+
46
+        wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
+
48
+        // Validate the IPN.
49
+        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
+            wp_die( 'PayPal IPN Request Failure', 500 );
51
+        }
52
+
53
+        // Process the IPN.
54
+        $posted  = wp_unslash( $_POST );
55
+        $invoice = $this->get_ipn_invoice( $posted );
56
+
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 );
61
+        }
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'] ) );
65
+
66
+        wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
+        wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
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 );
73
+        }
74
+
75
+        wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
+        wp_die( 'Unsupported IPN type', 200 );
77
+
78
+    }
79
+
80
+    /**
81
+     * Retrieves IPN Invoice.
82
+     *
83
+     * @param array $posted
84
+     * @return WPInv_Invoice
85
+     */
86
+    protected function get_ipn_invoice( $posted ) {
87
+
88
+        wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
+
90
+        if ( ! empty( $posted['custom'] ) ) {
91
+            $invoice = new WPInv_Invoice( $posted['custom'] );
92
+
93
+            if ( $invoice->exists() ) {
94
+                wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
+                return $invoice;
96
+            }
97
+
98
+        }
99
+
100
+        wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
+        wp_die( 'Could not retrieve the associated invoice.', 200 );
102
+    }
103
+
104
+    /**
105
+     * Check PayPal IPN validity.
106
+     */
107
+    protected function validate_ipn() {
108
+
109
+        wpinv_error_log( 'Validating PayPal IPN response', false );
110
+
111
+        // Retrieve the associated invoice.
112
+        $posted  = wp_unslash( $_POST );
113
+        $invoice = $this->get_ipn_invoice( $posted );
114
+
115
+        if ( $this->gateway->is_sandbox( $invoice ) ) {
116
+            wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
117
+        }
118
+
119
+        // Validate the IPN.
120
+        $posted['cmd'] = '_notify-validate';
121
+
122
+        // Send back post vars to paypal.
123
+        $params = array(
124
+            'body'        => $posted,
125
+            'timeout'     => 60,
126
+            'httpversion' => '1.1',
127
+            'compress'    => false,
128
+            'decompress'  => false,
129
+            'user-agent'  => 'GetPaid/' . WPINV_VERSION,
130
+        );
131
+
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 );
134
+
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 );
138
+            return true;
139
+        }
140
+
141
+        if ( is_wp_error( $response ) ) {
142
+            wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
143
+            return false;
144
+        }
145 145
 
146
-		wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
147
-		return false;
148
-
149
-	}
146
+        wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
147
+        return false;
148
+
149
+    }
150 150
 
151
-	/**
152
-	 * Check currency from IPN matches the invoice.
153
-	 *
154
-	 * @param WPInv_Invoice $invoice          Invoice object.
155
-	 * @param string   $currency currency to validate.
156
-	 */
157
-	protected function validate_ipn_currency( $invoice, $currency ) {
151
+    /**
152
+     * Check currency from IPN matches the invoice.
153
+     *
154
+     * @param WPInv_Invoice $invoice          Invoice object.
155
+     * @param string   $currency currency to validate.
156
+     */
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
-			/* translators: %s: currency code. */
162
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
161
+            /* translators: %s: currency code. */
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 );
165
-		}
164
+            wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
165
+        }
166 166
 
167
-		wpinv_error_log( $currency, 'Validated IPN Currency', false );
168
-	}
167
+        wpinv_error_log( $currency, 'Validated IPN Currency', false );
168
+    }
169 169
 
170
-	/**
171
-	 * Check payment amount from IPN matches the invoice.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice          Invoice object.
174
-	 * @param float   $amount amount to validate.
175
-	 */
176
-	protected function validate_ipn_amount( $invoice, $amount ) {
177
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
170
+    /**
171
+     * Check payment amount from IPN matches the invoice.
172
+     *
173
+     * @param WPInv_Invoice $invoice          Invoice object.
174
+     * @param float   $amount amount to validate.
175
+     */
176
+    protected function validate_ipn_amount( $invoice, $amount ) {
177
+        if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
178 178
 
179
-			/* translators: %s: Amount. */
180
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
179
+            /* translators: %s: 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 );
183
-		}
182
+            wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
183
+        }
184 184
 
185
-		wpinv_error_log( $amount, 'Validated IPN Amount', false );
186
-	}
185
+        wpinv_error_log( $amount, 'Validated IPN Amount', false );
186
+    }
187 187
 
188
-	/**
189
-	 * Verify receiver email from PayPal.
190
-	 *
191
-	 * @param WPInv_Invoice $invoice          Invoice object.
192
-	 * @param string   $receiver_email Email to validate.
193
-	 */
194
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
195
-		$paypal_email = wpinv_get_option( 'paypal_email' );
188
+    /**
189
+     * Verify receiver email from PayPal.
190
+     *
191
+     * @param WPInv_Invoice $invoice          Invoice object.
192
+     * @param string   $receiver_email Email to validate.
193
+     */
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
-			/* 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 ) );
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 ) );
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 );
204
-		}
203
+            return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
204
+        }
205 205
 
206
-		wpinv_error_log( 'Validated PayPal Email', false );
207
-	}
206
+        wpinv_error_log( 'Validated PayPal Email', false );
207
+    }
208 208
 
209
-	/**
210
-	 * Handles one time payments.
211
-	 *
212
-	 * @param WPInv_Invoice $invoice  Invoice object.
213
-	 * @param array    $posted Posted data.
214
-	 */
215
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
209
+    /**
210
+     * Handles one time payments.
211
+     *
212
+     * @param WPInv_Invoice $invoice  Invoice object.
213
+     * @param array    $posted Posted data.
214
+     */
215
+    protected function ipn_txn_web_accept( $invoice, $posted ) {
216 216
 
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'] );
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'] );
220 220
 
221
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
222
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
223
-
224
-		// Update the transaction id.
225
-		if ( ! empty( $posted['txn_id'] ) ) {
226
-			$invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
227
-			$invoice->save();
228
-		}
221
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
222
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
223
+
224
+        // Update the transaction id.
225
+        if ( ! empty( $posted['txn_id'] ) ) {
226
+            $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
227
+            $invoice->save();
228
+        }
229 229
 
230
-		// Process a refund.
231
-		if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
230
+        // Process a refund.
231
+        if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
232 232
 
233
-			update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
233
+            update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
234 234
 
235
-			if ( ! $invoice->is_refunded() ) {
236
-				$invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
237
-			}
235
+            if ( ! $invoice->is_refunded() ) {
236
+                $invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
237
+            }
238 238
 
239
-			return wpinv_error_log( $posted['reason_code'], false );
240
-		}
239
+            return wpinv_error_log( $posted['reason_code'], false );
240
+        }
241 241
 
242
-		// Process payments.
243
-		if ( $payment_status == 'completed' ) {
242
+        // Process payments.
243
+        if ( $payment_status == 'completed' ) {
244 244
 
245
-			if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
246
-				return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
247
-			}
245
+            if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
246
+                return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
247
+            }
248 248
 
249
-			$this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
249
+            $this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
250 250
 
251
-			$note = '';
251
+            $note = '';
252 252
 
253
-			if ( ! empty( $posted['mc_fee'] ) ) {
254
-				$note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
255
-			}
253
+            if ( ! empty( $posted['mc_fee'] ) ) {
254
+                $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
255
+            }
256 256
 
257
-			if ( ! empty( $posted['payer_status'] ) ) {
258
-				$note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
259
-			}
257
+            if ( ! empty( $posted['payer_status'] ) ) {
258
+                $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
259
+            }
260 260
 
261
-			$invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
262
-			return wpinv_error_log( 'Invoice marked as paid.', false );
261
+            $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
262
+            return wpinv_error_log( 'Invoice marked as paid.', false );
263 263
 
264
-		}
264
+        }
265 265
 
266
-		// Pending payments.
267
-		if ( $payment_status == 'pending' ) {
266
+        // Pending payments.
267
+        if ( $payment_status == 'pending' ) {
268 268
 
269
-			/* translators: %s: pending reason. */
270
-			$invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
269
+            /* translators: %s: pending reason. */
270
+            $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
271 271
 
272
-			return wpinv_error_log( 'Invoice marked as "payment held".', false );
273
-		}
272
+            return wpinv_error_log( 'Invoice marked as "payment held".', false );
273
+        }
274 274
 
275
-		/* translators: %s: payment status. */
276
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
275
+        /* translators: %s: payment status. */
276
+        $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
277 277
 
278
-	}
278
+    }
279 279
 
280
-	/**
281
-	 * Handles one time payments.
282
-	 *
283
-	 * @param WPInv_Invoice $invoice  Invoice object.
284
-	 * @param array    $posted Posted data.
285
-	 */
286
-	protected function ipn_txn_cart( $invoice, $posted ) {
287
-		$this->ipn_txn_web_accept( $invoice, $posted );
288
-	}
280
+    /**
281
+     * Handles one time payments.
282
+     *
283
+     * @param WPInv_Invoice $invoice  Invoice object.
284
+     * @param array    $posted Posted data.
285
+     */
286
+    protected function ipn_txn_cart( $invoice, $posted ) {
287
+        $this->ipn_txn_web_accept( $invoice, $posted );
288
+    }
289 289
 
290
-	/**
291
-	 * Handles subscription sign ups.
292
-	 *
293
-	 * @param WPInv_Invoice $invoice  Invoice object.
294
-	 * @param array    $posted Posted data.
295
-	 */
296
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
290
+    /**
291
+     * Handles subscription sign ups.
292
+     *
293
+     * @param WPInv_Invoice $invoice  Invoice object.
294
+     * @param array    $posted Posted data.
295
+     */
296
+    protected function ipn_txn_subscr_signup( $invoice, $posted ) {
297 297
 
298
-		wpinv_error_log( 'Processing subscription signup', false );
298
+        wpinv_error_log( 'Processing subscription signup', false );
299 299
 
300
-		// Make sure the invoice has a subscription.
301
-		$subscription = getpaid_get_invoice_subscription( $invoice );
300
+        // Make sure the invoice has a subscription.
301
+        $subscription = getpaid_get_invoice_subscription( $invoice );
302 302
 
303
-		if ( empty( $subscription ) ) {
304
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
305
-		}
303
+        if ( empty( $subscription ) ) {
304
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
305
+        }
306 306
 
307
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
307
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
308 308
 
309
-		// Validate the IPN.
310
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
311
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
312
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
309
+        // Validate the IPN.
310
+        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
311
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
312
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
313 313
 
314
-		// Activate the subscription.
315
-		$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
316
-		$subscription->set_date_created( current_time( 'mysql' ) );
317
-		$subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
318
-		$subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
319
-		$subscription->activate();
314
+        // Activate the subscription.
315
+        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
316
+        $subscription->set_date_created( current_time( 'mysql' ) );
317
+        $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
318
+        $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
319
+        $subscription->activate();
320 320
 
321
-		// Set the transaction id.
322
-		if ( ! empty( $posted['txn_id'] ) ) {
323
-			$invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
324
-			$invoice->set_transaction_id( $posted['txn_id'] );
325
-		}
321
+        // Set the transaction id.
322
+        if ( ! empty( $posted['txn_id'] ) ) {
323
+            $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
324
+            $invoice->set_transaction_id( $posted['txn_id'] );
325
+        }
326 326
 
327
-		// Update the payment status.
328
-		$invoice->mark_paid();
327
+        // Update the payment status.
328
+        $invoice->mark_paid();
329 329
 
330
-		$invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
330
+        $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
331 331
 
332
-		wpinv_error_log( 'Subscription started.', false );
333
-	}
332
+        wpinv_error_log( 'Subscription started.', false );
333
+    }
334 334
 
335
-	/**
336
-	 * Handles subscription renewals.
337
-	 *
338
-	 * @param WPInv_Invoice $invoice  Invoice object.
339
-	 * @param array    $posted Posted data.
340
-	 */
341
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
335
+    /**
336
+     * Handles subscription renewals.
337
+     *
338
+     * @param WPInv_Invoice $invoice  Invoice object.
339
+     * @param array    $posted Posted data.
340
+     */
341
+    protected function ipn_txn_subscr_payment( $invoice, $posted ) {
342 342
 
343
-		// Make sure the invoice has a subscription.
344
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
343
+        // Make sure the invoice has a subscription.
344
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
345 345
 
346
-		if ( empty( $subscription ) ) {
347
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
348
-		}
346
+        if ( empty( $subscription ) ) {
347
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
348
+        }
349 349
 
350
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
350
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
351 351
 
352
-		// PayPal sends a subscr_payment for the first payment too.
353
-		$date_completed = getpaid_format_date( $invoice->get_date_completed() );
354
-		$date_created   = getpaid_format_date( $invoice->get_date_created() );
355
-		$today_date     = getpaid_format_date( current_time( 'mysql' ) );
356
-		$payment_date   = getpaid_format_date( $posted['payment_date'] );
357
-		$subscribe_date = getpaid_format_date( $subscription->get_date_created() );
358
-		$dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
352
+        // PayPal sends a subscr_payment for the first payment too.
353
+        $date_completed = getpaid_format_date( $invoice->get_date_completed() );
354
+        $date_created   = getpaid_format_date( $invoice->get_date_created() );
355
+        $today_date     = getpaid_format_date( current_time( 'mysql' ) );
356
+        $payment_date   = getpaid_format_date( $posted['payment_date'] );
357
+        $subscribe_date = getpaid_format_date( $subscription->get_date_created() );
358
+        $dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
359 359
 
360
-		foreach( $dates as $date ) {
360
+        foreach( $dates as $date ) {
361 361
 
362
-			if ( $date !== $today_date && $date !== $payment_date ) {
363
-				continue;
364
-			}
362
+            if ( $date !== $today_date && $date !== $payment_date ) {
363
+                continue;
364
+            }
365 365
 
366
-			if ( ! empty( $posted['txn_id'] ) ) {
367
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
368
-				$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
369
-			}
366
+            if ( ! empty( $posted['txn_id'] ) ) {
367
+                $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
368
+                $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
369
+            }
370 370
 
371
-			return $invoice->mark_paid();
372
-
373
-		}
371
+            return $invoice->mark_paid();
372
+
373
+        }
374 374
 
375
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
376
-
377
-		// Abort if the payment is already recorded.
378
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
379
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
380
-		}
381
-
382
-		$args = array(
383
-			'transaction_id' => $posted['txn_id'],
384
-			'gateway'        => $this->id,
385
-		);
386
-
387
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
375
+        wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
376
+
377
+        // Abort if the payment is already recorded.
378
+        if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
379
+            return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
380
+        }
381
+
382
+        $args = array(
383
+            'transaction_id' => $posted['txn_id'],
384
+            'gateway'        => $this->id,
385
+        );
386
+
387
+        $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
388 388
 
389
-		if ( empty( $invoice ) ) {
390
-			return;
391
-		}
389
+        if ( empty( $invoice ) ) {
390
+            return;
391
+        }
392 392
 
393
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
394
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
393
+        $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
394
+        $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
395 395
 
396
-		$subscription->renew();
397
-		wpinv_error_log( 'Subscription renewed.', false );
396
+        $subscription->renew();
397
+        wpinv_error_log( 'Subscription renewed.', false );
398 398
 
399
-	}
399
+    }
400 400
 
401
-	/**
402
-	 * Handles subscription cancelations.
403
-	 *
404
-	 * @param WPInv_Invoice $invoice  Invoice object.
405
-	 */
406
-	protected function ipn_txn_subscr_cancel( $invoice ) {
401
+    /**
402
+     * Handles subscription cancelations.
403
+     *
404
+     * @param WPInv_Invoice $invoice  Invoice object.
405
+     */
406
+    protected function ipn_txn_subscr_cancel( $invoice ) {
407 407
 
408
-		// Make sure the invoice has a subscription.
409
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
410
-
411
-		if ( empty( $subscription ) ) {
412
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
413
-		}
414
-
415
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
416
-		$subscription->cancel();
417
-		wpinv_error_log( 'Subscription cancelled.', false );
408
+        // Make sure the invoice has a subscription.
409
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
410
+
411
+        if ( empty( $subscription ) ) {
412
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
413
+        }
414
+
415
+        wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
416
+        $subscription->cancel();
417
+        wpinv_error_log( 'Subscription cancelled.', false );
418 418
 
419
-	}
419
+    }
420 420
 
421
-	/**
422
-	 * Handles subscription completions.
423
-	 *
424
-	 * @param WPInv_Invoice $invoice  Invoice object.
425
-	 * @param array    $posted Posted data.
426
-	 */
427
-	protected function ipn_txn_subscr_eot( $invoice ) {
421
+    /**
422
+     * Handles subscription completions.
423
+     *
424
+     * @param WPInv_Invoice $invoice  Invoice object.
425
+     * @param array    $posted Posted data.
426
+     */
427
+    protected function ipn_txn_subscr_eot( $invoice ) {
428 428
 
429
-		// Make sure the invoice has a subscription.
430
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
429
+        // Make sure the invoice has a subscription.
430
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
431 431
 
432
-		if ( empty( $subscription ) ) {
433
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
434
-		}
432
+        if ( empty( $subscription ) ) {
433
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
434
+        }
435 435
 
436
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
437
-		$subscription->complete();
438
-		wpinv_error_log( 'Subscription completed.', false );
436
+        wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
437
+        $subscription->complete();
438
+        wpinv_error_log( 'Subscription completed.', false );
439 439
 
440
-	}
440
+    }
441 441
 
442
-	/**
443
-	 * Handles subscription fails.
444
-	 *
445
-	 * @param WPInv_Invoice $invoice  Invoice object.
446
-	 * @param array    $posted Posted data.
447
-	 */
448
-	protected function ipn_txn_subscr_failed( $invoice ) {
442
+    /**
443
+     * Handles subscription fails.
444
+     *
445
+     * @param WPInv_Invoice $invoice  Invoice object.
446
+     * @param array    $posted Posted data.
447
+     */
448
+    protected function ipn_txn_subscr_failed( $invoice ) {
449 449
 
450
-		// Make sure the invoice has a subscription.
451
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
450
+        // Make sure the invoice has a subscription.
451
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
452 452
 
453
-		if ( empty( $subscription ) ) {
454
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
455
-		}
453
+        if ( empty( $subscription ) ) {
454
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
455
+        }
456 456
 
457
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
458
-		$subscription->failing();
459
-		wpinv_error_log( 'Subscription marked as failing.', false );
457
+        wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
458
+        $subscription->failing();
459
+        wpinv_error_log( 'Subscription marked as failing.', false );
460 460
 
461
-	}
461
+    }
462 462
 
463
-	/**
464
-	 * Handles subscription suspensions.
465
-	 *
466
-	 * @param WPInv_Invoice $invoice  Invoice object.
467
-	 * @param array    $posted Posted data.
468
-	 */
469
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
463
+    /**
464
+     * Handles subscription suspensions.
465
+     *
466
+     * @param WPInv_Invoice $invoice  Invoice object.
467
+     * @param array    $posted Posted data.
468
+     */
469
+    protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
470 470
 
471
-		// Make sure the invoice has a subscription.
472
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
471
+        // Make sure the invoice has a subscription.
472
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
473 473
 
474
-		if ( empty( $subscription ) ) {
475
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
476
-		}
477
-
478
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
479
-		$subscription->cancel();
480
-		wpinv_error_log( 'Subscription cancelled.', false );
481
-	}
474
+        if ( empty( $subscription ) ) {
475
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
476
+        }
477
+
478
+        wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
479
+        $subscription->cancel();
480
+        wpinv_error_log( 'Subscription cancelled.', false );
481
+    }
482 482
 
483 483
 }
Please login to merge, or discard this patch.
Spacing   +150 added lines, -150 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Paypal Payment Gateway IPN handler class.
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
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
 block discarded – undo
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_unslash( $_POST );
55
-		$invoice = $this->get_ipn_invoice( $posted );
54
+		$posted  = 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
 block discarded – undo
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
 block discarded – undo
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_unslash( $_POST );
113
-		$invoice = $this->get_ipn_invoice( $posted );
112
+		$posted  = 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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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,68 +212,68 @@  discard block
 block discarded – undo
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 230
 		// Process a refund.
231
-		if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
231
+		if ($payment_status == 'refunded' || $payment_status == 'reversed') {
232 232
 
233
-			update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
233
+			update_post_meta($invoice->get_id(), 'refunded_remotely', 1);
234 234
 
235
-			if ( ! $invoice->is_refunded() ) {
236
-				$invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
235
+			if (!$invoice->is_refunded()) {
236
+				$invoice->update_status('wpi-refunded', $posted['reason_code']);
237 237
 			}
238 238
 
239
-			return wpinv_error_log( $posted['reason_code'], false );
239
+			return wpinv_error_log($posted['reason_code'], false);
240 240
 		}
241 241
 
242 242
 		// Process payments.
243
-		if ( $payment_status == 'completed' ) {
243
+		if ($payment_status == 'completed') {
244 244
 
245
-			if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
246
-				return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
245
+			if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) {
246
+				return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false);
247 247
 			}
248 248
 
249
-			$this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
249
+			$this->validate_ipn_amount($invoice, $posted['mc_gross']);
250 250
 
251 251
 			$note = '';
252 252
 
253
-			if ( ! empty( $posted['mc_fee'] ) ) {
254
-				$note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
253
+			if (!empty($posted['mc_fee'])) {
254
+				$note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee']));
255 255
 			}
256 256
 
257
-			if ( ! empty( $posted['payer_status'] ) ) {
258
-				$note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
257
+			if (!empty($posted['payer_status'])) {
258
+				$note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status']));
259 259
 			}
260 260
 
261
-			$invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
262
-			return wpinv_error_log( 'Invoice marked as paid.', false );
261
+			$invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note));
262
+			return wpinv_error_log('Invoice marked as paid.', false);
263 263
 
264 264
 		}
265 265
 
266 266
 		// Pending payments.
267
-		if ( $payment_status == 'pending' ) {
267
+		if ($payment_status == 'pending') {
268 268
 
269 269
 			/* translators: %s: pending reason. */
270
-			$invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
270
+			$invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason']));
271 271
 
272
-			return wpinv_error_log( 'Invoice marked as "payment held".', false );
272
+			return wpinv_error_log('Invoice marked as "payment held".', false);
273 273
 		}
274 274
 
275 275
 		/* translators: %s: payment status. */
276
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
276
+		$invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status'])));
277 277
 
278 278
 	}
279 279
 
@@ -283,8 +283,8 @@  discard block
 block discarded – undo
283 283
 	 * @param WPInv_Invoice $invoice  Invoice object.
284 284
 	 * @param array    $posted Posted data.
285 285
 	 */
286
-	protected function ipn_txn_cart( $invoice, $posted ) {
287
-		$this->ipn_txn_web_accept( $invoice, $posted );
286
+	protected function ipn_txn_cart($invoice, $posted) {
287
+		$this->ipn_txn_web_accept($invoice, $posted);
288 288
 	}
289 289
 
290 290
 	/**
@@ -293,43 +293,43 @@  discard block
 block discarded – undo
293 293
 	 * @param WPInv_Invoice $invoice  Invoice object.
294 294
 	 * @param array    $posted Posted data.
295 295
 	 */
296
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
296
+	protected function ipn_txn_subscr_signup($invoice, $posted) {
297 297
 
298
-		wpinv_error_log( 'Processing subscription signup', false );
298
+		wpinv_error_log('Processing subscription signup', false);
299 299
 
300 300
 		// Make sure the invoice has a subscription.
301
-		$subscription = getpaid_get_invoice_subscription( $invoice );
301
+		$subscription = getpaid_get_invoice_subscription($invoice);
302 302
 
303
-		if ( empty( $subscription ) ) {
304
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
303
+		if (empty($subscription)) {
304
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
305 305
 		}
306 306
 
307
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
307
+		wpinv_error_log('Found subscription #' . $subscription->get_id(), false);
308 308
 
309 309
 		// Validate the IPN.
310
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
311
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
312
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
310
+		$business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']);
311
+		$this->validate_ipn_receiver_email($invoice, $business_email);
312
+		$this->validate_ipn_currency($invoice, $posted['mc_currency']);
313 313
 
314 314
 		// Activate the subscription.
315
-		$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
316
-		$subscription->set_date_created( current_time( 'mysql' ) );
317
-		$subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
318
-		$subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
315
+		$duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
316
+		$subscription->set_date_created(current_time('mysql'));
317
+		$subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration)));
318
+		$subscription->set_profile_id(sanitize_text_field($posted['subscr_id']));
319 319
 		$subscription->activate();
320 320
 
321 321
 		// Set the transaction id.
322
-		if ( ! empty( $posted['txn_id'] ) ) {
323
-			$invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
324
-			$invoice->set_transaction_id( $posted['txn_id'] );
322
+		if (!empty($posted['txn_id'])) {
323
+			$invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
324
+			$invoice->set_transaction_id($posted['txn_id']);
325 325
 		}
326 326
 
327 327
 		// Update the payment status.
328 328
 		$invoice->mark_paid();
329 329
 
330
-		$invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
330
+		$invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
331 331
 
332
-		wpinv_error_log( 'Subscription started.', false );
332
+		wpinv_error_log('Subscription started.', false);
333 333
 	}
334 334
 
335 335
 	/**
@@ -338,45 +338,45 @@  discard block
 block discarded – undo
338 338
 	 * @param WPInv_Invoice $invoice  Invoice object.
339 339
 	 * @param array    $posted Posted data.
340 340
 	 */
341
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
341
+	protected function ipn_txn_subscr_payment($invoice, $posted) {
342 342
 
343 343
 		// Make sure the invoice has a subscription.
344
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
344
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
345 345
 
346
-		if ( empty( $subscription ) ) {
347
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
346
+		if (empty($subscription)) {
347
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
348 348
 		}
349 349
 
350
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
350
+		wpinv_error_log('Found subscription #' . $subscription->get_id(), false);
351 351
 
352 352
 		// PayPal sends a subscr_payment for the first payment too.
353
-		$date_completed = getpaid_format_date( $invoice->get_date_completed() );
354
-		$date_created   = getpaid_format_date( $invoice->get_date_created() );
355
-		$today_date     = getpaid_format_date( current_time( 'mysql' ) );
356
-		$payment_date   = getpaid_format_date( $posted['payment_date'] );
357
-		$subscribe_date = getpaid_format_date( $subscription->get_date_created() );
358
-		$dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
353
+		$date_completed = getpaid_format_date($invoice->get_date_completed());
354
+		$date_created   = getpaid_format_date($invoice->get_date_created());
355
+		$today_date     = getpaid_format_date(current_time('mysql'));
356
+		$payment_date   = getpaid_format_date($posted['payment_date']);
357
+		$subscribe_date = getpaid_format_date($subscription->get_date_created());
358
+		$dates          = array_filter(compact('date_completed', 'date_created', 'subscribe_date'));
359 359
 
360
-		foreach( $dates as $date ) {
360
+		foreach ($dates as $date) {
361 361
 
362
-			if ( $date !== $today_date && $date !== $payment_date ) {
362
+			if ($date !== $today_date && $date !== $payment_date) {
363 363
 				continue;
364 364
 			}
365 365
 
366
-			if ( ! empty( $posted['txn_id'] ) ) {
367
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
368
-				$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
366
+			if (!empty($posted['txn_id'])) {
367
+				$invoice->set_transaction_id(sanitize_text_field($posted['txn_id']));	
368
+				$invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true);
369 369
 			}
370 370
 
371 371
 			return $invoice->mark_paid();
372 372
 
373 373
 		}
374 374
 
375
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
375
+		wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false);
376 376
 
377 377
 		// Abort if the payment is already recorded.
378
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
379
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
378
+		if (wpinv_get_id_by_transaction_id($posted['txn_id'])) {
379
+			return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false);
380 380
 		}
381 381
 
382 382
 		$args = array(
@@ -384,17 +384,17 @@  discard block
 block discarded – undo
384 384
 			'gateway'        => $this->id,
385 385
 		);
386 386
 
387
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
387
+		$invoice = wpinv_get_invoice($subscription->add_payment($args));
388 388
 
389
-		if ( empty( $invoice ) ) {
389
+		if (empty($invoice)) {
390 390
 			return;
391 391
 		}
392 392
 
393
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
394
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
393
+		$invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
394
+		$invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
395 395
 
396 396
 		$subscription->renew();
397
-		wpinv_error_log( 'Subscription renewed.', false );
397
+		wpinv_error_log('Subscription renewed.', false);
398 398
 
399 399
 	}
400 400
 
@@ -403,18 +403,18 @@  discard block
 block discarded – undo
403 403
 	 *
404 404
 	 * @param WPInv_Invoice $invoice  Invoice object.
405 405
 	 */
406
-	protected function ipn_txn_subscr_cancel( $invoice ) {
406
+	protected function ipn_txn_subscr_cancel($invoice) {
407 407
 
408 408
 		// Make sure the invoice has a subscription.
409
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
409
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
410 410
 
411
-		if ( empty( $subscription ) ) {
412
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
411
+		if (empty($subscription)) {
412
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
413 413
 		}
414 414
 
415
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
415
+		wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false);
416 416
 		$subscription->cancel();
417
-		wpinv_error_log( 'Subscription cancelled.', false );
417
+		wpinv_error_log('Subscription cancelled.', false);
418 418
 
419 419
 	}
420 420
 
@@ -424,18 +424,18 @@  discard block
 block discarded – undo
424 424
 	 * @param WPInv_Invoice $invoice  Invoice object.
425 425
 	 * @param array    $posted Posted data.
426 426
 	 */
427
-	protected function ipn_txn_subscr_eot( $invoice ) {
427
+	protected function ipn_txn_subscr_eot($invoice) {
428 428
 
429 429
 		// Make sure the invoice has a subscription.
430
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
430
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
431 431
 
432
-		if ( empty( $subscription ) ) {
433
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
432
+		if (empty($subscription)) {
433
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
434 434
 		}
435 435
 
436
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
436
+		wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false);
437 437
 		$subscription->complete();
438
-		wpinv_error_log( 'Subscription completed.', false );
438
+		wpinv_error_log('Subscription completed.', false);
439 439
 
440 440
 	}
441 441
 
@@ -445,18 +445,18 @@  discard block
 block discarded – undo
445 445
 	 * @param WPInv_Invoice $invoice  Invoice object.
446 446
 	 * @param array    $posted Posted data.
447 447
 	 */
448
-	protected function ipn_txn_subscr_failed( $invoice ) {
448
+	protected function ipn_txn_subscr_failed($invoice) {
449 449
 
450 450
 		// Make sure the invoice has a subscription.
451
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
451
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
452 452
 
453
-		if ( empty( $subscription ) ) {
454
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
453
+		if (empty($subscription)) {
454
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
455 455
 		}
456 456
 
457
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
457
+		wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false);
458 458
 		$subscription->failing();
459
-		wpinv_error_log( 'Subscription marked as failing.', false );
459
+		wpinv_error_log('Subscription marked as failing.', false);
460 460
 
461 461
 	}
462 462
 
@@ -466,18 +466,18 @@  discard block
 block discarded – undo
466 466
 	 * @param WPInv_Invoice $invoice  Invoice object.
467 467
 	 * @param array    $posted Posted data.
468 468
 	 */
469
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
469
+	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) {
470 470
 
471 471
 		// Make sure the invoice has a subscription.
472
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
472
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
473 473
 
474
-		if ( empty( $subscription ) ) {
475
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
474
+		if (empty($subscription)) {
475
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
476 476
 		}
477 477
 
478
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
478
+		wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false);
479 479
 		$subscription->cancel();
480
-		wpinv_error_log( 'Subscription cancelled.', false );
480
+		wpinv_error_log('Subscription cancelled.', false);
481 481
 	}
482 482
 
483 483
 }
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 2 patches
Indentation   +1035 added lines, -1035 removed lines patch added patch discarded remove patch
@@ -15,125 +15,125 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => '',
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	/**
66
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
-	 *
68
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
-	 * @param  bool $deprecated
70
-	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
72
-
73
-		parent::__construct( $subscription );
74
-
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} else {
84
-			$this->set_object_read( true );
85
-		}
86
-
87
-		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
-
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
92
-		}
93
-
94
-	}
95
-
96
-	/**
97
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
-	 *
99
-	 *
100
-	 * @static
101
-	 * @param string $value
102
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
103
-	 * @since 1.0.19
104
-	 * @return int
105
-	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => '',
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    /**
66
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
67
+     *
68
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69
+     * @param  bool $deprecated
70
+     */
71
+    function __construct( $subscription = 0, $deprecated = false ) {
72
+
73
+        parent::__construct( $subscription );
74
+
75
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
+            $this->set_id( $subscription );
77
+        } elseif ( $subscription instanceof self ) {
78
+            $this->set_id( $subscription->get_id() );
79
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
+            $this->set_id( $subscription_id );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } else {
84
+            $this->set_object_read( true );
85
+        }
86
+
87
+        // Load the datastore.
88
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
89
+
90
+        if ( $this->get_id() > 0 ) {
91
+            $this->data_store->read( $this );
92
+        }
93
+
94
+    }
95
+
96
+    /**
97
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
98
+     *
99
+     *
100
+     * @static
101
+     * @param string $value
102
+     * @param string $field Either invoice_id, transaction_id or profile_id.
103
+     * @since 1.0.19
104
+     * @return int
105
+     */
106
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
107 107
         global $wpdb;
108 108
 
109
-		// Trim the value.
110
-		$value = trim( $value );
109
+        // Trim the value.
110
+        $value = trim( $value );
111 111
 
112
-		if ( empty( $value ) ) {
113
-			return 0;
114
-		}
112
+        if ( empty( $value ) ) {
113
+            return 0;
114
+        }
115 115
 
116
-		if ( 'invoice_id' == $field ) {
117
-			$field = 'parent_payment_id';
118
-		}
116
+        if ( 'invoice_id' == $field ) {
117
+            $field = 'parent_payment_id';
118
+        }
119 119
 
120 120
         // Valid fields.
121 121
         $fields = array(
122
-			'parent_payment_id',
123
-			'transaction_id',
124
-			'profile_id'
125
-		);
126
-
127
-		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
-			return 0;
130
-		}
131
-
132
-		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
135
-			return $subscription_id;
136
-		}
122
+            'parent_payment_id',
123
+            'transaction_id',
124
+            'profile_id'
125
+        );
126
+
127
+        // Ensure a field has been passed.
128
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
129
+            return 0;
130
+        }
131
+
132
+        // Maybe retrieve from the cache.
133
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
+        if ( ! empty( $subscription_id ) ) {
135
+            return $subscription_id;
136
+        }
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -141,34 +141,34 @@  discard block
 block discarded – undo
141 141
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
145
-			return 0;
146
-		}
144
+        if ( empty( $subscription_id ) ) {
145
+            return 0;
146
+        }
147 147
 
148
-		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
148
+        // Update the cache with our data.
149
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150 150
 
151
-		return $subscription_id;
152
-	}
151
+        return $subscription_id;
152
+    }
153 153
 
154
-	/**
154
+    /**
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
-	}
158
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
162
+    }
163 163
 
164
-	/**
164
+    /**
165 165
      * Checks if a subscription key is set.
166 166
      */
167 167
     public function _isset( $key ) {
168 168
         return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
169
-	}
169
+    }
170 170
 
171
-	/*
171
+    /*
172 172
 	|--------------------------------------------------------------------------
173 173
 	| CRUD methods
174 174
 	|--------------------------------------------------------------------------
@@ -177,545 +177,545 @@  discard block
 block discarded – undo
177 177
 	|
178 178
     */
179 179
 
180
-	/*
181
-	|--------------------------------------------------------------------------
182
-	| Getters
183
-	|--------------------------------------------------------------------------
184
-	*/
180
+    /*
181
+	|--------------------------------------------------------------------------
182
+	| Getters
183
+	|--------------------------------------------------------------------------
184
+	*/
185
+
186
+    /**
187
+     * Get customer id.
188
+     *
189
+     * @since 1.0.19
190
+     * @param  string $context View or edit context.
191
+     * @return int
192
+     */
193
+    public function get_customer_id( $context = 'view' ) {
194
+        return (int) $this->get_prop( 'customer_id', $context );
195
+    }
196
+
197
+    /**
198
+     * Get customer information.
199
+     *
200
+     * @since 1.0.19
201
+     * @param  string $context View or edit context.
202
+     * @return WP_User|false WP_User object on success, false on failure.
203
+     */
204
+    public function get_customer( $context = 'view' ) {
205
+        return get_userdata( $this->get_customer_id( $context ) );
206
+    }
207
+
208
+    /**
209
+     * Get parent invoice id.
210
+     *
211
+     * @since 1.0.19
212
+     * @param  string $context View or edit context.
213
+     * @return int
214
+     */
215
+    public function get_parent_invoice_id( $context = 'view' ) {
216
+        return (int) $this->get_prop( 'parent_payment_id', $context );
217
+    }
218
+
219
+    /**
220
+     * Alias for self::get_parent_invoice_id().
221
+     *
222
+     * @since 1.0.19
223
+     * @param  string $context View or edit context.
224
+     * @return int
225
+     */
226
+    public function get_parent_payment_id( $context = 'view' ) {
227
+        return $this->get_parent_invoice_id( $context );
228
+    }
229
+
230
+    /**
231
+     * Alias for self::get_parent_invoice_id().
232
+     *
233
+     * @since  1.0.0
234
+     * @return int
235
+     */
236
+    public function get_original_payment_id( $context = 'view' ) {
237
+        return $this->get_parent_invoice_id( $context );
238
+    }
239
+
240
+    /**
241
+     * Get parent invoice.
242
+     *
243
+     * @since 1.0.19
244
+     * @param  string $context View or edit context.
245
+     * @return WPInv_Invoice
246
+     */
247
+    public function get_parent_invoice( $context = 'view' ) {
248
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
+    }
250
+
251
+    /**
252
+     * Alias for self::get_parent_invoice().
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @return WPInv_Invoice
257
+     */
258
+    public function get_parent_payment( $context = 'view' ) {
259
+        return $this->get_parent_invoice( $context );
260
+    }
261
+
262
+    /**
263
+     * Get subscription's product id.
264
+     *
265
+     * @since 1.0.19
266
+     * @param  string $context View or edit context.
267
+     * @return int
268
+     */
269
+    public function get_product_id( $context = 'view' ) {
270
+        return (int) $this->get_prop( 'product_id', $context );
271
+    }
272
+
273
+    /**
274
+     * Get the subscription product.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return WPInv_Item
279
+     */
280
+    public function get_product( $context = 'view' ) {
281
+        return new WPInv_Item( $this->get_product_id( $context ) );
282
+    }
283
+
284
+    /**
285
+     * Get parent invoice's gateway.
286
+     *
287
+     * Here for backwards compatibility.
288
+     *
289
+     * @since 1.0.19
290
+     * @param  string $context View or edit context.
291
+     * @return string
292
+     */
293
+    public function get_gateway( $context = 'view' ) {
294
+        return $this->get_parent_invoice( $context )->get_gateway();
295
+    }
296
+
297
+    /**
298
+     * Get the period of a renewal.
299
+     *
300
+     * @since 1.0.19
301
+     * @param  string $context View or edit context.
302
+     * @return string
303
+     */
304
+    public function get_period( $context = 'view' ) {
305
+        return $this->get_prop( 'period', $context );
306
+    }
307
+
308
+    /**
309
+     * Get number of periods each renewal is valid for.
310
+     *
311
+     * @since 1.0.19
312
+     * @param  string $context View or edit context.
313
+     * @return int
314
+     */
315
+    public function get_frequency( $context = 'view' ) {
316
+        return (int) $this->get_prop( 'frequency', $context );
317
+    }
318
+
319
+    /**
320
+     * Get the initial amount for the subscription.
321
+     *
322
+     * @since 1.0.19
323
+     * @param  string $context View or edit context.
324
+     * @return float
325
+     */
326
+    public function get_initial_amount( $context = 'view' ) {
327
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
+    }
329
+
330
+    /**
331
+     * Get the recurring amount for the subscription.
332
+     *
333
+     * @since 1.0.19
334
+     * @param  string $context View or edit context.
335
+     * @return float
336
+     */
337
+    public function get_recurring_amount( $context = 'view' ) {
338
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
+    }
340
+
341
+    /**
342
+     * Get number of times that this subscription can be renewed.
343
+     *
344
+     * @since 1.0.19
345
+     * @param  string $context View or edit context.
346
+     * @return int
347
+     */
348
+    public function get_bill_times( $context = 'view' ) {
349
+        return (int) $this->get_prop( 'bill_times', $context );
350
+    }
351
+
352
+    /**
353
+     * Get transaction id of this subscription's parent invoice.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  string $context View or edit context.
357
+     * @return string
358
+     */
359
+    public function get_transaction_id( $context = 'view' ) {
360
+        return $this->get_prop( 'transaction_id', $context );
361
+    }
362
+
363
+    /**
364
+     * Get the date that the subscription was created.
365
+     *
366
+     * @since 1.0.19
367
+     * @param  string $context View or edit context.
368
+     * @return string
369
+     */
370
+    public function get_created( $context = 'view' ) {
371
+        return $this->get_prop( 'created', $context );
372
+    }
373
+
374
+    /**
375
+     * Alias for self::get_created().
376
+     *
377
+     * @since 1.0.19
378
+     * @param  string $context View or edit context.
379
+     * @return string
380
+     */
381
+    public function get_date_created( $context = 'view' ) {
382
+        return $this->get_created( $context );
383
+    }
384
+
385
+    /**
386
+     * Retrieves the creation date in a timestamp
387
+     *
388
+     * @since  1.0.0
389
+     * @return int
390
+     */
391
+    public function get_time_created() {
392
+        $created = $this->get_date_created();
393
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
+    }
395
+
396
+    /**
397
+     * Get GMT date when the subscription was created.
398
+     *
399
+     * @since 1.0.19
400
+     * @param  string $context View or edit context.
401
+     * @return string
402
+     */
403
+    public function get_date_created_gmt( $context = 'view' ) {
404
+        $date = $this->get_date_created( $context );
405
+
406
+        if ( $date ) {
407
+            $date = get_gmt_from_date( $date );
408
+        }
409
+        return $date;
410
+    }
411
+
412
+    /**
413
+     * Get the date that the subscription will renew.
414
+     *
415
+     * @since 1.0.19
416
+     * @param  string $context View or edit context.
417
+     * @return string
418
+     */
419
+    public function get_next_renewal_date( $context = 'view' ) {
420
+        return $this->get_prop( 'expiration', $context );
421
+    }
422
+
423
+    /**
424
+     * Alias for self::get_next_renewal_date().
425
+     *
426
+     * @since 1.0.19
427
+     * @param  string $context View or edit context.
428
+     * @return string
429
+     */
430
+    public function get_expiration( $context = 'view' ) {
431
+        return $this->get_next_renewal_date( $context );
432
+    }
433
+
434
+    /**
435
+     * Retrieves the expiration date in a timestamp
436
+     *
437
+     * @since  1.0.0
438
+     * @return int
439
+     */
440
+    public function get_expiration_time() {
441
+        $expiration = $this->get_expiration();
442
+
443
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
+            return current_time( 'timestamp' );
445
+        }
446
+
447
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
+    }
450
+
451
+    /**
452
+     * Get GMT date when the subscription will renew.
453
+     *
454
+     * @since 1.0.19
455
+     * @param  string $context View or edit context.
456
+     * @return string
457
+     */
458
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
459
+        $date = $this->get_next_renewal_date( $context );
460
+
461
+        if ( $date ) {
462
+            $date = get_gmt_from_date( $date );
463
+        }
464
+        return $date;
465
+    }
466
+
467
+    /**
468
+     * Get the subscription's trial period.
469
+     *
470
+     * @since 1.0.19
471
+     * @param  string $context View or edit context.
472
+     * @return string
473
+     */
474
+    public function get_trial_period( $context = 'view' ) {
475
+        return $this->get_prop( 'trial_period', $context );
476
+    }
477
+
478
+    /**
479
+     * Get the subscription's status.
480
+     *
481
+     * @since 1.0.19
482
+     * @param  string $context View or edit context.
483
+     * @return string
484
+     */
485
+    public function get_status( $context = 'view' ) {
486
+        return $this->get_prop( 'status', $context );
487
+    }
488
+
489
+    /**
490
+     * Get the subscription's profile id.
491
+     *
492
+     * @since 1.0.19
493
+     * @param  string $context View or edit context.
494
+     * @return string
495
+     */
496
+    public function get_profile_id( $context = 'view' ) {
497
+        return $this->get_prop( 'profile_id', $context );
498
+    }
499
+
500
+    /*
501
+	|--------------------------------------------------------------------------
502
+	| Setters
503
+	|--------------------------------------------------------------------------
504
+	*/
505
+
506
+    /**
507
+     * Set customer id.
508
+     *
509
+     * @since 1.0.19
510
+     * @param  int $value The customer's id.
511
+     */
512
+    public function set_customer_id( $value ) {
513
+        $this->set_prop( 'customer_id', (int) $value );
514
+    }
515
+
516
+    /**
517
+     * Set parent invoice id.
518
+     *
519
+     * @since 1.0.19
520
+     * @param  int $value The parent invoice id.
521
+     */
522
+    public function set_parent_invoice_id( $value ) {
523
+        $this->set_prop( 'parent_payment_id', (int) $value );
524
+    }
525
+
526
+    /**
527
+     * Alias for self::set_parent_invoice_id().
528
+     *
529
+     * @since 1.0.19
530
+     * @param  int $value The parent invoice id.
531
+     */
532
+    public function set_parent_payment_id( $value ) {
533
+        $this->set_parent_invoice_id( $value );
534
+    }
535
+
536
+    /**
537
+     * Alias for self::set_parent_invoice_id().
538
+     *
539
+     * @since 1.0.19
540
+     * @param  int $value The parent invoice id.
541
+     */
542
+    public function set_original_payment_id( $value ) {
543
+        $this->set_parent_invoice_id( $value );
544
+    }
545
+
546
+    /**
547
+     * Set subscription's product id.
548
+     *
549
+     * @since 1.0.19
550
+     * @param  int $value The subscription product id.
551
+     */
552
+    public function set_product_id( $value ) {
553
+        $this->set_prop( 'product_id', (int) $value );
554
+    }
555
+
556
+    /**
557
+     * Set the period of a renewal.
558
+     *
559
+     * @since 1.0.19
560
+     * @param  string $value The renewal period.
561
+     */
562
+    public function set_period( $value ) {
563
+        $this->set_prop( 'period', $value );
564
+    }
565
+
566
+    /**
567
+     * Set number of periods each renewal is valid for.
568
+     *
569
+     * @since 1.0.19
570
+     * @param  int $value The subscription frequency.
571
+     */
572
+    public function set_frequency( $value ) {
573
+        $value = empty( $value ) ? 1 : (int) $value;
574
+        $this->set_prop( 'frequency', absint( $value ) );
575
+    }
576
+
577
+    /**
578
+     * Set the initial amount for the subscription.
579
+     *
580
+     * @since 1.0.19
581
+     * @param  float $value The initial subcription amount.
582
+     */
583
+    public function set_initial_amount( $value ) {
584
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
+    }
586
+
587
+    /**
588
+     * Set the recurring amount for the subscription.
589
+     *
590
+     * @since 1.0.19
591
+     * @param  float $value The recurring subcription amount.
592
+     */
593
+    public function set_recurring_amount( $value ) {
594
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
+    }
596
+
597
+    /**
598
+     * Set number of times that this subscription can be renewed.
599
+     *
600
+     * @since 1.0.19
601
+     * @param  int $value Bill times.
602
+     */
603
+    public function set_bill_times( $value ) {
604
+        $this->set_prop( 'bill_times', (int) $value );
605
+    }
606
+
607
+    /**
608
+     * Get transaction id of this subscription's parent invoice.
609
+     *
610
+     * @since 1.0.19
611
+     * @param string $value Bill times.
612
+     */
613
+    public function set_transaction_id( $value ) {
614
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
+    }
616
+
617
+    /**
618
+     * Set date when this subscription started.
619
+     *
620
+     * @since 1.0.19
621
+     * @param string $value strtotime compliant date.
622
+     */
623
+    public function set_created( $value ) {
624
+        $date = strtotime( $value );
625
+
626
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
+            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
628
+            return;
629
+        }
630
+
631
+        $this->set_prop( 'created', '' );
185 632
 
186
-	/**
187
-	 * Get customer id.
188
-	 *
189
-	 * @since 1.0.19
190
-	 * @param  string $context View or edit context.
191
-	 * @return int
192
-	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
195
-	}
196
-
197
-	/**
198
-	 * Get customer information.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @param  string $context View or edit context.
202
-	 * @return WP_User|false WP_User object on success, false on failure.
203
-	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
206
-	}
207
-
208
-	/**
209
-	 * Get parent invoice id.
210
-	 *
211
-	 * @since 1.0.19
212
-	 * @param  string $context View or edit context.
213
-	 * @return int
214
-	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
217
-	}
218
-
219
-	/**
220
-	 * Alias for self::get_parent_invoice_id().
221
-	 *
222
-	 * @since 1.0.19
223
-	 * @param  string $context View or edit context.
224
-	 * @return int
225
-	 */
226
-    public function get_parent_payment_id( $context = 'view' ) {
227
-        return $this->get_parent_invoice_id( $context );
228
-	}
633
+    }
229 634
 
230
-	/**
231
-     * Alias for self::get_parent_invoice_id().
635
+    /**
636
+     * Alias for self::set_created().
232 637
      *
233
-     * @since  1.0.0
234
-     * @return int
638
+     * @since 1.0.19
639
+     * @param string $value strtotime compliant date.
235 640
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
641
+    public function set_date_created( $value ) {
642
+        $this->set_created( $value );
238 643
     }
239 644
 
240
-	/**
241
-	 * Get parent invoice.
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @param  string $context View or edit context.
245
-	 * @return WPInv_Invoice
246
-	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
249
-	}
250
-
251
-	/**
252
-	 * Alias for self::get_parent_invoice().
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @return WPInv_Invoice
257
-	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
260
-	}
261
-
262
-	/**
263
-	 * Get subscription's product id.
264
-	 *
265
-	 * @since 1.0.19
266
-	 * @param  string $context View or edit context.
267
-	 * @return int
268
-	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
271
-	}
272
-
273
-	/**
274
-	 * Get the subscription product.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return WPInv_Item
279
-	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
282
-	}
283
-
284
-	/**
285
-	 * Get parent invoice's gateway.
286
-	 *
287
-	 * Here for backwards compatibility.
288
-	 *
289
-	 * @since 1.0.19
290
-	 * @param  string $context View or edit context.
291
-	 * @return string
292
-	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
295
-	}
296
-
297
-	/**
298
-	 * Get the period of a renewal.
299
-	 *
300
-	 * @since 1.0.19
301
-	 * @param  string $context View or edit context.
302
-	 * @return string
303
-	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
306
-	}
307
-
308
-	/**
309
-	 * Get number of periods each renewal is valid for.
310
-	 *
311
-	 * @since 1.0.19
312
-	 * @param  string $context View or edit context.
313
-	 * @return int
314
-	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
317
-	}
318
-
319
-	/**
320
-	 * Get the initial amount for the subscription.
321
-	 *
322
-	 * @since 1.0.19
323
-	 * @param  string $context View or edit context.
324
-	 * @return float
325
-	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
328
-	}
329
-
330
-	/**
331
-	 * Get the recurring amount for the subscription.
332
-	 *
333
-	 * @since 1.0.19
334
-	 * @param  string $context View or edit context.
335
-	 * @return float
336
-	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
339
-	}
340
-
341
-	/**
342
-	 * Get number of times that this subscription can be renewed.
343
-	 *
344
-	 * @since 1.0.19
345
-	 * @param  string $context View or edit context.
346
-	 * @return int
347
-	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
350
-	}
351
-
352
-	/**
353
-	 * Get transaction id of this subscription's parent invoice.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  string $context View or edit context.
357
-	 * @return string
358
-	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
361
-	}
362
-
363
-	/**
364
-	 * Get the date that the subscription was created.
365
-	 *
366
-	 * @since 1.0.19
367
-	 * @param  string $context View or edit context.
368
-	 * @return string
369
-	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
372
-	}
373
-
374
-	/**
375
-	 * Alias for self::get_created().
376
-	 *
377
-	 * @since 1.0.19
378
-	 * @param  string $context View or edit context.
379
-	 * @return string
380
-	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
383
-	}
384
-
385
-	/**
386
-	 * Retrieves the creation date in a timestamp
387
-	 *
388
-	 * @since  1.0.0
389
-	 * @return int
390
-	 */
391
-	public function get_time_created() {
392
-		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
394
-	}
395
-
396
-	/**
397
-	 * Get GMT date when the subscription was created.
398
-	 *
399
-	 * @since 1.0.19
400
-	 * @param  string $context View or edit context.
401
-	 * @return string
402
-	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
645
+    /**
646
+     * Set the date that the subscription will renew.
647
+     *
648
+     * @since 1.0.19
649
+     * @param string $value strtotime compliant date.
650
+     */
651
+    public function set_next_renewal_date( $value ) {
652
+        $date = strtotime( $value );
405 653
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
654
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
+            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
656
+            return;
408 657
         }
409
-		return $date;
410
-	}
411
-
412
-	/**
413
-	 * Get the date that the subscription will renew.
414
-	 *
415
-	 * @since 1.0.19
416
-	 * @param  string $context View or edit context.
417
-	 * @return string
418
-	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
421
-	}
422
-
423
-	/**
424
-	 * Alias for self::get_next_renewal_date().
425
-	 *
426
-	 * @since 1.0.19
427
-	 * @param  string $context View or edit context.
428
-	 * @return string
429
-	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
432
-	}
433
-
434
-	/**
435
-	 * Retrieves the expiration date in a timestamp
436
-	 *
437
-	 * @since  1.0.0
438
-	 * @return int
439
-	 */
440
-	public function get_expiration_time() {
441
-		$expiration = $this->get_expiration();
442
-
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
445
-		}
446
-
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
449
-	}
450
-
451
-	/**
452
-	 * Get GMT date when the subscription will renew.
453
-	 *
454
-	 * @since 1.0.19
455
-	 * @param  string $context View or edit context.
456
-	 * @return string
457
-	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
460 658
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
463
-        }
464
-		return $date;
465
-	}
466
-
467
-	/**
468
-	 * Get the subscription's trial period.
469
-	 *
470
-	 * @since 1.0.19
471
-	 * @param  string $context View or edit context.
472
-	 * @return string
473
-	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
476
-	}
477
-
478
-	/**
479
-	 * Get the subscription's status.
480
-	 *
481
-	 * @since 1.0.19
482
-	 * @param  string $context View or edit context.
483
-	 * @return string
484
-	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
487
-	}
488
-
489
-	/**
490
-	 * Get the subscription's profile id.
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param  string $context View or edit context.
494
-	 * @return string
495
-	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
498
-	}
499
-
500
-	/*
501
-	|--------------------------------------------------------------------------
502
-	| Setters
503
-	|--------------------------------------------------------------------------
504
-	*/
659
+        $this->set_prop( 'expiration', '' );
505 660
 
506
-	/**
507
-	 * Set customer id.
508
-	 *
509
-	 * @since 1.0.19
510
-	 * @param  int $value The customer's id.
511
-	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
514
-	}
515
-
516
-	/**
517
-	 * Set parent invoice id.
518
-	 *
519
-	 * @since 1.0.19
520
-	 * @param  int $value The parent invoice id.
521
-	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
524
-	}
525
-
526
-	/**
527
-	 * Alias for self::set_parent_invoice_id().
528
-	 *
529
-	 * @since 1.0.19
530
-	 * @param  int $value The parent invoice id.
531
-	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
534
-	}
661
+    }
535 662
 
536
-	/**
537
-     * Alias for self::set_parent_invoice_id().
663
+    /**
664
+     * Alias for self::set_next_renewal_date().
538 665
      *
539 666
      * @since 1.0.19
540
-	 * @param  int $value The parent invoice id.
667
+     * @param string $value strtotime compliant date.
541 668
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
544
-	}
545
-
546
-	/**
547
-	 * Set subscription's product id.
548
-	 *
549
-	 * @since 1.0.19
550
-	 * @param  int $value The subscription product id.
551
-	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
554
-	}
555
-
556
-	/**
557
-	 * Set the period of a renewal.
558
-	 *
559
-	 * @since 1.0.19
560
-	 * @param  string $value The renewal period.
561
-	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
564
-	}
565
-
566
-	/**
567
-	 * Set number of periods each renewal is valid for.
568
-	 *
569
-	 * @since 1.0.19
570
-	 * @param  int $value The subscription frequency.
571
-	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
575
-	}
576
-
577
-	/**
578
-	 * Set the initial amount for the subscription.
579
-	 *
580
-	 * @since 1.0.19
581
-	 * @param  float $value The initial subcription amount.
582
-	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
585
-	}
586
-
587
-	/**
588
-	 * Set the recurring amount for the subscription.
589
-	 *
590
-	 * @since 1.0.19
591
-	 * @param  float $value The recurring subcription amount.
592
-	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
595
-	}
596
-
597
-	/**
598
-	 * Set number of times that this subscription can be renewed.
599
-	 *
600
-	 * @since 1.0.19
601
-	 * @param  int $value Bill times.
602
-	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
605
-	}
606
-
607
-	/**
608
-	 * Get transaction id of this subscription's parent invoice.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param string $value Bill times.
612
-	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
615
-	}
616
-
617
-	/**
618
-	 * Set date when this subscription started.
619
-	 *
620
-	 * @since 1.0.19
621
-	 * @param string $value strtotime compliant date.
622
-	 */
623
-	public function set_created( $value ) {
624
-        $date = strtotime( $value );
669
+    public function set_expiration( $value ) {
670
+        $this->set_next_renewal_date( $value );
671
+    }
625 672
 
626
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
673
+    /**
674
+     * Set the subscription's trial period.
675
+     *
676
+     * @since 1.0.19
677
+     * @param string $value trial period e.g 1 year.
678
+     */
679
+    public function set_trial_period( $value ) {
680
+        $this->set_prop( 'trial_period', $value );
681
+    }
682
+
683
+    /**
684
+     * Set the subscription's status.
685
+     *
686
+     * @since 1.0.19
687
+     * @param string $new_status    New subscription status.
688
+     */
689
+    public function set_status( $new_status ) {
690
+
691
+        // Abort if this is not a valid status;
692
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
628 693
             return;
629 694
         }
630 695
 
631
-		$this->set_prop( 'created', '' );
696
+        $old_status = $this->get_status();
697
+        $this->set_prop( 'status', $new_status );
632 698
 
633
-	}
699
+        if ( true === $this->object_read && $old_status !== $new_status ) {
700
+            $this->status_transition = array(
701
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
702
+                'to'     => $new_status,
703
+            );
704
+        }
634 705
 
635
-	/**
636
-	 * Alias for self::set_created().
637
-	 *
638
-	 * @since 1.0.19
639
-	 * @param string $value strtotime compliant date.
640
-	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
643 706
     }
644 707
 
645
-	/**
646
-	 * Set the date that the subscription will renew.
647
-	 *
648
-	 * @since 1.0.19
649
-	 * @param string $value strtotime compliant date.
650
-	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
708
+    /**
709
+     * Set the subscription's (remote) profile id.
710
+     *
711
+     * @since 1.0.19
712
+     * @param  string $value the remote profile id.
713
+     */
714
+    public function set_profile_id( $value ) {
715
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
716
+    }
653 717
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
656
-            return;
657
-		}
658
-
659
-		$this->set_prop( 'expiration', '' );
660
-
661
-	}
662
-
663
-	/**
664
-	 * Alias for self::set_next_renewal_date().
665
-	 *
666
-	 * @since 1.0.19
667
-	 * @param string $value strtotime compliant date.
668
-	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
671
-    }
672
-
673
-	/**
674
-	 * Set the subscription's trial period.
675
-	 *
676
-	 * @since 1.0.19
677
-	 * @param string $value trial period e.g 1 year.
678
-	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
681
-	}
682
-
683
-	/**
684
-	 * Set the subscription's status.
685
-	 *
686
-	 * @since 1.0.19
687
-	 * @param string $new_status    New subscription status.
688
-	 */
689
-	public function set_status( $new_status ) {
690
-
691
-		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
693
-			return;
694
-		}
695
-
696
-		$old_status = $this->get_status();
697
-		$this->set_prop( 'status', $new_status );
698
-
699
-		if ( true === $this->object_read && $old_status !== $new_status ) {
700
-			$this->status_transition = array(
701
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
702
-				'to'     => $new_status,
703
-			);
704
-		}
705
-
706
-	}
707
-
708
-	/**
709
-	 * Set the subscription's (remote) profile id.
710
-	 *
711
-	 * @since 1.0.19
712
-	 * @param  string $value the remote profile id.
713
-	 */
714
-	public function set_profile_id( $value ) {
715
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
716
-	}
717
-
718
-	/*
718
+    /*
719 719
 	|--------------------------------------------------------------------------
720 720
 	| Boolean methods
721 721
 	|--------------------------------------------------------------------------
@@ -724,55 +724,55 @@  discard block
 block discarded – undo
724 724
 	|
725 725
 	*/
726 726
 
727
-	/**
727
+    /**
728 728
      * Checks if the subscription has a given status.
729
-	 *
730
-	 * @param string|array String or array of strings to check for.
731
-	 * @return bool
729
+     *
730
+     * @param string|array String or array of strings to check for.
731
+     * @return bool
732 732
      */
733 733
     public function has_status( $status ) {
734 734
         return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
735
-	}
735
+    }
736 736
 
737
-	/**
737
+    /**
738 738
      * Checks if the subscription has a trial period.
739
-	 *
740
-	 * @return bool
739
+     *
740
+     * @return bool
741 741
      */
742 742
     public function has_trial_period() {
743
-		$period = $this->get_trial_period();
743
+        $period = $this->get_trial_period();
744 744
         return ! empty( $period );
745
-	}
746
-
747
-	/**
748
-	 * Is the subscription active?
749
-	 *
750
-	 * @return bool
751
-	 */
752
-	public function is_active() {
753
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
754
-	}
755
-
756
-	/**
757
-	 * Is the subscription expired?
758
-	 *
759
-	 * @return bool
760
-	 */
761
-	public function is_expired() {
762
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
763
-	}
764
-
765
-	/**
766
-	 * Is this the last renewals?
767
-	 *
768
-	 * @return bool
769
-	 */
770
-	public function is_last_renewal() {
771
-		$max_bills = $this->get_bill_times();
772
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
773
-	}
774
-
775
-	/*
745
+    }
746
+
747
+    /**
748
+     * Is the subscription active?
749
+     *
750
+     * @return bool
751
+     */
752
+    public function is_active() {
753
+        return $this->has_status( 'active trialling' ) && ! $this->is_expired();
754
+    }
755
+
756
+    /**
757
+     * Is the subscription expired?
758
+     *
759
+     * @return bool
760
+     */
761
+    public function is_expired() {
762
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
763
+    }
764
+
765
+    /**
766
+     * Is this the last renewals?
767
+     *
768
+     * @return bool
769
+     */
770
+    public function is_last_renewal() {
771
+        $max_bills = $this->get_bill_times();
772
+        return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
773
+    }
774
+
775
+    /*
776 776
 	|--------------------------------------------------------------------------
777 777
 	| Additional methods
778 778
 	|--------------------------------------------------------------------------
@@ -781,27 +781,27 @@  discard block
 block discarded – undo
781 781
 	|
782 782
 	*/
783 783
 
784
-	/**
785
-	 * Backwards compatibilty.
786
-	 */
787
-	public function create( $data = array() ) {
784
+    /**
785
+     * Backwards compatibilty.
786
+     */
787
+    public function create( $data = array() ) {
788 788
 
789
-		// Set the properties.
790
-		if ( is_array( $data ) ) {
791
-			$this->set_props( $data );
792
-		}
789
+        // Set the properties.
790
+        if ( is_array( $data ) ) {
791
+            $this->set_props( $data );
792
+        }
793 793
 
794
-		// Save the item.
795
-		return $this->save();
794
+        // Save the item.
795
+        return $this->save();
796 796
 
797
-	}
797
+    }
798 798
 
799
-	/**
800
-	 * Backwards compatibilty.
801
-	 */
802
-	public function update( $args = array() ) {
803
-		return $this->create( $args );
804
-	}
799
+    /**
800
+     * Backwards compatibilty.
801
+     */
802
+    public function update( $args = array() ) {
803
+        return $this->create( $args );
804
+    }
805 805
 
806 806
     /**
807 807
      * Retrieve renewal payments for a subscription
@@ -811,22 +811,22 @@  discard block
 block discarded – undo
811 811
      */
812 812
     public function get_child_payments( $hide_pending = true ) {
813 813
 
814
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
814
+        $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
815 815
 
816
-		if ( ! $hide_pending ) {
817
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
818
-		}
816
+        if ( ! $hide_pending ) {
817
+            $statuses = array_keys( wpinv_get_invoice_statuses() );
818
+        }
819 819
 
820 820
         return get_posts(
821
-			array(
822
-            	'post_parent'    => $this->get_parent_payment_id(),
823
-            	'numberposts'    => -1,
824
-            	'post_status'    => $statuses,
825
-            	'orderby'        => 'ID',
826
-            	'order'          => 'ASC',
827
-            	'post_type'      => 'wpi_invoice'
828
-			)
829
-		);
821
+            array(
822
+                'post_parent'    => $this->get_parent_payment_id(),
823
+                'numberposts'    => -1,
824
+                'post_status'    => $statuses,
825
+                'orderby'        => 'ID',
826
+                'order'          => 'ASC',
827
+                'post_type'      => 'wpi_invoice'
828
+            )
829
+        );
830 830
     }
831 831
 
832 832
     /**
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
      * @return int
837 837
      */
838 838
     public function get_total_payments() {
839
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
839
+        return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
840 840
     }
841 841
 
842 842
     /**
@@ -860,57 +860,57 @@  discard block
 block discarded – undo
860 860
      *
861 861
      * @since  2.4
862 862
      * @param  array $args Array of values for the payment, including amount and transaction ID
863
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
863
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
864 864
      * @return bool
865 865
      */
866 866
     public function add_payment( $args = array(), $invoice = false ) {
867 867
 
868
-		// Process each payment once.
868
+        // Process each payment once.
869 869
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
870 870
             return false;
871 871
         }
872 872
 
873
-		// Are we creating a new invoice?
874
-		if ( empty( $invoice ) ) {
875
-			$invoice = $this->create_payment();
873
+        // Are we creating a new invoice?
874
+        if ( empty( $invoice ) ) {
875
+            $invoice = $this->create_payment();
876 876
 
877
-			if ( empty( $invoice ) ) {
878
-				return false;
879
-			}
877
+            if ( empty( $invoice ) ) {
878
+                return false;
879
+            }
880 880
 
881
-		}
881
+        }
882 882
 
883
-		$invoice->set_status( 'wpi-renewal' );
883
+        $invoice->set_status( 'wpi-renewal' );
884 884
 
885
-		// Maybe set a transaction id.
886
-		if ( ! empty( $args['transaction_id'] ) ) {
887
-			$invoice->set_transaction_id( $args['transaction_id'] );
888
-		}
885
+        // Maybe set a transaction id.
886
+        if ( ! empty( $args['transaction_id'] ) ) {
887
+            $invoice->set_transaction_id( $args['transaction_id'] );
888
+        }
889 889
 
890
-		// Set the completed date.
891
-		$invoice->set_completed_date( current_time( 'mysql' ) );
890
+        // Set the completed date.
891
+        $invoice->set_completed_date( current_time( 'mysql' ) );
892 892
 
893
-		// And the gateway.
894
-		if ( ! empty( $args['gateway'] ) ) {
895
-			$invoice->set_gateway( $args['gateway'] );
896
-		}
893
+        // And the gateway.
894
+        if ( ! empty( $args['gateway'] ) ) {
895
+            $invoice->set_gateway( $args['gateway'] );
896
+        }
897 897
 
898
-		$invoice->save();
898
+        $invoice->save();
899 899
 
900
-		if ( ! $invoice->exists() ) {
901
-			return false;
902
-		}
900
+        if ( ! $invoice->exists() ) {
901
+            return false;
902
+        }
903 903
 
904
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
905
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
904
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
905
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
906 906
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
907 907
 
908 908
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
909 909
 
910 910
         return $invoice->get_id();
911
-	}
911
+    }
912 912
 
913
-	/**
913
+    /**
914 914
      * Creates a new invoice and returns it.
915 915
      *
916 916
      * @since  1.0.19
@@ -918,124 +918,124 @@  discard block
 block discarded – undo
918 918
      */
919 919
     public function create_payment() {
920 920
 
921
-		$parent_invoice = $this->get_parent_payment();
922
-
923
-		if ( ! $parent_invoice->exists() ) {
924
-			return false;
925
-		}
926
-
927
-		// Duplicate the parent invoice.
928
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
929
-		$invoice->set_parent_id( $parent_invoice->get_id() );
930
-		$invoice->set_subscription_id( $this->get_id() );
931
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
932
-
933
-		// Set invoice items.
934
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
935
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
936
-		$invoice_items      = array();
937
-
938
-		foreach ( $invoice->get_items() as $item ) {
939
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
940
-				$invoice_items[] = $item;
941
-			}
942
-		}
943
-
944
-		$invoice->set_items( $invoice_items );
945
-
946
-		if ( ! empty( $subscription_group['fees'] ) ) {
947
-			$invoice->set_fees( $subscription_group['fees'] );
948
-		}
949
-
950
-		// Maybe recalculate discount (Pre-GetPaid Fix).
951
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
952
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
953
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
954
-		}
955
-
956
-		$invoice->recalculate_total();
957
-		$invoice->set_status( 'wpi-pending' );
958
-		$invoice->save();
959
-
960
-		return $invoice->exists() ? $invoice : false;
961
-    }
962
-
963
-	/**
964
-	 * Renews or completes a subscription
965
-	 *
966
-	 * @since  1.0.0
967
-	 * @return int The subscription's id
968
-	 */
969
-	public function renew() {
970
-
971
-		// Complete subscription if applicable
972
-		if ( $this->is_last_renewal() ) {
973
-			return $this->complete();
974
-		}
975
-
976
-		// Calculate new expiration
977
-		$frequency      = $this->get_frequency();
978
-		$period         = $this->get_period();
979
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
980
-
981
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
982
-		$this->set_status( 'active' );
983
-		$this->save();
984
-
985
-		do_action( 'getpaid_subscription_renewed', $this );
986
-
987
-		return $this->get_id();
988
-	}
989
-
990
-	/**
991
-	 * Marks a subscription as completed
992
-	 *
993
-	 * Subscription is completed when the number of payments matches the billing_times field
994
-	 *
995
-	 * @since  1.0.0
996
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
997
-	 */
998
-	public function complete() {
999
-
1000
-		// Only mark a subscription as complete if it's not already cancelled.
1001
-		if ( $this->has_status( 'cancelled' ) ) {
1002
-			return false;
1003
-		}
1004
-
1005
-		$this->set_status( 'completed' );
1006
-		return $this->save();
1007
-
1008
-	}
1009
-
1010
-	/**
1011
-	 * Marks a subscription as expired
1012
-	 *
1013
-	 * @since  1.0.0
1014
-	 * @param  bool $check_expiration
1015
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1016
-	 */
1017
-	public function expire( $check_expiration = false ) {
1018
-
1019
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1020
-			// Do not mark as expired since real expiration date is in the future
1021
-			return false;
1022
-		}
1023
-
1024
-		$this->set_status( 'expired' );
1025
-		return $this->save();
1026
-
1027
-	}
1028
-
1029
-	/**
1030
-	 * Marks a subscription as failing
1031
-	 *
1032
-	 * @since  2.4.2
1033
-	 * @return int Subscription id.
1034
-	 */
1035
-	public function failing() {
1036
-		$this->set_status( 'failing' );
1037
-		return $this->save();
1038
-	}
921
+        $parent_invoice = $this->get_parent_payment();
922
+
923
+        if ( ! $parent_invoice->exists() ) {
924
+            return false;
925
+        }
926
+
927
+        // Duplicate the parent invoice.
928
+        $invoice = getpaid_duplicate_invoice( $parent_invoice );
929
+        $invoice->set_parent_id( $parent_invoice->get_id() );
930
+        $invoice->set_subscription_id( $this->get_id() );
931
+        $invoice->set_remote_subscription_id( $this->get_profile_id() );
932
+
933
+        // Set invoice items.
934
+        $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
935
+        $allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
936
+        $invoice_items      = array();
937
+
938
+        foreach ( $invoice->get_items() as $item ) {
939
+            if ( in_array( $item->get_id(), $allowed_items ) ) {
940
+                $invoice_items[] = $item;
941
+            }
942
+        }
943
+
944
+        $invoice->set_items( $invoice_items );
945
+
946
+        if ( ! empty( $subscription_group['fees'] ) ) {
947
+            $invoice->set_fees( $subscription_group['fees'] );
948
+        }
949
+
950
+        // Maybe recalculate discount (Pre-GetPaid Fix).
951
+        $discount = new WPInv_Discount( $invoice->get_discount_code() );
952
+        if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
953
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
954
+        }
955
+
956
+        $invoice->recalculate_total();
957
+        $invoice->set_status( 'wpi-pending' );
958
+        $invoice->save();
959
+
960
+        return $invoice->exists() ? $invoice : false;
961
+    }
962
+
963
+    /**
964
+     * Renews or completes a subscription
965
+     *
966
+     * @since  1.0.0
967
+     * @return int The subscription's id
968
+     */
969
+    public function renew() {
970
+
971
+        // Complete subscription if applicable
972
+        if ( $this->is_last_renewal() ) {
973
+            return $this->complete();
974
+        }
975
+
976
+        // Calculate new expiration
977
+        $frequency      = $this->get_frequency();
978
+        $period         = $this->get_period();
979
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
980
+
981
+        $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
982
+        $this->set_status( 'active' );
983
+        $this->save();
984
+
985
+        do_action( 'getpaid_subscription_renewed', $this );
986
+
987
+        return $this->get_id();
988
+    }
989
+
990
+    /**
991
+     * Marks a subscription as completed
992
+     *
993
+     * Subscription is completed when the number of payments matches the billing_times field
994
+     *
995
+     * @since  1.0.0
996
+     * @return int|bool Subscription id or false if the subscription is cancelled.
997
+     */
998
+    public function complete() {
999
+
1000
+        // Only mark a subscription as complete if it's not already cancelled.
1001
+        if ( $this->has_status( 'cancelled' ) ) {
1002
+            return false;
1003
+        }
1004
+
1005
+        $this->set_status( 'completed' );
1006
+        return $this->save();
1007
+
1008
+    }
1009
+
1010
+    /**
1011
+     * Marks a subscription as expired
1012
+     *
1013
+     * @since  1.0.0
1014
+     * @param  bool $check_expiration
1015
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1016
+     */
1017
+    public function expire( $check_expiration = false ) {
1018
+
1019
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1020
+            // Do not mark as expired since real expiration date is in the future
1021
+            return false;
1022
+        }
1023
+
1024
+        $this->set_status( 'expired' );
1025
+        return $this->save();
1026
+
1027
+    }
1028
+
1029
+    /**
1030
+     * Marks a subscription as failing
1031
+     *
1032
+     * @since  2.4.2
1033
+     * @return int Subscription id.
1034
+     */
1035
+    public function failing() {
1036
+        $this->set_status( 'failing' );
1037
+        return $this->save();
1038
+    }
1039 1039
 
1040 1040
     /**
1041 1041
      * Marks a subscription as cancelled
@@ -1044,19 +1044,19 @@  discard block
 block discarded – undo
1044 1044
      * @return int Subscription id.
1045 1045
      */
1046 1046
     public function cancel() {
1047
-		$this->set_status( 'cancelled' );
1048
-		return $this->save();
1047
+        $this->set_status( 'cancelled' );
1048
+        return $this->save();
1049 1049
     }
1050 1050
 
1051
-	/**
1052
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1053
-	 *
1054
-	 * @since  1.0.0
1055
-	 * @return bool
1056
-	 */
1057
-	public function can_cancel() {
1058
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1059
-	}
1051
+    /**
1052
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1053
+     *
1054
+     * @since  1.0.0
1055
+     * @return bool
1056
+     */
1057
+    public function can_cancel() {
1058
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1059
+    }
1060 1060
 
1061 1061
     /**
1062 1062
      * Returns an array of subscription statuses that can be cancelled
@@ -1069,96 +1069,96 @@  discard block
 block discarded – undo
1069 1069
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1070 1070
     }
1071 1071
 
1072
-	/**
1073
-	 * Retrieves the URL to cancel subscription
1074
-	 *
1075
-	 * @since  1.0.0
1076
-	 * @return string
1077
-	 */
1078
-	public function get_cancel_url() {
1079
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1080
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1081
-	}
1082
-
1083
-	/**
1084
-	 * Retrieves the URL to view a subscription
1085
-	 *
1086
-	 * @since  1.0.19
1087
-	 * @return string
1088
-	 */
1089
-	public function get_view_url() {
1090
-
1091
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1092
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1093
-
1094
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1095
-	}
1096
-
1097
-	/**
1098
-	 * Determines if subscription can be manually renewed
1099
-	 *
1100
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1101
-	 * that can be renewed manually
1102
-	 *
1103
-	 * @since  2.5
1104
-	 * @return bool
1105
-	 */
1106
-	public function can_renew() {
1107
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1108
-	}
1109
-
1110
-	/**
1111
-	 * Retrieves the URL to renew a subscription
1112
-	 *
1113
-	 * @since  2.5
1114
-	 * @return string
1115
-	 */
1116
-	public function get_renew_url() {
1117
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1118
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1119
-	}
1120
-
1121
-	/**
1122
-	 * Determines if subscription can have their payment method updated
1123
-	 *
1124
-	 * @since  1.0.0
1125
-	 * @return bool
1126
-	 */
1127
-	public function can_update() {
1128
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1129
-	}
1130
-
1131
-	/**
1132
-	 * Retrieves the URL to update subscription
1133
-	 *
1134
-	 * @since  1.0.0
1135
-	 * @return string
1136
-	 */
1137
-	public function get_update_url() {
1138
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1139
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1140
-	}
1141
-
1142
-	/**
1143
-	 * Retrieves the subscription status label
1144
-	 *
1145
-	 * @since  1.0.0
1146
-	 * @return string
1147
-	 */
1148
-	public function get_status_label() {
1149
-		return getpaid_get_subscription_status_label( $this->get_status() );
1150
-	}
1151
-
1152
-	/**
1153
-	 * Retrieves the subscription status class
1154
-	 *
1155
-	 * @since  1.0.19
1156
-	 * @return string
1157
-	 */
1158
-	public function get_status_class() {
1159
-		$statuses = getpaid_get_subscription_status_classes();
1160
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1161
-	}
1072
+    /**
1073
+     * Retrieves the URL to cancel subscription
1074
+     *
1075
+     * @since  1.0.0
1076
+     * @return string
1077
+     */
1078
+    public function get_cancel_url() {
1079
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1080
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1081
+    }
1082
+
1083
+    /**
1084
+     * Retrieves the URL to view a subscription
1085
+     *
1086
+     * @since  1.0.19
1087
+     * @return string
1088
+     */
1089
+    public function get_view_url() {
1090
+
1091
+        $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1092
+        $url = add_query_arg( 'subscription', $this->get_id(), $url );
1093
+
1094
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1095
+    }
1096
+
1097
+    /**
1098
+     * Determines if subscription can be manually renewed
1099
+     *
1100
+     * This method is filtered by payment gateways in order to return true on subscriptions
1101
+     * that can be renewed manually
1102
+     *
1103
+     * @since  2.5
1104
+     * @return bool
1105
+     */
1106
+    public function can_renew() {
1107
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1108
+    }
1109
+
1110
+    /**
1111
+     * Retrieves the URL to renew a subscription
1112
+     *
1113
+     * @since  2.5
1114
+     * @return string
1115
+     */
1116
+    public function get_renew_url() {
1117
+        $url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1118
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1119
+    }
1120
+
1121
+    /**
1122
+     * Determines if subscription can have their payment method updated
1123
+     *
1124
+     * @since  1.0.0
1125
+     * @return bool
1126
+     */
1127
+    public function can_update() {
1128
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1129
+    }
1130
+
1131
+    /**
1132
+     * Retrieves the URL to update subscription
1133
+     *
1134
+     * @since  1.0.0
1135
+     * @return string
1136
+     */
1137
+    public function get_update_url() {
1138
+        $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1139
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1140
+    }
1141
+
1142
+    /**
1143
+     * Retrieves the subscription status label
1144
+     *
1145
+     * @since  1.0.0
1146
+     * @return string
1147
+     */
1148
+    public function get_status_label() {
1149
+        return getpaid_get_subscription_status_label( $this->get_status() );
1150
+    }
1151
+
1152
+    /**
1153
+     * Retrieves the subscription status class
1154
+     *
1155
+     * @since  1.0.19
1156
+     * @return string
1157
+     */
1158
+    public function get_status_class() {
1159
+        $statuses = getpaid_get_subscription_status_classes();
1160
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1161
+    }
1162 1162
 
1163 1163
     /**
1164 1164
      * Retrieves the subscription status label
@@ -1168,11 +1168,11 @@  discard block
 block discarded – undo
1168 1168
      */
1169 1169
     public function get_status_label_html() {
1170 1170
 
1171
-		$status_label = sanitize_text_field( $this->get_status_label() );
1172
-		$class        = esc_attr( $this->get_status_class() );
1173
-		$status       = sanitize_html_class( $this->get_status() );
1171
+        $status_label = sanitize_text_field( $this->get_status_label() );
1172
+        $class        = esc_attr( $this->get_status_class() );
1173
+        $status       = sanitize_html_class( $this->get_status() );
1174 1174
 
1175
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1175
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1176 1176
     }
1177 1177
 
1178 1178
     /**
@@ -1183,75 +1183,75 @@  discard block
 block discarded – undo
1183 1183
      * @return bool
1184 1184
      */
1185 1185
     public function payment_exists( $txn_id = '' ) {
1186
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1186
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1187 1187
         return ! empty( $invoice_id );
1188
-	}
1189
-
1190
-	/**
1191
-	 * Handle the status transition.
1192
-	 */
1193
-	protected function status_transition() {
1194
-		$status_transition = $this->status_transition;
1195
-
1196
-		// Reset status transition variable.
1197
-		$this->status_transition = false;
1198
-
1199
-		if ( $status_transition ) {
1200
-			try {
1201
-
1202
-				// Fire a hook for the status change.
1203
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1204
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1205
-
1206
-				if ( ! empty( $status_transition['from'] ) ) {
1207
-
1208
-					/* translators: 1: old subscription status 2: new subscription status */
1209
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1210
-
1211
-					// Note the transition occurred.
1212
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1213
-
1214
-					// Fire another hook.
1215
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1216
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1217
-
1218
-				} else {
1219
-					/* translators: %s: new invoice status */
1220
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1221
-
1222
-					// Note the transition occurred.
1223
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1224
-
1225
-				}
1226
-			} catch ( Exception $e ) {
1227
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1228
-			}
1229
-		}
1230
-
1231
-	}
1232
-
1233
-	/**
1234
-	 * Save data to the database.
1235
-	 *
1236
-	 * @since 1.0.19
1237
-	 * @return int subscription ID
1238
-	 */
1239
-	public function save() {
1240
-		parent::save();
1241
-		$this->status_transition();
1242
-		return $this->get_id();
1243
-	}
1244
-
1245
-	/**
1246
-	 * Activates a subscription.
1247
-	 *
1248
-	 * @since 1.0.19
1249
-	 * @return int subscription ID
1250
-	 */
1251
-	public function activate() {
1252
-		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1253
-		$this->set_status( $status );
1254
-		return $this->save();
1255
-	}
1188
+    }
1189
+
1190
+    /**
1191
+     * Handle the status transition.
1192
+     */
1193
+    protected function status_transition() {
1194
+        $status_transition = $this->status_transition;
1195
+
1196
+        // Reset status transition variable.
1197
+        $this->status_transition = false;
1198
+
1199
+        if ( $status_transition ) {
1200
+            try {
1201
+
1202
+                // Fire a hook for the status change.
1203
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1204
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1205
+
1206
+                if ( ! empty( $status_transition['from'] ) ) {
1207
+
1208
+                    /* translators: 1: old subscription status 2: new subscription status */
1209
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1210
+
1211
+                    // Note the transition occurred.
1212
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1213
+
1214
+                    // Fire another hook.
1215
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1216
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1217
+
1218
+                } else {
1219
+                    /* translators: %s: new invoice status */
1220
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1221
+
1222
+                    // Note the transition occurred.
1223
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1224
+
1225
+                }
1226
+            } catch ( Exception $e ) {
1227
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1228
+            }
1229
+        }
1230
+
1231
+    }
1232
+
1233
+    /**
1234
+     * Save data to the database.
1235
+     *
1236
+     * @since 1.0.19
1237
+     * @return int subscription ID
1238
+     */
1239
+    public function save() {
1240
+        parent::save();
1241
+        $this->status_transition();
1242
+        return $this->get_id();
1243
+    }
1244
+
1245
+    /**
1246
+     * Activates a subscription.
1247
+     *
1248
+     * @since 1.0.19
1249
+     * @return int subscription ID
1250
+     */
1251
+    public function activate() {
1252
+        $status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1253
+        $this->set_status( $status );
1254
+        return $this->save();
1255
+    }
1256 1256
 
1257 1257
 }
Please login to merge, or discard this patch.
Spacing   +230 added lines, -230 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * The Subscription Class
@@ -68,27 +68,27 @@  discard block
 block discarded – undo
68 68
 	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
69 69
 	 * @param  bool $deprecated
70 70
 	 */
71
-	function __construct( $subscription = 0, $deprecated = false ) {
71
+	function __construct($subscription = 0, $deprecated = false) {
72 72
 
73
-		parent::__construct( $subscription );
73
+		parent::__construct($subscription);
74 74
 
75
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
76
-			$this->set_id( $subscription );
77
-		} elseif ( $subscription instanceof self ) {
78
-			$this->set_id( $subscription->get_id() );
79
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
80
-			$this->set_id( $subscription_id );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
75
+		if (!$deprecated && !empty($subscription) && is_numeric($subscription)) {
76
+			$this->set_id($subscription);
77
+		} elseif ($subscription instanceof self) {
78
+			$this->set_id($subscription->get_id());
79
+		} elseif ($deprecated && $subscription_id = self::get_subscription_id_by_field($subscription, 'profile_id')) {
80
+			$this->set_id($subscription_id);
81
+		} elseif (!empty($subscription->id)) {
82
+			$this->set_id($subscription->id);
83 83
 		} else {
84
-			$this->set_object_read( true );
84
+			$this->set_object_read(true);
85 85
 		}
86 86
 
87 87
 		// Load the datastore.
88
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
88
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
89 89
 
90
-		if ( $this->get_id() > 0 ) {
91
-			$this->data_store->read( $this );
90
+		if ($this->get_id() > 0) {
91
+			$this->data_store->read($this);
92 92
 		}
93 93
 
94 94
 	}
@@ -103,17 +103,17 @@  discard block
 block discarded – undo
103 103
 	 * @since 1.0.19
104 104
 	 * @return int
105 105
 	 */
106
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
106
+	public static function get_subscription_id_by_field($value, $field = 'profile_id') {
107 107
         global $wpdb;
108 108
 
109 109
 		// Trim the value.
110
-		$value = trim( $value );
110
+		$value = trim($value);
111 111
 
112
-		if ( empty( $value ) ) {
112
+		if (empty($value)) {
113 113
 			return 0;
114 114
 		}
115 115
 
116
-		if ( 'invoice_id' == $field ) {
116
+		if ('invoice_id' == $field) {
117 117
 			$field = 'parent_payment_id';
118 118
 		}
119 119
 
@@ -125,28 +125,28 @@  discard block
 block discarded – undo
125 125
 		);
126 126
 
127 127
 		// Ensure a field has been passed.
128
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
128
+		if (empty($field) || !in_array($field, $fields)) {
129 129
 			return 0;
130 130
 		}
131 131
 
132 132
 		// Maybe retrieve from the cache.
133
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
134
-		if ( ! empty( $subscription_id ) ) {
133
+		$subscription_id = wp_cache_get($value, "getpaid_subscription_{$field}s_to_subscription_ids");
134
+		if (!empty($subscription_id)) {
135 135
 			return $subscription_id;
136 136
 		}
137 137
 
138 138
         // Fetch from the db.
139 139
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
140 140
         $subscription_id  = (int) $wpdb->get_var(
141
-            $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
141
+            $wpdb->prepare("SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value)
142 142
         );
143 143
 
144
-		if ( empty( $subscription_id ) ) {
144
+		if (empty($subscription_id)) {
145 145
 			return 0;
146 146
 		}
147 147
 
148 148
 		// Update the cache with our data.
149
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
149
+		wp_cache_set($value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids");
150 150
 
151 151
 		return $subscription_id;
152 152
 	}
@@ -155,17 +155,17 @@  discard block
 block discarded – undo
155 155
      * Clears the subscription's cache.
156 156
      */
157 157
     public function clear_cache() {
158
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
159
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
160
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
158
+		wp_cache_delete($this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids');
159
+		wp_cache_delete($this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids');
160
+		wp_cache_delete($this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids');
161
+		wp_cache_delete($this->get_id(), 'getpaid_subscriptions');
162 162
 	}
163 163
 
164 164
 	/**
165 165
      * Checks if a subscription key is set.
166 166
      */
167
-    public function _isset( $key ) {
168
-        return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
167
+    public function _isset($key) {
168
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
169 169
 	}
170 170
 
171 171
 	/*
@@ -190,8 +190,8 @@  discard block
 block discarded – undo
190 190
 	 * @param  string $context View or edit context.
191 191
 	 * @return int
192 192
 	 */
193
-	public function get_customer_id( $context = 'view' ) {
194
-		return (int) $this->get_prop( 'customer_id', $context );
193
+	public function get_customer_id($context = 'view') {
194
+		return (int) $this->get_prop('customer_id', $context);
195 195
 	}
196 196
 
197 197
 	/**
@@ -201,8 +201,8 @@  discard block
 block discarded – undo
201 201
 	 * @param  string $context View or edit context.
202 202
 	 * @return WP_User|false WP_User object on success, false on failure.
203 203
 	 */
204
-	public function get_customer( $context = 'view' ) {
205
-		return get_userdata( $this->get_customer_id( $context ) );
204
+	public function get_customer($context = 'view') {
205
+		return get_userdata($this->get_customer_id($context));
206 206
 	}
207 207
 
208 208
 	/**
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
 	 * @param  string $context View or edit context.
213 213
 	 * @return int
214 214
 	 */
215
-	public function get_parent_invoice_id( $context = 'view' ) {
216
-		return (int) $this->get_prop( 'parent_payment_id', $context );
215
+	public function get_parent_invoice_id($context = 'view') {
216
+		return (int) $this->get_prop('parent_payment_id', $context);
217 217
 	}
218 218
 
219 219
 	/**
@@ -223,8 +223,8 @@  discard block
 block discarded – undo
223 223
 	 * @param  string $context View or edit context.
224 224
 	 * @return int
225 225
 	 */
226
-    public function get_parent_payment_id( $context = 'view' ) {
227
-        return $this->get_parent_invoice_id( $context );
226
+    public function get_parent_payment_id($context = 'view') {
227
+        return $this->get_parent_invoice_id($context);
228 228
 	}
229 229
 
230 230
 	/**
@@ -233,8 +233,8 @@  discard block
 block discarded – undo
233 233
      * @since  1.0.0
234 234
      * @return int
235 235
      */
236
-    public function get_original_payment_id( $context = 'view' ) {
237
-        return $this->get_parent_invoice_id( $context );
236
+    public function get_original_payment_id($context = 'view') {
237
+        return $this->get_parent_invoice_id($context);
238 238
     }
239 239
 
240 240
 	/**
@@ -244,8 +244,8 @@  discard block
 block discarded – undo
244 244
 	 * @param  string $context View or edit context.
245 245
 	 * @return WPInv_Invoice
246 246
 	 */
247
-	public function get_parent_invoice( $context = 'view' ) {
248
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
247
+	public function get_parent_invoice($context = 'view') {
248
+		return new WPInv_Invoice($this->get_parent_invoice_id($context));
249 249
 	}
250 250
 
251 251
 	/**
@@ -255,8 +255,8 @@  discard block
 block discarded – undo
255 255
 	 * @param  string $context View or edit context.
256 256
 	 * @return WPInv_Invoice
257 257
 	 */
258
-    public function get_parent_payment( $context = 'view' ) {
259
-        return $this->get_parent_invoice( $context );
258
+    public function get_parent_payment($context = 'view') {
259
+        return $this->get_parent_invoice($context);
260 260
 	}
261 261
 
262 262
 	/**
@@ -266,8 +266,8 @@  discard block
 block discarded – undo
266 266
 	 * @param  string $context View or edit context.
267 267
 	 * @return int
268 268
 	 */
269
-	public function get_product_id( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'product_id', $context );
269
+	public function get_product_id($context = 'view') {
270
+		return (int) $this->get_prop('product_id', $context);
271 271
 	}
272 272
 
273 273
 	/**
@@ -277,8 +277,8 @@  discard block
 block discarded – undo
277 277
 	 * @param  string $context View or edit context.
278 278
 	 * @return WPInv_Item
279 279
 	 */
280
-	public function get_product( $context = 'view' ) {
281
-		return new WPInv_Item( $this->get_product_id( $context ) );
280
+	public function get_product($context = 'view') {
281
+		return new WPInv_Item($this->get_product_id($context));
282 282
 	}
283 283
 
284 284
 	/**
@@ -290,8 +290,8 @@  discard block
 block discarded – undo
290 290
 	 * @param  string $context View or edit context.
291 291
 	 * @return string
292 292
 	 */
293
-	public function get_gateway( $context = 'view' ) {
294
-		return $this->get_parent_invoice( $context )->get_gateway();
293
+	public function get_gateway($context = 'view') {
294
+		return $this->get_parent_invoice($context)->get_gateway();
295 295
 	}
296 296
 
297 297
 	/**
@@ -301,8 +301,8 @@  discard block
 block discarded – undo
301 301
 	 * @param  string $context View or edit context.
302 302
 	 * @return string
303 303
 	 */
304
-	public function get_period( $context = 'view' ) {
305
-		return $this->get_prop( 'period', $context );
304
+	public function get_period($context = 'view') {
305
+		return $this->get_prop('period', $context);
306 306
 	}
307 307
 
308 308
 	/**
@@ -312,8 +312,8 @@  discard block
 block discarded – undo
312 312
 	 * @param  string $context View or edit context.
313 313
 	 * @return int
314 314
 	 */
315
-	public function get_frequency( $context = 'view' ) {
316
-		return (int) $this->get_prop( 'frequency', $context );
315
+	public function get_frequency($context = 'view') {
316
+		return (int) $this->get_prop('frequency', $context);
317 317
 	}
318 318
 
319 319
 	/**
@@ -323,8 +323,8 @@  discard block
 block discarded – undo
323 323
 	 * @param  string $context View or edit context.
324 324
 	 * @return float
325 325
 	 */
326
-	public function get_initial_amount( $context = 'view' ) {
327
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
326
+	public function get_initial_amount($context = 'view') {
327
+		return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context));
328 328
 	}
329 329
 
330 330
 	/**
@@ -334,8 +334,8 @@  discard block
 block discarded – undo
334 334
 	 * @param  string $context View or edit context.
335 335
 	 * @return float
336 336
 	 */
337
-	public function get_recurring_amount( $context = 'view' ) {
338
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
337
+	public function get_recurring_amount($context = 'view') {
338
+		return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context));
339 339
 	}
340 340
 
341 341
 	/**
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	 * @param  string $context View or edit context.
346 346
 	 * @return int
347 347
 	 */
348
-	public function get_bill_times( $context = 'view' ) {
349
-		return (int) $this->get_prop( 'bill_times', $context );
348
+	public function get_bill_times($context = 'view') {
349
+		return (int) $this->get_prop('bill_times', $context);
350 350
 	}
351 351
 
352 352
 	/**
@@ -356,8 +356,8 @@  discard block
 block discarded – undo
356 356
 	 * @param  string $context View or edit context.
357 357
 	 * @return string
358 358
 	 */
359
-	public function get_transaction_id( $context = 'view' ) {
360
-		return $this->get_prop( 'transaction_id', $context );
359
+	public function get_transaction_id($context = 'view') {
360
+		return $this->get_prop('transaction_id', $context);
361 361
 	}
362 362
 
363 363
 	/**
@@ -367,8 +367,8 @@  discard block
 block discarded – undo
367 367
 	 * @param  string $context View or edit context.
368 368
 	 * @return string
369 369
 	 */
370
-	public function get_created( $context = 'view' ) {
371
-		return $this->get_prop( 'created', $context );
370
+	public function get_created($context = 'view') {
371
+		return $this->get_prop('created', $context);
372 372
 	}
373 373
 
374 374
 	/**
@@ -378,8 +378,8 @@  discard block
 block discarded – undo
378 378
 	 * @param  string $context View or edit context.
379 379
 	 * @return string
380 380
 	 */
381
-	public function get_date_created( $context = 'view' ) {
382
-		return $this->get_created( $context );
381
+	public function get_date_created($context = 'view') {
382
+		return $this->get_created($context);
383 383
 	}
384 384
 
385 385
 	/**
@@ -390,7 +390,7 @@  discard block
 block discarded – undo
390 390
 	 */
391 391
 	public function get_time_created() {
392 392
 		$created = $this->get_date_created();
393
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
393
+		return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp'));
394 394
 	}
395 395
 
396 396
 	/**
@@ -400,11 +400,11 @@  discard block
 block discarded – undo
400 400
 	 * @param  string $context View or edit context.
401 401
 	 * @return string
402 402
 	 */
403
-	public function get_date_created_gmt( $context = 'view' ) {
404
-        $date = $this->get_date_created( $context );
403
+	public function get_date_created_gmt($context = 'view') {
404
+        $date = $this->get_date_created($context);
405 405
 
406
-        if ( $date ) {
407
-            $date = get_gmt_from_date( $date );
406
+        if ($date) {
407
+            $date = get_gmt_from_date($date);
408 408
         }
409 409
 		return $date;
410 410
 	}
@@ -416,8 +416,8 @@  discard block
 block discarded – undo
416 416
 	 * @param  string $context View or edit context.
417 417
 	 * @return string
418 418
 	 */
419
-	public function get_next_renewal_date( $context = 'view' ) {
420
-		return $this->get_prop( 'expiration', $context );
419
+	public function get_next_renewal_date($context = 'view') {
420
+		return $this->get_prop('expiration', $context);
421 421
 	}
422 422
 
423 423
 	/**
@@ -427,8 +427,8 @@  discard block
 block discarded – undo
427 427
 	 * @param  string $context View or edit context.
428 428
 	 * @return string
429 429
 	 */
430
-	public function get_expiration( $context = 'view' ) {
431
-		return $this->get_next_renewal_date( $context );
430
+	public function get_expiration($context = 'view') {
431
+		return $this->get_next_renewal_date($context);
432 432
 	}
433 433
 
434 434
 	/**
@@ -440,12 +440,12 @@  discard block
 block discarded – undo
440 440
 	public function get_expiration_time() {
441 441
 		$expiration = $this->get_expiration();
442 442
 
443
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
444
-			return current_time( 'timestamp' );
443
+		if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) {
444
+			return current_time('timestamp');
445 445
 		}
446 446
 
447
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
448
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
447
+		$expiration = strtotime($expiration, current_time('timestamp'));
448
+		return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration;
449 449
 	}
450 450
 
451 451
 	/**
@@ -455,11 +455,11 @@  discard block
 block discarded – undo
455 455
 	 * @param  string $context View or edit context.
456 456
 	 * @return string
457 457
 	 */
458
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
459
-        $date = $this->get_next_renewal_date( $context );
458
+	public function get_next_renewal_date_gmt($context = 'view') {
459
+        $date = $this->get_next_renewal_date($context);
460 460
 
461
-        if ( $date ) {
462
-            $date = get_gmt_from_date( $date );
461
+        if ($date) {
462
+            $date = get_gmt_from_date($date);
463 463
         }
464 464
 		return $date;
465 465
 	}
@@ -471,8 +471,8 @@  discard block
 block discarded – undo
471 471
 	 * @param  string $context View or edit context.
472 472
 	 * @return string
473 473
 	 */
474
-	public function get_trial_period( $context = 'view' ) {
475
-		return $this->get_prop( 'trial_period', $context );
474
+	public function get_trial_period($context = 'view') {
475
+		return $this->get_prop('trial_period', $context);
476 476
 	}
477 477
 
478 478
 	/**
@@ -482,8 +482,8 @@  discard block
 block discarded – undo
482 482
 	 * @param  string $context View or edit context.
483 483
 	 * @return string
484 484
 	 */
485
-	public function get_status( $context = 'view' ) {
486
-		return $this->get_prop( 'status', $context );
485
+	public function get_status($context = 'view') {
486
+		return $this->get_prop('status', $context);
487 487
 	}
488 488
 
489 489
 	/**
@@ -493,8 +493,8 @@  discard block
 block discarded – undo
493 493
 	 * @param  string $context View or edit context.
494 494
 	 * @return string
495 495
 	 */
496
-	public function get_profile_id( $context = 'view' ) {
497
-		return $this->get_prop( 'profile_id', $context );
496
+	public function get_profile_id($context = 'view') {
497
+		return $this->get_prop('profile_id', $context);
498 498
 	}
499 499
 
500 500
 	/*
@@ -509,8 +509,8 @@  discard block
 block discarded – undo
509 509
 	 * @since 1.0.19
510 510
 	 * @param  int $value The customer's id.
511 511
 	 */
512
-	public function set_customer_id( $value ) {
513
-		$this->set_prop( 'customer_id', (int) $value );
512
+	public function set_customer_id($value) {
513
+		$this->set_prop('customer_id', (int) $value);
514 514
 	}
515 515
 
516 516
 	/**
@@ -519,8 +519,8 @@  discard block
 block discarded – undo
519 519
 	 * @since 1.0.19
520 520
 	 * @param  int $value The parent invoice id.
521 521
 	 */
522
-	public function set_parent_invoice_id( $value ) {
523
-		$this->set_prop( 'parent_payment_id', (int) $value );
522
+	public function set_parent_invoice_id($value) {
523
+		$this->set_prop('parent_payment_id', (int) $value);
524 524
 	}
525 525
 
526 526
 	/**
@@ -529,8 +529,8 @@  discard block
 block discarded – undo
529 529
 	 * @since 1.0.19
530 530
 	 * @param  int $value The parent invoice id.
531 531
 	 */
532
-    public function set_parent_payment_id( $value ) {
533
-        $this->set_parent_invoice_id( $value );
532
+    public function set_parent_payment_id($value) {
533
+        $this->set_parent_invoice_id($value);
534 534
 	}
535 535
 
536 536
 	/**
@@ -539,8 +539,8 @@  discard block
 block discarded – undo
539 539
      * @since 1.0.19
540 540
 	 * @param  int $value The parent invoice id.
541 541
      */
542
-    public function set_original_payment_id( $value ) {
543
-        $this->set_parent_invoice_id( $value );
542
+    public function set_original_payment_id($value) {
543
+        $this->set_parent_invoice_id($value);
544 544
 	}
545 545
 
546 546
 	/**
@@ -549,8 +549,8 @@  discard block
 block discarded – undo
549 549
 	 * @since 1.0.19
550 550
 	 * @param  int $value The subscription product id.
551 551
 	 */
552
-	public function set_product_id( $value ) {
553
-		$this->set_prop( 'product_id', (int) $value );
552
+	public function set_product_id($value) {
553
+		$this->set_prop('product_id', (int) $value);
554 554
 	}
555 555
 
556 556
 	/**
@@ -559,8 +559,8 @@  discard block
 block discarded – undo
559 559
 	 * @since 1.0.19
560 560
 	 * @param  string $value The renewal period.
561 561
 	 */
562
-	public function set_period( $value ) {
563
-		$this->set_prop( 'period', $value );
562
+	public function set_period($value) {
563
+		$this->set_prop('period', $value);
564 564
 	}
565 565
 
566 566
 	/**
@@ -569,9 +569,9 @@  discard block
 block discarded – undo
569 569
 	 * @since 1.0.19
570 570
 	 * @param  int $value The subscription frequency.
571 571
 	 */
572
-	public function set_frequency( $value ) {
573
-		$value = empty( $value ) ? 1 : (int) $value;
574
-		$this->set_prop( 'frequency', absint( $value ) );
572
+	public function set_frequency($value) {
573
+		$value = empty($value) ? 1 : (int) $value;
574
+		$this->set_prop('frequency', absint($value));
575 575
 	}
576 576
 
577 577
 	/**
@@ -580,8 +580,8 @@  discard block
 block discarded – undo
580 580
 	 * @since 1.0.19
581 581
 	 * @param  float $value The initial subcription amount.
582 582
 	 */
583
-	public function set_initial_amount( $value ) {
584
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
583
+	public function set_initial_amount($value) {
584
+		$this->set_prop('initial_amount', wpinv_sanitize_amount($value));
585 585
 	}
586 586
 
587 587
 	/**
@@ -590,8 +590,8 @@  discard block
 block discarded – undo
590 590
 	 * @since 1.0.19
591 591
 	 * @param  float $value The recurring subcription amount.
592 592
 	 */
593
-	public function set_recurring_amount( $value ) {
594
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
593
+	public function set_recurring_amount($value) {
594
+		$this->set_prop('recurring_amount', wpinv_sanitize_amount($value));
595 595
 	}
596 596
 
597 597
 	/**
@@ -600,8 +600,8 @@  discard block
 block discarded – undo
600 600
 	 * @since 1.0.19
601 601
 	 * @param  int $value Bill times.
602 602
 	 */
603
-	public function set_bill_times( $value ) {
604
-		$this->set_prop( 'bill_times', (int) $value );
603
+	public function set_bill_times($value) {
604
+		$this->set_prop('bill_times', (int) $value);
605 605
 	}
606 606
 
607 607
 	/**
@@ -610,8 +610,8 @@  discard block
 block discarded – undo
610 610
 	 * @since 1.0.19
611 611
 	 * @param string $value Bill times.
612 612
 	 */
613
-	public function set_transaction_id( $value ) {
614
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
613
+	public function set_transaction_id($value) {
614
+		$this->set_prop('transaction_id', sanitize_text_field($value));
615 615
 	}
616 616
 
617 617
 	/**
@@ -620,15 +620,15 @@  discard block
 block discarded – undo
620 620
 	 * @since 1.0.19
621 621
 	 * @param string $value strtotime compliant date.
622 622
 	 */
623
-	public function set_created( $value ) {
624
-        $date = strtotime( $value );
623
+	public function set_created($value) {
624
+        $date = strtotime($value);
625 625
 
626
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
627
-            $this->set_prop( 'created', date( 'Y-m-d H:i:s', $date ) );
626
+        if ($date && $value !== '0000-00-00 00:00:00') {
627
+            $this->set_prop('created', date('Y-m-d H:i:s', $date));
628 628
             return;
629 629
         }
630 630
 
631
-		$this->set_prop( 'created', '' );
631
+		$this->set_prop('created', '');
632 632
 
633 633
 	}
634 634
 
@@ -638,8 +638,8 @@  discard block
 block discarded – undo
638 638
 	 * @since 1.0.19
639 639
 	 * @param string $value strtotime compliant date.
640 640
 	 */
641
-	public function set_date_created( $value ) {
642
-		$this->set_created( $value );
641
+	public function set_date_created($value) {
642
+		$this->set_created($value);
643 643
     }
644 644
 
645 645
 	/**
@@ -648,15 +648,15 @@  discard block
 block discarded – undo
648 648
 	 * @since 1.0.19
649 649
 	 * @param string $value strtotime compliant date.
650 650
 	 */
651
-	public function set_next_renewal_date( $value ) {
652
-		$date = strtotime( $value );
651
+	public function set_next_renewal_date($value) {
652
+		$date = strtotime($value);
653 653
 
654
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
655
-            $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
654
+        if ($date && $value !== '0000-00-00 00:00:00') {
655
+            $this->set_prop('expiration', date('Y-m-d H:i:s', $date));
656 656
             return;
657 657
 		}
658 658
 
659
-		$this->set_prop( 'expiration', '' );
659
+		$this->set_prop('expiration', '');
660 660
 
661 661
 	}
662 662
 
@@ -666,8 +666,8 @@  discard block
 block discarded – undo
666 666
 	 * @since 1.0.19
667 667
 	 * @param string $value strtotime compliant date.
668 668
 	 */
669
-	public function set_expiration( $value ) {
670
-		$this->set_next_renewal_date( $value );
669
+	public function set_expiration($value) {
670
+		$this->set_next_renewal_date($value);
671 671
     }
672 672
 
673 673
 	/**
@@ -676,8 +676,8 @@  discard block
 block discarded – undo
676 676
 	 * @since 1.0.19
677 677
 	 * @param string $value trial period e.g 1 year.
678 678
 	 */
679
-	public function set_trial_period( $value ) {
680
-		$this->set_prop( 'trial_period', $value );
679
+	public function set_trial_period($value) {
680
+		$this->set_prop('trial_period', $value);
681 681
 	}
682 682
 
683 683
 	/**
@@ -686,19 +686,19 @@  discard block
 block discarded – undo
686 686
 	 * @since 1.0.19
687 687
 	 * @param string $new_status    New subscription status.
688 688
 	 */
689
-	public function set_status( $new_status ) {
689
+	public function set_status($new_status) {
690 690
 
691 691
 		// Abort if this is not a valid status;
692
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
692
+		if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) {
693 693
 			return;
694 694
 		}
695 695
 
696 696
 		$old_status = $this->get_status();
697
-		$this->set_prop( 'status', $new_status );
697
+		$this->set_prop('status', $new_status);
698 698
 
699
-		if ( true === $this->object_read && $old_status !== $new_status ) {
699
+		if (true === $this->object_read && $old_status !== $new_status) {
700 700
 			$this->status_transition = array(
701
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
701
+				'from'   => !empty($this->status_transition['from']) ? $this->status_transition['from'] : $old_status,
702 702
 				'to'     => $new_status,
703 703
 			);
704 704
 		}
@@ -711,8 +711,8 @@  discard block
 block discarded – undo
711 711
 	 * @since 1.0.19
712 712
 	 * @param  string $value the remote profile id.
713 713
 	 */
714
-	public function set_profile_id( $value ) {
715
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
714
+	public function set_profile_id($value) {
715
+		$this->set_prop('profile_id', sanitize_text_field($value));
716 716
 	}
717 717
 
718 718
 	/*
@@ -730,8 +730,8 @@  discard block
 block discarded – undo
730 730
 	 * @param string|array String or array of strings to check for.
731 731
 	 * @return bool
732 732
      */
733
-    public function has_status( $status ) {
734
-        return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
733
+    public function has_status($status) {
734
+        return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status)));
735 735
 	}
736 736
 
737 737
 	/**
@@ -741,7 +741,7 @@  discard block
 block discarded – undo
741 741
      */
742 742
     public function has_trial_period() {
743 743
 		$period = $this->get_trial_period();
744
-        return ! empty( $period );
744
+        return !empty($period);
745 745
 	}
746 746
 
747 747
 	/**
@@ -750,7 +750,7 @@  discard block
 block discarded – undo
750 750
 	 * @return bool
751 751
 	 */
752 752
 	public function is_active() {
753
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
753
+		return $this->has_status('active trialling') && !$this->is_expired();
754 754
 	}
755 755
 
756 756
 	/**
@@ -759,7 +759,7 @@  discard block
 block discarded – undo
759 759
 	 * @return bool
760 760
 	 */
761 761
 	public function is_expired() {
762
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
762
+		return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('mysql'));
763 763
 	}
764 764
 
765 765
 	/**
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
 	 */
770 770
 	public function is_last_renewal() {
771 771
 		$max_bills = $this->get_bill_times();
772
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
772
+		return !empty($max_bills) && $max_bills <= $this->get_times_billed();
773 773
 	}
774 774
 
775 775
 	/*
@@ -784,11 +784,11 @@  discard block
 block discarded – undo
784 784
 	/**
785 785
 	 * Backwards compatibilty.
786 786
 	 */
787
-	public function create( $data = array() ) {
787
+	public function create($data = array()) {
788 788
 
789 789
 		// Set the properties.
790
-		if ( is_array( $data ) ) {
791
-			$this->set_props( $data );
790
+		if (is_array($data)) {
791
+			$this->set_props($data);
792 792
 		}
793 793
 
794 794
 		// Save the item.
@@ -799,8 +799,8 @@  discard block
 block discarded – undo
799 799
 	/**
800 800
 	 * Backwards compatibilty.
801 801
 	 */
802
-	public function update( $args = array() ) {
803
-		return $this->create( $args );
802
+	public function update($args = array()) {
803
+		return $this->create($args);
804 804
 	}
805 805
 
806 806
     /**
@@ -809,12 +809,12 @@  discard block
 block discarded – undo
809 809
      * @since  1.0.0
810 810
      * @return WP_Post[]
811 811
      */
812
-    public function get_child_payments( $hide_pending = true ) {
812
+    public function get_child_payments($hide_pending = true) {
813 813
 
814
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
814
+		$statuses = array('publish', 'wpi-processing', 'wpi-renewal');
815 815
 
816
-		if ( ! $hide_pending ) {
817
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
816
+		if (!$hide_pending) {
817
+			$statuses = array_keys(wpinv_get_invoice_statuses());
818 818
 		}
819 819
 
820 820
         return get_posts(
@@ -836,7 +836,7 @@  discard block
 block discarded – undo
836 836
      * @return int
837 837
      */
838 838
     public function get_total_payments() {
839
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
839
+		return getpaid_count_subscription_invoices($this->get_parent_invoice_id(), $this->get_id());
840 840
     }
841 841
 
842 842
     /**
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
     public function get_times_billed() {
849 849
         $times_billed = $this->get_total_payments();
850 850
 
851
-        if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) {
851
+        if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) {
852 852
             $times_billed--;
853 853
         }
854 854
 
@@ -863,49 +863,49 @@  discard block
 block discarded – undo
863 863
 	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
864 864
      * @return bool
865 865
      */
866
-    public function add_payment( $args = array(), $invoice = false ) {
866
+    public function add_payment($args = array(), $invoice = false) {
867 867
 
868 868
 		// Process each payment once.
869
-        if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
869
+        if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) {
870 870
             return false;
871 871
         }
872 872
 
873 873
 		// Are we creating a new invoice?
874
-		if ( empty( $invoice ) ) {
874
+		if (empty($invoice)) {
875 875
 			$invoice = $this->create_payment();
876 876
 
877
-			if ( empty( $invoice ) ) {
877
+			if (empty($invoice)) {
878 878
 				return false;
879 879
 			}
880 880
 
881 881
 		}
882 882
 
883
-		$invoice->set_status( 'wpi-renewal' );
883
+		$invoice->set_status('wpi-renewal');
884 884
 
885 885
 		// Maybe set a transaction id.
886
-		if ( ! empty( $args['transaction_id'] ) ) {
887
-			$invoice->set_transaction_id( $args['transaction_id'] );
886
+		if (!empty($args['transaction_id'])) {
887
+			$invoice->set_transaction_id($args['transaction_id']);
888 888
 		}
889 889
 
890 890
 		// Set the completed date.
891
-		$invoice->set_completed_date( current_time( 'mysql' ) );
891
+		$invoice->set_completed_date(current_time('mysql'));
892 892
 
893 893
 		// And the gateway.
894
-		if ( ! empty( $args['gateway'] ) ) {
895
-			$invoice->set_gateway( $args['gateway'] );
894
+		if (!empty($args['gateway'])) {
895
+			$invoice->set_gateway($args['gateway']);
896 896
 		}
897 897
 
898 898
 		$invoice->save();
899 899
 
900
-		if ( ! $invoice->exists() ) {
900
+		if (!$invoice->exists()) {
901 901
 			return false;
902 902
 		}
903 903
 
904
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
905
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
906
-        do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
904
+		do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this);
905
+		do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
906
+        do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id());
907 907
 
908
-        update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
908
+        update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id);
909 909
 
910 910
         return $invoice->get_id();
911 911
 	}
@@ -920,41 +920,41 @@  discard block
 block discarded – undo
920 920
 
921 921
 		$parent_invoice = $this->get_parent_payment();
922 922
 
923
-		if ( ! $parent_invoice->exists() ) {
923
+		if (!$parent_invoice->exists()) {
924 924
 			return false;
925 925
 		}
926 926
 
927 927
 		// Duplicate the parent invoice.
928
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
929
-		$invoice->set_parent_id( $parent_invoice->get_id() );
930
-		$invoice->set_subscription_id( $this->get_id() );
931
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
928
+		$invoice = getpaid_duplicate_invoice($parent_invoice);
929
+		$invoice->set_parent_id($parent_invoice->get_id());
930
+		$invoice->set_subscription_id($this->get_id());
931
+		$invoice->set_remote_subscription_id($this->get_profile_id());
932 932
 
933 933
 		// Set invoice items.
934
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
935
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
934
+		$subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id());
935
+		$allowed_items      = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']);
936 936
 		$invoice_items      = array();
937 937
 
938
-		foreach ( $invoice->get_items() as $item ) {
939
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
938
+		foreach ($invoice->get_items() as $item) {
939
+			if (in_array($item->get_id(), $allowed_items)) {
940 940
 				$invoice_items[] = $item;
941 941
 			}
942 942
 		}
943 943
 
944
-		$invoice->set_items( $invoice_items );
944
+		$invoice->set_items($invoice_items);
945 945
 
946
-		if ( ! empty( $subscription_group['fees'] ) ) {
947
-			$invoice->set_fees( $subscription_group['fees'] );
946
+		if (!empty($subscription_group['fees'])) {
947
+			$invoice->set_fees($subscription_group['fees']);
948 948
 		}
949 949
 
950 950
 		// Maybe recalculate discount (Pre-GetPaid Fix).
951
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
952
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
953
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
951
+		$discount = new WPInv_Discount($invoice->get_discount_code());
952
+		if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) {
953
+			$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
954 954
 		}
955 955
 
956 956
 		$invoice->recalculate_total();
957
-		$invoice->set_status( 'wpi-pending' );
957
+		$invoice->set_status('wpi-pending');
958 958
 		$invoice->save();
959 959
 
960 960
 		return $invoice->exists() ? $invoice : false;
@@ -969,20 +969,20 @@  discard block
 block discarded – undo
969 969
 	public function renew() {
970 970
 
971 971
 		// Complete subscription if applicable
972
-		if ( $this->is_last_renewal() ) {
972
+		if ($this->is_last_renewal()) {
973 973
 			return $this->complete();
974 974
 		}
975 975
 
976 976
 		// Calculate new expiration
977 977
 		$frequency      = $this->get_frequency();
978 978
 		$period         = $this->get_period();
979
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
979
+		$new_expiration = strtotime("+ $frequency $period", $this->get_expiration_time());
980 980
 
981
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
982
-		$this->set_status( 'active' );
981
+		$this->set_expiration(date('Y-m-d H:i:s', $new_expiration));
982
+		$this->set_status('active');
983 983
 		$this->save();
984 984
 
985
-		do_action( 'getpaid_subscription_renewed', $this );
985
+		do_action('getpaid_subscription_renewed', $this);
986 986
 
987 987
 		return $this->get_id();
988 988
 	}
@@ -998,11 +998,11 @@  discard block
 block discarded – undo
998 998
 	public function complete() {
999 999
 
1000 1000
 		// Only mark a subscription as complete if it's not already cancelled.
1001
-		if ( $this->has_status( 'cancelled' ) ) {
1001
+		if ($this->has_status('cancelled')) {
1002 1002
 			return false;
1003 1003
 		}
1004 1004
 
1005
-		$this->set_status( 'completed' );
1005
+		$this->set_status('completed');
1006 1006
 		return $this->save();
1007 1007
 
1008 1008
 	}
@@ -1014,14 +1014,14 @@  discard block
 block discarded – undo
1014 1014
 	 * @param  bool $check_expiration
1015 1015
 	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1016 1016
 	 */
1017
-	public function expire( $check_expiration = false ) {
1017
+	public function expire($check_expiration = false) {
1018 1018
 
1019
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1019
+		if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) {
1020 1020
 			// Do not mark as expired since real expiration date is in the future
1021 1021
 			return false;
1022 1022
 		}
1023 1023
 
1024
-		$this->set_status( 'expired' );
1024
+		$this->set_status('expired');
1025 1025
 		return $this->save();
1026 1026
 
1027 1027
 	}
@@ -1033,7 +1033,7 @@  discard block
 block discarded – undo
1033 1033
 	 * @return int Subscription id.
1034 1034
 	 */
1035 1035
 	public function failing() {
1036
-		$this->set_status( 'failing' );
1036
+		$this->set_status('failing');
1037 1037
 		return $this->save();
1038 1038
 	}
1039 1039
 
@@ -1044,7 +1044,7 @@  discard block
 block discarded – undo
1044 1044
      * @return int Subscription id.
1045 1045
      */
1046 1046
     public function cancel() {
1047
-		$this->set_status( 'cancelled' );
1047
+		$this->set_status('cancelled');
1048 1048
 		return $this->save();
1049 1049
     }
1050 1050
 
@@ -1055,7 +1055,7 @@  discard block
 block discarded – undo
1055 1055
 	 * @return bool
1056 1056
 	 */
1057 1057
 	public function can_cancel() {
1058
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1058
+		return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this);
1059 1059
 	}
1060 1060
 
1061 1061
     /**
@@ -1066,7 +1066,7 @@  discard block
 block discarded – undo
1066 1066
      * @return      array
1067 1067
      */
1068 1068
     public function get_cancellable_statuses() {
1069
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1069
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
1070 1070
     }
1071 1071
 
1072 1072
 	/**
@@ -1076,8 +1076,8 @@  discard block
 block discarded – undo
1076 1076
 	 * @return string
1077 1077
 	 */
1078 1078
 	public function get_cancel_url() {
1079
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1080
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1079
+		$url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url());
1080
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
1081 1081
 	}
1082 1082
 
1083 1083
 	/**
@@ -1088,10 +1088,10 @@  discard block
 block discarded – undo
1088 1088
 	 */
1089 1089
 	public function get_view_url() {
1090 1090
 
1091
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1092
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1091
+		$url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')));
1092
+		$url = add_query_arg('subscription', $this->get_id(), $url);
1093 1093
 
1094
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1094
+		return apply_filters('getpaid_get_subscription_view_url', $url, $this);
1095 1095
 	}
1096 1096
 
1097 1097
 	/**
@@ -1104,7 +1104,7 @@  discard block
 block discarded – undo
1104 1104
 	 * @return bool
1105 1105
 	 */
1106 1106
 	public function can_renew() {
1107
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1107
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
1108 1108
 	}
1109 1109
 
1110 1110
 	/**
@@ -1114,8 +1114,8 @@  discard block
 block discarded – undo
1114 1114
 	 * @return string
1115 1115
 	 */
1116 1116
 	public function get_renew_url() {
1117
-		$url = wp_nonce_url( add_query_arg( array( 'getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'getpaid-nonce' );
1118
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1117
+		$url = wp_nonce_url(add_query_arg(array('getpaid-action' => 'renew_subscription', 'sub_id' => $this->get_id)), 'getpaid-nonce');
1118
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
1119 1119
 	}
1120 1120
 
1121 1121
 	/**
@@ -1125,7 +1125,7 @@  discard block
 block discarded – undo
1125 1125
 	 * @return bool
1126 1126
 	 */
1127 1127
 	public function can_update() {
1128
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1128
+		return apply_filters('wpinv_subscription_can_update', false, $this);
1129 1129
 	}
1130 1130
 
1131 1131
 	/**
@@ -1135,8 +1135,8 @@  discard block
 block discarded – undo
1135 1135
 	 * @return string
1136 1136
 	 */
1137 1137
 	public function get_update_url() {
1138
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1139
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1138
+		$url = add_query_arg(array('action' => 'update', 'subscription_id' => $this->get_id()));
1139
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
1140 1140
 	}
1141 1141
 
1142 1142
 	/**
@@ -1146,7 +1146,7 @@  discard block
 block discarded – undo
1146 1146
 	 * @return string
1147 1147
 	 */
1148 1148
 	public function get_status_label() {
1149
-		return getpaid_get_subscription_status_label( $this->get_status() );
1149
+		return getpaid_get_subscription_status_label($this->get_status());
1150 1150
 	}
1151 1151
 
1152 1152
 	/**
@@ -1157,7 +1157,7 @@  discard block
 block discarded – undo
1157 1157
 	 */
1158 1158
 	public function get_status_class() {
1159 1159
 		$statuses = getpaid_get_subscription_status_classes();
1160
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'badge-dark';
1160
+		return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'badge-dark';
1161 1161
 	}
1162 1162
 
1163 1163
     /**
@@ -1168,9 +1168,9 @@  discard block
 block discarded – undo
1168 1168
      */
1169 1169
     public function get_status_label_html() {
1170 1170
 
1171
-		$status_label = sanitize_text_field( $this->get_status_label() );
1172
-		$class        = esc_attr( $this->get_status_class() );
1173
-		$status       = sanitize_html_class( $this->get_status() );
1171
+		$status_label = sanitize_text_field($this->get_status_label());
1172
+		$class        = esc_attr($this->get_status_class());
1173
+		$status       = sanitize_html_class($this->get_status());
1174 1174
 
1175 1175
 		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1176 1176
     }
@@ -1182,9 +1182,9 @@  discard block
 block discarded – undo
1182 1182
      * @param  string $txn_id The transaction ID from the merchant processor
1183 1183
      * @return bool
1184 1184
      */
1185
-    public function payment_exists( $txn_id = '' ) {
1186
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1187
-        return ! empty( $invoice_id );
1185
+    public function payment_exists($txn_id = '') {
1186
+		$invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id');
1187
+        return !empty($invoice_id);
1188 1188
 	}
1189 1189
 
1190 1190
 	/**
@@ -1196,35 +1196,35 @@  discard block
 block discarded – undo
1196 1196
 		// Reset status transition variable.
1197 1197
 		$this->status_transition = false;
1198 1198
 
1199
-		if ( $status_transition ) {
1199
+		if ($status_transition) {
1200 1200
 			try {
1201 1201
 
1202 1202
 				// Fire a hook for the status change.
1203
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1204
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1203
+				do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
1204
+				do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition);
1205 1205
 
1206
-				if ( ! empty( $status_transition['from'] ) ) {
1206
+				if (!empty($status_transition['from'])) {
1207 1207
 
1208 1208
 					/* translators: 1: old subscription status 2: new subscription status */
1209
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1209
+					$transition_note = sprintf(__('Subscription status changed from %1$s to %2$s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['from']), getpaid_get_subscription_status_label($status_transition['to']));
1210 1210
 
1211 1211
 					// Note the transition occurred.
1212
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1212
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1213 1213
 
1214 1214
 					// Fire another hook.
1215
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1216
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1215
+					do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
1216
+					do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']);
1217 1217
 
1218 1218
 				} else {
1219 1219
 					/* translators: %s: new invoice status */
1220
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1220
+					$transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to']));
1221 1221
 
1222 1222
 					// Note the transition occurred.
1223
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1223
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1224 1224
 
1225 1225
 				}
1226
-			} catch ( Exception $e ) {
1227
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1226
+			} catch (Exception $e) {
1227
+				$this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage());
1228 1228
 			}
1229 1229
 		}
1230 1230
 
@@ -1250,7 +1250,7 @@  discard block
 block discarded – undo
1250 1250
 	 */
1251 1251
 	public function activate() {
1252 1252
 		$status = 'trialling' == $this->get_status() ? 'trialling' : 'active';
1253
-		$this->set_status( $status );
1253
+		$this->set_status($status);
1254 1254
 		return $this->save();
1255 1255
 	}
1256 1256
 
Please login to merge, or discard this patch.