Passed
Push — master ( 0a4695...d83d21 )
by Brian
04:16
created
includes/gateways/class-getpaid-authorize-net-gateway.php 2 patches
Indentation   +232 added lines, -232 removed lines patch added patch discarded remove patch
@@ -13,17 +13,17 @@  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(
28 28
         'subscription',
29 29
         'sandbox',
@@ -36,44 +36,44 @@  discard block
 block discarded – undo
36 36
     );
37 37
 
38 38
     /**
39
-	 * Payment method order.
40
-	 *
41
-	 * @var int
42
-	 */
39
+     * Payment method order.
40
+     *
41
+     * @var int
42
+     */
43 43
     public $order = 4;
44 44
 
45 45
     /**
46
-	 * Endpoint for requests from Authorize.net.
47
-	 *
48
-	 * @var string
49
-	 */
50
-	protected $notify_url;
51
-
52
-	/**
53
-	 * Endpoint for requests to Authorize.net.
54
-	 *
55
-	 * @var string
56
-	 */
46
+     * Endpoint for requests from Authorize.net.
47
+     *
48
+     * @var string
49
+     */
50
+    protected $notify_url;
51
+
52
+    /**
53
+     * Endpoint for requests to Authorize.net.
54
+     *
55
+     * @var string
56
+     */
57 57
     protected $endpoint;
58 58
 
59 59
     /**
60
-	 * Currencies this gateway is allowed for.
61
-	 *
62
-	 * @var array
63
-	 */
64
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
60
+     * Currencies this gateway is allowed for.
61
+     *
62
+     * @var array
63
+     */
64
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
65 65
 
66 66
     /**
67
-	 * URL to view a transaction.
68
-	 *
69
-	 * @var string
70
-	 */
67
+     * URL to view a transaction.
68
+     *
69
+     * @var string
70
+     */
71 71
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
72 72
 
73 73
     /**
74
-	 * Class constructor.
75
-	 */
76
-	public function __construct() {
74
+     * Class constructor.
75
+     */
76
+    public function __construct() {
77 77
 
78 78
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
79 79
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -85,11 +85,11 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     /**
88
-	 * Displays the payment method select field.
89
-	 *
90
-	 * @param int $invoice_id 0 or invoice id.
91
-	 * @param GetPaid_Payment_Form $form Current payment form.
92
-	 */
88
+     * Displays the payment method select field.
89
+     *
90
+     * @param int $invoice_id 0 or invoice id.
91
+     * @param GetPaid_Payment_Form $form Current payment form.
92
+     */
93 93
     public function payment_fields( $invoice_id, $form ) {
94 94
 
95 95
         // Let the user select a payment method.
@@ -100,16 +100,16 @@  discard block
 block discarded – undo
100 100
     }
101 101
 
102 102
     /**
103
-	 * Creates a customer profile.
104
-	 *
105
-	 *
106
-	 * @param WPInv_Invoice $invoice Invoice.
103
+     * Creates a customer profile.
104
+     *
105
+     *
106
+     * @param WPInv_Invoice $invoice Invoice.
107 107
      * @param array $submission_data Posted checkout fields.
108 108
      * @param bool $save Whether or not to save the payment as a token.
109 109
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
110
-	 * @return string|WP_Error Payment profile id.
111
-	 */
112
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
110
+     * @return string|WP_Error Payment profile id.
111
+     */
112
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
113 113
 
114 114
         // Remove non-digits from the number
115 115
         $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -191,14 +191,14 @@  discard block
 block discarded – undo
191 191
     }
192 192
 
193 193
     /**
194
-	 * Retrieves a customer profile.
195
-	 *
196
-	 *
197
-	 * @param string $profile_id profile id.
198
-	 * @return string|WP_Error Profile id.
194
+     * Retrieves a customer profile.
195
+     *
196
+     *
197
+     * @param string $profile_id profile id.
198
+     * @return string|WP_Error Profile id.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
200
-	 */
201
-	public function get_customer_profile( $profile_id ) {
200
+     */
201
+    public function get_customer_profile( $profile_id ) {
202 202
 
203 203
         // Generate args.
204 204
         $args = array(
@@ -213,17 +213,17 @@  discard block
 block discarded – undo
213 213
     }
214 214
 
215 215
     /**
216
-	 * Creates a customer profile.
217
-	 *
218
-	 *
216
+     * Creates a customer profile.
217
+     *
218
+     *
219 219
      * @param string $profile_id profile id.
220
-	 * @param WPInv_Invoice $invoice Invoice.
220
+     * @param WPInv_Invoice $invoice Invoice.
221 221
      * @param array $submission_data Posted checkout fields.
222 222
      * @param bool $save Whether or not to save the payment as a token.
223 223
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
224
-	 * @return string|WP_Error Profile id.
225
-	 */
226
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
224
+     * @return string|WP_Error Profile id.
225
+     */
226
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
227 227
 
228 228
         // Remove non-digits from the number
229 229
         $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -311,13 +311,13 @@  discard block
 block discarded – undo
311 311
     }
312 312
 
313 313
     /**
314
-	 * Retrieves payment details from cache.
315
-	 *
316
-	 *
314
+     * Retrieves payment details from cache.
315
+     *
316
+     *
317 317
      * @param array $payment_details.
318
-	 * @return array|false Profile id.
319
-	 */
320
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
318
+     * @return array|false Profile id.
319
+     */
320
+    public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
321 321
 
322 322
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
323 323
         $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
@@ -342,13 +342,13 @@  discard block
 block discarded – undo
342 342
     }
343 343
 
344 344
     /**
345
-	 * Securely adds payment details to cache.
346
-	 *
347
-	 *
345
+     * Securely adds payment details to cache.
346
+     *
347
+     *
348 348
      * @param array $payment_details.
349 349
      * @param string $payment_profile_id.
350
-	 */
351
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
350
+     */
351
+    public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
352 352
 
353 353
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
354 354
         $cached_information = is_array( $cached_information ) ? $cached_information : array();
@@ -360,15 +360,15 @@  discard block
 block discarded – undo
360 360
     }
361 361
 
362 362
     /**
363
-	 * Retrieves a customer payment profile.
364
-	 *
365
-	 *
366
-	 * @param string $customer_profile_id customer profile id.
363
+     * Retrieves a customer payment profile.
364
+     *
365
+     *
366
+     * @param string $customer_profile_id customer profile id.
367 367
      * @param string $payment_profile_id payment profile id.
368
-	 * @return string|WP_Error Profile id.
368
+     * @return string|WP_Error Profile id.
369 369
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
370
-	 */
371
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
370
+     */
371
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
372 372
 
373 373
         // Generate args.
374 374
         $args = array(
@@ -384,15 +384,15 @@  discard block
 block discarded – undo
384 384
     }
385 385
 
386 386
     /**
387
-	 * Charges a customer payment profile.
388
-	 *
387
+     * Charges a customer payment profile.
388
+     *
389 389
      * @param string $customer_profile_id customer profile id.
390 390
      * @param string $payment_profile_id payment profile id.
391
-	 * @param WPInv_Invoice $invoice Invoice.
391
+     * @param WPInv_Invoice $invoice Invoice.
392 392
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
393
-	 * @return WP_Error|object
394
-	 */
395
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
393
+     * @return WP_Error|object
394
+     */
395
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
396 396
 
397 397
         // Generate args.
398 398
         $args = array(
@@ -438,43 +438,43 @@  discard block
 block discarded – undo
438 438
     }
439 439
 
440 440
     /**
441
-	 * Processes a customer charge.
442
-	 *
441
+     * Processes a customer charge.
442
+     *
443 443
      * @param stdClass $result Api response.
444
-	 * @param WPInv_Invoice $invoice Invoice.
445
-	 */
446
-	public function process_charge_response( $result, $invoice ) {
444
+     * @param WPInv_Invoice $invoice Invoice.
445
+     */
446
+    public function process_charge_response( $result, $invoice ) {
447 447
 
448 448
         wpinv_clear_errors();
449
-		$response_code = (int) $result->transactionResponse->responseCode;
449
+        $response_code = (int) $result->transactionResponse->responseCode;
450 450
 
451 451
         $invoice->add_note( 'Transaction Response: ' . print_r( $result->transactionResponse, true ), false, false, true );
452 452
 
453
-		// Succeeded.
454
-		if ( 1 == $response_code || 4 == $response_code ) {
453
+        // Succeeded.
454
+        if ( 1 == $response_code || 4 == $response_code ) {
455 455
 
456
-			// Maybe set a transaction id.
457
-			if ( ! empty( $result->transactionResponse->transId ) ) {
458
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
459
-			}
456
+            // Maybe set a transaction id.
457
+            if ( ! empty( $result->transactionResponse->transId ) ) {
458
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
459
+            }
460 460
 
461
-			$invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
461
+            $invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
462 462
 
463
-			if ( 1 == $response_code ) {
464
-				return $invoice->mark_paid();
465
-			}
463
+            if ( 1 == $response_code ) {
464
+                return $invoice->mark_paid();
465
+            }
466 466
 
467
-			$invoice->set_status( 'wpi-onhold' );
468
-        	$invoice->add_note(
467
+            $invoice->set_status( 'wpi-onhold' );
468
+            $invoice->add_note(
469 469
                 sprintf(
470 470
                     __( 'Held for review: %s', 'invoicing' ),
471 471
                     $result->transactionResponse->messages->message[0]->description
472 472
                 )
473
-			);
473
+            );
474 474
 
475
-			return $invoice->save();
475
+            return $invoice->save();
476 476
 
477
-		}
477
+        }
478 478
 
479 479
         wpinv_set_error( 'card_declined' );
480 480
 
@@ -486,13 +486,13 @@  discard block
 block discarded – undo
486 486
     }
487 487
 
488 488
     /**
489
-	 * Returns payment information.
490
-	 *
491
-	 *
492
-	 * @param array $card Card details.
493
-	 * @return array
494
-	 */
495
-	public function get_payment_information( $card ) {
489
+     * Returns payment information.
490
+     *
491
+     *
492
+     * @param array $card Card details.
493
+     * @return array
494
+     */
495
+    public function get_payment_information( $card ) {
496 496
         return array(
497 497
 
498 498
             'creditCard' => array(
@@ -505,25 +505,25 @@  discard block
 block discarded – undo
505 505
     }
506 506
 
507 507
     /**
508
-	 * Returns the customer profile meta name.
509
-	 *
510
-	 *
511
-	 * @param WPInv_Invoice $invoice Invoice.
512
-	 * @return string
513
-	 */
514
-	public function get_customer_profile_meta_name( $invoice ) {
508
+     * Returns the customer profile meta name.
509
+     *
510
+     *
511
+     * @param WPInv_Invoice $invoice Invoice.
512
+     * @return string
513
+     */
514
+    public function get_customer_profile_meta_name( $invoice ) {
515 515
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
516 516
     }
517 517
 
518 518
     /**
519
-	 * Validates the submitted data.
520
-	 *
521
-	 *
522
-	 * @param array $submission_data Posted checkout fields.
519
+     * Validates the submitted data.
520
+     *
521
+     *
522
+     * @param array $submission_data Posted checkout fields.
523 523
      * @param WPInv_Invoice $invoice
524
-	 * @return WP_Error|string The payment profile id
525
-	 */
526
-	public function validate_submission_data( $submission_data, $invoice ) {
524
+     * @return WP_Error|string The payment profile id
525
+     */
526
+    public function validate_submission_data( $submission_data, $invoice ) {
527 527
 
528 528
         // Validate authentication details.
529 529
         $auth = $this->get_auth_params();
@@ -555,13 +555,13 @@  discard block
 block discarded – undo
555 555
     }
556 556
 
557 557
     /**
558
-	 * Returns invoice line items.
559
-	 *
560
-	 *
561
-	 * @param WPInv_Invoice $invoice Invoice.
562
-	 * @return array
563
-	 */
564
-	public function get_line_items( $invoice ) {
558
+     * Returns invoice line items.
559
+     *
560
+     *
561
+     * @param WPInv_Invoice $invoice Invoice.
562
+     * @return array
563
+     */
564
+    public function get_line_items( $invoice ) {
565 565
         $items = array();
566 566
 
567 567
         foreach ( $invoice->get_items() as $item ) {
@@ -598,15 +598,15 @@  discard block
 block discarded – undo
598 598
     }
599 599
 
600 600
     /**
601
-	 * Process Payment.
602
-	 *
603
-	 *
604
-	 * @param WPInv_Invoice $invoice Invoice.
605
-	 * @param array $submission_data Posted checkout fields.
606
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607
-	 * @return array
608
-	 */
609
-	public function process_payment( $invoice, $submission_data, $submission ) {
601
+     * Process Payment.
602
+     *
603
+     *
604
+     * @param WPInv_Invoice $invoice Invoice.
605
+     * @param array $submission_data Posted checkout fields.
606
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607
+     * @return array
608
+     */
609
+    public function process_payment( $invoice, $submission_data, $submission ) {
610 610
 
611 611
         // Validate the submitted data.
612 612
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -639,45 +639,45 @@  discard block
 block discarded – undo
639 639
 
640 640
         exit;
641 641
 
642
-	}
642
+    }
643 643
 
644
-	/**
645
-	 * Processes the initial payment.
646
-	 *
644
+    /**
645
+     * Processes the initial payment.
646
+     *
647 647
      * @param WPInv_Invoice $invoice Invoice.
648
-	 */
649
-	protected function process_initial_payment( $invoice ) {
648
+     */
649
+    protected function process_initial_payment( $invoice ) {
650 650
 
651
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
651
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
652 652
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
653
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
653
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
654 654
 
655
-		// Do we have an error?
656
-		if ( is_wp_error( $result ) ) {
657
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
-			wpinv_send_back_to_checkout( $invoice );
659
-		}
655
+        // Do we have an error?
656
+        if ( is_wp_error( $result ) ) {
657
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
+            wpinv_send_back_to_checkout( $invoice );
659
+        }
660 660
 
661
-		// Process the response.
662
-		$this->process_charge_response( $result, $invoice );
661
+        // Process the response.
662
+        $this->process_charge_response( $result, $invoice );
663 663
 
664
-		if ( wpinv_get_errors() ) {
665
-			wpinv_send_back_to_checkout( $invoice );
666
-		}
664
+        if ( wpinv_get_errors() ) {
665
+            wpinv_send_back_to_checkout( $invoice );
666
+        }
667 667
 
668
-	}
668
+    }
669 669
 
670 670
     /**
671
-	 * Processes recurring payments.
672
-	 *
671
+     * Processes recurring payments.
672
+     *
673 673
      * @param WPInv_Invoice $invoice Invoice.
674 674
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
675
-	 */
676
-	public function process_subscription( $invoice, $subscriptions ) {
675
+     */
676
+    public function process_subscription( $invoice, $subscriptions ) {
677 677
 
678 678
         // Check if there is an initial amount to charge.
679 679
         if ( (float) $invoice->get_total() > 0 ) {
680
-			$this->process_initial_payment( $invoice );
680
+            $this->process_initial_payment( $invoice );
681 681
         }
682 682
 
683 683
         // Activate the subscriptions.
@@ -695,36 +695,36 @@  discard block
 block discarded – undo
695 695
             }
696 696
         }
697 697
 
698
-		// Redirect to the success page.
698
+        // Redirect to the success page.
699 699
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
700 700
 
701 701
     }
702 702
 
703
-	/**
704
-	 * (Maybe) renews an authorize.net subscription profile.
705
-	 *
706
-	 *
703
+    /**
704
+     * (Maybe) renews an authorize.net subscription profile.
705
+     *
706
+     *
707 707
      * @param WPInv_Subscription $subscription
708
-	 */
709
-	public function maybe_renew_subscription( $subscription ) {
708
+     */
709
+    public function maybe_renew_subscription( $subscription ) {
710 710
 
711 711
         // Ensure its our subscription && it's active.
712 712
         if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
713 713
             $this->renew_subscription( $subscription );
714 714
         }
715 715
 
716
-	}
716
+    }
717 717
 
718 718
     /**
719
-	 * Renews a subscription.
720
-	 *
719
+     * Renews a subscription.
720
+     *
721 721
      * @param WPInv_Subscription $subscription
722
-	 */
723
-	public function renew_subscription( $subscription ) {
722
+     */
723
+    public function renew_subscription( $subscription ) {
724 724
 
725
-		// Generate the renewal invoice.
726
-		$new_invoice = $subscription->create_payment();
727
-		$old_invoice = $subscription->get_parent_payment();
725
+        // Generate the renewal invoice.
726
+        $new_invoice = $subscription->create_payment();
727
+        $old_invoice = $subscription->get_parent_payment();
728 728
 
729 729
         if ( empty( $new_invoice ) ) {
730 730
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -733,37 +733,37 @@  discard block
 block discarded – undo
733 733
         }
734 734
 
735 735
         // Charge the payment method.
736
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
739
-
740
-		// Do we have an error?
741
-		if ( is_wp_error( $result ) ) {
742
-
743
-			$old_invoice->add_note(
744
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
745
-				true,
746
-				false,
747
-				true
748
-			);
749
-			$subscription->failing();
750
-			return;
751
-
752
-		}
753
-
754
-		// Process the response.
755
-		$this->process_charge_response( $result, $new_invoice );
756
-
757
-		if ( wpinv_get_errors() ) {
758
-
759
-			$old_invoice->add_note(
760
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
761
-				true,
762
-				false,
763
-				true
764
-			);
765
-			$subscription->failing();
766
-			return;
736
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
739
+
740
+        // Do we have an error?
741
+        if ( is_wp_error( $result ) ) {
742
+
743
+            $old_invoice->add_note(
744
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
745
+                true,
746
+                false,
747
+                true
748
+            );
749
+            $subscription->failing();
750
+            return;
751
+
752
+        }
753
+
754
+        // Process the response.
755
+        $this->process_charge_response( $result, $new_invoice );
756
+
757
+        if ( wpinv_get_errors() ) {
758
+
759
+            $old_invoice->add_note(
760
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
761
+                true,
762
+                false,
763
+                true
764
+            );
765
+            $subscription->failing();
766
+            return;
767 767
 
768 768
         }
769 769
 
@@ -776,13 +776,13 @@  discard block
 block discarded – undo
776 776
     }
777 777
 
778 778
     /**
779
-	 * Processes invoice addons.
780
-	 *
781
-	 * @param WPInv_Invoice $invoice
782
-	 * @param GetPaid_Form_Item[] $items
783
-	 * @return WPInv_Invoice
784
-	 */
785
-	public function process_addons( $invoice, $items ) {
779
+     * Processes invoice addons.
780
+     *
781
+     * @param WPInv_Invoice $invoice
782
+     * @param GetPaid_Form_Item[] $items
783
+     * @return WPInv_Invoice
784
+     */
785
+    public function process_addons( $invoice, $items ) {
786 786
 
787 787
         global $getpaid_authorize_addons;
788 788
 
@@ -801,7 +801,7 @@  discard block
 block discarded – undo
801 801
         $invoice->recalculate_total();
802 802
 
803 803
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
804
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
804
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
805 805
 
806 806
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
807 807
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -816,11 +816,11 @@  discard block
 block discarded – undo
816 816
     }
817 817
 
818 818
     /**
819
-	 * Processes invoice addons.
820
-	 *
819
+     * Processes invoice addons.
820
+     *
821 821
      * @param array $args
822
-	 * @return array
823
-	 */
822
+     * @return array
823
+     */
824 824
     public function filter_addons_request( $args ) {
825 825
 
826 826
         global $getpaid_authorize_addons;
@@ -854,11 +854,11 @@  discard block
 block discarded – undo
854 854
     }
855 855
 
856 856
     /**
857
-	 * Filters the gateway settings.
858
-	 *
859
-	 * @param array $admin_settings
860
-	 */
861
-	public function admin_settings( $admin_settings ) {
857
+     * Filters the gateway settings.
858
+     *
859
+     * @param array $admin_settings
860
+     */
861
+    public function admin_settings( $admin_settings ) {
862 862
 
863 863
         $currencies = sprintf(
864 864
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -898,7 +898,7 @@  discard block
 block discarded – undo
898 898
             'readonly' => true,
899 899
         );
900 900
 
901
-		return $admin_settings;
902
-	}
901
+        return $admin_settings;
902
+    }
903 903
 
904 904
 }
Please login to merge, or discard this patch.
Spacing   +206 added lines, -206 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.
@@ -61,7 +61,7 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @var array
63 63
 	 */
64
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
64
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
65 65
 
66 66
     /**
67 67
 	 * URL to view a transaction.
@@ -75,12 +75,12 @@  discard block
 block discarded – undo
75 75
 	 */
76 76
 	public function __construct() {
77 77
 
78
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
79
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
80
-        $this->notify_url           = getpaid_get_non_query_string_ipn_url( $this->id );
78
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
79
+        $this->method_title         = __('Authorize.Net', 'invoicing');
80
+        $this->notify_url           = getpaid_get_non_query_string_ipn_url($this->id);
81 81
 
82
-        add_action( 'getpaid_should_renew_subscription', array( $this, 'maybe_renew_subscription' ) );
83
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
82
+        add_action('getpaid_should_renew_subscription', array($this, 'maybe_renew_subscription'));
83
+        add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice'));
84 84
         parent::__construct();
85 85
     }
86 86
 
@@ -90,13 +90,13 @@  discard block
 block discarded – undo
90 90
 	 * @param int $invoice_id 0 or invoice id.
91 91
 	 * @param GetPaid_Payment_Form $form Current payment form.
92 92
 	 */
93
-    public function payment_fields( $invoice_id, $form ) {
93
+    public function payment_fields($invoice_id, $form) {
94 94
 
95 95
         // Let the user select a payment method.
96 96
         $this->saved_payment_methods();
97 97
 
98 98
         // Show the credit card entry form.
99
-        $this->new_payment_method_entry( $this->get_cc_form( true ) );
99
+        $this->new_payment_method_entry($this->get_cc_form(true));
100 100
     }
101 101
 
102 102
     /**
@@ -109,79 +109,79 @@  discard block
 block discarded – undo
109 109
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
110 110
 	 * @return string|WP_Error Payment profile id.
111 111
 	 */
112
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
112
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
113 113
 
114 114
         // Remove non-digits from the number
115
-        $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
115
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
116 116
 
117 117
         // Generate args.
118 118
         $args = array(
119 119
             'createCustomerProfileRequest' => array(
120 120
                 'merchantAuthentication' => $this->get_auth_params(),
121 121
                 'profile'                => array(
122
-                    'merchantCustomerId' => getpaid_limit_length( $invoice->get_user_id(), 20 ),
123
-                    'description'        => getpaid_limit_length( $invoice->get_full_name(), 255 ),
124
-                    'email'              => getpaid_limit_length( $invoice->get_email(), 255 ),
122
+                    'merchantCustomerId' => getpaid_limit_length($invoice->get_user_id(), 20),
123
+                    'description'        => getpaid_limit_length($invoice->get_full_name(), 255),
124
+                    'email'              => getpaid_limit_length($invoice->get_email(), 255),
125 125
                     'paymentProfiles'    => array(
126 126
                         'customerType' => 'individual',
127 127
 
128 128
                         // Billing information.
129 129
                         'billTo'       => array(
130
-                            'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ),
131
-                            'lastName'  => getpaid_limit_length( $invoice->get_last_name(), 50 ),
132
-                            'address'   => getpaid_limit_length( $invoice->get_address(), 60 ),
133
-                            'city'      => getpaid_limit_length( $invoice->get_city(), 40 ),
134
-                            'state'     => getpaid_limit_length( $invoice->get_state(), 40 ),
135
-                            'zip'       => getpaid_limit_length( $invoice->get_zip(), 20 ),
136
-                            'country'   => getpaid_limit_length( $invoice->get_country(), 60 ),
130
+                            'firstName' => getpaid_limit_length($invoice->get_first_name(), 50),
131
+                            'lastName'  => getpaid_limit_length($invoice->get_last_name(), 50),
132
+                            'address'   => getpaid_limit_length($invoice->get_address(), 60),
133
+                            'city'      => getpaid_limit_length($invoice->get_city(), 40),
134
+                            'state'     => getpaid_limit_length($invoice->get_state(), 40),
135
+                            'zip'       => getpaid_limit_length($invoice->get_zip(), 20),
136
+                            'country'   => getpaid_limit_length($invoice->get_country(), 60),
137 137
                         ),
138 138
 
139 139
                         // Payment information.
140
-                        'payment'      => $this->get_payment_information( $submission_data['authorizenet'] ),
140
+                        'payment'      => $this->get_payment_information($submission_data['authorizenet']),
141 141
                     ),
142 142
                 ),
143
-                'validationMode'         => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
143
+                'validationMode'         => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
144 144
             ),
145 145
         );
146 146
 
147
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
147
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
148 148
 
149
-        if ( is_wp_error( $response ) ) {
149
+        if (is_wp_error($response)) {
150 150
 
151 151
             // In case the payment profile already exists remotely.
152
-            if ( 'dup_payment_profile' === $response->get_error_code() ) {
153
-                $customer_profile_id = strtok( $response->get_error_message(), '.' );
154
-                update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id );
155
-                return strtok( '.' );
152
+            if ('dup_payment_profile' === $response->get_error_code()) {
153
+                $customer_profile_id = strtok($response->get_error_message(), '.');
154
+                update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id);
155
+                return strtok('.');
156 156
             }
157 157
 
158 158
             // In case the customer profile already exists remotely.
159
-            if ( 'E00039' === $response->get_error_code() ) {
160
-                $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() );
161
-                $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id );
162
-                return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save );
159
+            if ('E00039' === $response->get_error_code()) {
160
+                $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message());
161
+                $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id);
162
+                return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save);
163 163
             }
164 164
 
165 165
             return $response;
166 166
         }
167 167
 
168
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
168
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
169 169
 
170 170
         // Save the payment token.
171
-        if ( $save ) {
171
+        if ($save) {
172 172
             $this->save_token(
173 173
                 array(
174 174
                     'id'      => $response->customerPaymentProfileIdList[0],
175
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '····' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
175
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '····' . substr($submission_data['authorizenet']['cc_number'], -4),
176 176
                     'default' => true,
177
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
177
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
178 178
                 )
179 179
             );
180 180
         }
181 181
 
182 182
         // Add a note about the validation response.
183 183
         $invoice->add_note(
184
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
184
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
185 185
             false,
186 186
             false,
187 187
             true
@@ -198,7 +198,7 @@  discard block
 block discarded – undo
198 198
 	 * @return string|WP_Error Profile id.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
200 200
 	 */
201
-	public function get_customer_profile( $profile_id ) {
201
+	public function get_customer_profile($profile_id) {
202 202
 
203 203
         // Generate args.
204 204
         $args = array(
@@ -208,7 +208,7 @@  discard block
 block discarded – undo
208 208
             ),
209 209
         );
210 210
 
211
-        return $this->post( $args, false );
211
+        return $this->post($args, false);
212 212
 
213 213
     }
214 214
 
@@ -223,18 +223,18 @@  discard block
 block discarded – undo
223 223
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
224 224
 	 * @return string|WP_Error Profile id.
225 225
 	 */
226
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
226
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
227 227
 
228 228
         // Remove non-digits from the number
229
-        $submission_data['authorizenet']['cc_number'] = preg_replace( '/\D/', '', $submission_data['authorizenet']['cc_number'] );
229
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
230 230
 
231 231
         // Prepare card details.
232
-        $payment_information                          = $this->get_payment_information( $submission_data['authorizenet'] );
232
+        $payment_information                          = $this->get_payment_information($submission_data['authorizenet']);
233 233
 
234 234
         // Authorize.NET does not support saving the same card twice.
235
-        $cached_information                           = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice );
235
+        $cached_information                           = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice);
236 236
 
237
-        if ( $cached_information ) {
237
+        if ($cached_information) {
238 238
             return $cached_information;
239 239
         }
240 240
 
@@ -247,34 +247,34 @@  discard block
 block discarded – undo
247 247
 
248 248
                     // Billing information.
249 249
                     'billTo'  => array(
250
-                        'firstName' => getpaid_limit_length( $invoice->get_first_name(), 50 ),
251
-                        'lastName'  => getpaid_limit_length( $invoice->get_last_name(), 50 ),
252
-                        'address'   => getpaid_limit_length( $invoice->get_address(), 60 ),
253
-                        'city'      => getpaid_limit_length( $invoice->get_city(), 40 ),
254
-                        'state'     => getpaid_limit_length( $invoice->get_state(), 40 ),
255
-                        'zip'       => getpaid_limit_length( $invoice->get_zip(), 20 ),
256
-                        'country'   => getpaid_limit_length( $invoice->get_country(), 60 ),
250
+                        'firstName' => getpaid_limit_length($invoice->get_first_name(), 50),
251
+                        'lastName'  => getpaid_limit_length($invoice->get_last_name(), 50),
252
+                        'address'   => getpaid_limit_length($invoice->get_address(), 60),
253
+                        'city'      => getpaid_limit_length($invoice->get_city(), 40),
254
+                        'state'     => getpaid_limit_length($invoice->get_state(), 40),
255
+                        'zip'       => getpaid_limit_length($invoice->get_zip(), 20),
256
+                        'country'   => getpaid_limit_length($invoice->get_country(), 60),
257 257
                     ),
258 258
 
259 259
                     // Payment information.
260 260
                     'payment' => $payment_information,
261 261
                 ),
262
-                'validationMode'         => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
262
+                'validationMode'         => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
263 263
             ),
264 264
         );
265 265
 
266
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
266
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
267 267
 
268
-        if ( is_wp_error( $response ) ) {
268
+        if (is_wp_error($response)) {
269 269
 
270 270
             // In case the payment profile already exists remotely.
271
-            if ( 'dup_payment_profile' == $response->get_error_code() ) {
272
-                $customer_profile_id = strtok( $response->get_error_message(), '.' );
273
-                $payment_profile_id  = strtok( '.' );
274
-                update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile_id );
271
+            if ('dup_payment_profile' == $response->get_error_code()) {
272
+                $customer_profile_id = strtok($response->get_error_message(), '.');
273
+                $payment_profile_id  = strtok('.');
274
+                update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile_id);
275 275
 
276 276
                 // Cache payment profile id.
277
-                $this->add_payment_profile_to_cache( $payment_information, $payment_profile_id );
277
+                $this->add_payment_profile_to_cache($payment_information, $payment_profile_id);
278 278
 
279 279
                 return $payment_profile_id;
280 280
             }
@@ -283,29 +283,29 @@  discard block
 block discarded – undo
283 283
         }
284 284
 
285 285
         // Save the payment token.
286
-        if ( $save ) {
286
+        if ($save) {
287 287
             $this->save_token(
288 288
                 array(
289 289
                     'id'      => $response->customerPaymentProfileId,
290
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' ···· ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
290
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' ···· ' . substr($submission_data['authorizenet']['cc_number'], -4),
291 291
                     'default' => true,
292
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
292
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
293 293
                 )
294 294
             );
295 295
         }
296 296
 
297 297
         // Cache payment profile id.
298
-        $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId );
298
+        $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId);
299 299
 
300 300
         // Add a note about the validation response.
301 301
         $invoice->add_note(
302
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
302
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
303 303
             false,
304 304
             false,
305 305
             true
306 306
         );
307 307
 
308
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile );
308
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile);
309 309
 
310 310
         return $response->customerPaymentProfileId;
311 311
     }
@@ -317,12 +317,12 @@  discard block
 block discarded – undo
317 317
      * @param array $payment_details.
318 318
 	 * @return array|false Profile id.
319 319
 	 */
320
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
320
+	public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) {
321 321
 
322
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
323
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
322
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
323
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
324 324
 
325
-        if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) {
325
+        if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) {
326 326
             return false;
327 327
         }
328 328
 
@@ -331,13 +331,13 @@  discard block
 block discarded – undo
331 331
             'getCustomerPaymentProfileRequest' => array(
332 332
                 'merchantAuthentication'   => $this->get_auth_params(),
333 333
                 'customerProfileId'        => $customer_profile,
334
-                'customerPaymentProfileId' => $cached_information[ $payment_details ],
334
+                'customerPaymentProfileId' => $cached_information[$payment_details],
335 335
             ),
336 336
         );
337 337
 
338
-        $response = $this->post( $args, $invoice );
338
+        $response = $this->post($args, $invoice);
339 339
 
340
-        return is_wp_error( $response ) ? false : $cached_information[ $payment_details ];
340
+        return is_wp_error($response) ? false : $cached_information[$payment_details];
341 341
 
342 342
     }
343 343
 
@@ -348,14 +348,14 @@  discard block
 block discarded – undo
348 348
      * @param array $payment_details.
349 349
      * @param string $payment_profile_id.
350 350
 	 */
351
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
351
+	public function add_payment_profile_to_cache($payment_details, $payment_profile_id) {
352 352
 
353
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
354
-        $cached_information = is_array( $cached_information ) ? $cached_information : array();
355
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
353
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
354
+        $cached_information = is_array($cached_information) ? $cached_information : array();
355
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
356 356
 
357
-        $cached_information[ $payment_details ] = $payment_profile_id;
358
-        update_option( 'getpaid_authorize_net_cached_profiles', $cached_information );
357
+        $cached_information[$payment_details] = $payment_profile_id;
358
+        update_option('getpaid_authorize_net_cached_profiles', $cached_information);
359 359
 
360 360
     }
361 361
 
@@ -368,7 +368,7 @@  discard block
 block discarded – undo
368 368
 	 * @return string|WP_Error Profile id.
369 369
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
370 370
 	 */
371
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
371
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
372 372
 
373 373
         // Generate args.
374 374
         $args = array(
@@ -379,7 +379,7 @@  discard block
 block discarded – undo
379 379
             ),
380 380
         );
381 381
 
382
-        return $this->post( $args, false );
382
+        return $this->post($args, false);
383 383
 
384 384
     }
385 385
 
@@ -392,7 +392,7 @@  discard block
 block discarded – undo
392 392
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
393 393
 	 * @return WP_Error|object
394 394
 	 */
395
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
395
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
396 396
 
397 397
         // Generate args.
398 398
         $args = array(
@@ -412,28 +412,28 @@  discard block
 block discarded – undo
412 412
                         ),
413 413
                     ),
414 414
                     'order'           => array(
415
-                        'invoiceNumber' => getpaid_limit_length( $invoice->get_number(), 20 ),
415
+                        'invoiceNumber' => getpaid_limit_length($invoice->get_number(), 20),
416 416
                     ),
417
-                    'lineItems'       => array( 'lineItem' => $this->get_line_items( $invoice ) ),
417
+                    'lineItems'       => array('lineItem' => $this->get_line_items($invoice)),
418 418
                     'tax'             => array(
419 419
                         'amount' => $invoice->get_total_tax(),
420
-                        'name'   => __( 'TAX', 'invoicing' ),
420
+                        'name'   => __('TAX', 'invoicing'),
421 421
                     ),
422
-                    'poNumber'        => getpaid_limit_length( $invoice->get_number(), 25 ),
422
+                    'poNumber'        => getpaid_limit_length($invoice->get_number(), 25),
423 423
                     'customer'        => array(
424
-                        'id'    => getpaid_limit_length( $invoice->get_user_id(), 25 ),
425
-                        'email' => getpaid_limit_length( $invoice->get_email(), 25 ),
424
+                        'id'    => getpaid_limit_length($invoice->get_user_id(), 25),
425
+                        'email' => getpaid_limit_length($invoice->get_email(), 25),
426 426
                     ),
427 427
                     'customerIP'      => $invoice->get_ip(),
428 428
                 ),
429 429
             ),
430 430
         );
431 431
 
432
-        if ( 0 == $invoice->get_total_tax() ) {
433
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
432
+        if (0 == $invoice->get_total_tax()) {
433
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
434 434
         }
435 435
 
436
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
436
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
437 437
 
438 438
     }
439 439
 
@@ -443,31 +443,31 @@  discard block
 block discarded – undo
443 443
      * @param stdClass $result Api response.
444 444
 	 * @param WPInv_Invoice $invoice Invoice.
445 445
 	 */
446
-	public function process_charge_response( $result, $invoice ) {
446
+	public function process_charge_response($result, $invoice) {
447 447
 
448 448
         wpinv_clear_errors();
449 449
 		$response_code = (int) $result->transactionResponse->responseCode;
450 450
 
451
-        $invoice->add_note( 'Transaction Response: ' . print_r( $result->transactionResponse, true ), false, false, true );
451
+        $invoice->add_note('Transaction Response: ' . print_r($result->transactionResponse, true), false, false, true);
452 452
 
453 453
 		// Succeeded.
454
-		if ( 1 == $response_code || 4 == $response_code ) {
454
+		if (1 == $response_code || 4 == $response_code) {
455 455
 
456 456
 			// Maybe set a transaction id.
457
-			if ( ! empty( $result->transactionResponse->transId ) ) {
458
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
457
+			if (!empty($result->transactionResponse->transId)) {
458
+				$invoice->set_transaction_id($result->transactionResponse->transId);
459 459
 			}
460 460
 
461
-			$invoice->add_note( sprintf( __( 'Authentication code: %1$s (%2$s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
461
+			$invoice->add_note(sprintf(__('Authentication code: %1$s (%2$s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
462 462
 
463
-			if ( 1 == $response_code ) {
463
+			if (1 == $response_code) {
464 464
 				return $invoice->mark_paid();
465 465
 			}
466 466
 
467
-			$invoice->set_status( 'wpi-onhold' );
467
+			$invoice->set_status('wpi-onhold');
468 468
         	$invoice->add_note(
469 469
                 sprintf(
470
-                    __( 'Held for review: %s', 'invoicing' ),
470
+                    __('Held for review: %s', 'invoicing'),
471 471
                     $result->transactionResponse->messages->message[0]->description
472 472
                 )
473 473
 			);
@@ -476,11 +476,11 @@  discard block
 block discarded – undo
476 476
 
477 477
 		}
478 478
 
479
-        wpinv_set_error( 'card_declined' );
479
+        wpinv_set_error('card_declined');
480 480
 
481
-        if ( ! empty( $result->transactionResponse->errors ) ) {
481
+        if (!empty($result->transactionResponse->errors)) {
482 482
             $errors = (object) $result->transactionResponse->errors;
483
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
483
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
484 484
         }
485 485
 
486 486
     }
@@ -492,7 +492,7 @@  discard block
 block discarded – undo
492 492
 	 * @param array $card Card details.
493 493
 	 * @return array
494 494
 	 */
495
-	public function get_payment_information( $card ) {
495
+	public function get_payment_information($card) {
496 496
         return array(
497 497
 
498 498
             'creditCard' => array(
@@ -511,8 +511,8 @@  discard block
 block discarded – undo
511 511
 	 * @param WPInv_Invoice $invoice Invoice.
512 512
 	 * @return string
513 513
 	 */
514
-	public function get_customer_profile_meta_name( $invoice ) {
515
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
514
+	public function get_customer_profile_meta_name($invoice) {
515
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
516 516
     }
517 517
 
518 518
     /**
@@ -523,34 +523,34 @@  discard block
 block discarded – undo
523 523
      * @param WPInv_Invoice $invoice
524 524
 	 * @return WP_Error|string The payment profile id
525 525
 	 */
526
-	public function validate_submission_data( $submission_data, $invoice ) {
526
+	public function validate_submission_data($submission_data, $invoice) {
527 527
 
528 528
         // Validate authentication details.
529 529
         $auth = $this->get_auth_params();
530 530
 
531
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
532
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing' ) );
531
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
532
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
533 533
         }
534 534
 
535 535
         // Validate the payment method.
536
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
537
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing' ) );
536
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
537
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
538 538
         }
539 539
 
540 540
         // Are we adding a new payment method?
541
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
541
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
542 542
             return $submission_data['getpaid-authorizenet-payment-method'];
543 543
         }
544 544
 
545 545
         // Retrieve the customer profile id.
546
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
546
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
547 547
 
548 548
         // Create payment method.
549
-        if ( empty( $profile_id ) ) {
550
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
549
+        if (empty($profile_id)) {
550
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
551 551
         }
552 552
 
553
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
553
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
554 554
 
555 555
     }
556 556
 
@@ -561,32 +561,32 @@  discard block
 block discarded – undo
561 561
 	 * @param WPInv_Invoice $invoice Invoice.
562 562
 	 * @return array
563 563
 	 */
564
-	public function get_line_items( $invoice ) {
564
+	public function get_line_items($invoice) {
565 565
         $items = array();
566 566
 
567
-        foreach ( $invoice->get_items() as $item ) {
567
+        foreach ($invoice->get_items() as $item) {
568 568
 
569 569
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
570 570
             $items[] = array(
571
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
572
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
573
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
574
-                'quantity'    => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ),
571
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
572
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
573
+                'description' => getpaid_limit_length($item->get_description(), 255),
574
+                'quantity'    => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()),
575 575
                 'unitPrice'   => (float) $amount,
576 576
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
577 577
             );
578 578
 
579 579
         }
580 580
 
581
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
581
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
582 582
 
583
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
583
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
584 584
 
585
-            if ( $amount > 0 ) {
585
+            if ($amount > 0) {
586 586
                 $items[] = array(
587
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
588
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
589
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
587
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
588
+                    'name'        => getpaid_limit_length($fee_name, 31),
589
+                    'description' => getpaid_limit_length($fee_name, 255),
590 590
                     'quantity'    => '1',
591 591
                     'unitPrice'   => (float) $amount,
592 592
                     'taxable'     => false,
@@ -606,36 +606,36 @@  discard block
 block discarded – undo
606 606
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
607 607
 	 * @return array
608 608
 	 */
609
-	public function process_payment( $invoice, $submission_data, $submission ) {
609
+	public function process_payment($invoice, $submission_data, $submission) {
610 610
 
611 611
         // Validate the submitted data.
612
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
612
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
613 613
 
614 614
         // Do we have an error?
615
-        if ( is_wp_error( $payment_profile_id ) ) {
616
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
617
-            wpinv_send_back_to_checkout( $invoice );
615
+        if (is_wp_error($payment_profile_id)) {
616
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
617
+            wpinv_send_back_to_checkout($invoice);
618 618
         }
619 619
 
620 620
         // Save the payment method to the order.
621
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
621
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
622 622
 
623 623
         // Check if this is a subscription or not.
624
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
625
-        if ( ! empty( $subscriptions ) ) {
626
-            $this->process_subscription( $invoice, $subscriptions );
624
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
625
+        if (!empty($subscriptions)) {
626
+            $this->process_subscription($invoice, $subscriptions);
627 627
         }
628 628
 
629 629
         // If it is free, send to the success page.
630
-        if ( ! $invoice->needs_payment() ) {
630
+        if (!$invoice->needs_payment()) {
631 631
             $invoice->mark_paid();
632
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
632
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
633 633
         }
634 634
 
635 635
         // Charge the payment profile.
636
-        $this->process_initial_payment( $invoice );
636
+        $this->process_initial_payment($invoice);
637 637
 
638
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
638
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
639 639
 
640 640
         exit;
641 641
 
@@ -646,23 +646,23 @@  discard block
 block discarded – undo
646 646
 	 *
647 647
      * @param WPInv_Invoice $invoice Invoice.
648 648
 	 */
649
-	protected function process_initial_payment( $invoice ) {
649
+	protected function process_initial_payment($invoice) {
650 650
 
651
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
652
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
653
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
651
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
652
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
653
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
654 654
 
655 655
 		// Do we have an error?
656
-		if ( is_wp_error( $result ) ) {
657
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
658
-			wpinv_send_back_to_checkout( $invoice );
656
+		if (is_wp_error($result)) {
657
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
658
+			wpinv_send_back_to_checkout($invoice);
659 659
 		}
660 660
 
661 661
 		// Process the response.
662
-		$this->process_charge_response( $result, $invoice );
662
+		$this->process_charge_response($result, $invoice);
663 663
 
664
-		if ( wpinv_get_errors() ) {
665
-			wpinv_send_back_to_checkout( $invoice );
664
+		if (wpinv_get_errors()) {
665
+			wpinv_send_back_to_checkout($invoice);
666 666
 		}
667 667
 
668 668
 	}
@@ -673,30 +673,30 @@  discard block
 block discarded – undo
673 673
      * @param WPInv_Invoice $invoice Invoice.
674 674
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
675 675
 	 */
676
-	public function process_subscription( $invoice, $subscriptions ) {
676
+	public function process_subscription($invoice, $subscriptions) {
677 677
 
678 678
         // Check if there is an initial amount to charge.
679
-        if ( (float) $invoice->get_total() > 0 ) {
680
-			$this->process_initial_payment( $invoice );
679
+        if ((float) $invoice->get_total() > 0) {
680
+			$this->process_initial_payment($invoice);
681 681
         }
682 682
 
683 683
         // Activate the subscriptions.
684
-        $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
684
+        $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
685 685
 
686
-        foreach ( $subscriptions as $subscription ) {
687
-            if ( $subscription->exists() ) {
688
-                $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
689
-                $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
686
+        foreach ($subscriptions as $subscription) {
687
+            if ($subscription->exists()) {
688
+                $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
689
+                $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
690 690
 
691
-                $subscription->set_next_renewal_date( $expiry );
692
-                $subscription->set_date_created( current_time( 'mysql' ) );
693
-                $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) );
691
+                $subscription->set_next_renewal_date($expiry);
692
+                $subscription->set_date_created(current_time('mysql'));
693
+                $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id()));
694 694
                 $subscription->activate();
695 695
             }
696 696
         }
697 697
 
698 698
 		// Redirect to the success page.
699
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
699
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
700 700
 
701 701
     }
702 702
 
@@ -706,11 +706,11 @@  discard block
 block discarded – undo
706 706
 	 *
707 707
      * @param WPInv_Subscription $subscription
708 708
 	 */
709
-	public function maybe_renew_subscription( $subscription ) {
709
+	public function maybe_renew_subscription($subscription) {
710 710
 
711 711
         // Ensure its our subscription && it's active.
712
-        if ( $this->id === $subscription->get_gateway() && $subscription->has_status( 'active trialling' ) ) {
713
-            $this->renew_subscription( $subscription );
712
+        if ($this->id === $subscription->get_gateway() && $subscription->has_status('active trialling')) {
713
+            $this->renew_subscription($subscription);
714 714
         }
715 715
 
716 716
 	}
@@ -720,28 +720,28 @@  discard block
 block discarded – undo
720 720
 	 *
721 721
      * @param WPInv_Subscription $subscription
722 722
 	 */
723
-	public function renew_subscription( $subscription ) {
723
+	public function renew_subscription($subscription) {
724 724
 
725 725
 		// Generate the renewal invoice.
726 726
 		$new_invoice = $subscription->create_payment();
727 727
 		$old_invoice = $subscription->get_parent_payment();
728 728
 
729
-        if ( empty( $new_invoice ) ) {
730
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
729
+        if (empty($new_invoice)) {
730
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
731 731
             $subscription->failing();
732 732
             return;
733 733
         }
734 734
 
735 735
         // Charge the payment method.
736
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
737
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
738
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
736
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
737
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
738
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
739 739
 
740 740
 		// Do we have an error?
741
-		if ( is_wp_error( $result ) ) {
741
+		if (is_wp_error($result)) {
742 742
 
743 743
 			$old_invoice->add_note(
744
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
744
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
745 745
 				true,
746 746
 				false,
747 747
 				true
@@ -752,12 +752,12 @@  discard block
 block discarded – undo
752 752
 		}
753 753
 
754 754
 		// Process the response.
755
-		$this->process_charge_response( $result, $new_invoice );
755
+		$this->process_charge_response($result, $new_invoice);
756 756
 
757
-		if ( wpinv_get_errors() ) {
757
+		if (wpinv_get_errors()) {
758 758
 
759 759
 			$old_invoice->add_note(
760
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
760
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
761 761
 				true,
762 762
 				false,
763 763
 				true
@@ -767,9 +767,9 @@  discard block
 block discarded – undo
767 767
 
768 768
         }
769 769
 
770
-        if ( ! $new_invoice->needs_payment() ) {
770
+        if (!$new_invoice->needs_payment()) {
771 771
             $subscription->renew();
772
-            $subscription->after_add_payment( $new_invoice );
772
+            $subscription->after_add_payment($new_invoice);
773 773
         } else {
774 774
             $subscription->failing();
775 775
         }
@@ -782,33 +782,33 @@  discard block
 block discarded – undo
782 782
 	 * @param GetPaid_Form_Item[] $items
783 783
 	 * @return WPInv_Invoice
784 784
 	 */
785
-	public function process_addons( $invoice, $items ) {
785
+	public function process_addons($invoice, $items) {
786 786
 
787 787
         global $getpaid_authorize_addons;
788 788
 
789 789
         $getpaid_authorize_addons = array();
790
-        foreach ( $items as $item ) {
790
+        foreach ($items as $item) {
791 791
 
792
-            if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) {
792
+            if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) {
793 793
                 $getpaid_authorize_addons[] = $item;
794 794
             }
795 795
 }
796 796
 
797
-        if ( empty( $getpaid_authorize_addons ) ) {
797
+        if (empty($getpaid_authorize_addons)) {
798 798
             return;
799 799
         }
800 800
 
801 801
         $invoice->recalculate_total();
802 802
 
803
-        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
804
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
803
+        $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
804
+		$customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
805 805
 
806
-        add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
807
-        $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
808
-        remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) );
806
+        add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2);
807
+        $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
808
+        remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'));
809 809
 
810
-        if ( is_wp_error( $result ) ) {
811
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
810
+        if (is_wp_error($result)) {
811
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
812 812
             return;
813 813
         }
814 814
 
@@ -821,19 +821,19 @@  discard block
 block discarded – undo
821 821
      * @param array $args
822 822
 	 * @return array
823 823
 	 */
824
-    public function filter_addons_request( $args ) {
824
+    public function filter_addons_request($args) {
825 825
 
826 826
         global $getpaid_authorize_addons;
827 827
         $total = 0;
828 828
 
829
-        foreach ( $getpaid_authorize_addons as $addon ) {
829
+        foreach ($getpaid_authorize_addons as $addon) {
830 830
             $total += $addon->get_sub_total();
831 831
         }
832 832
 
833 833
         $args['createTransactionRequest']['transactionRequest']['amount'] = $total;
834 834
 
835
-        if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) {
836
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
835
+        if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) {
836
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
837 837
         }
838 838
 
839 839
         return $args;
@@ -846,7 +846,7 @@  discard block
 block discarded – undo
846 846
     public function sandbox_notice() {
847 847
 
848 848
         return sprintf(
849
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing' ),
849
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %1$sAuthorize.NET Sandbox Testing Guide%2$s for more details.', 'invoicing'),
850 850
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
851 851
             '</a>'
852 852
         );
@@ -858,42 +858,42 @@  discard block
 block discarded – undo
858 858
 	 *
859 859
 	 * @param array $admin_settings
860 860
 	 */
861
-	public function admin_settings( $admin_settings ) {
861
+	public function admin_settings($admin_settings) {
862 862
 
863 863
         $currencies = sprintf(
864
-            __( 'Supported Currencies: %s', 'invoicing' ),
865
-            implode( ', ', $this->currencies )
864
+            __('Supported Currencies: %s', 'invoicing'),
865
+            implode(', ', $this->currencies)
866 866
         );
867 867
 
868 868
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
869
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
869
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
870 870
 
871 871
         $admin_settings['authorizenet_login_id'] = array(
872 872
             'type' => 'text',
873 873
             'id'   => 'authorizenet_login_id',
874
-            'name' => __( 'API Login ID', 'invoicing' ),
875
-            '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>',
874
+            'name' => __('API Login ID', 'invoicing'),
875
+            '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>',
876 876
         );
877 877
 
878 878
         $admin_settings['authorizenet_transaction_key'] = array(
879 879
             'type' => 'text',
880 880
             'id'   => 'authorizenet_transaction_key',
881
-            'name' => __( 'Transaction Key', 'invoicing' ),
881
+            'name' => __('Transaction Key', 'invoicing'),
882 882
         );
883 883
 
884 884
         $admin_settings['authorizenet_signature_key'] = array(
885 885
             'type' => 'text',
886 886
             'id'   => 'authorizenet_signature_key',
887
-            'name' => __( 'Signature Key', 'invoicing' ),
888
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
887
+            'name' => __('Signature Key', 'invoicing'),
888
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
889 889
         );
890 890
 
891 891
         $admin_settings['authorizenet_ipn_url'] = array(
892 892
             'type'     => 'ipn_url',
893 893
             'id'       => 'authorizenet_ipn_url',
894
-            'name'     => __( 'Webhook URL', 'invoicing' ),
894
+            'name'     => __('Webhook URL', 'invoicing'),
895 895
             'std'      => $this->notify_url,
896
-            '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>',
896
+            '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>',
897 897
             'custom'   => 'authorizenet',
898 898
             'readonly' => true,
899 899
         );
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 2 patches
Indentation   +1051 added lines, -1051 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,42 +141,42 @@  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
-		$caches = array(
159
-			'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(),
160
-			'getpaid_subscription_transaction_ids_to_subscription_ids'    => $this->get_transaction_id(),
161
-			'getpaid_subscription_profile_ids_to_subscription_ids'        => $this->get_profile_id(),
162
-			'getpaid_subscriptions'                                       => $this->get_id(),
163
-		);
164
-
165
-		foreach ( $caches as $cache => $value ) {
166
-			if ( '' !== $value && false !== $value ) {
167
-				wp_cache_delete( $value, $cache );
168
-			}
169
-		}
170
-	}
171
-
172
-	/**
158
+        $caches = array(
159
+            'getpaid_subscription_parent_payment_ids_to_subscription_ids' => $this->get_parent_payment_id(),
160
+            'getpaid_subscription_transaction_ids_to_subscription_ids'    => $this->get_transaction_id(),
161
+            'getpaid_subscription_profile_ids_to_subscription_ids'        => $this->get_profile_id(),
162
+            'getpaid_subscriptions'                                       => $this->get_id(),
163
+        );
164
+
165
+        foreach ( $caches as $cache => $value ) {
166
+            if ( '' !== $value && false !== $value ) {
167
+                wp_cache_delete( $value, $cache );
168
+            }
169
+        }
170
+    }
171
+
172
+    /**
173 173
      * Checks if a subscription key is set.
174 174
      */
175 175
     public function _isset( $key ) {
176 176
         return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" );
177
-	}
177
+    }
178 178
 
179
-	/*
179
+    /*
180 180
 	|--------------------------------------------------------------------------
181 181
 	| CRUD methods
182 182
 	|--------------------------------------------------------------------------
@@ -185,544 +185,544 @@  discard block
 block discarded – undo
185 185
 	|
186 186
     */
187 187
 
188
-	/*
188
+    /*
189 189
 	|--------------------------------------------------------------------------
190 190
 	| Getters
191 191
 	|--------------------------------------------------------------------------
192 192
 	*/
193 193
 
194
-	/**
195
-	 * Get customer id.
196
-	 *
197
-	 * @since 1.0.19
198
-	 * @param  string $context View or edit context.
199
-	 * @return int
200
-	 */
201
-	public function get_customer_id( $context = 'view' ) {
202
-		return (int) $this->get_prop( 'customer_id', $context );
203
-	}
204
-
205
-	/**
206
-	 * Get customer information.
207
-	 *
208
-	 * @since 1.0.19
209
-	 * @param  string $context View or edit context.
210
-	 * @return WP_User|false WP_User object on success, false on failure.
211
-	 */
212
-	public function get_customer( $context = 'view' ) {
213
-		return get_userdata( $this->get_customer_id( $context ) );
214
-	}
215
-
216
-	/**
217
-	 * Get parent invoice id.
218
-	 *
219
-	 * @since 1.0.19
220
-	 * @param  string $context View or edit context.
221
-	 * @return int
222
-	 */
223
-	public function get_parent_invoice_id( $context = 'view' ) {
224
-		return (int) $this->get_prop( 'parent_payment_id', $context );
225
-	}
226
-
227
-	/**
228
-	 * Alias for self::get_parent_invoice_id().
229
-	 *
230
-	 * @since 1.0.19
231
-	 * @param  string $context View or edit context.
232
-	 * @return int
233
-	 */
194
+    /**
195
+     * Get customer id.
196
+     *
197
+     * @since 1.0.19
198
+     * @param  string $context View or edit context.
199
+     * @return int
200
+     */
201
+    public function get_customer_id( $context = 'view' ) {
202
+        return (int) $this->get_prop( 'customer_id', $context );
203
+    }
204
+
205
+    /**
206
+     * Get customer information.
207
+     *
208
+     * @since 1.0.19
209
+     * @param  string $context View or edit context.
210
+     * @return WP_User|false WP_User object on success, false on failure.
211
+     */
212
+    public function get_customer( $context = 'view' ) {
213
+        return get_userdata( $this->get_customer_id( $context ) );
214
+    }
215
+
216
+    /**
217
+     * Get parent invoice id.
218
+     *
219
+     * @since 1.0.19
220
+     * @param  string $context View or edit context.
221
+     * @return int
222
+     */
223
+    public function get_parent_invoice_id( $context = 'view' ) {
224
+        return (int) $this->get_prop( 'parent_payment_id', $context );
225
+    }
226
+
227
+    /**
228
+     * Alias for self::get_parent_invoice_id().
229
+     *
230
+     * @since 1.0.19
231
+     * @param  string $context View or edit context.
232
+     * @return int
233
+     */
234 234
     public function get_parent_payment_id( $context = 'view' ) {
235 235
         return $this->get_parent_invoice_id( $context );
236
-	}
236
+    }
237
+
238
+    /**
239
+     * Alias for self::get_parent_invoice_id().
240
+     *
241
+     * @since  1.0.0
242
+     * @return int
243
+     */
244
+    public function get_original_payment_id( $context = 'view' ) {
245
+        return $this->get_parent_invoice_id( $context );
246
+    }
247
+
248
+    /**
249
+     * Get parent invoice.
250
+     *
251
+     * @since 1.0.19
252
+     * @param  string $context View or edit context.
253
+     * @return WPInv_Invoice
254
+     */
255
+    public function get_parent_invoice( $context = 'view' ) {
256
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
257
+    }
258
+
259
+    /**
260
+     * Alias for self::get_parent_invoice().
261
+     *
262
+     * @since 1.0.19
263
+     * @param  string $context View or edit context.
264
+     * @return WPInv_Invoice
265
+     */
266
+    public function get_parent_payment( $context = 'view' ) {
267
+        return $this->get_parent_invoice( $context );
268
+    }
269
+
270
+    /**
271
+     * Get subscription's product id.
272
+     *
273
+     * @since 1.0.19
274
+     * @param  string $context View or edit context.
275
+     * @return int
276
+     */
277
+    public function get_product_id( $context = 'view' ) {
278
+        return (int) $this->get_prop( 'product_id', $context );
279
+    }
280
+
281
+    /**
282
+     * Get the subscription product.
283
+     *
284
+     * @since 1.0.19
285
+     * @param  string $context View or edit context.
286
+     * @return WPInv_Item
287
+     */
288
+    public function get_product( $context = 'view' ) {
289
+        return new WPInv_Item( $this->get_product_id( $context ) );
290
+    }
291
+
292
+    /**
293
+     * Get parent invoice's gateway.
294
+     *
295
+     * Here for backwards compatibility.
296
+     *
297
+     * @since 1.0.19
298
+     * @param  string $context View or edit context.
299
+     * @return string
300
+     */
301
+    public function get_gateway( $context = 'view' ) {
302
+        return $this->get_parent_invoice( $context )->get_gateway();
303
+    }
304
+
305
+    /**
306
+     * Get the period of a renewal.
307
+     *
308
+     * @since 1.0.19
309
+     * @param  string $context View or edit context.
310
+     * @return string
311
+     */
312
+    public function get_period( $context = 'view' ) {
313
+        return $this->get_prop( 'period', $context );
314
+    }
315
+
316
+    /**
317
+     * Get number of periods each renewal is valid for.
318
+     *
319
+     * @since 1.0.19
320
+     * @param  string $context View or edit context.
321
+     * @return int
322
+     */
323
+    public function get_frequency( $context = 'view' ) {
324
+        return (int) $this->get_prop( 'frequency', $context );
325
+    }
326
+
327
+    /**
328
+     * Get the initial amount for the subscription.
329
+     *
330
+     * @since 1.0.19
331
+     * @param  string $context View or edit context.
332
+     * @return float
333
+     */
334
+    public function get_initial_amount( $context = 'view' ) {
335
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
336
+    }
337
+
338
+    /**
339
+     * Get the recurring amount for the subscription.
340
+     *
341
+     * @since 1.0.19
342
+     * @param  string $context View or edit context.
343
+     * @return float
344
+     */
345
+    public function get_recurring_amount( $context = 'view' ) {
346
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
347
+    }
348
+
349
+    /**
350
+     * Get number of times that this subscription can be renewed.
351
+     *
352
+     * @since 1.0.19
353
+     * @param  string $context View or edit context.
354
+     * @return int
355
+     */
356
+    public function get_bill_times( $context = 'view' ) {
357
+        return (int) $this->get_prop( 'bill_times', $context );
358
+    }
359
+
360
+    /**
361
+     * Get transaction id of this subscription's parent invoice.
362
+     *
363
+     * @since 1.0.19
364
+     * @param  string $context View or edit context.
365
+     * @return string
366
+     */
367
+    public function get_transaction_id( $context = 'view' ) {
368
+        return $this->get_prop( 'transaction_id', $context );
369
+    }
370
+
371
+    /**
372
+     * Get the date that the subscription was created.
373
+     *
374
+     * @since 1.0.19
375
+     * @param  string $context View or edit context.
376
+     * @return string
377
+     */
378
+    public function get_created( $context = 'view' ) {
379
+        return $this->get_prop( 'created', $context );
380
+    }
381
+
382
+    /**
383
+     * Alias for self::get_created().
384
+     *
385
+     * @since 1.0.19
386
+     * @param  string $context View or edit context.
387
+     * @return string
388
+     */
389
+    public function get_date_created( $context = 'view' ) {
390
+        return $this->get_created( $context );
391
+    }
392
+
393
+    /**
394
+     * Retrieves the creation date in a timestamp
395
+     *
396
+     * @since  1.0.0
397
+     * @return int
398
+     */
399
+    public function get_time_created() {
400
+        $created = $this->get_date_created();
401
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
402
+    }
403
+
404
+    /**
405
+     * Get GMT date when the subscription was created.
406
+     *
407
+     * @since 1.0.19
408
+     * @param  string $context View or edit context.
409
+     * @return string
410
+     */
411
+    public function get_date_created_gmt( $context = 'view' ) {
412
+        $date = $this->get_date_created( $context );
413
+
414
+        if ( $date ) {
415
+            $date = get_gmt_from_date( $date );
416
+        }
417
+        return $date;
418
+    }
419
+
420
+    /**
421
+     * Get the date that the subscription will renew.
422
+     *
423
+     * @since 1.0.19
424
+     * @param  string $context View or edit context.
425
+     * @return string
426
+     */
427
+    public function get_next_renewal_date( $context = 'view' ) {
428
+        return $this->get_prop( 'expiration', $context );
429
+    }
430
+
431
+    /**
432
+     * Alias for self::get_next_renewal_date().
433
+     *
434
+     * @since 1.0.19
435
+     * @param  string $context View or edit context.
436
+     * @return string
437
+     */
438
+    public function get_expiration( $context = 'view' ) {
439
+        return $this->get_next_renewal_date( $context );
440
+    }
441
+
442
+    /**
443
+     * Retrieves the expiration date in a timestamp
444
+     *
445
+     * @since  1.0.0
446
+     * @return int
447
+     */
448
+    public function get_expiration_time() {
449
+        $expiration = $this->get_expiration();
450
+
451
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
452
+            return current_time( 'timestamp' );
453
+        }
454
+
455
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
456
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
457
+    }
458
+
459
+    /**
460
+     * Get GMT date when the subscription will renew.
461
+     *
462
+     * @since 1.0.19
463
+     * @param  string $context View or edit context.
464
+     * @return string
465
+     */
466
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
467
+        $date = $this->get_next_renewal_date( $context );
468
+
469
+        if ( $date ) {
470
+            $date = get_gmt_from_date( $date );
471
+        }
472
+        return $date;
473
+    }
474
+
475
+    /**
476
+     * Get the subscription's trial period.
477
+     *
478
+     * @since 1.0.19
479
+     * @param  string $context View or edit context.
480
+     * @return string
481
+     */
482
+    public function get_trial_period( $context = 'view' ) {
483
+        return $this->get_prop( 'trial_period', $context );
484
+    }
485
+
486
+    /**
487
+     * Get the subscription's status.
488
+     *
489
+     * @since 1.0.19
490
+     * @param  string $context View or edit context.
491
+     * @return string
492
+     */
493
+    public function get_status( $context = 'view' ) {
494
+        return $this->get_prop( 'status', $context );
495
+    }
496
+
497
+    /**
498
+     * Get the subscription's profile id.
499
+     *
500
+     * @since 1.0.19
501
+     * @param  string $context View or edit context.
502
+     * @return string
503
+     */
504
+    public function get_profile_id( $context = 'view' ) {
505
+        return $this->get_prop( 'profile_id', $context );
506
+    }
507
+
508
+    /*
509
+	|--------------------------------------------------------------------------
510
+	| Setters
511
+	|--------------------------------------------------------------------------
512
+	*/
513
+
514
+    /**
515
+     * Set customer id.
516
+     *
517
+     * @since 1.0.19
518
+     * @param  int $value The customer's id.
519
+     */
520
+    public function set_customer_id( $value ) {
521
+        $this->set_prop( 'customer_id', (int) $value );
522
+    }
523
+
524
+    /**
525
+     * Set parent invoice id.
526
+     *
527
+     * @since 1.0.19
528
+     * @param  int $value The parent invoice id.
529
+     */
530
+    public function set_parent_invoice_id( $value ) {
531
+        $this->set_prop( 'parent_payment_id', (int) $value );
532
+    }
533
+
534
+    /**
535
+     * Alias for self::set_parent_invoice_id().
536
+     *
537
+     * @since 1.0.19
538
+     * @param  int $value The parent invoice id.
539
+     */
540
+    public function set_parent_payment_id( $value ) {
541
+        $this->set_parent_invoice_id( $value );
542
+    }
543
+
544
+    /**
545
+     * Alias for self::set_parent_invoice_id().
546
+     *
547
+     * @since 1.0.19
548
+     * @param  int $value The parent invoice id.
549
+     */
550
+    public function set_original_payment_id( $value ) {
551
+        $this->set_parent_invoice_id( $value );
552
+    }
553
+
554
+    /**
555
+     * Set subscription's product id.
556
+     *
557
+     * @since 1.0.19
558
+     * @param  int $value The subscription product id.
559
+     */
560
+    public function set_product_id( $value ) {
561
+        $this->set_prop( 'product_id', (int) $value );
562
+    }
563
+
564
+    /**
565
+     * Set the period of a renewal.
566
+     *
567
+     * @since 1.0.19
568
+     * @param  string $value The renewal period.
569
+     */
570
+    public function set_period( $value ) {
571
+        $this->set_prop( 'period', $value );
572
+    }
573
+
574
+    /**
575
+     * Set number of periods each renewal is valid for.
576
+     *
577
+     * @since 1.0.19
578
+     * @param  int $value The subscription frequency.
579
+     */
580
+    public function set_frequency( $value ) {
581
+        $value = empty( $value ) ? 1 : (int) $value;
582
+        $this->set_prop( 'frequency', absint( $value ) );
583
+    }
584
+
585
+    /**
586
+     * Set the initial amount for the subscription.
587
+     *
588
+     * @since 1.0.19
589
+     * @param  float $value The initial subcription amount.
590
+     */
591
+    public function set_initial_amount( $value ) {
592
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
593
+    }
594
+
595
+    /**
596
+     * Set the recurring amount for the subscription.
597
+     *
598
+     * @since 1.0.19
599
+     * @param  float $value The recurring subcription amount.
600
+     */
601
+    public function set_recurring_amount( $value ) {
602
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
603
+    }
604
+
605
+    /**
606
+     * Set number of times that this subscription can be renewed.
607
+     *
608
+     * @since 1.0.19
609
+     * @param  int $value Bill times.
610
+     */
611
+    public function set_bill_times( $value ) {
612
+        $this->set_prop( 'bill_times', (int) $value );
613
+    }
614
+
615
+    /**
616
+     * Get transaction id of this subscription's parent invoice.
617
+     *
618
+     * @since 1.0.19
619
+     * @param string $value Bill times.
620
+     */
621
+    public function set_transaction_id( $value ) {
622
+        $this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
623
+    }
624
+
625
+    /**
626
+     * Set date when this subscription started.
627
+     *
628
+     * @since 1.0.19
629
+     * @param string $value strtotime compliant date.
630
+     */
631
+    public function set_created( $value ) {
632
+        $date = strtotime( $value );
633
+
634
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
635
+            $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) );
636
+            return;
637
+        }
638
+
639
+        $this->set_prop( 'created', '' );
640
+
641
+    }
237 642
 
238
-	/**
239
-     * Alias for self::get_parent_invoice_id().
643
+    /**
644
+     * Alias for self::set_created().
240 645
      *
241
-     * @since  1.0.0
242
-     * @return int
646
+     * @since 1.0.19
647
+     * @param string $value strtotime compliant date.
243 648
      */
244
-    public function get_original_payment_id( $context = 'view' ) {
245
-        return $this->get_parent_invoice_id( $context );
649
+    public function set_date_created( $value ) {
650
+        $this->set_created( $value );
246 651
     }
247 652
 
248
-	/**
249
-	 * Get parent invoice.
250
-	 *
251
-	 * @since 1.0.19
252
-	 * @param  string $context View or edit context.
253
-	 * @return WPInv_Invoice
254
-	 */
255
-	public function get_parent_invoice( $context = 'view' ) {
256
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
257
-	}
258
-
259
-	/**
260
-	 * Alias for self::get_parent_invoice().
261
-	 *
262
-	 * @since 1.0.19
263
-	 * @param  string $context View or edit context.
264
-	 * @return WPInv_Invoice
265
-	 */
266
-    public function get_parent_payment( $context = 'view' ) {
267
-        return $this->get_parent_invoice( $context );
268
-	}
269
-
270
-	/**
271
-	 * Get subscription's product id.
272
-	 *
273
-	 * @since 1.0.19
274
-	 * @param  string $context View or edit context.
275
-	 * @return int
276
-	 */
277
-	public function get_product_id( $context = 'view' ) {
278
-		return (int) $this->get_prop( 'product_id', $context );
279
-	}
280
-
281
-	/**
282
-	 * Get the subscription product.
283
-	 *
284
-	 * @since 1.0.19
285
-	 * @param  string $context View or edit context.
286
-	 * @return WPInv_Item
287
-	 */
288
-	public function get_product( $context = 'view' ) {
289
-		return new WPInv_Item( $this->get_product_id( $context ) );
290
-	}
291
-
292
-	/**
293
-	 * Get parent invoice's gateway.
294
-	 *
295
-	 * Here for backwards compatibility.
296
-	 *
297
-	 * @since 1.0.19
298
-	 * @param  string $context View or edit context.
299
-	 * @return string
300
-	 */
301
-	public function get_gateway( $context = 'view' ) {
302
-		return $this->get_parent_invoice( $context )->get_gateway();
303
-	}
304
-
305
-	/**
306
-	 * Get the period of a renewal.
307
-	 *
308
-	 * @since 1.0.19
309
-	 * @param  string $context View or edit context.
310
-	 * @return string
311
-	 */
312
-	public function get_period( $context = 'view' ) {
313
-		return $this->get_prop( 'period', $context );
314
-	}
315
-
316
-	/**
317
-	 * Get number of periods each renewal is valid for.
318
-	 *
319
-	 * @since 1.0.19
320
-	 * @param  string $context View or edit context.
321
-	 * @return int
322
-	 */
323
-	public function get_frequency( $context = 'view' ) {
324
-		return (int) $this->get_prop( 'frequency', $context );
325
-	}
326
-
327
-	/**
328
-	 * Get the initial amount for the subscription.
329
-	 *
330
-	 * @since 1.0.19
331
-	 * @param  string $context View or edit context.
332
-	 * @return float
333
-	 */
334
-	public function get_initial_amount( $context = 'view' ) {
335
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
336
-	}
337
-
338
-	/**
339
-	 * Get the recurring amount for the subscription.
340
-	 *
341
-	 * @since 1.0.19
342
-	 * @param  string $context View or edit context.
343
-	 * @return float
344
-	 */
345
-	public function get_recurring_amount( $context = 'view' ) {
346
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
347
-	}
348
-
349
-	/**
350
-	 * Get number of times that this subscription can be renewed.
351
-	 *
352
-	 * @since 1.0.19
353
-	 * @param  string $context View or edit context.
354
-	 * @return int
355
-	 */
356
-	public function get_bill_times( $context = 'view' ) {
357
-		return (int) $this->get_prop( 'bill_times', $context );
358
-	}
359
-
360
-	/**
361
-	 * Get transaction id of this subscription's parent invoice.
362
-	 *
363
-	 * @since 1.0.19
364
-	 * @param  string $context View or edit context.
365
-	 * @return string
366
-	 */
367
-	public function get_transaction_id( $context = 'view' ) {
368
-		return $this->get_prop( 'transaction_id', $context );
369
-	}
370
-
371
-	/**
372
-	 * Get the date that the subscription was created.
373
-	 *
374
-	 * @since 1.0.19
375
-	 * @param  string $context View or edit context.
376
-	 * @return string
377
-	 */
378
-	public function get_created( $context = 'view' ) {
379
-		return $this->get_prop( 'created', $context );
380
-	}
381
-
382
-	/**
383
-	 * Alias for self::get_created().
384
-	 *
385
-	 * @since 1.0.19
386
-	 * @param  string $context View or edit context.
387
-	 * @return string
388
-	 */
389
-	public function get_date_created( $context = 'view' ) {
390
-		return $this->get_created( $context );
391
-	}
392
-
393
-	/**
394
-	 * Retrieves the creation date in a timestamp
395
-	 *
396
-	 * @since  1.0.0
397
-	 * @return int
398
-	 */
399
-	public function get_time_created() {
400
-		$created = $this->get_date_created();
401
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
402
-	}
403
-
404
-	/**
405
-	 * Get GMT date when the subscription was created.
406
-	 *
407
-	 * @since 1.0.19
408
-	 * @param  string $context View or edit context.
409
-	 * @return string
410
-	 */
411
-	public function get_date_created_gmt( $context = 'view' ) {
412
-        $date = $this->get_date_created( $context );
653
+    /**
654
+     * Set the date that the subscription will renew.
655
+     *
656
+     * @since 1.0.19
657
+     * @param string $value strtotime compliant date.
658
+     */
659
+    public function set_next_renewal_date( $value ) {
660
+        $date = strtotime( $value );
413 661
 
414
-        if ( $date ) {
415
-            $date = get_gmt_from_date( $date );
662
+        if ( $date && $value !== '0000-00-00 00:00:00' ) {
663
+            $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) );
664
+            return;
416 665
         }
417
-		return $date;
418
-	}
419
-
420
-	/**
421
-	 * Get the date that the subscription will renew.
422
-	 *
423
-	 * @since 1.0.19
424
-	 * @param  string $context View or edit context.
425
-	 * @return string
426
-	 */
427
-	public function get_next_renewal_date( $context = 'view' ) {
428
-		return $this->get_prop( 'expiration', $context );
429
-	}
430
-
431
-	/**
432
-	 * Alias for self::get_next_renewal_date().
433
-	 *
434
-	 * @since 1.0.19
435
-	 * @param  string $context View or edit context.
436
-	 * @return string
437
-	 */
438
-	public function get_expiration( $context = 'view' ) {
439
-		return $this->get_next_renewal_date( $context );
440
-	}
441
-
442
-	/**
443
-	 * Retrieves the expiration date in a timestamp
444
-	 *
445
-	 * @since  1.0.0
446
-	 * @return int
447
-	 */
448
-	public function get_expiration_time() {
449
-		$expiration = $this->get_expiration();
450
-
451
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
452
-			return current_time( 'timestamp' );
453
-		}
454
-
455
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
456
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
457
-	}
458
-
459
-	/**
460
-	 * Get GMT date when the subscription will renew.
461
-	 *
462
-	 * @since 1.0.19
463
-	 * @param  string $context View or edit context.
464
-	 * @return string
465
-	 */
466
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
467
-        $date = $this->get_next_renewal_date( $context );
468 666
 
469
-        if ( $date ) {
470
-            $date = get_gmt_from_date( $date );
471
-        }
472
-		return $date;
473
-	}
474
-
475
-	/**
476
-	 * Get the subscription's trial period.
477
-	 *
478
-	 * @since 1.0.19
479
-	 * @param  string $context View or edit context.
480
-	 * @return string
481
-	 */
482
-	public function get_trial_period( $context = 'view' ) {
483
-		return $this->get_prop( 'trial_period', $context );
484
-	}
485
-
486
-	/**
487
-	 * Get the subscription's status.
488
-	 *
489
-	 * @since 1.0.19
490
-	 * @param  string $context View or edit context.
491
-	 * @return string
492
-	 */
493
-	public function get_status( $context = 'view' ) {
494
-		return $this->get_prop( 'status', $context );
495
-	}
496
-
497
-	/**
498
-	 * Get the subscription's profile id.
499
-	 *
500
-	 * @since 1.0.19
501
-	 * @param  string $context View or edit context.
502
-	 * @return string
503
-	 */
504
-	public function get_profile_id( $context = 'view' ) {
505
-		return $this->get_prop( 'profile_id', $context );
506
-	}
507
-
508
-	/*
509
-	|--------------------------------------------------------------------------
510
-	| Setters
511
-	|--------------------------------------------------------------------------
512
-	*/
667
+        $this->set_prop( 'expiration', '' );
513 668
 
514
-	/**
515
-	 * Set customer id.
516
-	 *
517
-	 * @since 1.0.19
518
-	 * @param  int $value The customer's id.
519
-	 */
520
-	public function set_customer_id( $value ) {
521
-		$this->set_prop( 'customer_id', (int) $value );
522
-	}
523
-
524
-	/**
525
-	 * Set parent invoice id.
526
-	 *
527
-	 * @since 1.0.19
528
-	 * @param  int $value The parent invoice id.
529
-	 */
530
-	public function set_parent_invoice_id( $value ) {
531
-		$this->set_prop( 'parent_payment_id', (int) $value );
532
-	}
533
-
534
-	/**
535
-	 * Alias for self::set_parent_invoice_id().
536
-	 *
537
-	 * @since 1.0.19
538
-	 * @param  int $value The parent invoice id.
539
-	 */
540
-    public function set_parent_payment_id( $value ) {
541
-        $this->set_parent_invoice_id( $value );
542
-	}
669
+    }
543 670
 
544
-	/**
545
-     * Alias for self::set_parent_invoice_id().
671
+    /**
672
+     * Alias for self::set_next_renewal_date().
546 673
      *
547 674
      * @since 1.0.19
548
-	 * @param  int $value The parent invoice id.
675
+     * @param string $value strtotime compliant date.
549 676
      */
550
-    public function set_original_payment_id( $value ) {
551
-        $this->set_parent_invoice_id( $value );
552
-	}
553
-
554
-	/**
555
-	 * Set subscription's product id.
556
-	 *
557
-	 * @since 1.0.19
558
-	 * @param  int $value The subscription product id.
559
-	 */
560
-	public function set_product_id( $value ) {
561
-		$this->set_prop( 'product_id', (int) $value );
562
-	}
563
-
564
-	/**
565
-	 * Set the period of a renewal.
566
-	 *
567
-	 * @since 1.0.19
568
-	 * @param  string $value The renewal period.
569
-	 */
570
-	public function set_period( $value ) {
571
-		$this->set_prop( 'period', $value );
572
-	}
573
-
574
-	/**
575
-	 * Set number of periods each renewal is valid for.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param  int $value The subscription frequency.
579
-	 */
580
-	public function set_frequency( $value ) {
581
-		$value = empty( $value ) ? 1 : (int) $value;
582
-		$this->set_prop( 'frequency', absint( $value ) );
583
-	}
584
-
585
-	/**
586
-	 * Set the initial amount for the subscription.
587
-	 *
588
-	 * @since 1.0.19
589
-	 * @param  float $value The initial subcription amount.
590
-	 */
591
-	public function set_initial_amount( $value ) {
592
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
593
-	}
594
-
595
-	/**
596
-	 * Set the recurring amount for the subscription.
597
-	 *
598
-	 * @since 1.0.19
599
-	 * @param  float $value The recurring subcription amount.
600
-	 */
601
-	public function set_recurring_amount( $value ) {
602
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
603
-	}
604
-
605
-	/**
606
-	 * Set number of times that this subscription can be renewed.
607
-	 *
608
-	 * @since 1.0.19
609
-	 * @param  int $value Bill times.
610
-	 */
611
-	public function set_bill_times( $value ) {
612
-		$this->set_prop( 'bill_times', (int) $value );
613
-	}
614
-
615
-	/**
616
-	 * Get transaction id of this subscription's parent invoice.
617
-	 *
618
-	 * @since 1.0.19
619
-	 * @param string $value Bill times.
620
-	 */
621
-	public function set_transaction_id( $value ) {
622
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
623
-	}
624
-
625
-	/**
626
-	 * Set date when this subscription started.
627
-	 *
628
-	 * @since 1.0.19
629
-	 * @param string $value strtotime compliant date.
630
-	 */
631
-	public function set_created( $value ) {
632
-        $date = strtotime( $value );
677
+    public function set_expiration( $value ) {
678
+        $this->set_next_renewal_date( $value );
679
+    }
633 680
 
634
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
635
-            $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) );
681
+    /**
682
+     * Set the subscription's trial period.
683
+     *
684
+     * @since 1.0.19
685
+     * @param string $value trial period e.g 1 year.
686
+     */
687
+    public function set_trial_period( $value ) {
688
+        $this->set_prop( 'trial_period', $value );
689
+    }
690
+
691
+    /**
692
+     * Set the subscription's status.
693
+     *
694
+     * @since 1.0.19
695
+     * @param string $new_status    New subscription status.
696
+     */
697
+    public function set_status( $new_status ) {
698
+
699
+        // Abort if this is not a valid status;
700
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
636 701
             return;
637 702
         }
638 703
 
639
-		$this->set_prop( 'created', '' );
640
-
641
-	}
704
+        $old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
705
+        if ( true === $this->object_read && $old_status !== $new_status ) {
706
+            $this->status_transition = array(
707
+                'from' => $old_status,
708
+                'to'   => $new_status,
709
+            );
710
+        }
642 711
 
643
-	/**
644
-	 * Alias for self::set_created().
645
-	 *
646
-	 * @since 1.0.19
647
-	 * @param string $value strtotime compliant date.
648
-	 */
649
-	public function set_date_created( $value ) {
650
-		$this->set_created( $value );
712
+        $this->set_prop( 'status', $new_status );
651 713
     }
652 714
 
653
-	/**
654
-	 * Set the date that the subscription will renew.
655
-	 *
656
-	 * @since 1.0.19
657
-	 * @param string $value strtotime compliant date.
658
-	 */
659
-	public function set_next_renewal_date( $value ) {
660
-		$date = strtotime( $value );
715
+    /**
716
+     * Set the subscription's (remote) profile id.
717
+     *
718
+     * @since 1.0.19
719
+     * @param  string $value the remote profile id.
720
+     */
721
+    public function set_profile_id( $value ) {
722
+        $this->set_prop( 'profile_id', sanitize_text_field( $value ) );
723
+    }
661 724
 
662
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
663
-            $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) );
664
-            return;
665
-		}
666
-
667
-		$this->set_prop( 'expiration', '' );
668
-
669
-	}
670
-
671
-	/**
672
-	 * Alias for self::set_next_renewal_date().
673
-	 *
674
-	 * @since 1.0.19
675
-	 * @param string $value strtotime compliant date.
676
-	 */
677
-	public function set_expiration( $value ) {
678
-		$this->set_next_renewal_date( $value );
679
-    }
680
-
681
-	/**
682
-	 * Set the subscription's trial period.
683
-	 *
684
-	 * @since 1.0.19
685
-	 * @param string $value trial period e.g 1 year.
686
-	 */
687
-	public function set_trial_period( $value ) {
688
-		$this->set_prop( 'trial_period', $value );
689
-	}
690
-
691
-	/**
692
-	 * Set the subscription's status.
693
-	 *
694
-	 * @since 1.0.19
695
-	 * @param string $new_status    New subscription status.
696
-	 */
697
-	public function set_status( $new_status ) {
698
-
699
-		// Abort if this is not a valid status;
700
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
701
-			return;
702
-		}
703
-
704
-		$old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
705
-		if ( true === $this->object_read && $old_status !== $new_status ) {
706
-			$this->status_transition = array(
707
-				'from' => $old_status,
708
-				'to'   => $new_status,
709
-			);
710
-		}
711
-
712
-		$this->set_prop( 'status', $new_status );
713
-	}
714
-
715
-	/**
716
-	 * Set the subscription's (remote) profile id.
717
-	 *
718
-	 * @since 1.0.19
719
-	 * @param  string $value the remote profile id.
720
-	 */
721
-	public function set_profile_id( $value ) {
722
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
723
-	}
724
-
725
-	/*
725
+    /*
726 726
 	|--------------------------------------------------------------------------
727 727
 	| Boolean methods
728 728
 	|--------------------------------------------------------------------------
@@ -731,55 +731,55 @@  discard block
 block discarded – undo
731 731
 	|
732 732
 	*/
733 733
 
734
-	/**
734
+    /**
735 735
      * Checks if the subscription has a given status.
736
-	 *
737
-	 * @param string|array String or array of strings to check for.
738
-	 * @return bool
736
+     *
737
+     * @param string|array String or array of strings to check for.
738
+     * @return bool
739 739
      */
740 740
     public function has_status( $status ) {
741 741
         return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
742
-	}
742
+    }
743 743
 
744
-	/**
744
+    /**
745 745
      * Checks if the subscription has a trial period.
746
-	 *
747
-	 * @return bool
746
+     *
747
+     * @return bool
748 748
      */
749 749
     public function has_trial_period() {
750
-		$period = $this->get_trial_period();
750
+        $period = $this->get_trial_period();
751 751
         return ! empty( $period );
752
-	}
753
-
754
-	/**
755
-	 * Is the subscription active?
756
-	 *
757
-	 * @return bool
758
-	 */
759
-	public function is_active() {
760
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
761
-	}
762
-
763
-	/**
764
-	 * Is the subscription expired?
765
-	 *
766
-	 * @return bool
767
-	 */
768
-	public function is_expired() {
769
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
770
-	}
771
-
772
-	/**
773
-	 * Is this the last renewals?
774
-	 *
775
-	 * @return bool
776
-	 */
777
-	public function is_last_renewal() {
778
-		$max_bills = $this->get_bill_times();
779
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
780
-	}
781
-
782
-	/*
752
+    }
753
+
754
+    /**
755
+     * Is the subscription active?
756
+     *
757
+     * @return bool
758
+     */
759
+    public function is_active() {
760
+        return $this->has_status( 'active trialling' ) && ! $this->is_expired();
761
+    }
762
+
763
+    /**
764
+     * Is the subscription expired?
765
+     *
766
+     * @return bool
767
+     */
768
+    public function is_expired() {
769
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
770
+    }
771
+
772
+    /**
773
+     * Is this the last renewals?
774
+     *
775
+     * @return bool
776
+     */
777
+    public function is_last_renewal() {
778
+        $max_bills = $this->get_bill_times();
779
+        return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
780
+    }
781
+
782
+    /*
783 783
 	|--------------------------------------------------------------------------
784 784
 	| Additional methods
785 785
 	|--------------------------------------------------------------------------
@@ -788,27 +788,27 @@  discard block
 block discarded – undo
788 788
 	|
789 789
 	*/
790 790
 
791
-	/**
792
-	 * Backwards compatibilty.
793
-	 */
794
-	public function create( $data = array() ) {
791
+    /**
792
+     * Backwards compatibilty.
793
+     */
794
+    public function create( $data = array() ) {
795 795
 
796
-		// Set the properties.
797
-		if ( is_array( $data ) ) {
798
-			$this->set_props( $data );
799
-		}
796
+        // Set the properties.
797
+        if ( is_array( $data ) ) {
798
+            $this->set_props( $data );
799
+        }
800 800
 
801
-		// Save the item.
802
-		return $this->save();
801
+        // Save the item.
802
+        return $this->save();
803 803
 
804
-	}
804
+    }
805 805
 
806
-	/**
807
-	 * Backwards compatibilty.
808
-	 */
809
-	public function update( $args = array() ) {
810
-		return $this->create( $args );
811
-	}
806
+    /**
807
+     * Backwards compatibilty.
808
+     */
809
+    public function update( $args = array() ) {
810
+        return $this->create( $args );
811
+    }
812 812
 
813 813
     /**
814 814
      * Retrieve renewal payments for a subscription
@@ -818,22 +818,22 @@  discard block
 block discarded – undo
818 818
      */
819 819
     public function get_child_payments( $hide_pending = true ) {
820 820
 
821
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
821
+        $statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
822 822
 
823
-		if ( ! $hide_pending ) {
824
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
825
-		}
823
+        if ( ! $hide_pending ) {
824
+            $statuses = array_keys( wpinv_get_invoice_statuses() );
825
+        }
826 826
 
827 827
         return get_posts(
828
-			array(
829
-            	'post_parent' => $this->get_parent_payment_id(),
830
-            	'numberposts' => -1,
831
-            	'post_status' => $statuses,
832
-            	'orderby'     => 'ID',
833
-            	'order'       => 'ASC',
834
-            	'post_type'   => 'wpi_invoice',
835
-			)
836
-		);
828
+            array(
829
+                'post_parent' => $this->get_parent_payment_id(),
830
+                'numberposts' => -1,
831
+                'post_status' => $statuses,
832
+                'orderby'     => 'ID',
833
+                'order'       => 'ASC',
834
+                'post_type'   => 'wpi_invoice',
835
+            )
836
+        );
837 837
     }
838 838
 
839 839
     /**
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
      * @return int
844 844
      */
845 845
     public function get_total_payments() {
846
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
846
+        return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
847 847
     }
848 848
 
849 849
     /**
@@ -867,192 +867,192 @@  discard block
 block discarded – undo
867 867
      *
868 868
      * @since  2.4
869 869
      * @param  array $args Array of values for the payment, including amount and transaction ID
870
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
870
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
871 871
      * @return bool
872 872
      */
873 873
     public function add_payment( $args = array(), $invoice = false ) {
874 874
 
875
-		// Process each payment once.
875
+        // Process each payment once.
876 876
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
877 877
             return false;
878 878
         }
879 879
 
880
-		// Are we creating a new invoice?
881
-		if ( empty( $invoice ) ) {
882
-			$invoice = $this->create_payment( false );
880
+        // Are we creating a new invoice?
881
+        if ( empty( $invoice ) ) {
882
+            $invoice = $this->create_payment( false );
883 883
 
884
-			if ( empty( $invoice ) ) {
885
-				return false;
886
-			}
887
-		}
884
+            if ( empty( $invoice ) ) {
885
+                return false;
886
+            }
887
+        }
888 888
 
889
-		// Maybe set a transaction id.
890
-		if ( ! empty( $args['transaction_id'] ) ) {
891
-			$invoice->set_transaction_id( $args['transaction_id'] );
892
-		}
889
+        // Maybe set a transaction id.
890
+        if ( ! empty( $args['transaction_id'] ) ) {
891
+            $invoice->set_transaction_id( $args['transaction_id'] );
892
+        }
893 893
 
894
-		// Set the completed date.
895
-		$invoice->set_completed_date( current_time( 'mysql' ) );
894
+        // Set the completed date.
895
+        $invoice->set_completed_date( current_time( 'mysql' ) );
896 896
 
897
-		// And the gateway.
898
-		if ( ! empty( $args['gateway'] ) ) {
899
-			$invoice->set_gateway( $args['gateway'] );
900
-		}
897
+        // And the gateway.
898
+        if ( ! empty( $args['gateway'] ) ) {
899
+            $invoice->set_gateway( $args['gateway'] );
900
+        }
901 901
 
902
-		$invoice->set_status( 'wpi-renewal' );
903
-		$invoice->save();
902
+        $invoice->set_status( 'wpi-renewal' );
903
+        $invoice->save();
904 904
 
905
-		if ( ! $invoice->exists() ) {
906
-			return false;
907
-		}
905
+        if ( ! $invoice->exists() ) {
906
+            return false;
907
+        }
908 908
 
909
-		return $this->after_add_payment( $invoice );
910
-	}
909
+        return $this->after_add_payment( $invoice );
910
+    }
911 911
 
912 912
     public function after_add_payment( $invoice ) {
913 913
 
914
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
915
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
914
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
915
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
916 916
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
917 917
 
918 918
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
919 919
 
920 920
         return $invoice->get_id();
921
-	}
921
+    }
922 922
 
923
-	/**
923
+    /**
924 924
      * Creates a new invoice and returns it.
925 925
      *
926 926
      * @since  1.0.19
927
-	 * @param bool $save Whether we should save the invoice.
927
+     * @param bool $save Whether we should save the invoice.
928 928
      * @return WPInv_Invoice|bool
929 929
      */
930 930
     public function create_payment( $save = true ) {
931 931
 
932
-		$parent_invoice = $this->get_parent_payment();
933
-
934
-		if ( ! $parent_invoice->exists() ) {
935
-			return false;
936
-		}
937
-
938
-		// Duplicate the parent invoice.
939
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
940
-		$invoice->set_parent_id( $parent_invoice->get_id() );
941
-		$invoice->set_subscription_id( $this->get_id() );
942
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
943
-
944
-		// Set invoice items.
945
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
946
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
947
-		$invoice_items      = array();
948
-
949
-		foreach ( $invoice->get_items() as $item ) {
950
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
951
-				$invoice_items[] = $item;
952
-			}
953
-		}
954
-
955
-		$invoice->set_items( $invoice_items );
956
-
957
-		if ( ! empty( $subscription_group['fees'] ) ) {
958
-			$invoice->set_fees( $subscription_group['fees'] );
959
-		}
960
-
961
-		// Maybe recalculate discount (Pre-GetPaid Fix).
962
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
963
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
964
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
965
-		}
966
-
967
-		$invoice->recalculate_total();
968
-		$invoice->set_status( 'wpi-pending' );
969
-
970
-		if ( ! $save ) {
971
-			return $invoice;
972
-		}
973
-
974
-		$invoice->save();
975
-
976
-		return $invoice->exists() ? $invoice : false;
977
-    }
978
-
979
-	/**
980
-	 * Renews or completes a subscription
981
-	 *
982
-	 * @since  1.0.0
983
-	 * @return int The subscription's id
984
-	 */
985
-	public function renew( $calculate_from = null ) {
986
-
987
-		// Complete subscription if applicable
988
-		if ( $this->is_last_renewal() ) {
989
-			return $this->complete();
990
-		}
991
-
992
-		// Calculate new expiration
993
-		$frequency      = $this->get_frequency();
994
-		$period         = $this->get_period();
995
-		$calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
996
-		$new_expiration = strtotime( "+ $frequency $period", $calculate_from );
997
-
998
-		$this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
999
-		$this->set_status( 'active' );
1000
-		$this->save();
1001
-
1002
-		do_action( 'getpaid_subscription_renewed', $this );
1003
-
1004
-		return $this->get_id();
1005
-	}
1006
-
1007
-	/**
1008
-	 * Marks a subscription as completed
1009
-	 *
1010
-	 * Subscription is completed when the number of payments matches the billing_times field
1011
-	 *
1012
-	 * @since  1.0.0
1013
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
1014
-	 */
1015
-	public function complete() {
1016
-
1017
-		// Only mark a subscription as complete if it's not already cancelled.
1018
-		if ( $this->has_status( 'cancelled' ) ) {
1019
-			return false;
1020
-		}
1021
-
1022
-		$this->set_status( 'completed' );
1023
-		return $this->save();
1024
-
1025
-	}
1026
-
1027
-	/**
1028
-	 * Marks a subscription as expired
1029
-	 *
1030
-	 * @since  1.0.0
1031
-	 * @param  bool $check_expiration
1032
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1033
-	 */
1034
-	public function expire( $check_expiration = false ) {
1035
-
1036
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1037
-			// Do not mark as expired since real expiration date is in the future
1038
-			return false;
1039
-		}
1040
-
1041
-		$this->set_status( 'expired' );
1042
-		return $this->save();
1043
-
1044
-	}
1045
-
1046
-	/**
1047
-	 * Marks a subscription as failing
1048
-	 *
1049
-	 * @since  2.4.2
1050
-	 * @return int Subscription id.
1051
-	 */
1052
-	public function failing() {
1053
-		$this->set_status( 'failing' );
1054
-		return $this->save();
1055
-	}
932
+        $parent_invoice = $this->get_parent_payment();
933
+
934
+        if ( ! $parent_invoice->exists() ) {
935
+            return false;
936
+        }
937
+
938
+        // Duplicate the parent invoice.
939
+        $invoice = getpaid_duplicate_invoice( $parent_invoice );
940
+        $invoice->set_parent_id( $parent_invoice->get_id() );
941
+        $invoice->set_subscription_id( $this->get_id() );
942
+        $invoice->set_remote_subscription_id( $this->get_profile_id() );
943
+
944
+        // Set invoice items.
945
+        $subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
946
+        $allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
947
+        $invoice_items      = array();
948
+
949
+        foreach ( $invoice->get_items() as $item ) {
950
+            if ( in_array( $item->get_id(), $allowed_items ) ) {
951
+                $invoice_items[] = $item;
952
+            }
953
+        }
954
+
955
+        $invoice->set_items( $invoice_items );
956
+
957
+        if ( ! empty( $subscription_group['fees'] ) ) {
958
+            $invoice->set_fees( $subscription_group['fees'] );
959
+        }
960
+
961
+        // Maybe recalculate discount (Pre-GetPaid Fix).
962
+        $discount = new WPInv_Discount( $invoice->get_discount_code() );
963
+        if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
964
+            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
965
+        }
966
+
967
+        $invoice->recalculate_total();
968
+        $invoice->set_status( 'wpi-pending' );
969
+
970
+        if ( ! $save ) {
971
+            return $invoice;
972
+        }
973
+
974
+        $invoice->save();
975
+
976
+        return $invoice->exists() ? $invoice : false;
977
+    }
978
+
979
+    /**
980
+     * Renews or completes a subscription
981
+     *
982
+     * @since  1.0.0
983
+     * @return int The subscription's id
984
+     */
985
+    public function renew( $calculate_from = null ) {
986
+
987
+        // Complete subscription if applicable
988
+        if ( $this->is_last_renewal() ) {
989
+            return $this->complete();
990
+        }
991
+
992
+        // Calculate new expiration
993
+        $frequency      = $this->get_frequency();
994
+        $period         = $this->get_period();
995
+        $calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
996
+        $new_expiration = strtotime( "+ $frequency $period", $calculate_from );
997
+
998
+        $this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
999
+        $this->set_status( 'active' );
1000
+        $this->save();
1001
+
1002
+        do_action( 'getpaid_subscription_renewed', $this );
1003
+
1004
+        return $this->get_id();
1005
+    }
1006
+
1007
+    /**
1008
+     * Marks a subscription as completed
1009
+     *
1010
+     * Subscription is completed when the number of payments matches the billing_times field
1011
+     *
1012
+     * @since  1.0.0
1013
+     * @return int|bool Subscription id or false if the subscription is cancelled.
1014
+     */
1015
+    public function complete() {
1016
+
1017
+        // Only mark a subscription as complete if it's not already cancelled.
1018
+        if ( $this->has_status( 'cancelled' ) ) {
1019
+            return false;
1020
+        }
1021
+
1022
+        $this->set_status( 'completed' );
1023
+        return $this->save();
1024
+
1025
+    }
1026
+
1027
+    /**
1028
+     * Marks a subscription as expired
1029
+     *
1030
+     * @since  1.0.0
1031
+     * @param  bool $check_expiration
1032
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1033
+     */
1034
+    public function expire( $check_expiration = false ) {
1035
+
1036
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1037
+            // Do not mark as expired since real expiration date is in the future
1038
+            return false;
1039
+        }
1040
+
1041
+        $this->set_status( 'expired' );
1042
+        return $this->save();
1043
+
1044
+    }
1045
+
1046
+    /**
1047
+     * Marks a subscription as failing
1048
+     *
1049
+     * @since  2.4.2
1050
+     * @return int Subscription id.
1051
+     */
1052
+    public function failing() {
1053
+        $this->set_status( 'failing' );
1054
+        return $this->save();
1055
+    }
1056 1056
 
1057 1057
     /**
1058 1058
      * Marks a subscription as cancelled
@@ -1061,19 +1061,19 @@  discard block
 block discarded – undo
1061 1061
      * @return int Subscription id.
1062 1062
      */
1063 1063
     public function cancel() {
1064
-		$this->set_status( 'cancelled' );
1065
-		return $this->save();
1064
+        $this->set_status( 'cancelled' );
1065
+        return $this->save();
1066 1066
     }
1067 1067
 
1068
-	/**
1069
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1070
-	 *
1071
-	 * @since  1.0.0
1072
-	 * @return bool
1073
-	 */
1074
-	public function can_cancel() {
1075
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1076
-	}
1068
+    /**
1069
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1070
+     *
1071
+     * @since  1.0.0
1072
+     * @return bool
1073
+     */
1074
+    public function can_cancel() {
1075
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1076
+    }
1077 1077
 
1078 1078
     /**
1079 1079
      * Returns an array of subscription statuses that can be cancelled
@@ -1086,109 +1086,109 @@  discard block
 block discarded – undo
1086 1086
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1087 1087
     }
1088 1088
 
1089
-	/**
1090
-	 * Retrieves the URL to cancel subscription
1091
-	 *
1092
-	 * @since  1.0.0
1093
-	 * @return string
1094
-	 */
1095
-	public function get_cancel_url() {
1096
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1097
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1098
-	}
1099
-
1100
-	/**
1101
-	 * Retrieves the URL to view a subscription
1102
-	 *
1103
-	 * @since  1.0.19
1104
-	 * @return string
1105
-	 */
1106
-	public function get_view_url() {
1107
-
1108
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1109
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1110
-
1111
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1112
-	}
1113
-
1114
-	/**
1115
-	 * Determines if subscription can be manually renewed
1116
-	 *
1117
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1118
-	 * that can be renewed manually
1119
-	 *
1120
-	 * @since  2.5
1121
-	 * @return bool
1122
-	 */
1123
-	public function can_renew() {
1124
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1125
-	}
1126
-
1127
-	/**
1128
-	 * Retrieves the URL to renew a subscription
1129
-	 *
1130
-	 * @since  2.5
1131
-	 * @return string
1132
-	 */
1133
-	public function get_renew_url() {
1134
-		$url = wp_nonce_url(
1089
+    /**
1090
+     * Retrieves the URL to cancel subscription
1091
+     *
1092
+     * @since  1.0.0
1093
+     * @return string
1094
+     */
1095
+    public function get_cancel_url() {
1096
+        $url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1097
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1098
+    }
1099
+
1100
+    /**
1101
+     * Retrieves the URL to view a subscription
1102
+     *
1103
+     * @since  1.0.19
1104
+     * @return string
1105
+     */
1106
+    public function get_view_url() {
1107
+
1108
+        $url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1109
+        $url = add_query_arg( 'subscription', $this->get_id(), $url );
1110
+
1111
+        return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1112
+    }
1113
+
1114
+    /**
1115
+     * Determines if subscription can be manually renewed
1116
+     *
1117
+     * This method is filtered by payment gateways in order to return true on subscriptions
1118
+     * that can be renewed manually
1119
+     *
1120
+     * @since  2.5
1121
+     * @return bool
1122
+     */
1123
+    public function can_renew() {
1124
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1125
+    }
1126
+
1127
+    /**
1128
+     * Retrieves the URL to renew a subscription
1129
+     *
1130
+     * @since  2.5
1131
+     * @return string
1132
+     */
1133
+    public function get_renew_url() {
1134
+        $url = wp_nonce_url(
1135 1135
             add_query_arg(
1136 1136
                 array(
1137
-					'getpaid-action' => 'renew_subscription',
1138
-					'sub_id'         => $this->get_id,
1137
+                    'getpaid-action' => 'renew_subscription',
1138
+                    'sub_id'         => $this->get_id,
1139 1139
                 )
1140 1140
             ),
1141 1141
             'getpaid-nonce'
1142 1142
         );
1143
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1144
-	}
1145
-
1146
-	/**
1147
-	 * Determines if subscription can have their payment method updated
1148
-	 *
1149
-	 * @since  1.0.0
1150
-	 * @return bool
1151
-	 */
1152
-	public function can_update() {
1153
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1154
-	}
1155
-
1156
-	/**
1157
-	 * Retrieves the URL to update subscription
1158
-	 *
1159
-	 * @since  1.0.0
1160
-	 * @return string
1161
-	 */
1162
-	public function get_update_url() {
1163
-		$url = add_query_arg(
1143
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1144
+    }
1145
+
1146
+    /**
1147
+     * Determines if subscription can have their payment method updated
1148
+     *
1149
+     * @since  1.0.0
1150
+     * @return bool
1151
+     */
1152
+    public function can_update() {
1153
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1154
+    }
1155
+
1156
+    /**
1157
+     * Retrieves the URL to update subscription
1158
+     *
1159
+     * @since  1.0.0
1160
+     * @return string
1161
+     */
1162
+    public function get_update_url() {
1163
+        $url = add_query_arg(
1164 1164
             array(
1165
-				'action'          => 'update',
1166
-				'subscription_id' => $this->get_id(),
1165
+                'action'          => 'update',
1166
+                'subscription_id' => $this->get_id(),
1167 1167
             )
1168 1168
         );
1169
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1170
-	}
1171
-
1172
-	/**
1173
-	 * Retrieves the subscription status label
1174
-	 *
1175
-	 * @since  1.0.0
1176
-	 * @return string
1177
-	 */
1178
-	public function get_status_label() {
1179
-		return getpaid_get_subscription_status_label( $this->get_status() );
1180
-	}
1181
-
1182
-	/**
1183
-	 * Retrieves the subscription status class
1184
-	 *
1185
-	 * @since  1.0.19
1186
-	 * @return string
1187
-	 */
1188
-	public function get_status_class() {
1189
-		$statuses = getpaid_get_subscription_status_classes();
1190
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark';
1191
-	}
1169
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1170
+    }
1171
+
1172
+    /**
1173
+     * Retrieves the subscription status label
1174
+     *
1175
+     * @since  1.0.0
1176
+     * @return string
1177
+     */
1178
+    public function get_status_label() {
1179
+        return getpaid_get_subscription_status_label( $this->get_status() );
1180
+    }
1181
+
1182
+    /**
1183
+     * Retrieves the subscription status class
1184
+     *
1185
+     * @since  1.0.19
1186
+     * @return string
1187
+     */
1188
+    public function get_status_class() {
1189
+        $statuses = getpaid_get_subscription_status_classes();
1190
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark';
1191
+    }
1192 1192
 
1193 1193
     /**
1194 1194
      * Retrieves the subscription status label
@@ -1198,11 +1198,11 @@  discard block
 block discarded – undo
1198 1198
      */
1199 1199
     public function get_status_label_html() {
1200 1200
 
1201
-		$status_label = sanitize_text_field( $this->get_status_label() );
1202
-		$class        = esc_attr( $this->get_status_class() );
1203
-		$status       = sanitize_html_class( $this->get_status() );
1201
+        $status_label = sanitize_text_field( $this->get_status_label() );
1202
+        $class        = esc_attr( $this->get_status_class() );
1203
+        $status       = sanitize_html_class( $this->get_status() );
1204 1204
 
1205
-		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1205
+        return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1206 1206
     }
1207 1207
 
1208 1208
     /**
@@ -1213,75 +1213,75 @@  discard block
 block discarded – undo
1213 1213
      * @return bool
1214 1214
      */
1215 1215
     public function payment_exists( $txn_id = '' ) {
1216
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1216
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1217 1217
         return ! empty( $invoice_id );
1218
-	}
1219
-
1220
-	/**
1221
-	 * Handle the status transition.
1222
-	 */
1223
-	protected function status_transition() {
1224
-		$status_transition = $this->status_transition;
1225
-
1226
-		// Reset status transition variable.
1227
-		$this->status_transition = false;
1228
-
1229
-		if ( $status_transition ) {
1230
-			try {
1231
-
1232
-				// Fire a hook for the status change.
1233
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1234
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1235
-
1236
-				if ( ! empty( $status_transition['from'] ) ) {
1237
-
1238
-					/* translators: 1: old subscription status 2: new subscription status */
1239
-					$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'] ) );
1240
-
1241
-					// Note the transition occurred.
1242
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1243
-
1244
-					// Fire another hook.
1245
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1246
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1247
-
1248
-				} else {
1249
-					/* translators: %s: new invoice status */
1250
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1251
-
1252
-					// Note the transition occurred.
1253
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1254
-
1255
-				}
1256
-			} catch ( Exception $e ) {
1257
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1258
-			}
1259
-		}
1260
-
1261
-	}
1262
-
1263
-	/**
1264
-	 * Save data to the database.
1265
-	 *
1266
-	 * @since 1.0.19
1267
-	 * @return int subscription ID
1268
-	 */
1269
-	public function save() {
1270
-		parent::save();
1271
-		$this->status_transition();
1272
-		return $this->get_id();
1273
-	}
1274
-
1275
-	/**
1276
-	 * Activates a subscription.
1277
-	 *
1278
-	 * @since 1.0.19
1279
-	 * @return int subscription ID
1280
-	 */
1281
-	public function activate() {
1282
-		$status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active';
1283
-		$this->set_status( $status );
1284
-		return $this->save();
1285
-	}
1218
+    }
1219
+
1220
+    /**
1221
+     * Handle the status transition.
1222
+     */
1223
+    protected function status_transition() {
1224
+        $status_transition = $this->status_transition;
1225
+
1226
+        // Reset status transition variable.
1227
+        $this->status_transition = false;
1228
+
1229
+        if ( $status_transition ) {
1230
+            try {
1231
+
1232
+                // Fire a hook for the status change.
1233
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1234
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1235
+
1236
+                if ( ! empty( $status_transition['from'] ) ) {
1237
+
1238
+                    /* translators: 1: old subscription status 2: new subscription status */
1239
+                    $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'] ) );
1240
+
1241
+                    // Note the transition occurred.
1242
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1243
+
1244
+                    // Fire another hook.
1245
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1246
+                    do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1247
+
1248
+                } else {
1249
+                    /* translators: %s: new invoice status */
1250
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1251
+
1252
+                    // Note the transition occurred.
1253
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1254
+
1255
+                }
1256
+            } catch ( Exception $e ) {
1257
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1258
+            }
1259
+        }
1260
+
1261
+    }
1262
+
1263
+    /**
1264
+     * Save data to the database.
1265
+     *
1266
+     * @since 1.0.19
1267
+     * @return int subscription ID
1268
+     */
1269
+    public function save() {
1270
+        parent::save();
1271
+        $this->status_transition();
1272
+        return $this->get_id();
1273
+    }
1274
+
1275
+    /**
1276
+     * Activates a subscription.
1277
+     *
1278
+     * @since 1.0.19
1279
+     * @return int subscription ID
1280
+     */
1281
+    public function activate() {
1282
+        $status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active';
1283
+        $this->set_status( $status );
1284
+        return $this->save();
1285
+    }
1286 1286
 
1287 1287
 }
Please login to merge, or discard this patch.
Spacing   +234 added lines, -234 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
 	}
@@ -162,9 +162,9 @@  discard block
 block discarded – undo
162 162
 			'getpaid_subscriptions'                                       => $this->get_id(),
163 163
 		);
164 164
 
165
-		foreach ( $caches as $cache => $value ) {
166
-			if ( '' !== $value && false !== $value ) {
167
-				wp_cache_delete( $value, $cache );
165
+		foreach ($caches as $cache => $value) {
166
+			if ('' !== $value && false !== $value) {
167
+				wp_cache_delete($value, $cache);
168 168
 			}
169 169
 		}
170 170
 	}
@@ -172,8 +172,8 @@  discard block
 block discarded – undo
172 172
 	/**
173 173
      * Checks if a subscription key is set.
174 174
      */
175
-    public function _isset( $key ) {
176
-        return isset( $this->data[ $key ] ) || method_exists( $this, "get_$key" );
175
+    public function _isset($key) {
176
+        return isset($this->data[$key]) || method_exists($this, "get_$key");
177 177
 	}
178 178
 
179 179
 	/*
@@ -198,8 +198,8 @@  discard block
 block discarded – undo
198 198
 	 * @param  string $context View or edit context.
199 199
 	 * @return int
200 200
 	 */
201
-	public function get_customer_id( $context = 'view' ) {
202
-		return (int) $this->get_prop( 'customer_id', $context );
201
+	public function get_customer_id($context = 'view') {
202
+		return (int) $this->get_prop('customer_id', $context);
203 203
 	}
204 204
 
205 205
 	/**
@@ -209,8 +209,8 @@  discard block
 block discarded – undo
209 209
 	 * @param  string $context View or edit context.
210 210
 	 * @return WP_User|false WP_User object on success, false on failure.
211 211
 	 */
212
-	public function get_customer( $context = 'view' ) {
213
-		return get_userdata( $this->get_customer_id( $context ) );
212
+	public function get_customer($context = 'view') {
213
+		return get_userdata($this->get_customer_id($context));
214 214
 	}
215 215
 
216 216
 	/**
@@ -220,8 +220,8 @@  discard block
 block discarded – undo
220 220
 	 * @param  string $context View or edit context.
221 221
 	 * @return int
222 222
 	 */
223
-	public function get_parent_invoice_id( $context = 'view' ) {
224
-		return (int) $this->get_prop( 'parent_payment_id', $context );
223
+	public function get_parent_invoice_id($context = 'view') {
224
+		return (int) $this->get_prop('parent_payment_id', $context);
225 225
 	}
226 226
 
227 227
 	/**
@@ -231,8 +231,8 @@  discard block
 block discarded – undo
231 231
 	 * @param  string $context View or edit context.
232 232
 	 * @return int
233 233
 	 */
234
-    public function get_parent_payment_id( $context = 'view' ) {
235
-        return $this->get_parent_invoice_id( $context );
234
+    public function get_parent_payment_id($context = 'view') {
235
+        return $this->get_parent_invoice_id($context);
236 236
 	}
237 237
 
238 238
 	/**
@@ -241,8 +241,8 @@  discard block
 block discarded – undo
241 241
      * @since  1.0.0
242 242
      * @return int
243 243
      */
244
-    public function get_original_payment_id( $context = 'view' ) {
245
-        return $this->get_parent_invoice_id( $context );
244
+    public function get_original_payment_id($context = 'view') {
245
+        return $this->get_parent_invoice_id($context);
246 246
     }
247 247
 
248 248
 	/**
@@ -252,8 +252,8 @@  discard block
 block discarded – undo
252 252
 	 * @param  string $context View or edit context.
253 253
 	 * @return WPInv_Invoice
254 254
 	 */
255
-	public function get_parent_invoice( $context = 'view' ) {
256
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
255
+	public function get_parent_invoice($context = 'view') {
256
+		return new WPInv_Invoice($this->get_parent_invoice_id($context));
257 257
 	}
258 258
 
259 259
 	/**
@@ -263,8 +263,8 @@  discard block
 block discarded – undo
263 263
 	 * @param  string $context View or edit context.
264 264
 	 * @return WPInv_Invoice
265 265
 	 */
266
-    public function get_parent_payment( $context = 'view' ) {
267
-        return $this->get_parent_invoice( $context );
266
+    public function get_parent_payment($context = 'view') {
267
+        return $this->get_parent_invoice($context);
268 268
 	}
269 269
 
270 270
 	/**
@@ -274,8 +274,8 @@  discard block
 block discarded – undo
274 274
 	 * @param  string $context View or edit context.
275 275
 	 * @return int
276 276
 	 */
277
-	public function get_product_id( $context = 'view' ) {
278
-		return (int) $this->get_prop( 'product_id', $context );
277
+	public function get_product_id($context = 'view') {
278
+		return (int) $this->get_prop('product_id', $context);
279 279
 	}
280 280
 
281 281
 	/**
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 	 * @param  string $context View or edit context.
286 286
 	 * @return WPInv_Item
287 287
 	 */
288
-	public function get_product( $context = 'view' ) {
289
-		return new WPInv_Item( $this->get_product_id( $context ) );
288
+	public function get_product($context = 'view') {
289
+		return new WPInv_Item($this->get_product_id($context));
290 290
 	}
291 291
 
292 292
 	/**
@@ -298,8 +298,8 @@  discard block
 block discarded – undo
298 298
 	 * @param  string $context View or edit context.
299 299
 	 * @return string
300 300
 	 */
301
-	public function get_gateway( $context = 'view' ) {
302
-		return $this->get_parent_invoice( $context )->get_gateway();
301
+	public function get_gateway($context = 'view') {
302
+		return $this->get_parent_invoice($context)->get_gateway();
303 303
 	}
304 304
 
305 305
 	/**
@@ -309,8 +309,8 @@  discard block
 block discarded – undo
309 309
 	 * @param  string $context View or edit context.
310 310
 	 * @return string
311 311
 	 */
312
-	public function get_period( $context = 'view' ) {
313
-		return $this->get_prop( 'period', $context );
312
+	public function get_period($context = 'view') {
313
+		return $this->get_prop('period', $context);
314 314
 	}
315 315
 
316 316
 	/**
@@ -320,8 +320,8 @@  discard block
 block discarded – undo
320 320
 	 * @param  string $context View or edit context.
321 321
 	 * @return int
322 322
 	 */
323
-	public function get_frequency( $context = 'view' ) {
324
-		return (int) $this->get_prop( 'frequency', $context );
323
+	public function get_frequency($context = 'view') {
324
+		return (int) $this->get_prop('frequency', $context);
325 325
 	}
326 326
 
327 327
 	/**
@@ -331,8 +331,8 @@  discard block
 block discarded – undo
331 331
 	 * @param  string $context View or edit context.
332 332
 	 * @return float
333 333
 	 */
334
-	public function get_initial_amount( $context = 'view' ) {
335
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
334
+	public function get_initial_amount($context = 'view') {
335
+		return (float) wpinv_sanitize_amount($this->get_prop('initial_amount', $context));
336 336
 	}
337 337
 
338 338
 	/**
@@ -342,8 +342,8 @@  discard block
 block discarded – undo
342 342
 	 * @param  string $context View or edit context.
343 343
 	 * @return float
344 344
 	 */
345
-	public function get_recurring_amount( $context = 'view' ) {
346
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
345
+	public function get_recurring_amount($context = 'view') {
346
+		return (float) wpinv_sanitize_amount($this->get_prop('recurring_amount', $context));
347 347
 	}
348 348
 
349 349
 	/**
@@ -353,8 +353,8 @@  discard block
 block discarded – undo
353 353
 	 * @param  string $context View or edit context.
354 354
 	 * @return int
355 355
 	 */
356
-	public function get_bill_times( $context = 'view' ) {
357
-		return (int) $this->get_prop( 'bill_times', $context );
356
+	public function get_bill_times($context = 'view') {
357
+		return (int) $this->get_prop('bill_times', $context);
358 358
 	}
359 359
 
360 360
 	/**
@@ -364,8 +364,8 @@  discard block
 block discarded – undo
364 364
 	 * @param  string $context View or edit context.
365 365
 	 * @return string
366 366
 	 */
367
-	public function get_transaction_id( $context = 'view' ) {
368
-		return $this->get_prop( 'transaction_id', $context );
367
+	public function get_transaction_id($context = 'view') {
368
+		return $this->get_prop('transaction_id', $context);
369 369
 	}
370 370
 
371 371
 	/**
@@ -375,8 +375,8 @@  discard block
 block discarded – undo
375 375
 	 * @param  string $context View or edit context.
376 376
 	 * @return string
377 377
 	 */
378
-	public function get_created( $context = 'view' ) {
379
-		return $this->get_prop( 'created', $context );
378
+	public function get_created($context = 'view') {
379
+		return $this->get_prop('created', $context);
380 380
 	}
381 381
 
382 382
 	/**
@@ -386,8 +386,8 @@  discard block
 block discarded – undo
386 386
 	 * @param  string $context View or edit context.
387 387
 	 * @return string
388 388
 	 */
389
-	public function get_date_created( $context = 'view' ) {
390
-		return $this->get_created( $context );
389
+	public function get_date_created($context = 'view') {
390
+		return $this->get_created($context);
391 391
 	}
392 392
 
393 393
 	/**
@@ -398,7 +398,7 @@  discard block
 block discarded – undo
398 398
 	 */
399 399
 	public function get_time_created() {
400 400
 		$created = $this->get_date_created();
401
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
401
+		return empty($created) ? current_time('timestamp') : strtotime($created, current_time('timestamp'));
402 402
 	}
403 403
 
404 404
 	/**
@@ -408,11 +408,11 @@  discard block
 block discarded – undo
408 408
 	 * @param  string $context View or edit context.
409 409
 	 * @return string
410 410
 	 */
411
-	public function get_date_created_gmt( $context = 'view' ) {
412
-        $date = $this->get_date_created( $context );
411
+	public function get_date_created_gmt($context = 'view') {
412
+        $date = $this->get_date_created($context);
413 413
 
414
-        if ( $date ) {
415
-            $date = get_gmt_from_date( $date );
414
+        if ($date) {
415
+            $date = get_gmt_from_date($date);
416 416
         }
417 417
 		return $date;
418 418
 	}
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
 	 * @param  string $context View or edit context.
425 425
 	 * @return string
426 426
 	 */
427
-	public function get_next_renewal_date( $context = 'view' ) {
428
-		return $this->get_prop( 'expiration', $context );
427
+	public function get_next_renewal_date($context = 'view') {
428
+		return $this->get_prop('expiration', $context);
429 429
 	}
430 430
 
431 431
 	/**
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 	 * @param  string $context View or edit context.
436 436
 	 * @return string
437 437
 	 */
438
-	public function get_expiration( $context = 'view' ) {
439
-		return $this->get_next_renewal_date( $context );
438
+	public function get_expiration($context = 'view') {
439
+		return $this->get_next_renewal_date($context);
440 440
 	}
441 441
 
442 442
 	/**
@@ -448,12 +448,12 @@  discard block
 block discarded – undo
448 448
 	public function get_expiration_time() {
449 449
 		$expiration = $this->get_expiration();
450 450
 
451
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
452
-			return current_time( 'timestamp' );
451
+		if (empty($expiration) || '0000-00-00 00:00:00' == $expiration) {
452
+			return current_time('timestamp');
453 453
 		}
454 454
 
455
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
456
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
455
+		$expiration = strtotime($expiration, current_time('timestamp'));
456
+		return $expiration < current_time('timestamp') ? current_time('timestamp') : $expiration;
457 457
 	}
458 458
 
459 459
 	/**
@@ -463,11 +463,11 @@  discard block
 block discarded – undo
463 463
 	 * @param  string $context View or edit context.
464 464
 	 * @return string
465 465
 	 */
466
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
467
-        $date = $this->get_next_renewal_date( $context );
466
+	public function get_next_renewal_date_gmt($context = 'view') {
467
+        $date = $this->get_next_renewal_date($context);
468 468
 
469
-        if ( $date ) {
470
-            $date = get_gmt_from_date( $date );
469
+        if ($date) {
470
+            $date = get_gmt_from_date($date);
471 471
         }
472 472
 		return $date;
473 473
 	}
@@ -479,8 +479,8 @@  discard block
 block discarded – undo
479 479
 	 * @param  string $context View or edit context.
480 480
 	 * @return string
481 481
 	 */
482
-	public function get_trial_period( $context = 'view' ) {
483
-		return $this->get_prop( 'trial_period', $context );
482
+	public function get_trial_period($context = 'view') {
483
+		return $this->get_prop('trial_period', $context);
484 484
 	}
485 485
 
486 486
 	/**
@@ -490,8 +490,8 @@  discard block
 block discarded – undo
490 490
 	 * @param  string $context View or edit context.
491 491
 	 * @return string
492 492
 	 */
493
-	public function get_status( $context = 'view' ) {
494
-		return $this->get_prop( 'status', $context );
493
+	public function get_status($context = 'view') {
494
+		return $this->get_prop('status', $context);
495 495
 	}
496 496
 
497 497
 	/**
@@ -501,8 +501,8 @@  discard block
 block discarded – undo
501 501
 	 * @param  string $context View or edit context.
502 502
 	 * @return string
503 503
 	 */
504
-	public function get_profile_id( $context = 'view' ) {
505
-		return $this->get_prop( 'profile_id', $context );
504
+	public function get_profile_id($context = 'view') {
505
+		return $this->get_prop('profile_id', $context);
506 506
 	}
507 507
 
508 508
 	/*
@@ -517,8 +517,8 @@  discard block
 block discarded – undo
517 517
 	 * @since 1.0.19
518 518
 	 * @param  int $value The customer's id.
519 519
 	 */
520
-	public function set_customer_id( $value ) {
521
-		$this->set_prop( 'customer_id', (int) $value );
520
+	public function set_customer_id($value) {
521
+		$this->set_prop('customer_id', (int) $value);
522 522
 	}
523 523
 
524 524
 	/**
@@ -527,8 +527,8 @@  discard block
 block discarded – undo
527 527
 	 * @since 1.0.19
528 528
 	 * @param  int $value The parent invoice id.
529 529
 	 */
530
-	public function set_parent_invoice_id( $value ) {
531
-		$this->set_prop( 'parent_payment_id', (int) $value );
530
+	public function set_parent_invoice_id($value) {
531
+		$this->set_prop('parent_payment_id', (int) $value);
532 532
 	}
533 533
 
534 534
 	/**
@@ -537,8 +537,8 @@  discard block
 block discarded – undo
537 537
 	 * @since 1.0.19
538 538
 	 * @param  int $value The parent invoice id.
539 539
 	 */
540
-    public function set_parent_payment_id( $value ) {
541
-        $this->set_parent_invoice_id( $value );
540
+    public function set_parent_payment_id($value) {
541
+        $this->set_parent_invoice_id($value);
542 542
 	}
543 543
 
544 544
 	/**
@@ -547,8 +547,8 @@  discard block
 block discarded – undo
547 547
      * @since 1.0.19
548 548
 	 * @param  int $value The parent invoice id.
549 549
      */
550
-    public function set_original_payment_id( $value ) {
551
-        $this->set_parent_invoice_id( $value );
550
+    public function set_original_payment_id($value) {
551
+        $this->set_parent_invoice_id($value);
552 552
 	}
553 553
 
554 554
 	/**
@@ -557,8 +557,8 @@  discard block
 block discarded – undo
557 557
 	 * @since 1.0.19
558 558
 	 * @param  int $value The subscription product id.
559 559
 	 */
560
-	public function set_product_id( $value ) {
561
-		$this->set_prop( 'product_id', (int) $value );
560
+	public function set_product_id($value) {
561
+		$this->set_prop('product_id', (int) $value);
562 562
 	}
563 563
 
564 564
 	/**
@@ -567,8 +567,8 @@  discard block
 block discarded – undo
567 567
 	 * @since 1.0.19
568 568
 	 * @param  string $value The renewal period.
569 569
 	 */
570
-	public function set_period( $value ) {
571
-		$this->set_prop( 'period', $value );
570
+	public function set_period($value) {
571
+		$this->set_prop('period', $value);
572 572
 	}
573 573
 
574 574
 	/**
@@ -577,9 +577,9 @@  discard block
 block discarded – undo
577 577
 	 * @since 1.0.19
578 578
 	 * @param  int $value The subscription frequency.
579 579
 	 */
580
-	public function set_frequency( $value ) {
581
-		$value = empty( $value ) ? 1 : (int) $value;
582
-		$this->set_prop( 'frequency', absint( $value ) );
580
+	public function set_frequency($value) {
581
+		$value = empty($value) ? 1 : (int) $value;
582
+		$this->set_prop('frequency', absint($value));
583 583
 	}
584 584
 
585 585
 	/**
@@ -588,8 +588,8 @@  discard block
 block discarded – undo
588 588
 	 * @since 1.0.19
589 589
 	 * @param  float $value The initial subcription amount.
590 590
 	 */
591
-	public function set_initial_amount( $value ) {
592
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
591
+	public function set_initial_amount($value) {
592
+		$this->set_prop('initial_amount', wpinv_sanitize_amount($value));
593 593
 	}
594 594
 
595 595
 	/**
@@ -598,8 +598,8 @@  discard block
 block discarded – undo
598 598
 	 * @since 1.0.19
599 599
 	 * @param  float $value The recurring subcription amount.
600 600
 	 */
601
-	public function set_recurring_amount( $value ) {
602
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
601
+	public function set_recurring_amount($value) {
602
+		$this->set_prop('recurring_amount', wpinv_sanitize_amount($value));
603 603
 	}
604 604
 
605 605
 	/**
@@ -608,8 +608,8 @@  discard block
 block discarded – undo
608 608
 	 * @since 1.0.19
609 609
 	 * @param  int $value Bill times.
610 610
 	 */
611
-	public function set_bill_times( $value ) {
612
-		$this->set_prop( 'bill_times', (int) $value );
611
+	public function set_bill_times($value) {
612
+		$this->set_prop('bill_times', (int) $value);
613 613
 	}
614 614
 
615 615
 	/**
@@ -618,8 +618,8 @@  discard block
 block discarded – undo
618 618
 	 * @since 1.0.19
619 619
 	 * @param string $value Bill times.
620 620
 	 */
621
-	public function set_transaction_id( $value ) {
622
-		$this->set_prop( 'transaction_id', sanitize_text_field( $value ) );
621
+	public function set_transaction_id($value) {
622
+		$this->set_prop('transaction_id', sanitize_text_field($value));
623 623
 	}
624 624
 
625 625
 	/**
@@ -628,15 +628,15 @@  discard block
 block discarded – undo
628 628
 	 * @since 1.0.19
629 629
 	 * @param string $value strtotime compliant date.
630 630
 	 */
631
-	public function set_created( $value ) {
632
-        $date = strtotime( $value );
631
+	public function set_created($value) {
632
+        $date = strtotime($value);
633 633
 
634
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
635
-            $this->set_prop( 'created', gmdate( 'Y-m-d H:i:s', $date ) );
634
+        if ($date && $value !== '0000-00-00 00:00:00') {
635
+            $this->set_prop('created', gmdate('Y-m-d H:i:s', $date));
636 636
             return;
637 637
         }
638 638
 
639
-		$this->set_prop( 'created', '' );
639
+		$this->set_prop('created', '');
640 640
 
641 641
 	}
642 642
 
@@ -646,8 +646,8 @@  discard block
 block discarded – undo
646 646
 	 * @since 1.0.19
647 647
 	 * @param string $value strtotime compliant date.
648 648
 	 */
649
-	public function set_date_created( $value ) {
650
-		$this->set_created( $value );
649
+	public function set_date_created($value) {
650
+		$this->set_created($value);
651 651
     }
652 652
 
653 653
 	/**
@@ -656,15 +656,15 @@  discard block
 block discarded – undo
656 656
 	 * @since 1.0.19
657 657
 	 * @param string $value strtotime compliant date.
658 658
 	 */
659
-	public function set_next_renewal_date( $value ) {
660
-		$date = strtotime( $value );
659
+	public function set_next_renewal_date($value) {
660
+		$date = strtotime($value);
661 661
 
662
-        if ( $date && $value !== '0000-00-00 00:00:00' ) {
663
-            $this->set_prop( 'expiration', gmdate( 'Y-m-d H:i:s', $date ) );
662
+        if ($date && $value !== '0000-00-00 00:00:00') {
663
+            $this->set_prop('expiration', gmdate('Y-m-d H:i:s', $date));
664 664
             return;
665 665
 		}
666 666
 
667
-		$this->set_prop( 'expiration', '' );
667
+		$this->set_prop('expiration', '');
668 668
 
669 669
 	}
670 670
 
@@ -674,8 +674,8 @@  discard block
 block discarded – undo
674 674
 	 * @since 1.0.19
675 675
 	 * @param string $value strtotime compliant date.
676 676
 	 */
677
-	public function set_expiration( $value ) {
678
-		$this->set_next_renewal_date( $value );
677
+	public function set_expiration($value) {
678
+		$this->set_next_renewal_date($value);
679 679
     }
680 680
 
681 681
 	/**
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
 	 * @since 1.0.19
685 685
 	 * @param string $value trial period e.g 1 year.
686 686
 	 */
687
-	public function set_trial_period( $value ) {
688
-		$this->set_prop( 'trial_period', $value );
687
+	public function set_trial_period($value) {
688
+		$this->set_prop('trial_period', $value);
689 689
 	}
690 690
 
691 691
 	/**
@@ -694,22 +694,22 @@  discard block
 block discarded – undo
694 694
 	 * @since 1.0.19
695 695
 	 * @param string $new_status    New subscription status.
696 696
 	 */
697
-	public function set_status( $new_status ) {
697
+	public function set_status($new_status) {
698 698
 
699 699
 		// Abort if this is not a valid status;
700
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
700
+		if (!array_key_exists($new_status, getpaid_get_subscription_statuses())) {
701 701
 			return;
702 702
 		}
703 703
 
704
-		$old_status = ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $this->get_status();
705
-		if ( true === $this->object_read && $old_status !== $new_status ) {
704
+		$old_status = !empty($this->status_transition['from']) ? $this->status_transition['from'] : $this->get_status();
705
+		if (true === $this->object_read && $old_status !== $new_status) {
706 706
 			$this->status_transition = array(
707 707
 				'from' => $old_status,
708 708
 				'to'   => $new_status,
709 709
 			);
710 710
 		}
711 711
 
712
-		$this->set_prop( 'status', $new_status );
712
+		$this->set_prop('status', $new_status);
713 713
 	}
714 714
 
715 715
 	/**
@@ -718,8 +718,8 @@  discard block
 block discarded – undo
718 718
 	 * @since 1.0.19
719 719
 	 * @param  string $value the remote profile id.
720 720
 	 */
721
-	public function set_profile_id( $value ) {
722
-		$this->set_prop( 'profile_id', sanitize_text_field( $value ) );
721
+	public function set_profile_id($value) {
722
+		$this->set_prop('profile_id', sanitize_text_field($value));
723 723
 	}
724 724
 
725 725
 	/*
@@ -737,8 +737,8 @@  discard block
 block discarded – undo
737 737
 	 * @param string|array String or array of strings to check for.
738 738
 	 * @return bool
739 739
      */
740
-    public function has_status( $status ) {
741
-        return in_array( $this->get_status(), wpinv_clean( wpinv_parse_list( $status ) ) );
740
+    public function has_status($status) {
741
+        return in_array($this->get_status(), wpinv_clean(wpinv_parse_list($status)));
742 742
 	}
743 743
 
744 744
 	/**
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
      */
749 749
     public function has_trial_period() {
750 750
 		$period = $this->get_trial_period();
751
-        return ! empty( $period );
751
+        return !empty($period);
752 752
 	}
753 753
 
754 754
 	/**
@@ -757,7 +757,7 @@  discard block
 block discarded – undo
757 757
 	 * @return bool
758 758
 	 */
759 759
 	public function is_active() {
760
-		return $this->has_status( 'active trialling' ) && ! $this->is_expired();
760
+		return $this->has_status('active trialling') && !$this->is_expired();
761 761
 	}
762 762
 
763 763
 	/**
@@ -766,7 +766,7 @@  discard block
 block discarded – undo
766 766
 	 * @return bool
767 767
 	 */
768 768
 	public function is_expired() {
769
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'timestamp' ) );
769
+		return $this->has_status('expired') || ($this->has_status('active cancelled trialling') && $this->get_expiration_time() < current_time('timestamp'));
770 770
 	}
771 771
 
772 772
 	/**
@@ -776,7 +776,7 @@  discard block
 block discarded – undo
776 776
 	 */
777 777
 	public function is_last_renewal() {
778 778
 		$max_bills = $this->get_bill_times();
779
-		return ! empty( $max_bills ) && $max_bills <= $this->get_times_billed();
779
+		return !empty($max_bills) && $max_bills <= $this->get_times_billed();
780 780
 	}
781 781
 
782 782
 	/*
@@ -791,11 +791,11 @@  discard block
 block discarded – undo
791 791
 	/**
792 792
 	 * Backwards compatibilty.
793 793
 	 */
794
-	public function create( $data = array() ) {
794
+	public function create($data = array()) {
795 795
 
796 796
 		// Set the properties.
797
-		if ( is_array( $data ) ) {
798
-			$this->set_props( $data );
797
+		if (is_array($data)) {
798
+			$this->set_props($data);
799 799
 		}
800 800
 
801 801
 		// Save the item.
@@ -806,8 +806,8 @@  discard block
 block discarded – undo
806 806
 	/**
807 807
 	 * Backwards compatibilty.
808 808
 	 */
809
-	public function update( $args = array() ) {
810
-		return $this->create( $args );
809
+	public function update($args = array()) {
810
+		return $this->create($args);
811 811
 	}
812 812
 
813 813
     /**
@@ -816,12 +816,12 @@  discard block
 block discarded – undo
816 816
      * @since  1.0.0
817 817
      * @return WP_Post[]
818 818
      */
819
-    public function get_child_payments( $hide_pending = true ) {
819
+    public function get_child_payments($hide_pending = true) {
820 820
 
821
-		$statuses = array( 'publish', 'wpi-processing', 'wpi-renewal' );
821
+		$statuses = array('publish', 'wpi-processing', 'wpi-renewal');
822 822
 
823
-		if ( ! $hide_pending ) {
824
-			$statuses = array_keys( wpinv_get_invoice_statuses() );
823
+		if (!$hide_pending) {
824
+			$statuses = array_keys(wpinv_get_invoice_statuses());
825 825
 		}
826 826
 
827 827
         return get_posts(
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
      * @return int
844 844
      */
845 845
     public function get_total_payments() {
846
-		return getpaid_count_subscription_invoices( $this->get_parent_invoice_id(), $this->get_id() );
846
+		return getpaid_count_subscription_invoices($this->get_parent_invoice_id(), $this->get_id());
847 847
     }
848 848
 
849 849
     /**
@@ -855,7 +855,7 @@  discard block
 block discarded – undo
855 855
     public function get_times_billed() {
856 856
         $times_billed = $this->get_total_payments();
857 857
 
858
-        if ( (float) $this->get_initial_amount() == 0 && $times_billed > 0 ) {
858
+        if ((float) $this->get_initial_amount() == 0 && $times_billed > 0) {
859 859
             $times_billed--;
860 860
         }
861 861
 
@@ -870,52 +870,52 @@  discard block
 block discarded – undo
870 870
 	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
871 871
      * @return bool
872 872
      */
873
-    public function add_payment( $args = array(), $invoice = false ) {
873
+    public function add_payment($args = array(), $invoice = false) {
874 874
 
875 875
 		// Process each payment once.
876
-        if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
876
+        if (!empty($args['transaction_id']) && $this->payment_exists($args['transaction_id'])) {
877 877
             return false;
878 878
         }
879 879
 
880 880
 		// Are we creating a new invoice?
881
-		if ( empty( $invoice ) ) {
882
-			$invoice = $this->create_payment( false );
881
+		if (empty($invoice)) {
882
+			$invoice = $this->create_payment(false);
883 883
 
884
-			if ( empty( $invoice ) ) {
884
+			if (empty($invoice)) {
885 885
 				return false;
886 886
 			}
887 887
 		}
888 888
 
889 889
 		// Maybe set a transaction id.
890
-		if ( ! empty( $args['transaction_id'] ) ) {
891
-			$invoice->set_transaction_id( $args['transaction_id'] );
890
+		if (!empty($args['transaction_id'])) {
891
+			$invoice->set_transaction_id($args['transaction_id']);
892 892
 		}
893 893
 
894 894
 		// Set the completed date.
895
-		$invoice->set_completed_date( current_time( 'mysql' ) );
895
+		$invoice->set_completed_date(current_time('mysql'));
896 896
 
897 897
 		// And the gateway.
898
-		if ( ! empty( $args['gateway'] ) ) {
899
-			$invoice->set_gateway( $args['gateway'] );
898
+		if (!empty($args['gateway'])) {
899
+			$invoice->set_gateway($args['gateway']);
900 900
 		}
901 901
 
902
-		$invoice->set_status( 'wpi-renewal' );
902
+		$invoice->set_status('wpi-renewal');
903 903
 		$invoice->save();
904 904
 
905
-		if ( ! $invoice->exists() ) {
905
+		if (!$invoice->exists()) {
906 906
 			return false;
907 907
 		}
908 908
 
909
-		return $this->after_add_payment( $invoice );
909
+		return $this->after_add_payment($invoice);
910 910
 	}
911 911
 
912
-    public function after_add_payment( $invoice ) {
912
+    public function after_add_payment($invoice) {
913 913
 
914
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
915
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
916
-        do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
914
+		do_action('getpaid_after_create_subscription_renewal_invoice', $invoice, $this);
915
+		do_action('wpinv_recurring_add_subscription_payment', $invoice, $this);
916
+        do_action('wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id());
917 917
 
918
-        update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
918
+        update_post_meta($invoice->get_id(), '_wpinv_subscription_id', $this->id);
919 919
 
920 920
         return $invoice->get_id();
921 921
 	}
@@ -927,47 +927,47 @@  discard block
 block discarded – undo
927 927
 	 * @param bool $save Whether we should save the invoice.
928 928
      * @return WPInv_Invoice|bool
929 929
      */
930
-    public function create_payment( $save = true ) {
930
+    public function create_payment($save = true) {
931 931
 
932 932
 		$parent_invoice = $this->get_parent_payment();
933 933
 
934
-		if ( ! $parent_invoice->exists() ) {
934
+		if (!$parent_invoice->exists()) {
935 935
 			return false;
936 936
 		}
937 937
 
938 938
 		// Duplicate the parent invoice.
939
-		$invoice = getpaid_duplicate_invoice( $parent_invoice );
940
-		$invoice->set_parent_id( $parent_invoice->get_id() );
941
-		$invoice->set_subscription_id( $this->get_id() );
942
-		$invoice->set_remote_subscription_id( $this->get_profile_id() );
939
+		$invoice = getpaid_duplicate_invoice($parent_invoice);
940
+		$invoice->set_parent_id($parent_invoice->get_id());
941
+		$invoice->set_subscription_id($this->get_id());
942
+		$invoice->set_remote_subscription_id($this->get_profile_id());
943 943
 
944 944
 		// Set invoice items.
945
-		$subscription_group = getpaid_get_invoice_subscription_group( $parent_invoice->get_id(), $this->get_id() );
946
-		$allowed_items      = empty( $subscription_group ) ? array( $this->get_product_id() ) : array_keys( $subscription_group['items'] );
945
+		$subscription_group = getpaid_get_invoice_subscription_group($parent_invoice->get_id(), $this->get_id());
946
+		$allowed_items      = empty($subscription_group) ? array($this->get_product_id()) : array_keys($subscription_group['items']);
947 947
 		$invoice_items      = array();
948 948
 
949
-		foreach ( $invoice->get_items() as $item ) {
950
-			if ( in_array( $item->get_id(), $allowed_items ) ) {
949
+		foreach ($invoice->get_items() as $item) {
950
+			if (in_array($item->get_id(), $allowed_items)) {
951 951
 				$invoice_items[] = $item;
952 952
 			}
953 953
 		}
954 954
 
955
-		$invoice->set_items( $invoice_items );
955
+		$invoice->set_items($invoice_items);
956 956
 
957
-		if ( ! empty( $subscription_group['fees'] ) ) {
958
-			$invoice->set_fees( $subscription_group['fees'] );
957
+		if (!empty($subscription_group['fees'])) {
958
+			$invoice->set_fees($subscription_group['fees']);
959 959
 		}
960 960
 
961 961
 		// Maybe recalculate discount (Pre-GetPaid Fix).
962
-		$discount = new WPInv_Discount( $invoice->get_discount_code() );
963
-		if ( $discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount() ) {
964
-			$invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
962
+		$discount = new WPInv_Discount($invoice->get_discount_code());
963
+		if ($discount->exists() && $discount->is_recurring() && 0 == $invoice->get_total_discount()) {
964
+			$invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
965 965
 		}
966 966
 
967 967
 		$invoice->recalculate_total();
968
-		$invoice->set_status( 'wpi-pending' );
968
+		$invoice->set_status('wpi-pending');
969 969
 
970
-		if ( ! $save ) {
970
+		if (!$save) {
971 971
 			return $invoice;
972 972
 		}
973 973
 
@@ -982,24 +982,24 @@  discard block
 block discarded – undo
982 982
 	 * @since  1.0.0
983 983
 	 * @return int The subscription's id
984 984
 	 */
985
-	public function renew( $calculate_from = null ) {
985
+	public function renew($calculate_from = null) {
986 986
 
987 987
 		// Complete subscription if applicable
988
-		if ( $this->is_last_renewal() ) {
988
+		if ($this->is_last_renewal()) {
989 989
 			return $this->complete();
990 990
 		}
991 991
 
992 992
 		// Calculate new expiration
993 993
 		$frequency      = $this->get_frequency();
994 994
 		$period         = $this->get_period();
995
-		$calculate_from = empty( $calculate_from ) ? $this->get_expiration_time() : $calculate_from;
996
-		$new_expiration = strtotime( "+ $frequency $period", $calculate_from );
995
+		$calculate_from = empty($calculate_from) ? $this->get_expiration_time() : $calculate_from;
996
+		$new_expiration = strtotime("+ $frequency $period", $calculate_from);
997 997
 
998
-		$this->set_expiration( date( 'Y-m-d H:i:s', $new_expiration ) );
999
-		$this->set_status( 'active' );
998
+		$this->set_expiration(date('Y-m-d H:i:s', $new_expiration));
999
+		$this->set_status('active');
1000 1000
 		$this->save();
1001 1001
 
1002
-		do_action( 'getpaid_subscription_renewed', $this );
1002
+		do_action('getpaid_subscription_renewed', $this);
1003 1003
 
1004 1004
 		return $this->get_id();
1005 1005
 	}
@@ -1015,11 +1015,11 @@  discard block
 block discarded – undo
1015 1015
 	public function complete() {
1016 1016
 
1017 1017
 		// Only mark a subscription as complete if it's not already cancelled.
1018
-		if ( $this->has_status( 'cancelled' ) ) {
1018
+		if ($this->has_status('cancelled')) {
1019 1019
 			return false;
1020 1020
 		}
1021 1021
 
1022
-		$this->set_status( 'completed' );
1022
+		$this->set_status('completed');
1023 1023
 		return $this->save();
1024 1024
 
1025 1025
 	}
@@ -1031,14 +1031,14 @@  discard block
 block discarded – undo
1031 1031
 	 * @param  bool $check_expiration
1032 1032
 	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
1033 1033
 	 */
1034
-	public function expire( $check_expiration = false ) {
1034
+	public function expire($check_expiration = false) {
1035 1035
 
1036
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
1036
+		if ($check_expiration && $this->get_expiration_time() > current_time('timestamp')) {
1037 1037
 			// Do not mark as expired since real expiration date is in the future
1038 1038
 			return false;
1039 1039
 		}
1040 1040
 
1041
-		$this->set_status( 'expired' );
1041
+		$this->set_status('expired');
1042 1042
 		return $this->save();
1043 1043
 
1044 1044
 	}
@@ -1050,7 +1050,7 @@  discard block
 block discarded – undo
1050 1050
 	 * @return int Subscription id.
1051 1051
 	 */
1052 1052
 	public function failing() {
1053
-		$this->set_status( 'failing' );
1053
+		$this->set_status('failing');
1054 1054
 		return $this->save();
1055 1055
 	}
1056 1056
 
@@ -1061,7 +1061,7 @@  discard block
 block discarded – undo
1061 1061
      * @return int Subscription id.
1062 1062
      */
1063 1063
     public function cancel() {
1064
-		$this->set_status( 'cancelled' );
1064
+		$this->set_status('cancelled');
1065 1065
 		return $this->save();
1066 1066
     }
1067 1067
 
@@ -1072,7 +1072,7 @@  discard block
 block discarded – undo
1072 1072
 	 * @return bool
1073 1073
 	 */
1074 1074
 	public function can_cancel() {
1075
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1075
+		return apply_filters('wpinv_subscription_can_cancel', $this->has_status($this->get_cancellable_statuses()), $this);
1076 1076
 	}
1077 1077
 
1078 1078
     /**
@@ -1083,7 +1083,7 @@  discard block
 block discarded – undo
1083 1083
      * @return      array
1084 1084
      */
1085 1085
     public function get_cancellable_statuses() {
1086
-        return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1086
+        return apply_filters('wpinv_recurring_cancellable_statuses', array('active', 'trialling', 'failing'));
1087 1087
     }
1088 1088
 
1089 1089
 	/**
@@ -1093,8 +1093,8 @@  discard block
 block discarded – undo
1093 1093
 	 * @return string
1094 1094
 	 */
1095 1095
 	public function get_cancel_url() {
1096
-		$url = getpaid_get_authenticated_action_url( 'subscription_cancel', $this->get_view_url() );
1097
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1096
+		$url = getpaid_get_authenticated_action_url('subscription_cancel', $this->get_view_url());
1097
+		return apply_filters('wpinv_subscription_cancel_url', $url, $this);
1098 1098
 	}
1099 1099
 
1100 1100
 	/**
@@ -1105,10 +1105,10 @@  discard block
 block discarded – undo
1105 1105
 	 */
1106 1106
 	public function get_view_url() {
1107 1107
 
1108
-		$url = getpaid_get_tab_url( 'gp-subscriptions', get_permalink( (int) wpinv_get_option( 'invoice_subscription_page' ) ) );
1109
-		$url = add_query_arg( 'subscription', $this->get_id(), $url );
1108
+		$url = getpaid_get_tab_url('gp-subscriptions', get_permalink((int) wpinv_get_option('invoice_subscription_page')));
1109
+		$url = add_query_arg('subscription', $this->get_id(), $url);
1110 1110
 
1111
-		return apply_filters( 'getpaid_get_subscription_view_url', $url, $this );
1111
+		return apply_filters('getpaid_get_subscription_view_url', $url, $this);
1112 1112
 	}
1113 1113
 
1114 1114
 	/**
@@ -1121,7 +1121,7 @@  discard block
 block discarded – undo
1121 1121
 	 * @return bool
1122 1122
 	 */
1123 1123
 	public function can_renew() {
1124
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1124
+		return apply_filters('wpinv_subscription_can_renew', true, $this);
1125 1125
 	}
1126 1126
 
1127 1127
 	/**
@@ -1140,7 +1140,7 @@  discard block
 block discarded – undo
1140 1140
             ),
1141 1141
             'getpaid-nonce'
1142 1142
         );
1143
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1143
+		return apply_filters('wpinv_subscription_renew_url', $url, $this);
1144 1144
 	}
1145 1145
 
1146 1146
 	/**
@@ -1150,7 +1150,7 @@  discard block
 block discarded – undo
1150 1150
 	 * @return bool
1151 1151
 	 */
1152 1152
 	public function can_update() {
1153
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1153
+		return apply_filters('wpinv_subscription_can_update', false, $this);
1154 1154
 	}
1155 1155
 
1156 1156
 	/**
@@ -1166,7 +1166,7 @@  discard block
 block discarded – undo
1166 1166
 				'subscription_id' => $this->get_id(),
1167 1167
             )
1168 1168
         );
1169
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1169
+		return apply_filters('wpinv_subscription_update_url', $url, $this);
1170 1170
 	}
1171 1171
 
1172 1172
 	/**
@@ -1176,7 +1176,7 @@  discard block
 block discarded – undo
1176 1176
 	 * @return string
1177 1177
 	 */
1178 1178
 	public function get_status_label() {
1179
-		return getpaid_get_subscription_status_label( $this->get_status() );
1179
+		return getpaid_get_subscription_status_label($this->get_status());
1180 1180
 	}
1181 1181
 
1182 1182
 	/**
@@ -1187,7 +1187,7 @@  discard block
 block discarded – undo
1187 1187
 	 */
1188 1188
 	public function get_status_class() {
1189 1189
 		$statuses = getpaid_get_subscription_status_classes();
1190
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'bg-dark';
1190
+		return isset($statuses[$this->get_status()]) ? $statuses[$this->get_status()] : 'bg-dark';
1191 1191
 	}
1192 1192
 
1193 1193
     /**
@@ -1198,9 +1198,9 @@  discard block
 block discarded – undo
1198 1198
      */
1199 1199
     public function get_status_label_html() {
1200 1200
 
1201
-		$status_label = sanitize_text_field( $this->get_status_label() );
1202
-		$class        = esc_attr( $this->get_status_class() );
1203
-		$status       = sanitize_html_class( $this->get_status() );
1201
+		$status_label = sanitize_text_field($this->get_status_label());
1202
+		$class        = esc_attr($this->get_status_class());
1203
+		$status       = sanitize_html_class($this->get_status());
1204 1204
 
1205 1205
 		return "<span class='bsui'><span class='badge $class $status'>$status_label</span></span>";
1206 1206
     }
@@ -1212,9 +1212,9 @@  discard block
 block discarded – undo
1212 1212
      * @param  string $txn_id The transaction ID from the merchant processor
1213 1213
      * @return bool
1214 1214
      */
1215
-    public function payment_exists( $txn_id = '' ) {
1216
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1217
-        return ! empty( $invoice_id );
1215
+    public function payment_exists($txn_id = '') {
1216
+		$invoice_id = WPInv_Invoice::get_invoice_id_by_field($txn_id, 'transaction_id');
1217
+        return !empty($invoice_id);
1218 1218
 	}
1219 1219
 
1220 1220
 	/**
@@ -1226,35 +1226,35 @@  discard block
 block discarded – undo
1226 1226
 		// Reset status transition variable.
1227 1227
 		$this->status_transition = false;
1228 1228
 
1229
-		if ( $status_transition ) {
1229
+		if ($status_transition) {
1230 1230
 			try {
1231 1231
 
1232 1232
 				// Fire a hook for the status change.
1233
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1234
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1233
+				do_action('wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition);
1234
+				do_action('getpaid_subscription_' . $status_transition['to'], $this, $status_transition);
1235 1235
 
1236
-				if ( ! empty( $status_transition['from'] ) ) {
1236
+				if (!empty($status_transition['from'])) {
1237 1237
 
1238 1238
 					/* translators: 1: old subscription status 2: new subscription status */
1239
-					$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'] ) );
1239
+					$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']));
1240 1240
 
1241 1241
 					// Note the transition occurred.
1242
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1242
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1243 1243
 
1244 1244
 					// Fire another hook.
1245
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1246
-					do_action( 'getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to'] );
1245
+					do_action('getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this);
1246
+					do_action('getpaid_subscription_status_changed', $this, $status_transition['from'], $status_transition['to']);
1247 1247
 
1248 1248
 				} else {
1249 1249
 					/* translators: %s: new invoice status */
1250
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1250
+					$transition_note = sprintf(__('Subscription status set to %s.', 'invoicing'), getpaid_get_subscription_status_label($status_transition['to']));
1251 1251
 
1252 1252
 					// Note the transition occurred.
1253
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1253
+					$this->get_parent_payment()->add_note($transition_note, false, false, true);
1254 1254
 
1255 1255
 				}
1256
-			} catch ( Exception $e ) {
1257
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1256
+			} catch (Exception $e) {
1257
+				$this->get_parent_payment()->add_note(__('Error during subscription status transition.', 'invoicing') . ' ' . $e->getMessage());
1258 1258
 			}
1259 1259
 		}
1260 1260
 
@@ -1280,7 +1280,7 @@  discard block
 block discarded – undo
1280 1280
 	 */
1281 1281
 	public function activate() {
1282 1282
 		$status = $this->has_trial_period() && 'trialling' === $this->get_status() ? 'trialling' : 'active';
1283
-		$this->set_status( $status );
1283
+		$this->set_status($status);
1284 1284
 		return $this->save();
1285 1285
 	}
1286 1286
 
Please login to merge, or discard this patch.