Passed
Push — master ( fb83c5...9f060d )
by Brian
05:10
created
includes/wpinv-address-functions.php 1 patch
Indentation   +88 added lines, -88 removed lines patch added patch discarded remove patch
@@ -13,9 +13,9 @@  discard block
 block discarded – undo
13 13
 
14 14
 
15 15
 function wpinv_get_default_country() {
16
-	$country = wpinv_get_option( 'default_country', 'UK' );
16
+    $country = wpinv_get_option( 'default_country', 'UK' );
17 17
 
18
-	return apply_filters( 'wpinv_default_country', $country );
18
+    return apply_filters( 'wpinv_default_country', $country );
19 19
 }
20 20
 
21 21
 /**
@@ -26,7 +26,7 @@  discard block
 block discarded – undo
26 26
  */
27 27
 function wpinv_sanitize_country( $country ) {
28 28
 
29
-	// Enure the country is specified
29
+    // Enure the country is specified
30 30
     if ( empty( $country ) ) {
31 31
         $country = wpinv_get_default_country();
32 32
     }
@@ -56,9 +56,9 @@  discard block
 block discarded – undo
56 56
 }
57 57
 
58 58
 function wpinv_get_default_state() {
59
-	$state = wpinv_get_option( 'default_state', '' );
59
+    $state = wpinv_get_option( 'default_state', '' );
60 60
 
61
-	return apply_filters( 'wpinv_default_state', $state );
61
+    return apply_filters( 'wpinv_default_state', $state );
62 62
 }
63 63
 
64 64
 function wpinv_state_name( $state_code = '', $country_code = '' ) {
@@ -288,11 +288,11 @@  discard block
 block discarded – undo
288 288
 
289 289
     $country = wpinv_sanitize_country( $country );
290 290
     
291
-	foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
292
-		if ( false !== array_search( $country, $countries, true ) ) {
293
-			return $continent_code;
294
-		}
295
-	}
291
+    foreach ( wpinv_get_continents( 'countries' ) as $continent_code => $countries ) {
292
+        if ( false !== array_search( $country, $countries, true ) ) {
293
+            return $continent_code;
294
+        }
295
+    }
296 296
 
297 297
     return '';
298 298
     
@@ -584,30 +584,30 @@  discard block
 block discarded – undo
584 584
 }
585 585
 
586 586
 function wpinv_get_states_field() {
587
-	if( empty( $_POST['country'] ) ) {
588
-		$_POST['country'] = wpinv_get_default_country();
589
-	}
590
-	$states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
587
+    if( empty( $_POST['country'] ) ) {
588
+        $_POST['country'] = wpinv_get_default_country();
589
+    }
590
+    $states = wpinv_get_country_states( sanitize_text_field( $_POST['country'] ) );
591 591
 
592
-	if( !empty( $states ) ) {
593
-		$sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
592
+    if( !empty( $states ) ) {
593
+        $sanitized_field_name = sanitize_text_field( $_POST['field_name'] );
594 594
         
595 595
         $args = array(
596
-			'name'    => $sanitized_field_name,
597
-			'id'      => $sanitized_field_name,
598
-			'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
599
-			'options' => array_merge( array( '' => '' ), $states ),
600
-			'show_option_all'  => false,
601
-			'show_option_none' => false
602
-		);
603
-
604
-		$response = wpinv_html_select( $args );
605
-
606
-	} else {
607
-		$response = 'nostates';
608
-	}
596
+            'name'    => $sanitized_field_name,
597
+            'id'      => $sanitized_field_name,
598
+            'class'   => $sanitized_field_name . 'custom-select wpinv-select wpi_select2',
599
+            'options' => array_merge( array( '' => '' ), $states ),
600
+            'show_option_all'  => false,
601
+            'show_option_none' => false
602
+        );
603
+
604
+        $response = wpinv_html_select( $args );
605
+
606
+    } else {
607
+        $response = 'nostates';
608
+    }
609 609
 
610
-	return $response;
610
+    return $response;
611 611
 }
612 612
 
613 613
 function wpinv_default_billing_country( $country = '', $user_id = 0 ) {
@@ -625,46 +625,46 @@  discard block
 block discarded – undo
625 625
  */
626 626
 function wpinv_get_address_formats() {
627 627
 
628
-		return apply_filters( 'wpinv_localisation_address_formats',
629
-			array(
630
-				'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
631
-				'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
632
-				'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
633
-				'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
634
-				'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}  {{zip}}\n{{country}}",
635
-				'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
636
-				'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
637
-				'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
638
-				'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
639
-				'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
640
-				'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
641
-				'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
642
-				'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
643
-				'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
644
-				'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
645
-				'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
646
-				'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
647
-				'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
648
-				'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
649
-				'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
650
-				'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
651
-				'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
652
-				'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
653
-				'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
654
-				'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
655
-				'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
656
-				'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
657
-				'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
658
-				'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
659
-				'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
660
-				'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
661
-				'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
662
-				'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
663
-				'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
664
-				'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
665
-				'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
666
-			)
667
-		);
628
+        return apply_filters( 'wpinv_localisation_address_formats',
629
+            array(
630
+                'default' => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}\n{{zip}}\n{{country}}",
631
+                'AU'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}} {{zip}}\n{{country}}",
632
+                'AT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
633
+                'BE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
634
+                'CA'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{state_code}}  {{zip}}\n{{country}}",
635
+                'CH'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
636
+                'CL'      => "{{company}}\n{{name}}\n{{address}}\n{{state}}\n{{zip}} {{city}}\n{{country}}",
637
+                'CN'      => "{{country}} {{zip}}\n{{state}}, {{city}}, {{address}}\n{{company}}\n{{name}}",
638
+                'CZ'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
639
+                'DE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
640
+                'EE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
641
+                'FI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
642
+                'DK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
643
+                'FR'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city_upper}}\n{{country}}",
644
+                'HK'      => "{{company}}\n{{first_name}} {{last_name_upper}}\n{{address}}\n{{city_upper}}\n{{state_upper}}\n{{country}}",
645
+                'HU'      => "{{name}}\n{{company}}\n{{city}}\n{{address}}\n{{zip}}\n{{country}}",
646
+                'IN'      => "{{company}}\n{{name}}\n{{address}}\n{{city}} {{zip}}\n{{state}}, {{country}}",
647
+                'IS'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
648
+                'IT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}}\n{{city}}\n{{state_upper}}\n{{country}}",
649
+                'JP'      => "{{zip}}\n{{state}} {{city}} {{address}}\n{{company}}\n{{last_name}} {{first_name}}\n{{country}}",
650
+                'TW'      => "{{company}}\n{{last_name}} {{first_name}}\n{{address}}\n{{state}}, {{city}} {{zip}}\n{{country}}",
651
+                'LI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
652
+                'NL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
653
+                'NZ'      => "{{name}}\n{{company}}\n{{address}}\n{{city}} {{zip}}\n{{country}}",
654
+                'NO'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
655
+                'PL'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
656
+                'PT'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
657
+                'SK'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
658
+                'RS'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
659
+                'SI'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
660
+                'ES'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}}\n{{state}}\n{{country}}",
661
+                'SE'      => "{{company}}\n{{name}}\n{{address}}\n{{zip}} {{city}}\n{{country}}",
662
+                'TR'      => "{{name}}\n{{company}}\n{{address}}\n{{zip}} {{city}} {{state}}\n{{country}}",
663
+                'UG'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{state}}, {{country}}",
664
+                'US'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}, {{state_code}} {{zip}}\n{{country}}",
665
+                'VN'      => "{{name}}\n{{company}}\n{{address}}\n{{city}}\n{{country}}",
666
+            )
667
+        );
668 668
 }
669 669
 
670 670
 /**
@@ -681,21 +681,21 @@  discard block
 block discarded – undo
681 681
     }
682 682
 
683 683
     // Get all formats.
684
-	$formats = wpinv_get_address_formats();
684
+    $formats = wpinv_get_address_formats();
685 685
 
686
-	// Get format for the specified country.
687
-	$format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
686
+    // Get format for the specified country.
687
+    $format = ( $country && isset( $formats[ $country ] ) ) ? $formats[ $country ] : $formats['default'];
688 688
     
689 689
     /**
690
-	 * Filters the address format to use on Invoices.
690
+     * Filters the address format to use on Invoices.
691 691
      * 
692 692
      * New lines will be replaced by a `br` element. Double new lines will be replaced by a paragraph. HTML tags are allowed.
693
-	 *
694
-	 * @since 1.0.13
695
-	 *
696
-	 * @param string $format  The address format to use.
693
+     *
694
+     * @since 1.0.13
695
+     *
696
+     * @param string $format  The address format to use.
697 697
      * @param string $country The country who's address format is being retrieved.
698
-	 */
698
+     */
699 699
     return apply_filters( 'wpinv_get_full_address_format', $format, $country );
700 700
 }
701 701
 
@@ -716,8 +716,8 @@  discard block
 block discarded – undo
716 716
         'country'           => '',
717 717
         'zip'               => '',
718 718
         'first_name'        => '',
719
-		'last_name'         => '',
720
-		'company'           => '',
719
+        'last_name'         => '',
720
+        'company'           => '',
721 721
     );
722 722
 
723 723
     $args    = map_deep( wp_parse_args( $billing_details, $default_args ), 'trim' );
@@ -738,14 +738,14 @@  discard block
 block discarded – undo
738 738
     $args['country_code']= $country;
739 739
 
740 740
     /**
741
-	 * Filters the address format replacements to use on Invoices.
741
+     * Filters the address format replacements to use on Invoices.
742 742
      * 
743
-	 *
744
-	 * @since 1.0.13
745
-	 *
746
-	 * @param array $replacements  The address replacements to use.
743
+     *
744
+     * @since 1.0.13
745
+     *
746
+     * @param array $replacements  The address replacements to use.
747 747
      * @param array $billing_details  The billing details to use.
748
-	 */
748
+     */
749 749
     $replacements = apply_filters( 'wpinv_get_invoice_address_replacements', $args, $billing_details );
750 750
 
751 751
     $return = array();
@@ -768,5 +768,5 @@  discard block
 block discarded – undo
768 768
  * @return string
769 769
  */
770 770
 function wpinv_trim_formatted_address_line( $line ) {
771
-	return trim( $line, ', ' );
771
+    return trim( $line, ', ' );
772 772
 }
773 773
\ No newline at end of file
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data.php 1 patch
Indentation   +860 added lines, -860 removed lines patch added patch discarded remove patch
@@ -9,7 +9,7 @@  discard block
 block discarded – undo
9 9
  */
10 10
 
11 11
 if ( ! defined( 'ABSPATH' ) ) {
12
-	exit;
12
+    exit;
13 13
 }
14 14
 
15 15
 /**
@@ -21,356 +21,356 @@  discard block
 block discarded – undo
21 21
  */
22 22
 abstract class GetPaid_Data {
23 23
 
24
-	/**
25
-	 * ID for this object.
26
-	 *
27
-	 * @since 1.0.19
28
-	 * @var int
29
-	 */
30
-	protected $id = 0;
31
-
32
-	/**
33
-	 * Core data for this object. Name value pairs (name + default value).
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array();
39
-
40
-	/**
41
-	 * Core data changes for this object.
42
-	 *
43
-	 * @since 1.0.19
44
-	 * @var array
45
-	 */
46
-	protected $changes = array();
47
-
48
-	/**
49
-	 * This is false until the object is read from the DB.
50
-	 *
51
-	 * @since 1.0.19
52
-	 * @var bool
53
-	 */
54
-	protected $object_read = false;
55
-
56
-	/**
57
-	 * This is the name of this object type.
58
-	 *
59
-	 * @since 1.0.19
60
-	 * @var string
61
-	 */
62
-	protected $object_type = 'data';
63
-
64
-	/**
65
-	 * Extra data for this object. Name value pairs (name + default value).
66
-	 * Used as a standard way for sub classes (like item types) to add
67
-	 * additional information to an inherited class.
68
-	 *
69
-	 * @since 1.0.19
70
-	 * @var array
71
-	 */
72
-	protected $extra_data = array();
73
-
74
-	/**
75
-	 * Set to _data on construct so we can track and reset data if needed.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var array
79
-	 */
80
-	protected $default_data = array();
81
-
82
-	/**
83
-	 * Contains a reference to the data store for this class.
84
-	 *
85
-	 * @since 1.0.19
86
-	 * @var GetPaid_Data_Store
87
-	 */
88
-	protected $data_store;
89
-
90
-	/**
91
-	 * Stores meta in cache for future reads.
92
-	 * A group must be set to to enable caching.
93
-	 *
94
-	 * @since 1.0.19
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = '';
98
-
99
-	/**
100
-	 * Stores the last error.
101
-	 *
102
-	 * @since 1.0.19
103
-	 * @var string
104
-	 */
105
-	public $last_error = '';
106
-
107
-	/**
108
-	 * Stores additional meta data.
109
-	 *
110
-	 * @since 1.0.19
111
-	 * @var array
112
-	 */
113
-	protected $meta_data = null;
114
-
115
-	/**
116
-	 * Default constructor.
117
-	 *
118
-	 * @param int|object|array|string $read ID to load from the DB (optional) or already queried data.
119
-	 */
120
-	public function __construct( $read = 0 ) {
121
-		$this->data         = array_merge( $this->data, $this->extra_data );
122
-		$this->default_data = $this->data;
123
-	}
124
-
125
-	/**
126
-	 * Only store the object ID to avoid serializing the data object instance.
127
-	 *
128
-	 * @return array
129
-	 */
130
-	public function __sleep() {
131
-		return array( 'id' );
132
-	}
133
-
134
-	/**
135
-	 * Re-run the constructor with the object ID.
136
-	 *
137
-	 * If the object no longer exists, remove the ID.
138
-	 */
139
-	public function __wakeup() {
140
-		$this->__construct( absint( $this->id ) );
141
-
142
-		if ( ! empty( $this->last_error ) ) {
143
-			$this->set_id( 0 );
144
-		}
145
-
146
-	}
147
-
148
-	/**
149
-	 * When the object is cloned, make sure meta is duplicated correctly.
150
-	 *
151
-	 * @since 1.0.19
152
-	 */
153
-	public function __clone() {
154
-		$this->maybe_read_meta_data();
155
-		if ( ! empty( $this->meta_data ) ) {
156
-			foreach ( $this->meta_data as $array_key => $meta ) {
157
-				$this->meta_data[ $array_key ] = clone $meta;
158
-				if ( ! empty( $meta->id ) ) {
159
-					$this->meta_data[ $array_key ]->id = null;
160
-				}
161
-			}
162
-		}
163
-	}
164
-
165
-	/**
166
-	 * Get the data store.
167
-	 *
168
-	 * @since  1.0.19
169
-	 * @return object
170
-	 */
171
-	public function get_data_store() {
172
-		return $this->data_store;
173
-	}
174
-
175
-	/**
176
-	 * Get the object type.
177
-	 *
178
-	 * @since  1.0.19
179
-	 * @return string
180
-	 */
181
-	public function get_object_type() {
182
-		return $this->object_type;
183
-	}
184
-
185
-	/**
186
-	 * Returns the unique ID for this object.
187
-	 *
188
-	 * @since  1.0.19
189
-	 * @return int
190
-	 */
191
-	public function get_id() {
192
-		return $this->id;
193
-	}
194
-
195
-	/**
196
-	 * Get form status.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_status( $context = 'view' ) {
203
-		return $this->get_prop( 'status', $context );
204
-    }
205
-
206
-	/**
207
-	 * Delete an object, set the ID to 0, and return result.
208
-	 *
209
-	 * @since  1.0.19
210
-	 * @param  bool $force_delete Should the data be deleted permanently.
211
-	 * @return bool result
212
-	 */
213
-	public function delete( $force_delete = false ) {
214
-		if ( $this->data_store && $this->get_id() ) {
215
-			$this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
-			$this->set_id( 0 );
217
-			return true;
218
-		}
219
-		return false;
220
-	}
221
-
222
-	/**
223
-	 * Save should create or update based on object existence.
224
-	 *
225
-	 * @since  1.0.19
226
-	 * @return int
227
-	 */
228
-	public function save() {
229
-		if ( ! $this->data_store ) {
230
-			return $this->get_id();
231
-		}
232
-
233
-		/**
234
-		 * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
-		 *
236
-		 * @param GetPaid_Data          $this The object being saved.
237
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
-		 */
239
-		do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
-
241
-		if ( $this->get_id() ) {
242
-			$this->data_store->update( $this );
243
-		} else {
244
-			$this->data_store->create( $this );
245
-		}
246
-
247
-		/**
248
-		 * Trigger action after saving to the DB.
249
-		 *
250
-		 * @param GetPaid_Data          $this The object being saved.
251
-		 * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
-		 */
253
-		do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
-
255
-		return $this->get_id();
256
-	}
257
-
258
-	/**
259
-	 * Change data to JSON format.
260
-	 *
261
-	 * @since  1.0.19
262
-	 * @return string Data in JSON format.
263
-	 */
264
-	public function __toString() {
265
-		return wp_json_encode( $this->get_data() );
266
-	}
267
-
268
-	/**
269
-	 * Returns all data for this object.
270
-	 *
271
-	 * @since  1.0.19
272
-	 * @return array
273
-	 */
274
-	public function get_data() {
275
-		return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
-	}
277
-
278
-	/**
279
-	 * Returns array of expected data keys for this object.
280
-	 *
281
-	 * @since   1.0.19
282
-	 * @return array
283
-	 */
284
-	public function get_data_keys() {
285
-		return array_keys( $this->data );
286
-	}
287
-
288
-	/**
289
-	 * Returns all "extra" data keys for an object (for sub objects like item types).
290
-	 *
291
-	 * @since  1.0.19
292
-	 * @return array
293
-	 */
294
-	public function get_extra_data_keys() {
295
-		return array_keys( $this->extra_data );
296
-	}
297
-
298
-	/**
299
-	 * Filter null meta values from array.
300
-	 *
301
-	 * @since  1.0.19
302
-	 * @param mixed $meta Meta value to check.
303
-	 * @return bool
304
-	 */
305
-	protected function filter_null_meta( $meta ) {
306
-		return ! is_null( $meta->value );
307
-	}
308
-
309
-	/**
310
-	 * Get All Meta Data.
311
-	 *
312
-	 * @since 1.0.19
313
-	 * @return array of objects.
314
-	 */
315
-	public function get_meta_data() {
316
-		$this->maybe_read_meta_data();
317
-		return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
-	}
319
-
320
-	/**
321
-	 * Check if the key is an internal one.
322
-	 *
323
-	 * @since  1.0.19
324
-	 * @param  string $key Key to check.
325
-	 * @return bool   true if it's an internal key, false otherwise
326
-	 */
327
-	protected function is_internal_meta_key( $key ) {
328
-		$internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
-
330
-		if ( ! $internal_meta_key ) {
331
-			return false;
332
-		}
333
-
334
-		$has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
-
336
-		if ( ! $has_setter_or_getter ) {
337
-			return false;
338
-		}
339
-
340
-		/* translators: %s: $key Key to check */
341
-		getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
-
343
-		return true;
344
-	}
345
-
346
-	/**
347
-	 * Magic method for setting data fields.
348
-	 *
349
-	 * This method does not update custom fields in the database.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @access public
353
-	 *
354
-	 */
355
-	public function __set( $key, $value ) {
356
-
357
-		if ( 'id' == strtolower( $key ) ) {
358
-			return $this->set_id( $value );
359
-		}
360
-
361
-		if ( method_exists( $this, "set_$key") ) {
362
-
363
-			/* translators: %s: $key Key to set */
364
-			getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
-
366
-			call_user_func( array( $this, "set_$key" ), $value );
367
-		} else {
368
-			$this->set_prop( $key, $value );
369
-		}
370
-
371
-	}
372
-
373
-	/**
24
+    /**
25
+     * ID for this object.
26
+     *
27
+     * @since 1.0.19
28
+     * @var int
29
+     */
30
+    protected $id = 0;
31
+
32
+    /**
33
+     * Core data for this object. Name value pairs (name + default value).
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array();
39
+
40
+    /**
41
+     * Core data changes for this object.
42
+     *
43
+     * @since 1.0.19
44
+     * @var array
45
+     */
46
+    protected $changes = array();
47
+
48
+    /**
49
+     * This is false until the object is read from the DB.
50
+     *
51
+     * @since 1.0.19
52
+     * @var bool
53
+     */
54
+    protected $object_read = false;
55
+
56
+    /**
57
+     * This is the name of this object type.
58
+     *
59
+     * @since 1.0.19
60
+     * @var string
61
+     */
62
+    protected $object_type = 'data';
63
+
64
+    /**
65
+     * Extra data for this object. Name value pairs (name + default value).
66
+     * Used as a standard way for sub classes (like item types) to add
67
+     * additional information to an inherited class.
68
+     *
69
+     * @since 1.0.19
70
+     * @var array
71
+     */
72
+    protected $extra_data = array();
73
+
74
+    /**
75
+     * Set to _data on construct so we can track and reset data if needed.
76
+     *
77
+     * @since 1.0.19
78
+     * @var array
79
+     */
80
+    protected $default_data = array();
81
+
82
+    /**
83
+     * Contains a reference to the data store for this class.
84
+     *
85
+     * @since 1.0.19
86
+     * @var GetPaid_Data_Store
87
+     */
88
+    protected $data_store;
89
+
90
+    /**
91
+     * Stores meta in cache for future reads.
92
+     * A group must be set to to enable caching.
93
+     *
94
+     * @since 1.0.19
95
+     * @var string
96
+     */
97
+    protected $cache_group = '';
98
+
99
+    /**
100
+     * Stores the last error.
101
+     *
102
+     * @since 1.0.19
103
+     * @var string
104
+     */
105
+    public $last_error = '';
106
+
107
+    /**
108
+     * Stores additional meta data.
109
+     *
110
+     * @since 1.0.19
111
+     * @var array
112
+     */
113
+    protected $meta_data = null;
114
+
115
+    /**
116
+     * Default constructor.
117
+     *
118
+     * @param int|object|array|string $read ID to load from the DB (optional) or already queried data.
119
+     */
120
+    public function __construct( $read = 0 ) {
121
+        $this->data         = array_merge( $this->data, $this->extra_data );
122
+        $this->default_data = $this->data;
123
+    }
124
+
125
+    /**
126
+     * Only store the object ID to avoid serializing the data object instance.
127
+     *
128
+     * @return array
129
+     */
130
+    public function __sleep() {
131
+        return array( 'id' );
132
+    }
133
+
134
+    /**
135
+     * Re-run the constructor with the object ID.
136
+     *
137
+     * If the object no longer exists, remove the ID.
138
+     */
139
+    public function __wakeup() {
140
+        $this->__construct( absint( $this->id ) );
141
+
142
+        if ( ! empty( $this->last_error ) ) {
143
+            $this->set_id( 0 );
144
+        }
145
+
146
+    }
147
+
148
+    /**
149
+     * When the object is cloned, make sure meta is duplicated correctly.
150
+     *
151
+     * @since 1.0.19
152
+     */
153
+    public function __clone() {
154
+        $this->maybe_read_meta_data();
155
+        if ( ! empty( $this->meta_data ) ) {
156
+            foreach ( $this->meta_data as $array_key => $meta ) {
157
+                $this->meta_data[ $array_key ] = clone $meta;
158
+                if ( ! empty( $meta->id ) ) {
159
+                    $this->meta_data[ $array_key ]->id = null;
160
+                }
161
+            }
162
+        }
163
+    }
164
+
165
+    /**
166
+     * Get the data store.
167
+     *
168
+     * @since  1.0.19
169
+     * @return object
170
+     */
171
+    public function get_data_store() {
172
+        return $this->data_store;
173
+    }
174
+
175
+    /**
176
+     * Get the object type.
177
+     *
178
+     * @since  1.0.19
179
+     * @return string
180
+     */
181
+    public function get_object_type() {
182
+        return $this->object_type;
183
+    }
184
+
185
+    /**
186
+     * Returns the unique ID for this object.
187
+     *
188
+     * @since  1.0.19
189
+     * @return int
190
+     */
191
+    public function get_id() {
192
+        return $this->id;
193
+    }
194
+
195
+    /**
196
+     * Get form status.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_status( $context = 'view' ) {
203
+        return $this->get_prop( 'status', $context );
204
+    }
205
+
206
+    /**
207
+     * Delete an object, set the ID to 0, and return result.
208
+     *
209
+     * @since  1.0.19
210
+     * @param  bool $force_delete Should the data be deleted permanently.
211
+     * @return bool result
212
+     */
213
+    public function delete( $force_delete = false ) {
214
+        if ( $this->data_store && $this->get_id() ) {
215
+            $this->data_store->delete( $this, array( 'force_delete' => $force_delete ) );
216
+            $this->set_id( 0 );
217
+            return true;
218
+        }
219
+        return false;
220
+    }
221
+
222
+    /**
223
+     * Save should create or update based on object existence.
224
+     *
225
+     * @since  1.0.19
226
+     * @return int
227
+     */
228
+    public function save() {
229
+        if ( ! $this->data_store ) {
230
+            return $this->get_id();
231
+        }
232
+
233
+        /**
234
+         * Trigger action before saving to the DB. Allows you to adjust object props before save.
235
+         *
236
+         * @param GetPaid_Data          $this The object being saved.
237
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
238
+         */
239
+        do_action( 'getpaid_before_' . $this->object_type . '_object_save', $this, $this->data_store );
240
+
241
+        if ( $this->get_id() ) {
242
+            $this->data_store->update( $this );
243
+        } else {
244
+            $this->data_store->create( $this );
245
+        }
246
+
247
+        /**
248
+         * Trigger action after saving to the DB.
249
+         *
250
+         * @param GetPaid_Data          $this The object being saved.
251
+         * @param GetPaid_Data_Store_WP $data_store The data store persisting the data.
252
+         */
253
+        do_action( 'getpaid_after_' . $this->object_type . '_object_save', $this, $this->data_store );
254
+
255
+        return $this->get_id();
256
+    }
257
+
258
+    /**
259
+     * Change data to JSON format.
260
+     *
261
+     * @since  1.0.19
262
+     * @return string Data in JSON format.
263
+     */
264
+    public function __toString() {
265
+        return wp_json_encode( $this->get_data() );
266
+    }
267
+
268
+    /**
269
+     * Returns all data for this object.
270
+     *
271
+     * @since  1.0.19
272
+     * @return array
273
+     */
274
+    public function get_data() {
275
+        return array_merge( array( 'id' => $this->get_id() ), $this->data, array( 'meta_data' => $this->get_meta_data() ) );
276
+    }
277
+
278
+    /**
279
+     * Returns array of expected data keys for this object.
280
+     *
281
+     * @since   1.0.19
282
+     * @return array
283
+     */
284
+    public function get_data_keys() {
285
+        return array_keys( $this->data );
286
+    }
287
+
288
+    /**
289
+     * Returns all "extra" data keys for an object (for sub objects like item types).
290
+     *
291
+     * @since  1.0.19
292
+     * @return array
293
+     */
294
+    public function get_extra_data_keys() {
295
+        return array_keys( $this->extra_data );
296
+    }
297
+
298
+    /**
299
+     * Filter null meta values from array.
300
+     *
301
+     * @since  1.0.19
302
+     * @param mixed $meta Meta value to check.
303
+     * @return bool
304
+     */
305
+    protected function filter_null_meta( $meta ) {
306
+        return ! is_null( $meta->value );
307
+    }
308
+
309
+    /**
310
+     * Get All Meta Data.
311
+     *
312
+     * @since 1.0.19
313
+     * @return array of objects.
314
+     */
315
+    public function get_meta_data() {
316
+        $this->maybe_read_meta_data();
317
+        return array_values( array_filter( $this->meta_data, array( $this, 'filter_null_meta' ) ) );
318
+    }
319
+
320
+    /**
321
+     * Check if the key is an internal one.
322
+     *
323
+     * @since  1.0.19
324
+     * @param  string $key Key to check.
325
+     * @return bool   true if it's an internal key, false otherwise
326
+     */
327
+    protected function is_internal_meta_key( $key ) {
328
+        $internal_meta_key = ! empty( $key ) && $this->data_store && in_array( $key, $this->data_store->get_internal_meta_keys(), true );
329
+
330
+        if ( ! $internal_meta_key ) {
331
+            return false;
332
+        }
333
+
334
+        $has_setter_or_getter = is_callable( array( $this, 'set_' . $key ) ) || is_callable( array( $this, 'get_' . $key ) );
335
+
336
+        if ( ! $has_setter_or_getter ) {
337
+            return false;
338
+        }
339
+
340
+        /* translators: %s: $key Key to check */
341
+        getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Generic add/update/get meta methods should not be used for internal meta data, including "%s". Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
342
+
343
+        return true;
344
+    }
345
+
346
+    /**
347
+     * Magic method for setting data fields.
348
+     *
349
+     * This method does not update custom fields in the database.
350
+     *
351
+     * @since 1.0.19
352
+     * @access public
353
+     *
354
+     */
355
+    public function __set( $key, $value ) {
356
+
357
+        if ( 'id' == strtolower( $key ) ) {
358
+            return $this->set_id( $value );
359
+        }
360
+
361
+        if ( method_exists( $this, "set_$key") ) {
362
+
363
+            /* translators: %s: $key Key to set */
364
+            getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
365
+
366
+            call_user_func( array( $this, "set_$key" ), $value );
367
+        } else {
368
+            $this->set_prop( $key, $value );
369
+        }
370
+
371
+    }
372
+
373
+    /**
374 374
      * Margic method for retrieving a property.
375 375
      */
376 376
     public function __get( $key ) {
@@ -378,10 +378,10 @@  discard block
 block discarded – undo
378 378
         // Check if we have a helper method for that.
379 379
         if ( method_exists( $this, 'get_' . $key ) ) {
380 380
 
381
-			if ( 'post_type' != $key ) {
382
-				/* translators: %s: $key Key to set */
383
-				getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
-			}
381
+            if ( 'post_type' != $key ) {
382
+                /* translators: %s: $key Key to set */
383
+                getpaid_doing_it_wrong( __FUNCTION__, sprintf( __( 'Object data such as "%s" should not be accessed directly. Use getters and setters.', 'getpaid' ), $key ), '1.0.19' );
384
+            }
385 385
 
386 386
             return call_user_func( array( $this, 'get_' . $key ) );
387 387
         }
@@ -391,512 +391,512 @@  discard block
 block discarded – undo
391 391
             return $this->post->$key;
392 392
         }
393 393
 
394
-		return $this->get_prop( $key );
395
-
396
-    }
397
-
398
-	/**
399
-	 * Get Meta Data by Key.
400
-	 *
401
-	 * @since  1.0.19
402
-	 * @param  string $key Meta Key.
403
-	 * @param  bool   $single return first found meta with key, or all with $key.
404
-	 * @param  string $context What the value is for. Valid values are view and edit.
405
-	 * @return mixed
406
-	 */
407
-	public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
-
409
-		// Check if this is an internal meta key.
410
-		$_key = str_replace( '_wpinv', '', $key );
411
-		$_key = str_replace( 'wpinv', '', $_key );
412
-		if ( $this->is_internal_meta_key( $_key ) ) {
413
-			$function = 'get_' . $_key;
414
-
415
-			if ( is_callable( array( $this, $function ) ) ) {
416
-				return $this->{$function}();
417
-			}
418
-		}
419
-
420
-		// Read the meta data if not yet read.
421
-		$this->maybe_read_meta_data();
422
-		$meta_data  = $this->get_meta_data();
423
-		$array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
-		$value      = $single ? '' : array();
425
-
426
-		if ( ! empty( $array_keys ) ) {
427
-			// We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
-			if ( $single ) {
429
-				$value = $meta_data[ current( $array_keys ) ]->value;
430
-			} else {
431
-				$value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
-			}
433
-		}
434
-
435
-		if ( 'view' === $context ) {
436
-			$value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
-		}
438
-
439
-		return $value;
440
-	}
441
-
442
-	/**
443
-	 * See if meta data exists, since get_meta always returns a '' or array().
444
-	 *
445
-	 * @since  1.0.19
446
-	 * @param  string $key Meta Key.
447
-	 * @return boolean
448
-	 */
449
-	public function meta_exists( $key = '' ) {
450
-		$this->maybe_read_meta_data();
451
-		$array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
-		return in_array( $key, $array_keys, true );
453
-	}
454
-
455
-	/**
456
-	 * Set all meta data from array.
457
-	 *
458
-	 * @since 1.0.19
459
-	 * @param array $data Key/Value pairs.
460
-	 */
461
-	public function set_meta_data( $data ) {
462
-		if ( ! empty( $data ) && is_array( $data ) ) {
463
-			$this->maybe_read_meta_data();
464
-			foreach ( $data as $meta ) {
465
-				$meta = (array) $meta;
466
-				if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
-					$this->meta_data[] = new GetPaid_Meta_Data(
468
-						array(
469
-							'id'    => $meta['id'],
470
-							'key'   => $meta['key'],
471
-							'value' => $meta['value'],
472
-						)
473
-					);
474
-				}
475
-			}
476
-		}
477
-	}
478
-
479
-	/**
480
-	 * Add meta data.
481
-	 *
482
-	 * @since 1.0.19
483
-	 *
484
-	 * @param string       $key Meta key.
485
-	 * @param string|array $value Meta value.
486
-	 * @param bool         $unique Should this be a unique key?.
487
-	 */
488
-	public function add_meta_data( $key, $value, $unique = false ) {
489
-		if ( $this->is_internal_meta_key( $key ) ) {
490
-			$function = 'set_' . $key;
491
-
492
-			if ( is_callable( array( $this, $function ) ) ) {
493
-				return $this->{$function}( $value );
494
-			}
495
-		}
496
-
497
-		$this->maybe_read_meta_data();
498
-		if ( $unique ) {
499
-			$this->delete_meta_data( $key );
500
-		}
501
-		$this->meta_data[] = new GetPaid_Meta_Data(
502
-			array(
503
-				'key'   => $key,
504
-				'value' => $value,
505
-			)
506
-		);
507
-	}
508
-
509
-	/**
510
-	 * Update meta data by key or ID, if provided.
511
-	 *
512
-	 * @since  1.0.19
513
-	 *
514
-	 * @param  string       $key Meta key.
515
-	 * @param  string|array $value Meta value.
516
-	 * @param  int          $meta_id Meta ID.
517
-	 */
518
-	public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
-		if ( $this->is_internal_meta_key( $key ) ) {
520
-			$function = 'set_' . $key;
521
-
522
-			if ( is_callable( array( $this, $function ) ) ) {
523
-				return $this->{$function}( $value );
524
-			}
525
-		}
526
-
527
-		$this->maybe_read_meta_data();
528
-
529
-		$array_key = false;
530
-
531
-		if ( $meta_id ) {
532
-			$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
-			$array_key  = $array_keys ? current( $array_keys ) : false;
534
-		} else {
535
-			// Find matches by key.
536
-			$matches = array();
537
-			foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
-				if ( $meta->key === $key ) {
539
-					$matches[] = $meta_data_array_key;
540
-				}
541
-			}
542
-
543
-			if ( ! empty( $matches ) ) {
544
-				// Set matches to null so only one key gets the new value.
545
-				foreach ( $matches as $meta_data_array_key ) {
546
-					$this->meta_data[ $meta_data_array_key ]->value = null;
547
-				}
548
-				$array_key = current( $matches );
549
-			}
550
-		}
551
-
552
-		if ( false !== $array_key ) {
553
-			$meta        = $this->meta_data[ $array_key ];
554
-			$meta->key   = $key;
555
-			$meta->value = $value;
556
-		} else {
557
-			$this->add_meta_data( $key, $value, true );
558
-		}
559
-	}
560
-
561
-	/**
562
-	 * Delete meta data.
563
-	 *
564
-	 * @since 1.0.19
565
-	 * @param string $key Meta key.
566
-	 */
567
-	public function delete_meta_data( $key ) {
568
-		$this->maybe_read_meta_data();
569
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
-
571
-		if ( $array_keys ) {
572
-			foreach ( $array_keys as $array_key ) {
573
-				$this->meta_data[ $array_key ]->value = null;
574
-			}
575
-		}
576
-	}
577
-
578
-	/**
579
-	 * Delete meta data.
580
-	 *
581
-	 * @since 1.0.19
582
-	 * @param int $mid Meta ID.
583
-	 */
584
-	public function delete_meta_data_by_mid( $mid ) {
585
-		$this->maybe_read_meta_data();
586
-		$array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
-
588
-		if ( $array_keys ) {
589
-			foreach ( $array_keys as $array_key ) {
590
-				$this->meta_data[ $array_key ]->value = null;
591
-			}
592
-		}
593
-	}
594
-
595
-	/**
596
-	 * Read meta data if null.
597
-	 *
598
-	 * @since 1.0.19
599
-	 */
600
-	protected function maybe_read_meta_data() {
601
-		if ( is_null( $this->meta_data ) ) {
602
-			$this->read_meta_data();
603
-		}
604
-	}
605
-
606
-	/**
607
-	 * Read Meta Data from the database. Ignore any internal properties.
608
-	 * Uses it's own caches because get_metadata does not provide meta_ids.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param bool $force_read True to force a new DB read (and update cache).
612
-	 */
613
-	public function read_meta_data( $force_read = false ) {
614
-
615
-		// Reset meta data.
616
-		$this->meta_data = array();
617
-
618
-		// Maybe abort early.
619
-		if ( ! $this->get_id() || ! $this->data_store ) {
620
-			return;
621
-		}
622
-
623
-		// Only read from cache if the cache key is set.
624
-		$cache_key = null;
625
-		if ( ! $force_read && ! empty( $this->cache_group ) ) {
626
-			$cache_key     = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
627
-			$raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
628
-		}
629
-
630
-		// Should we force read?
631
-		if ( empty( $raw_meta_data ) ) {
632
-			$raw_meta_data = $this->data_store->read_meta( $this );
633
-
634
-			if ( ! empty( $cache_key ) ) {
635
-				wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
636
-			}
637
-
638
-		}
639
-
640
-		// Set meta data.
641
-		if ( is_array( $raw_meta_data ) ) {
642
-
643
-			foreach ( $raw_meta_data as $meta ) {
644
-				$this->meta_data[] = new GetPaid_Meta_Data(
645
-					array(
646
-						'id'    => (int) $meta->meta_id,
647
-						'key'   => $meta->meta_key,
648
-						'value' => maybe_unserialize( $meta->meta_value ),
649
-					)
650
-				);
651
-			}
652
-
653
-		}
654
-
655
-	}
656
-
657
-	/**
658
-	 * Update Meta Data in the database.
659
-	 *
660
-	 * @since 1.0.19
661
-	 */
662
-	public function save_meta_data() {
663
-		if ( ! $this->data_store || is_null( $this->meta_data ) ) {
664
-			return;
665
-		}
666
-		foreach ( $this->meta_data as $array_key => $meta ) {
667
-			if ( is_null( $meta->value ) ) {
668
-				if ( ! empty( $meta->id ) ) {
669
-					$this->data_store->delete_meta( $this, $meta );
670
-					unset( $this->meta_data[ $array_key ] );
671
-				}
672
-			} elseif ( empty( $meta->id ) ) {
673
-				$meta->id = $this->data_store->add_meta( $this, $meta );
674
-				$meta->apply_changes();
675
-			} else {
676
-				if ( $meta->get_changes() ) {
677
-					$this->data_store->update_meta( $this, $meta );
678
-					$meta->apply_changes();
679
-				}
680
-			}
681
-		}
682
-		if ( ! empty( $this->cache_group ) ) {
683
-			$cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
684
-			wp_cache_delete( $cache_key, $this->cache_group );
685
-		}
686
-	}
687
-
688
-	/**
689
-	 * Set ID.
690
-	 *
691
-	 * @since 1.0.19
692
-	 * @param int $id ID.
693
-	 */
694
-	public function set_id( $id ) {
695
-		$this->id = absint( $id );
696
-	}
697
-
698
-	/**
699
-	 * Sets item status.
700
-	 *
701
-	 * @since 1.0.19
702
-	 * @param string $status New status.
703
-	 * @return array details of change.
704
-	 */
705
-	public function set_status( $status ) {
394
+        return $this->get_prop( $key );
395
+
396
+    }
397
+
398
+    /**
399
+     * Get Meta Data by Key.
400
+     *
401
+     * @since  1.0.19
402
+     * @param  string $key Meta Key.
403
+     * @param  bool   $single return first found meta with key, or all with $key.
404
+     * @param  string $context What the value is for. Valid values are view and edit.
405
+     * @return mixed
406
+     */
407
+    public function get_meta( $key = '', $single = true, $context = 'view' ) {
408
+
409
+        // Check if this is an internal meta key.
410
+        $_key = str_replace( '_wpinv', '', $key );
411
+        $_key = str_replace( 'wpinv', '', $_key );
412
+        if ( $this->is_internal_meta_key( $_key ) ) {
413
+            $function = 'get_' . $_key;
414
+
415
+            if ( is_callable( array( $this, $function ) ) ) {
416
+                return $this->{$function}();
417
+            }
418
+        }
419
+
420
+        // Read the meta data if not yet read.
421
+        $this->maybe_read_meta_data();
422
+        $meta_data  = $this->get_meta_data();
423
+        $array_keys = array_keys( wp_list_pluck( $meta_data, 'key' ), $key, true );
424
+        $value      = $single ? '' : array();
425
+
426
+        if ( ! empty( $array_keys ) ) {
427
+            // We don't use the $this->meta_data property directly here because we don't want meta with a null value (i.e. meta which has been deleted via $this->delete_meta_data()).
428
+            if ( $single ) {
429
+                $value = $meta_data[ current( $array_keys ) ]->value;
430
+            } else {
431
+                $value = array_intersect_key( $meta_data, array_flip( $array_keys ) );
432
+            }
433
+        }
434
+
435
+        if ( 'view' === $context ) {
436
+            $value = apply_filters( $this->get_hook_prefix() . $key, $value, $this );
437
+        }
438
+
439
+        return $value;
440
+    }
441
+
442
+    /**
443
+     * See if meta data exists, since get_meta always returns a '' or array().
444
+     *
445
+     * @since  1.0.19
446
+     * @param  string $key Meta Key.
447
+     * @return boolean
448
+     */
449
+    public function meta_exists( $key = '' ) {
450
+        $this->maybe_read_meta_data();
451
+        $array_keys = wp_list_pluck( $this->get_meta_data(), 'key' );
452
+        return in_array( $key, $array_keys, true );
453
+    }
454
+
455
+    /**
456
+     * Set all meta data from array.
457
+     *
458
+     * @since 1.0.19
459
+     * @param array $data Key/Value pairs.
460
+     */
461
+    public function set_meta_data( $data ) {
462
+        if ( ! empty( $data ) && is_array( $data ) ) {
463
+            $this->maybe_read_meta_data();
464
+            foreach ( $data as $meta ) {
465
+                $meta = (array) $meta;
466
+                if ( isset( $meta['key'], $meta['value'], $meta['id'] ) ) {
467
+                    $this->meta_data[] = new GetPaid_Meta_Data(
468
+                        array(
469
+                            'id'    => $meta['id'],
470
+                            'key'   => $meta['key'],
471
+                            'value' => $meta['value'],
472
+                        )
473
+                    );
474
+                }
475
+            }
476
+        }
477
+    }
478
+
479
+    /**
480
+     * Add meta data.
481
+     *
482
+     * @since 1.0.19
483
+     *
484
+     * @param string       $key Meta key.
485
+     * @param string|array $value Meta value.
486
+     * @param bool         $unique Should this be a unique key?.
487
+     */
488
+    public function add_meta_data( $key, $value, $unique = false ) {
489
+        if ( $this->is_internal_meta_key( $key ) ) {
490
+            $function = 'set_' . $key;
491
+
492
+            if ( is_callable( array( $this, $function ) ) ) {
493
+                return $this->{$function}( $value );
494
+            }
495
+        }
496
+
497
+        $this->maybe_read_meta_data();
498
+        if ( $unique ) {
499
+            $this->delete_meta_data( $key );
500
+        }
501
+        $this->meta_data[] = new GetPaid_Meta_Data(
502
+            array(
503
+                'key'   => $key,
504
+                'value' => $value,
505
+            )
506
+        );
507
+    }
508
+
509
+    /**
510
+     * Update meta data by key or ID, if provided.
511
+     *
512
+     * @since  1.0.19
513
+     *
514
+     * @param  string       $key Meta key.
515
+     * @param  string|array $value Meta value.
516
+     * @param  int          $meta_id Meta ID.
517
+     */
518
+    public function update_meta_data( $key, $value, $meta_id = 0 ) {
519
+        if ( $this->is_internal_meta_key( $key ) ) {
520
+            $function = 'set_' . $key;
521
+
522
+            if ( is_callable( array( $this, $function ) ) ) {
523
+                return $this->{$function}( $value );
524
+            }
525
+        }
526
+
527
+        $this->maybe_read_meta_data();
528
+
529
+        $array_key = false;
530
+
531
+        if ( $meta_id ) {
532
+            $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), $meta_id, true );
533
+            $array_key  = $array_keys ? current( $array_keys ) : false;
534
+        } else {
535
+            // Find matches by key.
536
+            $matches = array();
537
+            foreach ( $this->meta_data as $meta_data_array_key => $meta ) {
538
+                if ( $meta->key === $key ) {
539
+                    $matches[] = $meta_data_array_key;
540
+                }
541
+            }
542
+
543
+            if ( ! empty( $matches ) ) {
544
+                // Set matches to null so only one key gets the new value.
545
+                foreach ( $matches as $meta_data_array_key ) {
546
+                    $this->meta_data[ $meta_data_array_key ]->value = null;
547
+                }
548
+                $array_key = current( $matches );
549
+            }
550
+        }
551
+
552
+        if ( false !== $array_key ) {
553
+            $meta        = $this->meta_data[ $array_key ];
554
+            $meta->key   = $key;
555
+            $meta->value = $value;
556
+        } else {
557
+            $this->add_meta_data( $key, $value, true );
558
+        }
559
+    }
560
+
561
+    /**
562
+     * Delete meta data.
563
+     *
564
+     * @since 1.0.19
565
+     * @param string $key Meta key.
566
+     */
567
+    public function delete_meta_data( $key ) {
568
+        $this->maybe_read_meta_data();
569
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'key' ), $key, true );
570
+
571
+        if ( $array_keys ) {
572
+            foreach ( $array_keys as $array_key ) {
573
+                $this->meta_data[ $array_key ]->value = null;
574
+            }
575
+        }
576
+    }
577
+
578
+    /**
579
+     * Delete meta data.
580
+     *
581
+     * @since 1.0.19
582
+     * @param int $mid Meta ID.
583
+     */
584
+    public function delete_meta_data_by_mid( $mid ) {
585
+        $this->maybe_read_meta_data();
586
+        $array_keys = array_keys( wp_list_pluck( $this->meta_data, 'id' ), (int) $mid, true );
587
+
588
+        if ( $array_keys ) {
589
+            foreach ( $array_keys as $array_key ) {
590
+                $this->meta_data[ $array_key ]->value = null;
591
+            }
592
+        }
593
+    }
594
+
595
+    /**
596
+     * Read meta data if null.
597
+     *
598
+     * @since 1.0.19
599
+     */
600
+    protected function maybe_read_meta_data() {
601
+        if ( is_null( $this->meta_data ) ) {
602
+            $this->read_meta_data();
603
+        }
604
+    }
605
+
606
+    /**
607
+     * Read Meta Data from the database. Ignore any internal properties.
608
+     * Uses it's own caches because get_metadata does not provide meta_ids.
609
+     *
610
+     * @since 1.0.19
611
+     * @param bool $force_read True to force a new DB read (and update cache).
612
+     */
613
+    public function read_meta_data( $force_read = false ) {
614
+
615
+        // Reset meta data.
616
+        $this->meta_data = array();
617
+
618
+        // Maybe abort early.
619
+        if ( ! $this->get_id() || ! $this->data_store ) {
620
+            return;
621
+        }
622
+
623
+        // Only read from cache if the cache key is set.
624
+        $cache_key = null;
625
+        if ( ! $force_read && ! empty( $this->cache_group ) ) {
626
+            $cache_key     = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
627
+            $raw_meta_data = wp_cache_get( $cache_key, $this->cache_group );
628
+        }
629
+
630
+        // Should we force read?
631
+        if ( empty( $raw_meta_data ) ) {
632
+            $raw_meta_data = $this->data_store->read_meta( $this );
633
+
634
+            if ( ! empty( $cache_key ) ) {
635
+                wp_cache_set( $cache_key, $raw_meta_data, $this->cache_group );
636
+            }
637
+
638
+        }
639
+
640
+        // Set meta data.
641
+        if ( is_array( $raw_meta_data ) ) {
642
+
643
+            foreach ( $raw_meta_data as $meta ) {
644
+                $this->meta_data[] = new GetPaid_Meta_Data(
645
+                    array(
646
+                        'id'    => (int) $meta->meta_id,
647
+                        'key'   => $meta->meta_key,
648
+                        'value' => maybe_unserialize( $meta->meta_value ),
649
+                    )
650
+                );
651
+            }
652
+
653
+        }
654
+
655
+    }
656
+
657
+    /**
658
+     * Update Meta Data in the database.
659
+     *
660
+     * @since 1.0.19
661
+     */
662
+    public function save_meta_data() {
663
+        if ( ! $this->data_store || is_null( $this->meta_data ) ) {
664
+            return;
665
+        }
666
+        foreach ( $this->meta_data as $array_key => $meta ) {
667
+            if ( is_null( $meta->value ) ) {
668
+                if ( ! empty( $meta->id ) ) {
669
+                    $this->data_store->delete_meta( $this, $meta );
670
+                    unset( $this->meta_data[ $array_key ] );
671
+                }
672
+            } elseif ( empty( $meta->id ) ) {
673
+                $meta->id = $this->data_store->add_meta( $this, $meta );
674
+                $meta->apply_changes();
675
+            } else {
676
+                if ( $meta->get_changes() ) {
677
+                    $this->data_store->update_meta( $this, $meta );
678
+                    $meta->apply_changes();
679
+                }
680
+            }
681
+        }
682
+        if ( ! empty( $this->cache_group ) ) {
683
+            $cache_key = GetPaid_Cache_Helper::get_cache_prefix( $this->cache_group ) . GetPaid_Cache_Helper::get_cache_prefix( 'object_' . $this->get_id() ) . 'object_meta_' . $this->get_id();
684
+            wp_cache_delete( $cache_key, $this->cache_group );
685
+        }
686
+    }
687
+
688
+    /**
689
+     * Set ID.
690
+     *
691
+     * @since 1.0.19
692
+     * @param int $id ID.
693
+     */
694
+    public function set_id( $id ) {
695
+        $this->id = absint( $id );
696
+    }
697
+
698
+    /**
699
+     * Sets item status.
700
+     *
701
+     * @since 1.0.19
702
+     * @param string $status New status.
703
+     * @return array details of change.
704
+     */
705
+    public function set_status( $status ) {
706 706
         $old_status = $this->get_status();
707 707
 
708
-		$this->set_prop( 'status', $status );
709
-
710
-		return array(
711
-			'from' => $old_status,
712
-			'to'   => $status,
713
-		);
714
-    }
715
-
716
-	/**
717
-	 * Set all props to default values.
718
-	 *
719
-	 * @since 1.0.19
720
-	 */
721
-	public function set_defaults() {
722
-		$this->data    = $this->default_data;
723
-		$this->changes = array();
724
-		$this->set_object_read( false );
725
-	}
726
-
727
-	/**
728
-	 * Set object read property.
729
-	 *
730
-	 * @since 1.0.19
731
-	 * @param boolean $read Should read?.
732
-	 */
733
-	public function set_object_read( $read = true ) {
734
-		$this->object_read = (bool) $read;
735
-	}
736
-
737
-	/**
738
-	 * Get object read property.
739
-	 *
740
-	 * @since  1.0.19
741
-	 * @return boolean
742
-	 */
743
-	public function get_object_read() {
744
-		return (bool) $this->object_read;
745
-	}
746
-
747
-	/**
748
-	 * Set a collection of props in one go, collect any errors, and return the result.
749
-	 * Only sets using public methods.
750
-	 *
751
-	 * @since  1.0.19
752
-	 *
753
-	 * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
754
-	 * @param string $context In what context to run this.
755
-	 *
756
-	 * @return bool|WP_Error
757
-	 */
758
-	public function set_props( $props, $context = 'set' ) {
759
-		$errors = false;
760
-
761
-		foreach ( $props as $prop => $value ) {
762
-			try {
763
-				/**
764
-				 * Checks if the prop being set is allowed, and the value is not null.
765
-				 */
766
-				if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
767
-					continue;
768
-				}
769
-				$setter = "set_$prop";
770
-
771
-				if ( is_callable( array( $this, $setter ) ) ) {
772
-					$this->{$setter}( $value );
773
-				}
774
-			} catch ( Exception $e ) {
775
-				if ( ! $errors ) {
776
-					$errors = new WP_Error();
777
-				}
778
-				$errors->add( $e->getCode(), $e->getMessage() );
779
-				$this->last_error = $e->getMessage();
780
-			}
781
-		}
782
-
783
-		return $errors && count( $errors->get_error_codes() ) ? $errors : true;
784
-	}
785
-
786
-	/**
787
-	 * Sets a prop for a setter method.
788
-	 *
789
-	 * This stores changes in a special array so we can track what needs saving
790
-	 * the the DB later.
791
-	 *
792
-	 * @since 1.0.19
793
-	 * @param string $prop Name of prop to set.
794
-	 * @param mixed  $value Value of the prop.
795
-	 */
796
-	protected function set_prop( $prop, $value ) {
797
-		if ( array_key_exists( $prop, $this->data ) ) {
798
-			if ( true === $this->object_read ) {
799
-				if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
800
-					$this->changes[ $prop ] = $value;
801
-				}
802
-			} else {
803
-				$this->data[ $prop ] = $value;
804
-			}
805
-		}
806
-	}
807
-
808
-	/**
809
-	 * Return data changes only.
810
-	 *
811
-	 * @since 1.0.19
812
-	 * @return array
813
-	 */
814
-	public function get_changes() {
815
-		return $this->changes;
816
-	}
817
-
818
-	/**
819
-	 * Merge changes with data and clear.
820
-	 *
821
-	 * @since 1.0.19
822
-	 */
823
-	public function apply_changes() {
824
-		$this->data    = array_replace_recursive( $this->data, $this->changes );
825
-		$this->changes = array();
826
-	}
827
-
828
-	/**
829
-	 * Prefix for action and filter hooks on data.
830
-	 *
831
-	 * @since  1.0.19
832
-	 * @return string
833
-	 */
834
-	protected function get_hook_prefix() {
835
-		return 'wpinv_get_' . $this->object_type . '_';
836
-	}
837
-
838
-	/**
839
-	 * Gets a prop for a getter method.
840
-	 *
841
-	 * Gets the value from either current pending changes, or the data itself.
842
-	 * Context controls what happens to the value before it's returned.
843
-	 *
844
-	 * @since  1.0.19
845
-	 * @param  string $prop Name of prop to get.
846
-	 * @param  string $context What the value is for. Valid values are view and edit.
847
-	 * @return mixed
848
-	 */
849
-	protected function get_prop( $prop, $context = 'view' ) {
850
-		$value = null;
851
-
852
-		if ( array_key_exists( $prop, $this->data ) ) {
853
-			$value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
854
-
855
-			if ( 'view' === $context ) {
856
-				$value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
857
-			}
858
-		}
859
-
860
-		return $value;
861
-	}
862
-
863
-	/**
864
-	 * Sets a date prop whilst handling formatting and datetime objects.
865
-	 *
866
-	 * @since 1.0.19
867
-	 * @param string         $prop Name of prop to set.
868
-	 * @param string|integer $value Value of the prop.
869
-	 */
870
-	protected function set_date_prop( $prop, $value ) {
871
-
872
-		if ( empty( $value ) ) {
873
-			$this->set_prop( $prop, null );
874
-			return;
875
-		}
876
-		$this->set_prop( $prop, $value );
877
-
878
-	}
879
-
880
-	/**
881
-	 * When invalid data is found, throw an exception unless reading from the DB.
882
-	 *
883
-	 * @since 1.0.19
884
-	 * @param string $code             Error code.
885
-	 * @param string $message          Error message.
886
-	 */
887
-	protected function error( $code, $message ) {
888
-		$this->last_error = $message;
889
-	}
890
-
891
-	/**
892
-	 * Checks if the object is saved in the database
893
-	 *
894
-	 * @since 1.0.19
895
-	 * @return bool
896
-	 */
897
-	public function exists() {
898
-		$id = $this->get_id();
899
-		return ! empty( $id );
900
-	}
708
+        $this->set_prop( 'status', $status );
709
+
710
+        return array(
711
+            'from' => $old_status,
712
+            'to'   => $status,
713
+        );
714
+    }
715
+
716
+    /**
717
+     * Set all props to default values.
718
+     *
719
+     * @since 1.0.19
720
+     */
721
+    public function set_defaults() {
722
+        $this->data    = $this->default_data;
723
+        $this->changes = array();
724
+        $this->set_object_read( false );
725
+    }
726
+
727
+    /**
728
+     * Set object read property.
729
+     *
730
+     * @since 1.0.19
731
+     * @param boolean $read Should read?.
732
+     */
733
+    public function set_object_read( $read = true ) {
734
+        $this->object_read = (bool) $read;
735
+    }
736
+
737
+    /**
738
+     * Get object read property.
739
+     *
740
+     * @since  1.0.19
741
+     * @return boolean
742
+     */
743
+    public function get_object_read() {
744
+        return (bool) $this->object_read;
745
+    }
746
+
747
+    /**
748
+     * Set a collection of props in one go, collect any errors, and return the result.
749
+     * Only sets using public methods.
750
+     *
751
+     * @since  1.0.19
752
+     *
753
+     * @param array  $props Key value pairs to set. Key is the prop and should map to a setter function name.
754
+     * @param string $context In what context to run this.
755
+     *
756
+     * @return bool|WP_Error
757
+     */
758
+    public function set_props( $props, $context = 'set' ) {
759
+        $errors = false;
760
+
761
+        foreach ( $props as $prop => $value ) {
762
+            try {
763
+                /**
764
+                 * Checks if the prop being set is allowed, and the value is not null.
765
+                 */
766
+                if ( is_null( $value ) || in_array( $prop, array( 'prop', 'date_prop', 'meta_data' ), true ) ) {
767
+                    continue;
768
+                }
769
+                $setter = "set_$prop";
770
+
771
+                if ( is_callable( array( $this, $setter ) ) ) {
772
+                    $this->{$setter}( $value );
773
+                }
774
+            } catch ( Exception $e ) {
775
+                if ( ! $errors ) {
776
+                    $errors = new WP_Error();
777
+                }
778
+                $errors->add( $e->getCode(), $e->getMessage() );
779
+                $this->last_error = $e->getMessage();
780
+            }
781
+        }
782
+
783
+        return $errors && count( $errors->get_error_codes() ) ? $errors : true;
784
+    }
785
+
786
+    /**
787
+     * Sets a prop for a setter method.
788
+     *
789
+     * This stores changes in a special array so we can track what needs saving
790
+     * the the DB later.
791
+     *
792
+     * @since 1.0.19
793
+     * @param string $prop Name of prop to set.
794
+     * @param mixed  $value Value of the prop.
795
+     */
796
+    protected function set_prop( $prop, $value ) {
797
+        if ( array_key_exists( $prop, $this->data ) ) {
798
+            if ( true === $this->object_read ) {
799
+                if ( $value !== $this->data[ $prop ] || array_key_exists( $prop, $this->changes ) ) {
800
+                    $this->changes[ $prop ] = $value;
801
+                }
802
+            } else {
803
+                $this->data[ $prop ] = $value;
804
+            }
805
+        }
806
+    }
807
+
808
+    /**
809
+     * Return data changes only.
810
+     *
811
+     * @since 1.0.19
812
+     * @return array
813
+     */
814
+    public function get_changes() {
815
+        return $this->changes;
816
+    }
817
+
818
+    /**
819
+     * Merge changes with data and clear.
820
+     *
821
+     * @since 1.0.19
822
+     */
823
+    public function apply_changes() {
824
+        $this->data    = array_replace_recursive( $this->data, $this->changes );
825
+        $this->changes = array();
826
+    }
827
+
828
+    /**
829
+     * Prefix for action and filter hooks on data.
830
+     *
831
+     * @since  1.0.19
832
+     * @return string
833
+     */
834
+    protected function get_hook_prefix() {
835
+        return 'wpinv_get_' . $this->object_type . '_';
836
+    }
837
+
838
+    /**
839
+     * Gets a prop for a getter method.
840
+     *
841
+     * Gets the value from either current pending changes, or the data itself.
842
+     * Context controls what happens to the value before it's returned.
843
+     *
844
+     * @since  1.0.19
845
+     * @param  string $prop Name of prop to get.
846
+     * @param  string $context What the value is for. Valid values are view and edit.
847
+     * @return mixed
848
+     */
849
+    protected function get_prop( $prop, $context = 'view' ) {
850
+        $value = null;
851
+
852
+        if ( array_key_exists( $prop, $this->data ) ) {
853
+            $value = array_key_exists( $prop, $this->changes ) ? $this->changes[ $prop ] : $this->data[ $prop ];
854
+
855
+            if ( 'view' === $context ) {
856
+                $value = apply_filters( $this->get_hook_prefix() . $prop, $value, $this );
857
+            }
858
+        }
859
+
860
+        return $value;
861
+    }
862
+
863
+    /**
864
+     * Sets a date prop whilst handling formatting and datetime objects.
865
+     *
866
+     * @since 1.0.19
867
+     * @param string         $prop Name of prop to set.
868
+     * @param string|integer $value Value of the prop.
869
+     */
870
+    protected function set_date_prop( $prop, $value ) {
871
+
872
+        if ( empty( $value ) ) {
873
+            $this->set_prop( $prop, null );
874
+            return;
875
+        }
876
+        $this->set_prop( $prop, $value );
877
+
878
+    }
879
+
880
+    /**
881
+     * When invalid data is found, throw an exception unless reading from the DB.
882
+     *
883
+     * @since 1.0.19
884
+     * @param string $code             Error code.
885
+     * @param string $message          Error message.
886
+     */
887
+    protected function error( $code, $message ) {
888
+        $this->last_error = $message;
889
+    }
890
+
891
+    /**
892
+     * Checks if the object is saved in the database
893
+     *
894
+     * @since 1.0.19
895
+     * @return bool
896
+     */
897
+    public function exists() {
898
+        $id = $this->get_id();
899
+        return ! empty( $id );
900
+    }
901 901
 
902 902
 }
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Indentation   +2348 added lines, -2348 removed lines patch added patch discarded remove patch
@@ -14,30 +14,30 @@  discard block
 block discarded – undo
14 14
 class WPInv_Invoice extends GetPaid_Data {
15 15
 
16 16
     /**
17
-	 * Which data store to load.
18
-	 *
19
-	 * @var string
20
-	 */
17
+     * Which data store to load.
18
+     *
19
+     * @var string
20
+     */
21 21
     protected $data_store_name = 'invoice';
22 22
 
23 23
     /**
24
-	 * This is the name of this object type.
25
-	 *
26
-	 * @var string
27
-	 */
24
+     * This is the name of this object type.
25
+     *
26
+     * @var string
27
+     */
28 28
     protected $object_type = 'invoice';
29 29
 
30 30
     /**
31
-	 * Item Data array. This is the core item data exposed in APIs.
32
-	 *
33
-	 * @since 1.0.19
34
-	 * @var array
35
-	 */
36
-	protected $data = array(
37
-		'parent_id'            => 0,
38
-		'status'               => 'wpi-pending',
39
-		'version'              => '',
40
-		'date_created'         => null,
31
+     * Item Data array. This is the core item data exposed in APIs.
32
+     *
33
+     * @since 1.0.19
34
+     * @var array
35
+     */
36
+    protected $data = array(
37
+        'parent_id'            => 0,
38
+        'status'               => 'wpi-pending',
39
+        'version'              => '',
40
+        'date_created'         => null,
41 41
         'date_modified'        => null,
42 42
         'due_date'             => null,
43 43
         'completed_date'       => null,
@@ -79,22 +79,22 @@  discard block
 block discarded – undo
79 79
         'transaction_id'       => '',
80 80
         'currency'             => '',
81 81
         'disable_taxes'        => false,
82
-		'subscription_id'      => null,
83
-		'remote_subscription_id' => null,
84
-		'is_viewed'            => false,
85
-		'email_cc'             => '',
86
-		'template'             => 'quantity', // hours, amount only
87
-		'created_via'          => null,
82
+        'subscription_id'      => null,
83
+        'remote_subscription_id' => null,
84
+        'is_viewed'            => false,
85
+        'email_cc'             => '',
86
+        'template'             => 'quantity', // hours, amount only
87
+        'created_via'          => null,
88 88
     );
89 89
 
90 90
     /**
91
-	 * Stores meta in cache for future reads.
92
-	 *
93
-	 * A group must be set to to enable caching.
94
-	 *
95
-	 * @var string
96
-	 */
97
-	protected $cache_group = 'getpaid_invoices';
91
+     * Stores meta in cache for future reads.
92
+     *
93
+     * A group must be set to to enable caching.
94
+     *
95
+     * @var string
96
+     */
97
+    protected $cache_group = 'getpaid_invoices';
98 98
 
99 99
     /**
100 100
      * Stores a reference to the original WP_Post object
@@ -108,104 +108,104 @@  discard block
 block discarded – undo
108 108
      *
109 109
      * @var int
110 110
      */
111
-	protected $recurring_item = null;
111
+    protected $recurring_item = null;
112 112
 
113
-	/**
113
+    /**
114 114
      * Stores an array of item totals.
115
-	 *
116
-	 * e.g $totals['discount'] = array(
117
-	 * 		'initial'   => 10,
118
-	 * 		'recurring' => 10,
119
-	 * )
115
+     *
116
+     * e.g $totals['discount'] = array(
117
+     * 		'initial'   => 10,
118
+     * 		'recurring' => 10,
119
+     * )
120 120
      *
121 121
      * @var array
122 122
      */
123
-	protected $totals = array();
123
+    protected $totals = array();
124 124
 
125
-	/**
126
-	 * Stores the status transition information.
127
-	 *
128
-	 * @since 1.0.19
129
-	 * @var bool|array
130
-	 */
131
-	protected $status_transition = false;
125
+    /**
126
+     * Stores the status transition information.
127
+     *
128
+     * @since 1.0.19
129
+     * @var bool|array
130
+     */
131
+    protected $status_transition = false;
132 132
 
133 133
     /**
134
-	 * Get the invoice if ID is passed, otherwise the invoice is new and empty.
135
-	 *
136
-	 * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
137
-	 */
134
+     * Get the invoice if ID is passed, otherwise the invoice is new and empty.
135
+     *
136
+     * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
137
+     */
138 138
     public function __construct( $invoice = 0 ) {
139 139
 
140 140
         parent::__construct( $invoice );
141 141
 
142
-		if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) {
143
-			$this->set_id( (int) $invoice );
144
-		} elseif ( $invoice instanceof self ) {
145
-			$this->set_id( $invoice->get_id() );
146
-		} elseif ( ! empty( $invoice->ID ) ) {
147
-			$this->set_id( $invoice->ID );
148
-		} elseif ( is_array( $invoice ) ) {
149
-			$this->set_props( $invoice );
150
-
151
-			if ( isset( $invoice['ID'] ) ) {
152
-				$this->set_id( $invoice['ID'] );
153
-			}
154
-
155
-		} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
156
-			$this->set_id( $invoice_id );
157
-		} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
158
-			$this->set_id( $invoice_id );
159
-		} elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
160
-			$this->set_id( $invoice_id );
161
-		}else {
162
-			$this->set_object_read( true );
163
-		}
142
+        if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( (int) $invoice ) ) ) {
143
+            $this->set_id( (int) $invoice );
144
+        } elseif ( $invoice instanceof self ) {
145
+            $this->set_id( $invoice->get_id() );
146
+        } elseif ( ! empty( $invoice->ID ) ) {
147
+            $this->set_id( $invoice->ID );
148
+        } elseif ( is_array( $invoice ) ) {
149
+            $this->set_props( $invoice );
150
+
151
+            if ( isset( $invoice['ID'] ) ) {
152
+                $this->set_id( $invoice['ID'] );
153
+            }
154
+
155
+        } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
156
+            $this->set_id( $invoice_id );
157
+        } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
158
+            $this->set_id( $invoice_id );
159
+        } elseif ( is_string( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
160
+            $this->set_id( $invoice_id );
161
+        }else {
162
+            $this->set_object_read( true );
163
+        }
164 164
 
165 165
         // Load the datastore.
166
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
166
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
167 167
 
168
-		if ( $this->get_id() > 0 ) {
168
+        if ( $this->get_id() > 0 ) {
169 169
             $this->post = get_post( $this->get_id() );
170 170
             $this->ID   = $this->get_id();
171
-			$this->data_store->read( $this );
171
+            $this->data_store->read( $this );
172 172
         }
173 173
 
174 174
     }
175 175
 
176 176
     /**
177
-	 * Given an invoice key/number, it returns its id.
178
-	 *
179
-	 *
180
-	 * @static
181
-	 * @param string $value The invoice key or number
182
-	 * @param string $field Either key, transaction_id or number.
183
-	 * @since 1.0.15
184
-	 * @return int
185
-	 */
186
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
177
+     * Given an invoice key/number, it returns its id.
178
+     *
179
+     *
180
+     * @static
181
+     * @param string $value The invoice key or number
182
+     * @param string $field Either key, transaction_id or number.
183
+     * @since 1.0.15
184
+     * @return int
185
+     */
186
+    public static function get_invoice_id_by_field( $value, $field = 'key' ) {
187 187
         global $wpdb;
188 188
 
189
-		// Trim the value.
190
-		$value = trim( $value );
189
+        // Trim the value.
190
+        $value = trim( $value );
191 191
 
192
-		if ( empty( $value ) ) {
193
-			return 0;
194
-		}
192
+        if ( empty( $value ) ) {
193
+            return 0;
194
+        }
195 195
 
196 196
         // Valid fields.
197 197
         $fields = array( 'key', 'number', 'transaction_id' );
198 198
 
199
-		// Ensure a field has been passed.
200
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
201
-			return 0;
202
-		}
199
+        // Ensure a field has been passed.
200
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
201
+            return 0;
202
+        }
203 203
 
204
-		// Maybe retrieve from the cache.
205
-		$invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
206
-		if ( false !== $invoice_id ) {
207
-			return $invoice_id;
208
-		}
204
+        // Maybe retrieve from the cache.
205
+        $invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
206
+        if ( false !== $invoice_id ) {
207
+            return $invoice_id;
208
+        }
209 209
 
210 210
         // Fetch from the db.
211 211
         $table       = $wpdb->prefix . 'getpaid_invoices';
@@ -213,10 +213,10 @@  discard block
 block discarded – undo
213 213
             $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
214 214
         );
215 215
 
216
-		// Update the cache with our data
217
-		wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
216
+        // Update the cache with our data
217
+        wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
218 218
 
219
-		return $invoice_id;
219
+        return $invoice_id;
220 220
     }
221 221
 
222 222
     /**
@@ -242,72 +242,72 @@  discard block
 block discarded – undo
242 242
     */
243 243
 
244 244
     /**
245
-	 * Get parent invoice ID.
246
-	 *
247
-	 * @since 1.0.19
248
-	 * @param  string $context View or edit context.
249
-	 * @return int
250
-	 */
251
-	public function get_parent_id( $context = 'view' ) {
252
-		return (int) $this->get_prop( 'parent_id', $context );
245
+     * Get parent invoice ID.
246
+     *
247
+     * @since 1.0.19
248
+     * @param  string $context View or edit context.
249
+     * @return int
250
+     */
251
+    public function get_parent_id( $context = 'view' ) {
252
+        return (int) $this->get_prop( 'parent_id', $context );
253 253
     }
254 254
 
255 255
     /**
256
-	 * Get parent invoice.
257
-	 *
258
-	 * @since 1.0.19
259
-	 * @return WPInv_Invoice
260
-	 */
256
+     * Get parent invoice.
257
+     *
258
+     * @since 1.0.19
259
+     * @return WPInv_Invoice
260
+     */
261 261
     public function get_parent_payment() {
262 262
         return new WPInv_Invoice( $this->get_parent_id() );
263 263
     }
264 264
 
265 265
     /**
266
-	 * Alias for self::get_parent_payment().
267
-	 *
268
-	 * @since 1.0.19
269
-	 * @return WPInv_Invoice
270
-	 */
266
+     * Alias for self::get_parent_payment().
267
+     *
268
+     * @since 1.0.19
269
+     * @return WPInv_Invoice
270
+     */
271 271
     public function get_parent() {
272 272
         return $this->get_parent_payment();
273 273
     }
274 274
 
275 275
     /**
276
-	 * Get invoice status.
277
-	 *
278
-	 * @since 1.0.19
279
-	 * @param  string $context View or edit context.
280
-	 * @return string
281
-	 */
282
-	public function get_status( $context = 'view' ) {
283
-		return $this->get_prop( 'status', $context );
284
-	}
276
+     * Get invoice status.
277
+     *
278
+     * @since 1.0.19
279
+     * @param  string $context View or edit context.
280
+     * @return string
281
+     */
282
+    public function get_status( $context = 'view' ) {
283
+        return $this->get_prop( 'status', $context );
284
+    }
285 285
 	
286
-	/**
287
-	 * Retrieves an array of possible invoice statuses.
288
-	 *
289
-	 * @since 1.0.19
290
-	 * @return array
291
-	 */
292
-	public function get_all_statuses() {
293
-		return wpinv_get_invoice_statuses( true, true, $this );
294
-    }
295
-
296
-    /**
297
-	 * Get invoice status nice name.
298
-	 *
299
-	 * @since 1.0.19
300
-	 * @return string
301
-	 */
286
+    /**
287
+     * Retrieves an array of possible invoice statuses.
288
+     *
289
+     * @since 1.0.19
290
+     * @return array
291
+     */
292
+    public function get_all_statuses() {
293
+        return wpinv_get_invoice_statuses( true, true, $this );
294
+    }
295
+
296
+    /**
297
+     * Get invoice status nice name.
298
+     *
299
+     * @since 1.0.19
300
+     * @return string
301
+     */
302 302
     public function get_status_nicename() {
303
-		$statuses = $this->get_all_statuses();
303
+        $statuses = $this->get_all_statuses();
304 304
 
305 305
         $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
306 306
 
307 307
         return apply_filters( 'wpinv_get_invoice_status_nicename', $status, $this );
308 308
     }
309 309
 
310
-	/**
310
+    /**
311 311
      * Retrieves the invoice status label html
312 312
      *
313 313
      * @since  1.0.0
@@ -315,262 +315,262 @@  discard block
 block discarded – undo
315 315
      */
316 316
     public function get_status_label_html() {
317 317
 
318
-		$status_label = sanitize_text_field( $this->get_status_nicename() );
319
-		$status       = sanitize_html_class( $this->get_status() );
318
+        $status_label = sanitize_text_field( $this->get_status_nicename() );
319
+        $status       = sanitize_html_class( $this->get_status() );
320 320
 
321
-		return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>";
322
-	}
321
+        return "<span class='bsui'><span class='d-inline-block py-2 px-3 rounded getpaid-invoice-status-$status'>$status_label</span></span>";
322
+    }
323 323
 
324 324
     /**
325
-	 * Get plugin version when the invoice was created.
326
-	 *
327
-	 * @since 1.0.19
328
-	 * @param  string $context View or edit context.
329
-	 * @return string
330
-	 */
331
-	public function get_version( $context = 'view' ) {
332
-		return $this->get_prop( 'version', $context );
333
-	}
325
+     * Get plugin version when the invoice was created.
326
+     *
327
+     * @since 1.0.19
328
+     * @param  string $context View or edit context.
329
+     * @return string
330
+     */
331
+    public function get_version( $context = 'view' ) {
332
+        return $this->get_prop( 'version', $context );
333
+    }
334 334
 
335
-	/**
336
-	 * @deprecated
337
-	 */
338
-	public function get_invoice_date( $format = true ) {
339
-		$date      = getpaid_format_date( $this->get_date_completed() );
340
-		$date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
341
-		$formatted = getpaid_format_date( $date );
335
+    /**
336
+     * @deprecated
337
+     */
338
+    public function get_invoice_date( $format = true ) {
339
+        $date      = getpaid_format_date( $this->get_date_completed() );
340
+        $date      = empty( $date ) ? $this->get_date_created() : $this->get_date_completed();
341
+        $formatted = getpaid_format_date( $date );
342 342
 
343
-		if ( $format ) {
344
-			return $formatted;
345
-		}
343
+        if ( $format ) {
344
+            return $formatted;
345
+        }
346 346
 
347
-		return empty( $formatted ) ? '' : $date;
347
+        return empty( $formatted ) ? '' : $date;
348 348
 
349 349
     }
350 350
 
351 351
     /**
352
-	 * Get date when the invoice was created.
353
-	 *
354
-	 * @since 1.0.19
355
-	 * @param  string $context View or edit context.
356
-	 * @return string
357
-	 */
358
-	public function get_date_created( $context = 'view' ) {
359
-		return $this->get_prop( 'date_created', $context );
360
-	}
352
+     * Get date when the invoice was created.
353
+     *
354
+     * @since 1.0.19
355
+     * @param  string $context View or edit context.
356
+     * @return string
357
+     */
358
+    public function get_date_created( $context = 'view' ) {
359
+        return $this->get_prop( 'date_created', $context );
360
+    }
361 361
 	
362
-	/**
363
-	 * Alias for self::get_date_created().
364
-	 *
365
-	 * @since 1.0.19
366
-	 * @param  string $context View or edit context.
367
-	 * @return string
368
-	 */
369
-	public function get_created_date( $context = 'view' ) {
370
-		return $this->get_date_created( $context );
371
-    }
372
-
373
-    /**
374
-	 * Get GMT date when the invoice was created.
375
-	 *
376
-	 * @since 1.0.19
377
-	 * @param  string $context View or edit context.
378
-	 * @return string
379
-	 */
380
-	public function get_date_created_gmt( $context = 'view' ) {
362
+    /**
363
+     * Alias for self::get_date_created().
364
+     *
365
+     * @since 1.0.19
366
+     * @param  string $context View or edit context.
367
+     * @return string
368
+     */
369
+    public function get_created_date( $context = 'view' ) {
370
+        return $this->get_date_created( $context );
371
+    }
372
+
373
+    /**
374
+     * Get GMT date when the invoice was created.
375
+     *
376
+     * @since 1.0.19
377
+     * @param  string $context View or edit context.
378
+     * @return string
379
+     */
380
+    public function get_date_created_gmt( $context = 'view' ) {
381 381
         $date = $this->get_date_created( $context );
382 382
 
383 383
         if ( $date ) {
384 384
             $date = get_gmt_from_date( $date );
385 385
         }
386
-		return $date;
386
+        return $date;
387 387
     }
388 388
 
389 389
     /**
390
-	 * Get date when the invoice was last modified.
391
-	 *
392
-	 * @since 1.0.19
393
-	 * @param  string $context View or edit context.
394
-	 * @return string
395
-	 */
396
-	public function get_date_modified( $context = 'view' ) {
397
-		return $this->get_prop( 'date_modified', $context );
398
-	}
390
+     * Get date when the invoice was last modified.
391
+     *
392
+     * @since 1.0.19
393
+     * @param  string $context View or edit context.
394
+     * @return string
395
+     */
396
+    public function get_date_modified( $context = 'view' ) {
397
+        return $this->get_prop( 'date_modified', $context );
398
+    }
399 399
 
400
-	/**
401
-	 * Alias for self::get_date_modified().
402
-	 *
403
-	 * @since 1.0.19
404
-	 * @param  string $context View or edit context.
405
-	 * @return string
406
-	 */
407
-	public function get_modified_date( $context = 'view' ) {
408
-		return $this->get_date_modified( $context );
400
+    /**
401
+     * Alias for self::get_date_modified().
402
+     *
403
+     * @since 1.0.19
404
+     * @param  string $context View or edit context.
405
+     * @return string
406
+     */
407
+    public function get_modified_date( $context = 'view' ) {
408
+        return $this->get_date_modified( $context );
409 409
     }
410 410
 
411 411
     /**
412
-	 * Get GMT date when the invoice was last modified.
413
-	 *
414
-	 * @since 1.0.19
415
-	 * @param  string $context View or edit context.
416
-	 * @return string
417
-	 */
418
-	public function get_date_modified_gmt( $context = 'view' ) {
412
+     * Get GMT date when the invoice was last modified.
413
+     *
414
+     * @since 1.0.19
415
+     * @param  string $context View or edit context.
416
+     * @return string
417
+     */
418
+    public function get_date_modified_gmt( $context = 'view' ) {
419 419
         $date = $this->get_date_modified( $context );
420 420
 
421 421
         if ( $date ) {
422 422
             $date = get_gmt_from_date( $date );
423 423
         }
424
-		return $date;
424
+        return $date;
425 425
     }
426 426
 
427 427
     /**
428
-	 * Get the invoice due date.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $context View or edit context.
432
-	 * @return string
433
-	 */
434
-	public function get_due_date( $context = 'view' ) {
435
-		return $this->get_prop( 'due_date', $context );
428
+     * Get the invoice due date.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $context View or edit context.
432
+     * @return string
433
+     */
434
+    public function get_due_date( $context = 'view' ) {
435
+        return $this->get_prop( 'due_date', $context );
436 436
     }
437 437
 
438 438
     /**
439
-	 * Alias for self::get_due_date().
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @param  string $context View or edit context.
443
-	 * @return string
444
-	 */
445
-	public function get_date_due( $context = 'view' ) {
446
-		return $this->get_due_date( $context );
439
+     * Alias for self::get_due_date().
440
+     *
441
+     * @since 1.0.19
442
+     * @param  string $context View or edit context.
443
+     * @return string
444
+     */
445
+    public function get_date_due( $context = 'view' ) {
446
+        return $this->get_due_date( $context );
447 447
     }
448 448
 
449 449
     /**
450
-	 * Get the invoice GMT due date.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return string
455
-	 */
456
-	public function get_due_date_gmt( $context = 'view' ) {
450
+     * Get the invoice GMT due date.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return string
455
+     */
456
+    public function get_due_date_gmt( $context = 'view' ) {
457 457
         $date = $this->get_due_date( $context );
458 458
 
459 459
         if ( $date ) {
460 460
             $date = get_gmt_from_date( $date );
461 461
         }
462
-		return $date;
462
+        return $date;
463 463
     }
464 464
 
465 465
     /**
466
-	 * Alias for self::get_due_date_gmt().
467
-	 *
468
-	 * @since 1.0.19
469
-	 * @param  string $context View or edit context.
470
-	 * @return string
471
-	 */
472
-	public function get_gmt_date_due( $context = 'view' ) {
473
-		return $this->get_due_date_gmt( $context );
466
+     * Alias for self::get_due_date_gmt().
467
+     *
468
+     * @since 1.0.19
469
+     * @param  string $context View or edit context.
470
+     * @return string
471
+     */
472
+    public function get_gmt_date_due( $context = 'view' ) {
473
+        return $this->get_due_date_gmt( $context );
474 474
     }
475 475
 
476 476
     /**
477
-	 * Get date when the invoice was completed.
478
-	 *
479
-	 * @since 1.0.19
480
-	 * @param  string $context View or edit context.
481
-	 * @return string
482
-	 */
483
-	public function get_completed_date( $context = 'view' ) {
484
-		return $this->get_prop( 'completed_date', $context );
477
+     * Get date when the invoice was completed.
478
+     *
479
+     * @since 1.0.19
480
+     * @param  string $context View or edit context.
481
+     * @return string
482
+     */
483
+    public function get_completed_date( $context = 'view' ) {
484
+        return $this->get_prop( 'completed_date', $context );
485 485
     }
486 486
 
487 487
     /**
488
-	 * Alias for self::get_completed_date().
489
-	 *
490
-	 * @since 1.0.19
491
-	 * @param  string $context View or edit context.
492
-	 * @return string
493
-	 */
494
-	public function get_date_completed( $context = 'view' ) {
495
-		return $this->get_completed_date( $context );
488
+     * Alias for self::get_completed_date().
489
+     *
490
+     * @since 1.0.19
491
+     * @param  string $context View or edit context.
492
+     * @return string
493
+     */
494
+    public function get_date_completed( $context = 'view' ) {
495
+        return $this->get_completed_date( $context );
496 496
     }
497 497
 
498 498
     /**
499
-	 * Get GMT date when the invoice was was completed.
500
-	 *
501
-	 * @since 1.0.19
502
-	 * @param  string $context View or edit context.
503
-	 * @return string
504
-	 */
505
-	public function get_completed_date_gmt( $context = 'view' ) {
499
+     * Get GMT date when the invoice was was completed.
500
+     *
501
+     * @since 1.0.19
502
+     * @param  string $context View or edit context.
503
+     * @return string
504
+     */
505
+    public function get_completed_date_gmt( $context = 'view' ) {
506 506
         $date = $this->get_completed_date( $context );
507 507
 
508 508
         if ( $date ) {
509 509
             $date = get_gmt_from_date( $date );
510 510
         }
511
-		return $date;
511
+        return $date;
512 512
     }
513 513
 
514 514
     /**
515
-	 * Alias for self::get_completed_date_gmt().
516
-	 *
517
-	 * @since 1.0.19
518
-	 * @param  string $context View or edit context.
519
-	 * @return string
520
-	 */
521
-	public function get_gmt_completed_date( $context = 'view' ) {
522
-		return $this->get_completed_date_gmt( $context );
515
+     * Alias for self::get_completed_date_gmt().
516
+     *
517
+     * @since 1.0.19
518
+     * @param  string $context View or edit context.
519
+     * @return string
520
+     */
521
+    public function get_gmt_completed_date( $context = 'view' ) {
522
+        return $this->get_completed_date_gmt( $context );
523 523
     }
524 524
 
525 525
     /**
526
-	 * Get the invoice number.
527
-	 *
528
-	 * @since 1.0.19
529
-	 * @param  string $context View or edit context.
530
-	 * @return string
531
-	 */
532
-	public function get_number( $context = 'view' ) {
533
-		$number = $this->get_prop( 'number', $context );
526
+     * Get the invoice number.
527
+     *
528
+     * @since 1.0.19
529
+     * @param  string $context View or edit context.
530
+     * @return string
531
+     */
532
+    public function get_number( $context = 'view' ) {
533
+        $number = $this->get_prop( 'number', $context );
534 534
 
535
-		if ( empty( $number ) ) {
536
-			$number = $this->generate_number();
537
-			$this->set_number( $this->generate_number() );
538
-		}
535
+        if ( empty( $number ) ) {
536
+            $number = $this->generate_number();
537
+            $this->set_number( $this->generate_number() );
538
+        }
539 539
 
540
-		return $number;
540
+        return $number;
541 541
     }
542 542
 
543
-	/**
544
-	 * Set the invoice number.
545
-	 *
546
-	 * @since 1.0.19
547
-	 */
548
-	public function maybe_set_number() {
543
+    /**
544
+     * Set the invoice number.
545
+     *
546
+     * @since 1.0.19
547
+     */
548
+    public function maybe_set_number() {
549 549
         $number = $this->get_number();
550 550
 
551 551
         if ( empty( $number ) || $this->get_id() == $number ) {
552
-			$this->set_number( $this->generate_number() );
552
+            $this->set_number( $this->generate_number() );
553 553
         }
554 554
 
555
-	}
555
+    }
556 556
 
557 557
     /**
558
-	 * Get the invoice key.
559
-	 *
560
-	 * @since 1.0.19
561
-	 * @param  string $context View or edit context.
562
-	 * @return string
563
-	 */
564
-	public function get_key( $context = 'view' ) {
558
+     * Get the invoice key.
559
+     *
560
+     * @since 1.0.19
561
+     * @param  string $context View or edit context.
562
+     * @return string
563
+     */
564
+    public function get_key( $context = 'view' ) {
565 565
         return $this->get_prop( 'key', $context );
566
-	}
567
-
568
-	/**
569
-	 * Set the invoice key.
570
-	 *
571
-	 * @since 1.0.19
572
-	 */
573
-	public function maybe_set_key() {
566
+    }
567
+
568
+    /**
569
+     * Set the invoice key.
570
+     *
571
+     * @since 1.0.19
572
+     */
573
+    public function maybe_set_key() {
574 574
         $key = $this->get_key();
575 575
 
576 576
         if ( empty( $key ) ) {
@@ -581,126 +581,126 @@  discard block
 block discarded – undo
581 581
     }
582 582
 
583 583
     /**
584
-	 * Get the invoice type.
585
-	 *
586
-	 * @since 1.0.19
587
-	 * @param  string $context View or edit context.
588
-	 * @return string
589
-	 */
590
-	public function get_type( $context = 'view' ) {
584
+     * Get the invoice type.
585
+     *
586
+     * @since 1.0.19
587
+     * @param  string $context View or edit context.
588
+     * @return string
589
+     */
590
+    public function get_type( $context = 'view' ) {
591 591
         return $this->get_prop( 'type', $context );
592
-	}
592
+    }
593 593
 
594
-	/**
595
-	 * @deprecated
596
-	 */
597
-	public function get_invoice_quote_type() {
594
+    /**
595
+     * @deprecated
596
+     */
597
+    public function get_invoice_quote_type() {
598 598
         ucfirst( $this->get_type() );
599 599
     }
600 600
 
601 601
     /**
602
-	 * Get the invoice post type.
603
-	 *
604
-	 * @since 1.0.19
605
-	 * @param  string $context View or edit context.
606
-	 * @return string
607
-	 */
608
-	public function get_post_type( $context = 'view' ) {
602
+     * Get the invoice post type.
603
+     *
604
+     * @since 1.0.19
605
+     * @param  string $context View or edit context.
606
+     * @return string
607
+     */
608
+    public function get_post_type( $context = 'view' ) {
609 609
         return $this->get_prop( 'post_type', $context );
610 610
     }
611 611
 
612 612
     /**
613
-	 * Get the invoice mode.
614
-	 *
615
-	 * @since 1.0.19
616
-	 * @param  string $context View or edit context.
617
-	 * @return string
618
-	 */
619
-	public function get_mode( $context = 'view' ) {
613
+     * Get the invoice mode.
614
+     *
615
+     * @since 1.0.19
616
+     * @param  string $context View or edit context.
617
+     * @return string
618
+     */
619
+    public function get_mode( $context = 'view' ) {
620 620
         return $this->get_prop( 'mode', $context );
621 621
     }
622 622
 
623 623
     /**
624
-	 * Get the invoice path.
625
-	 *
626
-	 * @since 1.0.19
627
-	 * @param  string $context View or edit context.
628
-	 * @return string
629
-	 */
630
-	public function get_path( $context = 'view' ) {
624
+     * Get the invoice path.
625
+     *
626
+     * @since 1.0.19
627
+     * @param  string $context View or edit context.
628
+     * @return string
629
+     */
630
+    public function get_path( $context = 'view' ) {
631 631
         $path   = $this->get_prop( 'path', $context );
632
-		$prefix = $this->get_type();
632
+        $prefix = $this->get_type();
633 633
 
634
-		if ( 0 !== strpos( $path, $prefix ) ) {
635
-			$path = sanitize_title(  $prefix . '-' . $this->get_id()  );
636
-			$this->set_path( $path );
637
-		}
634
+        if ( 0 !== strpos( $path, $prefix ) ) {
635
+            $path = sanitize_title(  $prefix . '-' . $this->get_id()  );
636
+            $this->set_path( $path );
637
+        }
638 638
 
639
-		return $path;
639
+        return $path;
640 640
     }
641 641
 
642 642
     /**
643
-	 * Get the invoice name/title.
644
-	 *
645
-	 * @since 1.0.19
646
-	 * @param  string $context View or edit context.
647
-	 * @return string
648
-	 */
649
-	public function get_name( $context = 'view' ) {
643
+     * Get the invoice name/title.
644
+     *
645
+     * @since 1.0.19
646
+     * @param  string $context View or edit context.
647
+     * @return string
648
+     */
649
+    public function get_name( $context = 'view' ) {
650 650
         return $this->get_prop( 'title', $context );
651 651
     }
652 652
 
653 653
     /**
654
-	 * Alias of self::get_name().
655
-	 *
656
-	 * @since 1.0.19
657
-	 * @param  string $context View or edit context.
658
-	 * @return string
659
-	 */
660
-	public function get_title( $context = 'view' ) {
661
-		return $this->get_name( $context );
654
+     * Alias of self::get_name().
655
+     *
656
+     * @since 1.0.19
657
+     * @param  string $context View or edit context.
658
+     * @return string
659
+     */
660
+    public function get_title( $context = 'view' ) {
661
+        return $this->get_name( $context );
662 662
     }
663 663
 
664 664
     /**
665
-	 * Get the invoice description.
666
-	 *
667
-	 * @since 1.0.19
668
-	 * @param  string $context View or edit context.
669
-	 * @return string
670
-	 */
671
-	public function get_description( $context = 'view' ) {
672
-		return $this->get_prop( 'description', $context );
665
+     * Get the invoice description.
666
+     *
667
+     * @since 1.0.19
668
+     * @param  string $context View or edit context.
669
+     * @return string
670
+     */
671
+    public function get_description( $context = 'view' ) {
672
+        return $this->get_prop( 'description', $context );
673 673
     }
674 674
 
675 675
     /**
676
-	 * Alias of self::get_description().
677
-	 *
678
-	 * @since 1.0.19
679
-	 * @param  string $context View or edit context.
680
-	 * @return string
681
-	 */
682
-	public function get_excerpt( $context = 'view' ) {
683
-		return $this->get_description( $context );
676
+     * Alias of self::get_description().
677
+     *
678
+     * @since 1.0.19
679
+     * @param  string $context View or edit context.
680
+     * @return string
681
+     */
682
+    public function get_excerpt( $context = 'view' ) {
683
+        return $this->get_description( $context );
684 684
     }
685 685
 
686 686
     /**
687
-	 * Alias of self::get_description().
688
-	 *
689
-	 * @since 1.0.19
690
-	 * @param  string $context View or edit context.
691
-	 * @return string
692
-	 */
693
-	public function get_summary( $context = 'view' ) {
694
-		return $this->get_description( $context );
687
+     * Alias of self::get_description().
688
+     *
689
+     * @since 1.0.19
690
+     * @param  string $context View or edit context.
691
+     * @return string
692
+     */
693
+    public function get_summary( $context = 'view' ) {
694
+        return $this->get_description( $context );
695 695
     }
696 696
 
697 697
     /**
698
-	 * Returns the user info.
699
-	 *
700
-	 * @since 1.0.19
698
+     * Returns the user info.
699
+     *
700
+     * @since 1.0.19
701 701
      * @param  string $context View or edit context.
702
-	 * @return array
703
-	 */
702
+     * @return array
703
+     */
704 704
     public function get_user_info( $context = 'view' ) {
705 705
 
706 706
         $user_info = array(
@@ -717,616 +717,616 @@  discard block
 block discarded – undo
717 717
             'company'    => $this->get_company( $context ),
718 718
             'vat_number' => $this->get_vat_number( $context ),
719 719
             'discount'   => $this->get_discount_code( $context ),
720
-		);
720
+        );
721 721
 
722
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
722
+        return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
723 723
 
724 724
     }
725 725
 
726 726
     /**
727
-	 * Get the customer id.
728
-	 *
729
-	 * @since 1.0.19
730
-	 * @param  string $context View or edit context.
731
-	 * @return int
732
-	 */
733
-	public function get_author( $context = 'view' ) {
734
-		return (int) $this->get_prop( 'author', $context );
727
+     * Get the customer id.
728
+     *
729
+     * @since 1.0.19
730
+     * @param  string $context View or edit context.
731
+     * @return int
732
+     */
733
+    public function get_author( $context = 'view' ) {
734
+        return (int) $this->get_prop( 'author', $context );
735 735
     }
736 736
 
737 737
     /**
738
-	 * Alias of self::get_author().
739
-	 *
740
-	 * @since 1.0.19
741
-	 * @param  string $context View or edit context.
742
-	 * @return int
743
-	 */
744
-	public function get_user_id( $context = 'view' ) {
745
-		return $this->get_author( $context );
738
+     * Alias of self::get_author().
739
+     *
740
+     * @since 1.0.19
741
+     * @param  string $context View or edit context.
742
+     * @return int
743
+     */
744
+    public function get_user_id( $context = 'view' ) {
745
+        return $this->get_author( $context );
746 746
     }
747 747
 
748
-     /**
749
-	 * Alias of self::get_author().
750
-	 *
751
-	 * @since 1.0.19
752
-	 * @param  string $context View or edit context.
753
-	 * @return int
754
-	 */
755
-	public function get_customer_id( $context = 'view' ) {
756
-		return $this->get_author( $context );
748
+        /**
749
+         * Alias of self::get_author().
750
+         *
751
+         * @since 1.0.19
752
+         * @param  string $context View or edit context.
753
+         * @return int
754
+         */
755
+    public function get_customer_id( $context = 'view' ) {
756
+        return $this->get_author( $context );
757 757
     }
758 758
 
759 759
     /**
760
-	 * Get the customer's ip.
761
-	 *
762
-	 * @since 1.0.19
763
-	 * @param  string $context View or edit context.
764
-	 * @return string
765
-	 */
766
-	public function get_ip( $context = 'view' ) {
767
-		return $this->get_prop( 'user_ip', $context );
760
+     * Get the customer's ip.
761
+     *
762
+     * @since 1.0.19
763
+     * @param  string $context View or edit context.
764
+     * @return string
765
+     */
766
+    public function get_ip( $context = 'view' ) {
767
+        return $this->get_prop( 'user_ip', $context );
768 768
     }
769 769
 
770 770
     /**
771
-	 * Alias of self::get_ip().
772
-	 *
773
-	 * @since 1.0.19
774
-	 * @param  string $context View or edit context.
775
-	 * @return string
776
-	 */
777
-	public function get_user_ip( $context = 'view' ) {
778
-		return $this->get_ip( $context );
771
+     * Alias of self::get_ip().
772
+     *
773
+     * @since 1.0.19
774
+     * @param  string $context View or edit context.
775
+     * @return string
776
+     */
777
+    public function get_user_ip( $context = 'view' ) {
778
+        return $this->get_ip( $context );
779 779
     }
780 780
 
781
-     /**
782
-	 * Alias of self::get_ip().
783
-	 *
784
-	 * @since 1.0.19
785
-	 * @param  string $context View or edit context.
786
-	 * @return string
787
-	 */
788
-	public function get_customer_ip( $context = 'view' ) {
789
-		return $this->get_ip( $context );
781
+        /**
782
+         * Alias of self::get_ip().
783
+         *
784
+         * @since 1.0.19
785
+         * @param  string $context View or edit context.
786
+         * @return string
787
+         */
788
+    public function get_customer_ip( $context = 'view' ) {
789
+        return $this->get_ip( $context );
790 790
     }
791 791
 
792 792
     /**
793
-	 * Get the customer's first name.
794
-	 *
795
-	 * @since 1.0.19
796
-	 * @param  string $context View or edit context.
797
-	 * @return string
798
-	 */
799
-	public function get_first_name( $context = 'view' ) {
800
-		return $this->get_prop( 'first_name', $context );
793
+     * Get the customer's first name.
794
+     *
795
+     * @since 1.0.19
796
+     * @param  string $context View or edit context.
797
+     * @return string
798
+     */
799
+    public function get_first_name( $context = 'view' ) {
800
+        return $this->get_prop( 'first_name', $context );
801 801
     }
802 802
 
803 803
     /**
804
-	 * Alias of self::get_first_name().
805
-	 *
806
-	 * @since 1.0.19
807
-	 * @param  string $context View or edit context.
808
-	 * @return string
809
-	 */
810
-	public function get_user_first_name( $context = 'view' ) {
811
-		return $this->get_first_name( $context );
804
+     * Alias of self::get_first_name().
805
+     *
806
+     * @since 1.0.19
807
+     * @param  string $context View or edit context.
808
+     * @return string
809
+     */
810
+    public function get_user_first_name( $context = 'view' ) {
811
+        return $this->get_first_name( $context );
812 812
     }
813 813
 
814
-     /**
815
-	 * Alias of self::get_first_name().
816
-	 *
817
-	 * @since 1.0.19
818
-	 * @param  string $context View or edit context.
819
-	 * @return string
820
-	 */
821
-	public function get_customer_first_name( $context = 'view' ) {
822
-		return $this->get_first_name( $context );
814
+        /**
815
+         * Alias of self::get_first_name().
816
+         *
817
+         * @since 1.0.19
818
+         * @param  string $context View or edit context.
819
+         * @return string
820
+         */
821
+    public function get_customer_first_name( $context = 'view' ) {
822
+        return $this->get_first_name( $context );
823 823
     }
824 824
 
825 825
     /**
826
-	 * Get the customer's last name.
827
-	 *
828
-	 * @since 1.0.19
829
-	 * @param  string $context View or edit context.
830
-	 * @return string
831
-	 */
832
-	public function get_last_name( $context = 'view' ) {
833
-		return $this->get_prop( 'last_name', $context );
826
+     * Get the customer's last name.
827
+     *
828
+     * @since 1.0.19
829
+     * @param  string $context View or edit context.
830
+     * @return string
831
+     */
832
+    public function get_last_name( $context = 'view' ) {
833
+        return $this->get_prop( 'last_name', $context );
834 834
     }
835 835
 
836 836
     /**
837
-	 * Alias of self::get_last_name().
838
-	 *
839
-	 * @since 1.0.19
840
-	 * @param  string $context View or edit context.
841
-	 * @return string
842
-	 */
843
-	public function get_user_last_name( $context = 'view' ) {
844
-		return $this->get_last_name( $context );
837
+     * Alias of self::get_last_name().
838
+     *
839
+     * @since 1.0.19
840
+     * @param  string $context View or edit context.
841
+     * @return string
842
+     */
843
+    public function get_user_last_name( $context = 'view' ) {
844
+        return $this->get_last_name( $context );
845 845
     }
846 846
 
847 847
     /**
848
-	 * Alias of self::get_last_name().
849
-	 *
850
-	 * @since 1.0.19
851
-	 * @param  string $context View or edit context.
852
-	 * @return string
853
-	 */
854
-	public function get_customer_last_name( $context = 'view' ) {
855
-		return $this->get_last_name( $context );
848
+     * Alias of self::get_last_name().
849
+     *
850
+     * @since 1.0.19
851
+     * @param  string $context View or edit context.
852
+     * @return string
853
+     */
854
+    public function get_customer_last_name( $context = 'view' ) {
855
+        return $this->get_last_name( $context );
856
+    }
857
+
858
+    /**
859
+     * Get the customer's full name.
860
+     *
861
+     * @since 1.0.19
862
+     * @param  string $context View or edit context.
863
+     * @return string
864
+     */
865
+    public function get_full_name( $context = 'view' ) {
866
+        return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
867
+    }
868
+
869
+    /**
870
+     * Alias of self::get_full_name().
871
+     *
872
+     * @since 1.0.19
873
+     * @param  string $context View or edit context.
874
+     * @return string
875
+     */
876
+    public function get_user_full_name( $context = 'view' ) {
877
+        return $this->get_full_name( $context );
878
+    }
879
+
880
+    /**
881
+     * Alias of self::get_full_name().
882
+     *
883
+     * @since 1.0.19
884
+     * @param  string $context View or edit context.
885
+     * @return string
886
+     */
887
+    public function get_customer_full_name( $context = 'view' ) {
888
+        return $this->get_full_name( $context );
889
+    }
890
+
891
+    /**
892
+     * Get the customer's phone number.
893
+     *
894
+     * @since 1.0.19
895
+     * @param  string $context View or edit context.
896
+     * @return string
897
+     */
898
+    public function get_phone( $context = 'view' ) {
899
+        return $this->get_prop( 'phone', $context );
856 900
     }
857 901
 
858 902
     /**
859
-	 * Get the customer's full name.
860
-	 *
861
-	 * @since 1.0.19
862
-	 * @param  string $context View or edit context.
863
-	 * @return string
864
-	 */
865
-	public function get_full_name( $context = 'view' ) {
866
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
903
+     * Alias of self::get_phone().
904
+     *
905
+     * @since 1.0.19
906
+     * @param  string $context View or edit context.
907
+     * @return string
908
+     */
909
+    public function get_phone_number( $context = 'view' ) {
910
+        return $this->get_phone( $context );
867 911
     }
868 912
 
869 913
     /**
870
-	 * Alias of self::get_full_name().
871
-	 *
872
-	 * @since 1.0.19
873
-	 * @param  string $context View or edit context.
874
-	 * @return string
875
-	 */
876
-	public function get_user_full_name( $context = 'view' ) {
877
-		return $this->get_full_name( $context );
914
+     * Alias of self::get_phone().
915
+     *
916
+     * @since 1.0.19
917
+     * @param  string $context View or edit context.
918
+     * @return string
919
+     */
920
+    public function get_user_phone( $context = 'view' ) {
921
+        return $this->get_phone( $context );
878 922
     }
879 923
 
880 924
     /**
881
-	 * Alias of self::get_full_name().
882
-	 *
883
-	 * @since 1.0.19
884
-	 * @param  string $context View or edit context.
885
-	 * @return string
886
-	 */
887
-	public function get_customer_full_name( $context = 'view' ) {
888
-		return $this->get_full_name( $context );
925
+     * Alias of self::get_phone().
926
+     *
927
+     * @since 1.0.19
928
+     * @param  string $context View or edit context.
929
+     * @return string
930
+     */
931
+    public function get_customer_phone( $context = 'view' ) {
932
+        return $this->get_phone( $context );
889 933
     }
890 934
 
891 935
     /**
892
-	 * Get the customer's phone number.
893
-	 *
894
-	 * @since 1.0.19
895
-	 * @param  string $context View or edit context.
896
-	 * @return string
897
-	 */
898
-	public function get_phone( $context = 'view' ) {
899
-		return $this->get_prop( 'phone', $context );
936
+     * Get the customer's email address.
937
+     *
938
+     * @since 1.0.19
939
+     * @param  string $context View or edit context.
940
+     * @return string
941
+     */
942
+    public function get_email( $context = 'view' ) {
943
+        return $this->get_prop( 'email', $context );
944
+    }
945
+
946
+    /**
947
+     * Alias of self::get_email().
948
+     *
949
+     * @since 1.0.19
950
+     * @param  string $context View or edit context.
951
+     * @return string
952
+     */
953
+    public function get_email_address( $context = 'view' ) {
954
+        return $this->get_email( $context );
955
+    }
956
+
957
+    /**
958
+     * Alias of self::get_email().
959
+     *
960
+     * @since 1.0.19
961
+     * @param  string $context View or edit context.
962
+     * @return string
963
+     */
964
+    public function get_user_email( $context = 'view' ) {
965
+        return $this->get_email( $context );
966
+    }
967
+
968
+    /**
969
+     * Alias of self::get_email().
970
+     *
971
+     * @since 1.0.19
972
+     * @param  string $context View or edit context.
973
+     * @return string
974
+     */
975
+    public function get_customer_email( $context = 'view' ) {
976
+        return $this->get_email( $context );
977
+    }
978
+
979
+    /**
980
+     * Get the customer's country.
981
+     *
982
+     * @since 1.0.19
983
+     * @param  string $context View or edit context.
984
+     * @return string
985
+     */
986
+    public function get_country( $context = 'view' ) {
987
+        $country = $this->get_prop( 'country', $context );
988
+        return empty( $country ) ? wpinv_get_default_country() : $country;
989
+    }
990
+
991
+    /**
992
+     * Alias of self::get_country().
993
+     *
994
+     * @since 1.0.19
995
+     * @param  string $context View or edit context.
996
+     * @return string
997
+     */
998
+    public function get_user_country( $context = 'view' ) {
999
+        return $this->get_country( $context );
1000
+    }
1001
+
1002
+    /**
1003
+     * Alias of self::get_country().
1004
+     *
1005
+     * @since 1.0.19
1006
+     * @param  string $context View or edit context.
1007
+     * @return string
1008
+     */
1009
+    public function get_customer_country( $context = 'view' ) {
1010
+        return $this->get_country( $context );
1011
+    }
1012
+
1013
+    /**
1014
+     * Get the customer's state.
1015
+     *
1016
+     * @since 1.0.19
1017
+     * @param  string $context View or edit context.
1018
+     * @return string
1019
+     */
1020
+    public function get_state( $context = 'view' ) {
1021
+        $state = $this->get_prop( 'state', $context );
1022
+        return empty( $state ) ? wpinv_get_default_state() : $state;
1023
+    }
1024
+
1025
+    /**
1026
+     * Alias of self::get_state().
1027
+     *
1028
+     * @since 1.0.19
1029
+     * @param  string $context View or edit context.
1030
+     * @return string
1031
+     */
1032
+    public function get_user_state( $context = 'view' ) {
1033
+        return $this->get_state( $context );
1034
+    }
1035
+
1036
+    /**
1037
+     * Alias of self::get_state().
1038
+     *
1039
+     * @since 1.0.19
1040
+     * @param  string $context View or edit context.
1041
+     * @return string
1042
+     */
1043
+    public function get_customer_state( $context = 'view' ) {
1044
+        return $this->get_state( $context );
900 1045
     }
901 1046
 
902 1047
     /**
903
-	 * Alias of self::get_phone().
904
-	 *
905
-	 * @since 1.0.19
906
-	 * @param  string $context View or edit context.
907
-	 * @return string
908
-	 */
909
-	public function get_phone_number( $context = 'view' ) {
910
-		return $this->get_phone( $context );
1048
+     * Get the customer's city.
1049
+     *
1050
+     * @since 1.0.19
1051
+     * @param  string $context View or edit context.
1052
+     * @return string
1053
+     */
1054
+    public function get_city( $context = 'view' ) {
1055
+        return $this->get_prop( 'city', $context );
911 1056
     }
912 1057
 
913 1058
     /**
914
-	 * Alias of self::get_phone().
915
-	 *
916
-	 * @since 1.0.19
917
-	 * @param  string $context View or edit context.
918
-	 * @return string
919
-	 */
920
-	public function get_user_phone( $context = 'view' ) {
921
-		return $this->get_phone( $context );
1059
+     * Alias of self::get_city().
1060
+     *
1061
+     * @since 1.0.19
1062
+     * @param  string $context View or edit context.
1063
+     * @return string
1064
+     */
1065
+    public function get_user_city( $context = 'view' ) {
1066
+        return $this->get_city( $context );
922 1067
     }
923 1068
 
924 1069
     /**
925
-	 * Alias of self::get_phone().
926
-	 *
927
-	 * @since 1.0.19
928
-	 * @param  string $context View or edit context.
929
-	 * @return string
930
-	 */
931
-	public function get_customer_phone( $context = 'view' ) {
932
-		return $this->get_phone( $context );
1070
+     * Alias of self::get_city().
1071
+     *
1072
+     * @since 1.0.19
1073
+     * @param  string $context View or edit context.
1074
+     * @return string
1075
+     */
1076
+    public function get_customer_city( $context = 'view' ) {
1077
+        return $this->get_city( $context );
933 1078
     }
934 1079
 
935 1080
     /**
936
-	 * Get the customer's email address.
937
-	 *
938
-	 * @since 1.0.19
939
-	 * @param  string $context View or edit context.
940
-	 * @return string
941
-	 */
942
-	public function get_email( $context = 'view' ) {
943
-		return $this->get_prop( 'email', $context );
1081
+     * Get the customer's zip.
1082
+     *
1083
+     * @since 1.0.19
1084
+     * @param  string $context View or edit context.
1085
+     * @return string
1086
+     */
1087
+    public function get_zip( $context = 'view' ) {
1088
+        return $this->get_prop( 'zip', $context );
944 1089
     }
945 1090
 
946 1091
     /**
947
-	 * Alias of self::get_email().
948
-	 *
949
-	 * @since 1.0.19
950
-	 * @param  string $context View or edit context.
951
-	 * @return string
952
-	 */
953
-	public function get_email_address( $context = 'view' ) {
954
-		return $this->get_email( $context );
1092
+     * Alias of self::get_zip().
1093
+     *
1094
+     * @since 1.0.19
1095
+     * @param  string $context View or edit context.
1096
+     * @return string
1097
+     */
1098
+    public function get_user_zip( $context = 'view' ) {
1099
+        return $this->get_zip( $context );
955 1100
     }
956 1101
 
957 1102
     /**
958
-	 * Alias of self::get_email().
959
-	 *
960
-	 * @since 1.0.19
961
-	 * @param  string $context View or edit context.
962
-	 * @return string
963
-	 */
964
-	public function get_user_email( $context = 'view' ) {
965
-		return $this->get_email( $context );
1103
+     * Alias of self::get_zip().
1104
+     *
1105
+     * @since 1.0.19
1106
+     * @param  string $context View or edit context.
1107
+     * @return string
1108
+     */
1109
+    public function get_customer_zip( $context = 'view' ) {
1110
+        return $this->get_zip( $context );
966 1111
     }
967 1112
 
968 1113
     /**
969
-	 * Alias of self::get_email().
970
-	 *
971
-	 * @since 1.0.19
972
-	 * @param  string $context View or edit context.
973
-	 * @return string
974
-	 */
975
-	public function get_customer_email( $context = 'view' ) {
976
-		return $this->get_email( $context );
1114
+     * Get the customer's company.
1115
+     *
1116
+     * @since 1.0.19
1117
+     * @param  string $context View or edit context.
1118
+     * @return string
1119
+     */
1120
+    public function get_company( $context = 'view' ) {
1121
+        return $this->get_prop( 'company', $context );
977 1122
     }
978 1123
 
979 1124
     /**
980
-	 * Get the customer's country.
981
-	 *
982
-	 * @since 1.0.19
983
-	 * @param  string $context View or edit context.
984
-	 * @return string
985
-	 */
986
-	public function get_country( $context = 'view' ) {
987
-		$country = $this->get_prop( 'country', $context );
988
-		return empty( $country ) ? wpinv_get_default_country() : $country;
1125
+     * Alias of self::get_company().
1126
+     *
1127
+     * @since 1.0.19
1128
+     * @param  string $context View or edit context.
1129
+     * @return string
1130
+     */
1131
+    public function get_user_company( $context = 'view' ) {
1132
+        return $this->get_company( $context );
989 1133
     }
990 1134
 
991 1135
     /**
992
-	 * Alias of self::get_country().
993
-	 *
994
-	 * @since 1.0.19
995
-	 * @param  string $context View or edit context.
996
-	 * @return string
997
-	 */
998
-	public function get_user_country( $context = 'view' ) {
999
-		return $this->get_country( $context );
1136
+     * Alias of self::get_company().
1137
+     *
1138
+     * @since 1.0.19
1139
+     * @param  string $context View or edit context.
1140
+     * @return string
1141
+     */
1142
+    public function get_customer_company( $context = 'view' ) {
1143
+        return $this->get_company( $context );
1000 1144
     }
1001 1145
 
1002 1146
     /**
1003
-	 * Alias of self::get_country().
1004
-	 *
1005
-	 * @since 1.0.19
1006
-	 * @param  string $context View or edit context.
1007
-	 * @return string
1008
-	 */
1009
-	public function get_customer_country( $context = 'view' ) {
1010
-		return $this->get_country( $context );
1147
+     * Get the customer's vat number.
1148
+     *
1149
+     * @since 1.0.19
1150
+     * @param  string $context View or edit context.
1151
+     * @return string
1152
+     */
1153
+    public function get_vat_number( $context = 'view' ) {
1154
+        return $this->get_prop( 'vat_number', $context );
1011 1155
     }
1012 1156
 
1013 1157
     /**
1014
-	 * Get the customer's state.
1015
-	 *
1016
-	 * @since 1.0.19
1017
-	 * @param  string $context View or edit context.
1018
-	 * @return string
1019
-	 */
1020
-	public function get_state( $context = 'view' ) {
1021
-		$state = $this->get_prop( 'state', $context );
1022
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1158
+     * Alias of self::get_vat_number().
1159
+     *
1160
+     * @since 1.0.19
1161
+     * @param  string $context View or edit context.
1162
+     * @return string
1163
+     */
1164
+    public function get_user_vat_number( $context = 'view' ) {
1165
+        return $this->get_vat_number( $context );
1023 1166
     }
1024 1167
 
1025 1168
     /**
1026
-	 * Alias of self::get_state().
1027
-	 *
1028
-	 * @since 1.0.19
1029
-	 * @param  string $context View or edit context.
1030
-	 * @return string
1031
-	 */
1032
-	public function get_user_state( $context = 'view' ) {
1033
-		return $this->get_state( $context );
1169
+     * Alias of self::get_vat_number().
1170
+     *
1171
+     * @since 1.0.19
1172
+     * @param  string $context View or edit context.
1173
+     * @return string
1174
+     */
1175
+    public function get_customer_vat_number( $context = 'view' ) {
1176
+        return $this->get_vat_number( $context );
1034 1177
     }
1035 1178
 
1036 1179
     /**
1037
-	 * Alias of self::get_state().
1038
-	 *
1039
-	 * @since 1.0.19
1040
-	 * @param  string $context View or edit context.
1041
-	 * @return string
1042
-	 */
1043
-	public function get_customer_state( $context = 'view' ) {
1044
-		return $this->get_state( $context );
1180
+     * Get the customer's vat rate.
1181
+     *
1182
+     * @since 1.0.19
1183
+     * @param  string $context View or edit context.
1184
+     * @return string
1185
+     */
1186
+    public function get_vat_rate( $context = 'view' ) {
1187
+        return $this->get_prop( 'vat_rate', $context );
1045 1188
     }
1046 1189
 
1047 1190
     /**
1048
-	 * Get the customer's city.
1049
-	 *
1050
-	 * @since 1.0.19
1051
-	 * @param  string $context View or edit context.
1052
-	 * @return string
1053
-	 */
1054
-	public function get_city( $context = 'view' ) {
1055
-		return $this->get_prop( 'city', $context );
1191
+     * Alias of self::get_vat_rate().
1192
+     *
1193
+     * @since 1.0.19
1194
+     * @param  string $context View or edit context.
1195
+     * @return string
1196
+     */
1197
+    public function get_user_vat_rate( $context = 'view' ) {
1198
+        return $this->get_vat_rate( $context );
1056 1199
     }
1057 1200
 
1058 1201
     /**
1059
-	 * Alias of self::get_city().
1060
-	 *
1061
-	 * @since 1.0.19
1062
-	 * @param  string $context View or edit context.
1063
-	 * @return string
1064
-	 */
1065
-	public function get_user_city( $context = 'view' ) {
1066
-		return $this->get_city( $context );
1202
+     * Alias of self::get_vat_rate().
1203
+     *
1204
+     * @since 1.0.19
1205
+     * @param  string $context View or edit context.
1206
+     * @return string
1207
+     */
1208
+    public function get_customer_vat_rate( $context = 'view' ) {
1209
+        return $this->get_vat_rate( $context );
1067 1210
     }
1068 1211
 
1069 1212
     /**
1070
-	 * Alias of self::get_city().
1071
-	 *
1072
-	 * @since 1.0.19
1073
-	 * @param  string $context View or edit context.
1074
-	 * @return string
1075
-	 */
1076
-	public function get_customer_city( $context = 'view' ) {
1077
-		return $this->get_city( $context );
1213
+     * Get the customer's address.
1214
+     *
1215
+     * @since 1.0.19
1216
+     * @param  string $context View or edit context.
1217
+     * @return string
1218
+     */
1219
+    public function get_address( $context = 'view' ) {
1220
+        return $this->get_prop( 'address', $context );
1078 1221
     }
1079 1222
 
1080 1223
     /**
1081
-	 * Get the customer's zip.
1082
-	 *
1083
-	 * @since 1.0.19
1084
-	 * @param  string $context View or edit context.
1085
-	 * @return string
1086
-	 */
1087
-	public function get_zip( $context = 'view' ) {
1088
-		return $this->get_prop( 'zip', $context );
1224
+     * Alias of self::get_address().
1225
+     *
1226
+     * @since 1.0.19
1227
+     * @param  string $context View or edit context.
1228
+     * @return string
1229
+     */
1230
+    public function get_user_address( $context = 'view' ) {
1231
+        return $this->get_address( $context );
1089 1232
     }
1090 1233
 
1091 1234
     /**
1092
-	 * Alias of self::get_zip().
1093
-	 *
1094
-	 * @since 1.0.19
1095
-	 * @param  string $context View or edit context.
1096
-	 * @return string
1097
-	 */
1098
-	public function get_user_zip( $context = 'view' ) {
1099
-		return $this->get_zip( $context );
1235
+     * Alias of self::get_address().
1236
+     *
1237
+     * @since 1.0.19
1238
+     * @param  string $context View or edit context.
1239
+     * @return string
1240
+     */
1241
+    public function get_customer_address( $context = 'view' ) {
1242
+        return $this->get_address( $context );
1100 1243
     }
1101 1244
 
1102 1245
     /**
1103
-	 * Alias of self::get_zip().
1104
-	 *
1105
-	 * @since 1.0.19
1106
-	 * @param  string $context View or edit context.
1107
-	 * @return string
1108
-	 */
1109
-	public function get_customer_zip( $context = 'view' ) {
1110
-		return $this->get_zip( $context );
1246
+     * Get whether the customer has viewed the invoice or not.
1247
+     *
1248
+     * @since 1.0.19
1249
+     * @param  string $context View or edit context.
1250
+     * @return bool
1251
+     */
1252
+    public function get_is_viewed( $context = 'view' ) {
1253
+        return (bool) $this->get_prop( 'is_viewed', $context );
1111 1254
     }
1112 1255
 
1113 1256
     /**
1114
-	 * Get the customer's company.
1115
-	 *
1116
-	 * @since 1.0.19
1117
-	 * @param  string $context View or edit context.
1118
-	 * @return string
1119
-	 */
1120
-	public function get_company( $context = 'view' ) {
1121
-		return $this->get_prop( 'company', $context );
1257
+     * Get other recipients for invoice communications.
1258
+     *
1259
+     * @since 1.0.19
1260
+     * @param  string $context View or edit context.
1261
+     * @return bool
1262
+     */
1263
+    public function get_email_cc( $context = 'view' ) {
1264
+        return $this->get_prop( 'email_cc', $context );
1122 1265
     }
1123 1266
 
1124 1267
     /**
1125
-	 * Alias of self::get_company().
1126
-	 *
1127
-	 * @since 1.0.19
1128
-	 * @param  string $context View or edit context.
1129
-	 * @return string
1130
-	 */
1131
-	public function get_user_company( $context = 'view' ) {
1132
-		return $this->get_company( $context );
1268
+     * Get invoice template.
1269
+     *
1270
+     * @since 1.0.19
1271
+     * @param  string $context View or edit context.
1272
+     * @return bool
1273
+     */
1274
+    public function get_template( $context = 'view' ) {
1275
+        return $this->get_prop( 'template', $context );
1133 1276
     }
1134 1277
 
1135 1278
     /**
1136
-	 * Alias of self::get_company().
1137
-	 *
1138
-	 * @since 1.0.19
1139
-	 * @param  string $context View or edit context.
1140
-	 * @return string
1141
-	 */
1142
-	public function get_customer_company( $context = 'view' ) {
1143
-		return $this->get_company( $context );
1279
+     * Get invoice source.
1280
+     *
1281
+     * @since 1.0.19
1282
+     * @param  string $context View or edit context.
1283
+     * @return bool
1284
+     */
1285
+    public function get_created_via( $context = 'view' ) {
1286
+        return $this->get_prop( 'created_via', $context );
1144 1287
     }
1145 1288
 
1146 1289
     /**
1147
-	 * Get the customer's vat number.
1148
-	 *
1149
-	 * @since 1.0.19
1150
-	 * @param  string $context View or edit context.
1151
-	 * @return string
1152
-	 */
1153
-	public function get_vat_number( $context = 'view' ) {
1154
-		return $this->get_prop( 'vat_number', $context );
1290
+     * Get whether the customer has confirmed their address.
1291
+     *
1292
+     * @since 1.0.19
1293
+     * @param  string $context View or edit context.
1294
+     * @return bool
1295
+     */
1296
+    public function get_address_confirmed( $context = 'view' ) {
1297
+        return (bool) $this->get_prop( 'address_confirmed', $context );
1155 1298
     }
1156 1299
 
1157 1300
     /**
1158
-	 * Alias of self::get_vat_number().
1159
-	 *
1160
-	 * @since 1.0.19
1161
-	 * @param  string $context View or edit context.
1162
-	 * @return string
1163
-	 */
1164
-	public function get_user_vat_number( $context = 'view' ) {
1165
-		return $this->get_vat_number( $context );
1301
+     * Alias of self::get_address_confirmed().
1302
+     *
1303
+     * @since 1.0.19
1304
+     * @param  string $context View or edit context.
1305
+     * @return bool
1306
+     */
1307
+    public function get_user_address_confirmed( $context = 'view' ) {
1308
+        return $this->get_address_confirmed( $context );
1166 1309
     }
1167 1310
 
1168 1311
     /**
1169
-	 * Alias of self::get_vat_number().
1170
-	 *
1171
-	 * @since 1.0.19
1172
-	 * @param  string $context View or edit context.
1173
-	 * @return string
1174
-	 */
1175
-	public function get_customer_vat_number( $context = 'view' ) {
1176
-		return $this->get_vat_number( $context );
1312
+     * Alias of self::get_address().
1313
+     *
1314
+     * @since 1.0.19
1315
+     * @param  string $context View or edit context.
1316
+     * @return bool
1317
+     */
1318
+    public function get_customer_address_confirmed( $context = 'view' ) {
1319
+        return $this->get_address_confirmed( $context );
1177 1320
     }
1178 1321
 
1179 1322
     /**
1180
-	 * Get the customer's vat rate.
1181
-	 *
1182
-	 * @since 1.0.19
1183
-	 * @param  string $context View or edit context.
1184
-	 * @return string
1185
-	 */
1186
-	public function get_vat_rate( $context = 'view' ) {
1187
-		return $this->get_prop( 'vat_rate', $context );
1188
-    }
1189
-
1190
-    /**
1191
-	 * Alias of self::get_vat_rate().
1192
-	 *
1193
-	 * @since 1.0.19
1194
-	 * @param  string $context View or edit context.
1195
-	 * @return string
1196
-	 */
1197
-	public function get_user_vat_rate( $context = 'view' ) {
1198
-		return $this->get_vat_rate( $context );
1199
-    }
1200
-
1201
-    /**
1202
-	 * Alias of self::get_vat_rate().
1203
-	 *
1204
-	 * @since 1.0.19
1205
-	 * @param  string $context View or edit context.
1206
-	 * @return string
1207
-	 */
1208
-	public function get_customer_vat_rate( $context = 'view' ) {
1209
-		return $this->get_vat_rate( $context );
1210
-    }
1211
-
1212
-    /**
1213
-	 * Get the customer's address.
1214
-	 *
1215
-	 * @since 1.0.19
1216
-	 * @param  string $context View or edit context.
1217
-	 * @return string
1218
-	 */
1219
-	public function get_address( $context = 'view' ) {
1220
-		return $this->get_prop( 'address', $context );
1221
-    }
1222
-
1223
-    /**
1224
-	 * Alias of self::get_address().
1225
-	 *
1226
-	 * @since 1.0.19
1227
-	 * @param  string $context View or edit context.
1228
-	 * @return string
1229
-	 */
1230
-	public function get_user_address( $context = 'view' ) {
1231
-		return $this->get_address( $context );
1232
-    }
1233
-
1234
-    /**
1235
-	 * Alias of self::get_address().
1236
-	 *
1237
-	 * @since 1.0.19
1238
-	 * @param  string $context View or edit context.
1239
-	 * @return string
1240
-	 */
1241
-	public function get_customer_address( $context = 'view' ) {
1242
-		return $this->get_address( $context );
1243
-    }
1244
-
1245
-    /**
1246
-	 * Get whether the customer has viewed the invoice or not.
1247
-	 *
1248
-	 * @since 1.0.19
1249
-	 * @param  string $context View or edit context.
1250
-	 * @return bool
1251
-	 */
1252
-	public function get_is_viewed( $context = 'view' ) {
1253
-		return (bool) $this->get_prop( 'is_viewed', $context );
1254
-	}
1255
-
1256
-	/**
1257
-	 * Get other recipients for invoice communications.
1258
-	 *
1259
-	 * @since 1.0.19
1260
-	 * @param  string $context View or edit context.
1261
-	 * @return bool
1262
-	 */
1263
-	public function get_email_cc( $context = 'view' ) {
1264
-		return $this->get_prop( 'email_cc', $context );
1265
-	}
1266
-
1267
-	/**
1268
-	 * Get invoice template.
1269
-	 *
1270
-	 * @since 1.0.19
1271
-	 * @param  string $context View or edit context.
1272
-	 * @return bool
1273
-	 */
1274
-	public function get_template( $context = 'view' ) {
1275
-		return $this->get_prop( 'template', $context );
1276
-	}
1277
-
1278
-	/**
1279
-	 * Get invoice source.
1280
-	 *
1281
-	 * @since 1.0.19
1282
-	 * @param  string $context View or edit context.
1283
-	 * @return bool
1284
-	 */
1285
-	public function get_created_via( $context = 'view' ) {
1286
-		return $this->get_prop( 'created_via', $context );
1287
-	}
1288
-
1289
-	/**
1290
-	 * Get whether the customer has confirmed their address.
1291
-	 *
1292
-	 * @since 1.0.19
1293
-	 * @param  string $context View or edit context.
1294
-	 * @return bool
1295
-	 */
1296
-	public function get_address_confirmed( $context = 'view' ) {
1297
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1298
-    }
1299
-
1300
-    /**
1301
-	 * Alias of self::get_address_confirmed().
1302
-	 *
1303
-	 * @since 1.0.19
1304
-	 * @param  string $context View or edit context.
1305
-	 * @return bool
1306
-	 */
1307
-	public function get_user_address_confirmed( $context = 'view' ) {
1308
-		return $this->get_address_confirmed( $context );
1309
-    }
1310
-
1311
-    /**
1312
-	 * Alias of self::get_address().
1313
-	 *
1314
-	 * @since 1.0.19
1315
-	 * @param  string $context View or edit context.
1316
-	 * @return bool
1317
-	 */
1318
-	public function get_customer_address_confirmed( $context = 'view' ) {
1319
-		return $this->get_address_confirmed( $context );
1320
-    }
1321
-
1322
-    /**
1323
-	 * Get the invoice subtotal.
1324
-	 *
1325
-	 * @since 1.0.19
1326
-	 * @param  string $context View or edit context.
1327
-	 * @return float
1328
-	 */
1329
-	public function get_subtotal( $context = 'view' ) {
1323
+     * Get the invoice subtotal.
1324
+     *
1325
+     * @since 1.0.19
1326
+     * @param  string $context View or edit context.
1327
+     * @return float
1328
+     */
1329
+    public function get_subtotal( $context = 'view' ) {
1330 1330
         $subtotal = (float) $this->get_prop( 'subtotal', $context );
1331 1331
 
1332 1332
         // Backwards compatibility.
@@ -1338,165 +1338,165 @@  discard block
 block discarded – undo
1338 1338
     }
1339 1339
 
1340 1340
     /**
1341
-	 * Get the invoice discount total.
1342
-	 *
1343
-	 * @since 1.0.19
1344
-	 * @param  string $context View or edit context.
1345
-	 * @return float
1346
-	 */
1347
-	public function get_total_discount( $context = 'view' ) {
1348
-		return (float) $this->get_prop( 'total_discount', $context );
1341
+     * Get the invoice discount total.
1342
+     *
1343
+     * @since 1.0.19
1344
+     * @param  string $context View or edit context.
1345
+     * @return float
1346
+     */
1347
+    public function get_total_discount( $context = 'view' ) {
1348
+        return (float) $this->get_prop( 'total_discount', $context );
1349
+    }
1350
+
1351
+    /**
1352
+     * Get the invoice tax total.
1353
+     *
1354
+     * @since 1.0.19
1355
+     * @param  string $context View or edit context.
1356
+     * @return float
1357
+     */
1358
+    public function get_total_tax( $context = 'view' ) {
1359
+        return (float) $this->get_prop( 'total_tax', $context );
1349 1360
     }
1350 1361
 
1351 1362
     /**
1352
-	 * Get the invoice tax total.
1353
-	 *
1354
-	 * @since 1.0.19
1355
-	 * @param  string $context View or edit context.
1356
-	 * @return float
1357
-	 */
1358
-	public function get_total_tax( $context = 'view' ) {
1359
-		return (float) $this->get_prop( 'total_tax', $context );
1360
-	}
1361
-
1362
-	/**
1363
-	 * @deprecated
1364
-	 */
1365
-	public function get_final_tax( $currency = false ) {
1366
-		$tax = $this->get_total_tax();
1363
+     * @deprecated
1364
+     */
1365
+    public function get_final_tax( $currency = false ) {
1366
+        $tax = $this->get_total_tax();
1367 1367
 
1368 1368
         if ( $currency ) {
1369
-			return wpinv_price( $tax, $this->get_currency() );
1369
+            return wpinv_price( $tax, $this->get_currency() );
1370 1370
         }
1371 1371
 
1372 1372
         return $tax;
1373 1373
     }
1374 1374
 
1375 1375
     /**
1376
-	 * Get the invoice fees total.
1377
-	 *
1378
-	 * @since 1.0.19
1379
-	 * @param  string $context View or edit context.
1380
-	 * @return float
1381
-	 */
1382
-	public function get_total_fees( $context = 'view' ) {
1383
-		return (float) $this->get_prop( 'total_fees', $context );
1376
+     * Get the invoice fees total.
1377
+     *
1378
+     * @since 1.0.19
1379
+     * @param  string $context View or edit context.
1380
+     * @return float
1381
+     */
1382
+    public function get_total_fees( $context = 'view' ) {
1383
+        return (float) $this->get_prop( 'total_fees', $context );
1384 1384
     }
1385 1385
 
1386 1386
     /**
1387
-	 * Alias for self::get_total_fees().
1388
-	 *
1389
-	 * @since 1.0.19
1390
-	 * @param  string $context View or edit context.
1391
-	 * @return float
1392
-	 */
1393
-	public function get_fees_total( $context = 'view' ) {
1394
-		return $this->get_total_fees( $context );
1387
+     * Alias for self::get_total_fees().
1388
+     *
1389
+     * @since 1.0.19
1390
+     * @param  string $context View or edit context.
1391
+     * @return float
1392
+     */
1393
+    public function get_fees_total( $context = 'view' ) {
1394
+        return $this->get_total_fees( $context );
1395 1395
     }
1396 1396
 
1397 1397
     /**
1398
-	 * Get the invoice total.
1399
-	 *
1400
-	 * @since 1.0.19
1398
+     * Get the invoice total.
1399
+     *
1400
+     * @since 1.0.19
1401 1401
      * @return float
1402
-	 */
1403
-	public function get_total() {
1404
-		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1405
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1406
-	}
1402
+     */
1403
+    public function get_total() {
1404
+        $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1405
+        return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1406
+    }
1407 1407
 	
1408
-	/**
1409
-	 * Get the invoice totals.
1410
-	 *
1411
-	 * @since 1.0.19
1408
+    /**
1409
+     * Get the invoice totals.
1410
+     *
1411
+     * @since 1.0.19
1412 1412
      * @return array
1413
-	 */
1414
-	public function get_totals() {
1415
-		return $this->totals;
1413
+     */
1414
+    public function get_totals() {
1415
+        return $this->totals;
1416 1416
     }
1417 1417
 
1418 1418
     /**
1419
-	 * Get the initial invoice total.
1420
-	 *
1421
-	 * @since 1.0.19
1419
+     * Get the initial invoice total.
1420
+     *
1421
+     * @since 1.0.19
1422 1422
      * @param  string $context View or edit context.
1423 1423
      * @return float
1424
-	 */
1424
+     */
1425 1425
     public function get_initial_total() {
1426 1426
 
1427
-		if ( empty( $this->totals ) ) {
1428
-			$this->recalculate_total();
1429
-		}
1427
+        if ( empty( $this->totals ) ) {
1428
+            $this->recalculate_total();
1429
+        }
1430 1430
 
1431
-		$tax      = $this->totals['tax']['initial'];
1432
-		$fee      = $this->totals['fee']['initial'];
1433
-		$discount = $this->totals['discount']['initial'];
1434
-		$subtotal = $this->totals['subtotal']['initial'];
1435
-		$total    = $tax + $fee - $discount + $subtotal;
1431
+        $tax      = $this->totals['tax']['initial'];
1432
+        $fee      = $this->totals['fee']['initial'];
1433
+        $discount = $this->totals['discount']['initial'];
1434
+        $subtotal = $this->totals['subtotal']['initial'];
1435
+        $total    = $tax + $fee - $discount + $subtotal;
1436 1436
 
1437
-		if ( 0 > $total ) {
1438
-			$total = 0;
1439
-		}
1437
+        if ( 0 > $total ) {
1438
+            $total = 0;
1439
+        }
1440 1440
 
1441 1441
         return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1442
-	}
1442
+    }
1443 1443
 
1444
-	/**
1445
-	 * Get the recurring invoice total.
1446
-	 *
1447
-	 * @since 1.0.19
1444
+    /**
1445
+     * Get the recurring invoice total.
1446
+     *
1447
+     * @since 1.0.19
1448 1448
      * @param  string $context View or edit context.
1449 1449
      * @return float
1450
-	 */
1450
+     */
1451 1451
     public function get_recurring_total() {
1452 1452
 
1453
-		if ( empty( $this->totals ) ) {
1454
-			$this->recalculate_total();
1455
-		}
1453
+        if ( empty( $this->totals ) ) {
1454
+            $this->recalculate_total();
1455
+        }
1456 1456
 
1457
-		$tax      = $this->totals['tax']['recurring'];
1458
-		$fee      = $this->totals['fee']['recurring'];
1459
-		$discount = $this->totals['discount']['recurring'];
1460
-		$subtotal = $this->totals['subtotal']['recurring'];
1461
-		$total    = $tax + $fee - $discount + $subtotal;
1457
+        $tax      = $this->totals['tax']['recurring'];
1458
+        $fee      = $this->totals['fee']['recurring'];
1459
+        $discount = $this->totals['discount']['recurring'];
1460
+        $subtotal = $this->totals['subtotal']['recurring'];
1461
+        $total    = $tax + $fee - $discount + $subtotal;
1462 1462
 
1463
-		if ( 0 > $total ) {
1464
-			$total = 0;
1465
-		}
1463
+        if ( 0 > $total ) {
1464
+            $total = 0;
1465
+        }
1466 1466
 
1467 1467
         return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1468
-	}
1468
+    }
1469 1469
 
1470
-	/**
1471
-	 * Returns recurring payment details.
1472
-	 *
1473
-	 * @since 1.0.19
1470
+    /**
1471
+     * Returns recurring payment details.
1472
+     *
1473
+     * @since 1.0.19
1474 1474
      * @param  string $field Optionally provide a field to return.
1475
-	 * @param string $currency Whether to include the currency.
1475
+     * @param string $currency Whether to include the currency.
1476 1476
      * @return float|string
1477
-	 */
1477
+     */
1478 1478
     public function get_recurring_details( $field = '', $currency = false ) {
1479 1479
 
1480
-		// Maybe recalculate totals.
1481
-		if ( empty( $this->totals ) ) {
1482
-			$this->recalculate_total();
1483
-		}
1480
+        // Maybe recalculate totals.
1481
+        if ( empty( $this->totals ) ) {
1482
+            $this->recalculate_total();
1483
+        }
1484 1484
 
1485
-		// Prepare recurring totals.
1485
+        // Prepare recurring totals.
1486 1486
         $data = apply_filters(
1487
-			'wpinv_get_invoice_recurring_details',
1488
-			array(
1489
-				'cart_details' => $this->get_cart_details(),
1490
-				'subtotal'     => $this->totals['subtotal']['recurring'],
1491
-				'discount'     => $this->totals['discount']['recurring'],
1492
-				'tax'          => $this->totals['tax']['recurring'],
1493
-				'fee'          => $this->totals['fee']['recurring'],
1494
-				'total'        => $this->get_recurring_total(),
1495
-			),
1496
-			$this,
1497
-			$field,
1498
-			$currency
1499
-		);
1487
+            'wpinv_get_invoice_recurring_details',
1488
+            array(
1489
+                'cart_details' => $this->get_cart_details(),
1490
+                'subtotal'     => $this->totals['subtotal']['recurring'],
1491
+                'discount'     => $this->totals['discount']['recurring'],
1492
+                'tax'          => $this->totals['tax']['recurring'],
1493
+                'fee'          => $this->totals['fee']['recurring'],
1494
+                'total'        => $this->get_recurring_total(),
1495
+            ),
1496
+            $this,
1497
+            $field,
1498
+            $currency
1499
+        );
1500 1500
 
1501 1501
         if ( isset( $data[$field] ) ) {
1502 1502
             return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
@@ -1506,156 +1506,156 @@  discard block
 block discarded – undo
1506 1506
     }
1507 1507
 
1508 1508
     /**
1509
-	 * Get the invoice fees.
1510
-	 *
1511
-	 * @since 1.0.19
1512
-	 * @param  string $context View or edit context.
1513
-	 * @return array
1514
-	 */
1515
-	public function get_fees( $context = 'view' ) {
1516
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1509
+     * Get the invoice fees.
1510
+     *
1511
+     * @since 1.0.19
1512
+     * @param  string $context View or edit context.
1513
+     * @return array
1514
+     */
1515
+    public function get_fees( $context = 'view' ) {
1516
+        return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1517 1517
     }
1518 1518
 
1519 1519
     /**
1520
-	 * Get the invoice discounts.
1521
-	 *
1522
-	 * @since 1.0.19
1523
-	 * @param  string $context View or edit context.
1524
-	 * @return array
1525
-	 */
1526
-	public function get_discounts( $context = 'view' ) {
1527
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1520
+     * Get the invoice discounts.
1521
+     *
1522
+     * @since 1.0.19
1523
+     * @param  string $context View or edit context.
1524
+     * @return array
1525
+     */
1526
+    public function get_discounts( $context = 'view' ) {
1527
+        return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1528 1528
     }
1529 1529
 
1530 1530
     /**
1531
-	 * Get the invoice taxes.
1532
-	 *
1533
-	 * @since 1.0.19
1534
-	 * @param  string $context View or edit context.
1535
-	 * @return array
1536
-	 */
1537
-	public function get_taxes( $context = 'view' ) {
1538
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1531
+     * Get the invoice taxes.
1532
+     *
1533
+     * @since 1.0.19
1534
+     * @param  string $context View or edit context.
1535
+     * @return array
1536
+     */
1537
+    public function get_taxes( $context = 'view' ) {
1538
+        return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1539 1539
     }
1540 1540
 
1541 1541
     /**
1542
-	 * Get the invoice items.
1543
-	 *
1544
-	 * @since 1.0.19
1545
-	 * @param  string $context View or edit context.
1546
-	 * @return GetPaid_Form_Item[]
1547
-	 */
1548
-	public function get_items( $context = 'view' ) {
1542
+     * Get the invoice items.
1543
+     *
1544
+     * @since 1.0.19
1545
+     * @param  string $context View or edit context.
1546
+     * @return GetPaid_Form_Item[]
1547
+     */
1548
+    public function get_items( $context = 'view' ) {
1549 1549
         return $this->get_prop( 'items', $context );
1550 1550
     }
1551 1551
 
1552 1552
     /**
1553
-	 * Get the invoice's payment form.
1554
-	 *
1555
-	 * @since 1.0.19
1556
-	 * @param  string $context View or edit context.
1557
-	 * @return int
1558
-	 */
1559
-	public function get_payment_form( $context = 'view' ) {
1560
-		return intval( $this->get_prop( 'payment_form', $context ) );
1553
+     * Get the invoice's payment form.
1554
+     *
1555
+     * @since 1.0.19
1556
+     * @param  string $context View or edit context.
1557
+     * @return int
1558
+     */
1559
+    public function get_payment_form( $context = 'view' ) {
1560
+        return intval( $this->get_prop( 'payment_form', $context ) );
1561 1561
     }
1562 1562
 
1563 1563
     /**
1564
-	 * Get the invoice's submission id.
1565
-	 *
1566
-	 * @since 1.0.19
1567
-	 * @param  string $context View or edit context.
1568
-	 * @return string
1569
-	 */
1570
-	public function get_submission_id( $context = 'view' ) {
1571
-		return $this->get_prop( 'submission_id', $context );
1564
+     * Get the invoice's submission id.
1565
+     *
1566
+     * @since 1.0.19
1567
+     * @param  string $context View or edit context.
1568
+     * @return string
1569
+     */
1570
+    public function get_submission_id( $context = 'view' ) {
1571
+        return $this->get_prop( 'submission_id', $context );
1572 1572
     }
1573 1573
 
1574 1574
     /**
1575
-	 * Get the invoice's discount code.
1576
-	 *
1577
-	 * @since 1.0.19
1578
-	 * @param  string $context View or edit context.
1579
-	 * @return string
1580
-	 */
1581
-	public function get_discount_code( $context = 'view' ) {
1582
-		return $this->get_prop( 'discount_code', $context );
1575
+     * Get the invoice's discount code.
1576
+     *
1577
+     * @since 1.0.19
1578
+     * @param  string $context View or edit context.
1579
+     * @return string
1580
+     */
1581
+    public function get_discount_code( $context = 'view' ) {
1582
+        return $this->get_prop( 'discount_code', $context );
1583 1583
     }
1584 1584
 
1585 1585
     /**
1586
-	 * Get the invoice's gateway.
1587
-	 *
1588
-	 * @since 1.0.19
1589
-	 * @param  string $context View or edit context.
1590
-	 * @return string
1591
-	 */
1592
-	public function get_gateway( $context = 'view' ) {
1593
-		return $this->get_prop( 'gateway', $context );
1586
+     * Get the invoice's gateway.
1587
+     *
1588
+     * @since 1.0.19
1589
+     * @param  string $context View or edit context.
1590
+     * @return string
1591
+     */
1592
+    public function get_gateway( $context = 'view' ) {
1593
+        return $this->get_prop( 'gateway', $context );
1594 1594
     }
1595 1595
 
1596 1596
     /**
1597
-	 * Get the invoice's gateway display title.
1598
-	 *
1599
-	 * @since 1.0.19
1600
-	 * @return string
1601
-	 */
1597
+     * Get the invoice's gateway display title.
1598
+     *
1599
+     * @since 1.0.19
1600
+     * @return string
1601
+     */
1602 1602
     public function get_gateway_title() {
1603 1603
         $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1604 1604
         return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1605 1605
     }
1606 1606
 
1607 1607
     /**
1608
-	 * Get the invoice's transaction id.
1609
-	 *
1610
-	 * @since 1.0.19
1611
-	 * @param  string $context View or edit context.
1612
-	 * @return string
1613
-	 */
1614
-	public function get_transaction_id( $context = 'view' ) {
1615
-		return $this->get_prop( 'transaction_id', $context );
1608
+     * Get the invoice's transaction id.
1609
+     *
1610
+     * @since 1.0.19
1611
+     * @param  string $context View or edit context.
1612
+     * @return string
1613
+     */
1614
+    public function get_transaction_id( $context = 'view' ) {
1615
+        return $this->get_prop( 'transaction_id', $context );
1616 1616
     }
1617 1617
 
1618 1618
     /**
1619
-	 * Get the invoice's currency.
1620
-	 *
1621
-	 * @since 1.0.19
1622
-	 * @param  string $context View or edit context.
1623
-	 * @return string
1624
-	 */
1625
-	public function get_currency( $context = 'view' ) {
1619
+     * Get the invoice's currency.
1620
+     *
1621
+     * @since 1.0.19
1622
+     * @param  string $context View or edit context.
1623
+     * @return string
1624
+     */
1625
+    public function get_currency( $context = 'view' ) {
1626 1626
         $currency = $this->get_prop( 'currency', $context );
1627 1627
         return empty( $currency ) ? wpinv_get_currency() : $currency;
1628 1628
     }
1629 1629
 
1630 1630
     /**
1631
-	 * Checks if we are charging taxes for this invoice.
1632
-	 *
1633
-	 * @since 1.0.19
1634
-	 * @param  string $context View or edit context.
1635
-	 * @return bool
1636
-	 */
1637
-	public function get_disable_taxes( $context = 'view' ) {
1631
+     * Checks if we are charging taxes for this invoice.
1632
+     *
1633
+     * @since 1.0.19
1634
+     * @param  string $context View or edit context.
1635
+     * @return bool
1636
+     */
1637
+    public function get_disable_taxes( $context = 'view' ) {
1638 1638
         return (bool) $this->get_prop( 'disable_taxes', $context );
1639 1639
     }
1640 1640
 
1641 1641
     /**
1642
-	 * Retrieves the subscription id for an invoice.
1643
-	 *
1644
-	 * @since 1.0.19
1645
-	 * @param  string $context View or edit context.
1646
-	 * @return int
1647
-	 */
1642
+     * Retrieves the subscription id for an invoice.
1643
+     *
1644
+     * @since 1.0.19
1645
+     * @param  string $context View or edit context.
1646
+     * @return int
1647
+     */
1648 1648
     public function get_subscription_id( $context = 'view' ) {
1649
-		return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1650
-	}
1651
-
1652
-	/**
1653
-	 * Retrieves the remote subscription id for an invoice.
1654
-	 *
1655
-	 * @since 1.0.19
1656
-	 * @param  string $context View or edit context.
1657
-	 * @return int
1658
-	 */
1649
+        return $this->is_renewal() ? $this->get_parent()->get_subscription_id( $context ) : $this->get_prop( 'subscription_id', $context );
1650
+    }
1651
+
1652
+    /**
1653
+     * Retrieves the remote subscription id for an invoice.
1654
+     *
1655
+     * @since 1.0.19
1656
+     * @param  string $context View or edit context.
1657
+     * @return int
1658
+     */
1659 1659
     public function get_remote_subscription_id( $context = 'view' ) {
1660 1660
         $subscription_id = $this->get_prop( 'remote_subscription_id', $context );
1661 1661
 
@@ -1668,12 +1668,12 @@  discard block
 block discarded – undo
1668 1668
     }
1669 1669
 
1670 1670
     /**
1671
-	 * Retrieves the payment meta for an invoice.
1672
-	 *
1673
-	 * @since 1.0.19
1674
-	 * @param  string $context View or edit context.
1675
-	 * @return array
1676
-	 */
1671
+     * Retrieves the payment meta for an invoice.
1672
+     *
1673
+     * @since 1.0.19
1674
+     * @param  string $context View or edit context.
1675
+     * @return array
1676
+     */
1677 1677
     public function get_payment_meta( $context = 'view' ) {
1678 1678
 
1679 1679
         return array(
@@ -1693,31 +1693,31 @@  discard block
 block discarded – undo
1693 1693
     }
1694 1694
 
1695 1695
     /**
1696
-	 * Retrieves the cart details for an invoice.
1697
-	 *
1698
-	 * @since 1.0.19
1699
-	 * @return array
1700
-	 */
1696
+     * Retrieves the cart details for an invoice.
1697
+     *
1698
+     * @since 1.0.19
1699
+     * @return array
1700
+     */
1701 1701
     public function get_cart_details() {
1702 1702
         $items        = $this->get_items();
1703 1703
         $cart_details = array();
1704 1704
 
1705 1705
         foreach ( $items as $item_id => $item ) {
1706
-			$item->invoice_id = $this->get_id();
1706
+            $item->invoice_id = $this->get_id();
1707 1707
             $cart_details[]   = $item->prepare_data_for_saving();
1708 1708
         }
1709 1709
 
1710 1710
         return $cart_details;
1711
-	}
1711
+    }
1712 1712
 
1713
-	/**
1714
-	 * Retrieves the recurring item.
1715
-	 *
1716
-	 * @return null|GetPaid_Form_Item|int
1717
-	 */
1718
-	public function get_recurring( $object = false ) {
1713
+    /**
1714
+     * Retrieves the recurring item.
1715
+     *
1716
+     * @return null|GetPaid_Form_Item|int
1717
+     */
1718
+    public function get_recurring( $object = false ) {
1719 1719
 
1720
-		// Are we returning an object?
1720
+        // Are we returning an object?
1721 1721
         if ( $object ) {
1722 1722
             return $this->get_item( $this->recurring_item );
1723 1723
         }
@@ -1725,114 +1725,114 @@  discard block
 block discarded – undo
1725 1725
         return $this->recurring_item;
1726 1726
     }
1727 1727
 
1728
-	/**
1729
-	 * Retrieves the subscription name.
1730
-	 *
1731
-	 * @since 1.0.19
1732
-	 * @return string
1733
-	 */
1734
-	public function get_subscription_name() {
1728
+    /**
1729
+     * Retrieves the subscription name.
1730
+     *
1731
+     * @since 1.0.19
1732
+     * @return string
1733
+     */
1734
+    public function get_subscription_name() {
1735 1735
 
1736
-		// Retrieve the recurring name
1736
+        // Retrieve the recurring name
1737 1737
         $item = $this->get_recurring( true );
1738 1738
 
1739
-		// Abort if it does not exist.
1739
+        // Abort if it does not exist.
1740 1740
         if ( empty( $item ) ) {
1741 1741
             return '';
1742 1742
         }
1743 1743
 
1744
-		// Return the item name.
1744
+        // Return the item name.
1745 1745
         return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1746
-	}
1747
-
1748
-	/**
1749
-	 * Retrieves the view url.
1750
-	 *
1751
-	 * @since 1.0.19
1752
-	 * @return string
1753
-	 */
1754
-	public function get_view_url() {
1746
+    }
1747
+
1748
+    /**
1749
+     * Retrieves the view url.
1750
+     *
1751
+     * @since 1.0.19
1752
+     * @return string
1753
+     */
1754
+    public function get_view_url() {
1755 1755
         $invoice_url = get_permalink( $this->get_id() );
1756
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1756
+        $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1757 1757
         return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1758
-	}
1758
+    }
1759 1759
 
1760
-	/**
1761
-	 * Retrieves the payment url.
1762
-	 *
1763
-	 * @since 1.0.19
1764
-	 * @return string
1765
-	 */
1766
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1760
+    /**
1761
+     * Retrieves the payment url.
1762
+     *
1763
+     * @since 1.0.19
1764
+     * @return string
1765
+     */
1766
+    public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1767 1767
 
1768
-		// Retrieve the checkout url.
1768
+        // Retrieve the checkout url.
1769 1769
         $pay_url = wpinv_get_checkout_uri();
1770 1770
 
1771
-		// Maybe force ssl.
1771
+        // Maybe force ssl.
1772 1772
         if ( is_ssl() ) {
1773 1773
             $pay_url = str_replace( 'http:', 'https:', $pay_url );
1774 1774
         }
1775 1775
 
1776
-		// Add the invoice key.
1777
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1776
+        // Add the invoice key.
1777
+        $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1778 1778
 
1779
-		// (Maybe?) add a secret
1779
+        // (Maybe?) add a secret
1780 1780
         if ( $secret ) {
1781 1781
             $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1782 1782
         }
1783 1783
 
1784 1784
         return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1785
-	}
1785
+    }
1786 1786
 	
1787
-	/**
1788
-	 * Retrieves the receipt url.
1789
-	 *
1790
-	 * @since 1.0.19
1791
-	 * @return string
1792
-	 */
1793
-	public function get_receipt_url() {
1794
-
1795
-		// Retrieve the checkout url.
1787
+    /**
1788
+     * Retrieves the receipt url.
1789
+     *
1790
+     * @since 1.0.19
1791
+     * @return string
1792
+     */
1793
+    public function get_receipt_url() {
1794
+
1795
+        // Retrieve the checkout url.
1796 1796
         $receipt_url = wpinv_get_success_page_uri();
1797 1797
 
1798
-		// Maybe force ssl.
1798
+        // Maybe force ssl.
1799 1799
         if ( is_ssl() ) {
1800 1800
             $receipt_url = str_replace( 'http:', 'https:', $receipt_url );
1801 1801
         }
1802 1802
 
1803
-		// Add the invoice key.
1804
-		$receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1803
+        // Add the invoice key.
1804
+        $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1805 1805
 
1806 1806
         return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this );
1807
-	}
1807
+    }
1808 1808
 	
1809
-	/**
1810
-	 * Retrieves the default status.
1811
-	 *
1812
-	 * @since 1.0.19
1813
-	 * @return string
1814
-	 */
1815
-	public function get_default_status() {
1816
-
1817
-		$type   = $this->get_type();
1818
-		$status = "wpi-$type-pending";
1819
-		return str_replace( '-invoice', '', $status );
1820
-
1821
-	}
1822
-
1823
-    /**
1824
-	 * Magic method for accessing invoice properties.
1825
-	 *
1826
-	 * @since 1.0.15
1827
-	 * @access public
1828
-	 *
1829
-	 * @param string $key Discount data to retrieve
1830
-	 * @param  string $context View or edit context.
1831
-	 * @return mixed Value of the given invoice property (if set).
1832
-	 */
1833
-	public function get( $key, $context = 'view' ) {
1809
+    /**
1810
+     * Retrieves the default status.
1811
+     *
1812
+     * @since 1.0.19
1813
+     * @return string
1814
+     */
1815
+    public function get_default_status() {
1816
+
1817
+        $type   = $this->get_type();
1818
+        $status = "wpi-$type-pending";
1819
+        return str_replace( '-invoice', '', $status );
1820
+
1821
+    }
1822
+
1823
+    /**
1824
+     * Magic method for accessing invoice properties.
1825
+     *
1826
+     * @since 1.0.15
1827
+     * @access public
1828
+     *
1829
+     * @param string $key Discount data to retrieve
1830
+     * @param  string $context View or edit context.
1831
+     * @return mixed Value of the given invoice property (if set).
1832
+     */
1833
+    public function get( $key, $context = 'view' ) {
1834 1834
         return $this->get_prop( $key, $context );
1835
-	}
1835
+    }
1836 1836
 
1837 1837
     /*
1838 1838
 	|--------------------------------------------------------------------------
@@ -1845,130 +1845,130 @@  discard block
 block discarded – undo
1845 1845
     */
1846 1846
 
1847 1847
     /**
1848
-	 * Magic method for setting invoice properties.
1849
-	 *
1850
-	 * @since 1.0.19
1851
-	 * @access public
1852
-	 *
1853
-	 * @param string $key Discount data to retrieve
1854
-	 * @param  mixed $value new value.
1855
-	 * @return mixed Value of the given invoice property (if set).
1856
-	 */
1857
-	public function set( $key, $value ) {
1848
+     * Magic method for setting invoice properties.
1849
+     *
1850
+     * @since 1.0.19
1851
+     * @access public
1852
+     *
1853
+     * @param string $key Discount data to retrieve
1854
+     * @param  mixed $value new value.
1855
+     * @return mixed Value of the given invoice property (if set).
1856
+     */
1857
+    public function set( $key, $value ) {
1858 1858
 
1859 1859
         $setter = "set_$key";
1860 1860
         if ( is_callable( array( $this, $setter ) ) ) {
1861 1861
             $this->{$setter}( $value );
1862 1862
         }
1863 1863
 
1864
-	}
1864
+    }
1865 1865
 
1866
-	/**
1867
-	 * Sets item status.
1868
-	 *
1869
-	 * @since 1.0.19
1870
-	 * @param string $new_status    New status.
1871
-	 * @param string $note          Optional note to add.
1872
-	 * @param bool   $manual_update Is this a manual status change?.
1873
-	 * @return array details of change.
1874
-	 */
1875
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1876
-		$old_status = $this->get_status();
1866
+    /**
1867
+     * Sets item status.
1868
+     *
1869
+     * @since 1.0.19
1870
+     * @param string $new_status    New status.
1871
+     * @param string $note          Optional note to add.
1872
+     * @param bool   $manual_update Is this a manual status change?.
1873
+     * @return array details of change.
1874
+     */
1875
+    public function set_status( $new_status, $note = '', $manual_update = false ) {
1876
+        $old_status = $this->get_status();
1877 1877
 
1878
-		$statuses = $this->get_all_statuses();
1878
+        $statuses = $this->get_all_statuses();
1879 1879
 
1880
-		if ( isset( $statuses[ 'draft' ] ) ) {
1881
-			unset( $statuses[ 'draft' ] );
1882
-		}
1880
+        if ( isset( $statuses[ 'draft' ] ) ) {
1881
+            unset( $statuses[ 'draft' ] );
1882
+        }
1883 1883
 
1884
-		$this->set_prop( 'status', $new_status );
1884
+        $this->set_prop( 'status', $new_status );
1885 1885
 
1886
-		// If setting the status, ensure it's set to a valid status.
1887
-		if ( true === $this->object_read ) {
1886
+        // If setting the status, ensure it's set to a valid status.
1887
+        if ( true === $this->object_read ) {
1888 1888
 
1889
-			// Only allow valid new status.
1890
-			if ( ! array_key_exists( $new_status, $statuses ) ) {
1891
-				$new_status = $this->get_default_status();
1892
-			}
1889
+            // Only allow valid new status.
1890
+            if ( ! array_key_exists( $new_status, $statuses ) ) {
1891
+                $new_status = $this->get_default_status();
1892
+            }
1893 1893
 
1894
-			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1895
-			if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1896
-				$old_status = $this->get_default_status();
1897
-			}
1894
+            // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1895
+            if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1896
+                $old_status = $this->get_default_status();
1897
+            }
1898 1898
 
1899
-			// Paid - Renewal (i.e when duplicating a parent invoice )
1900
-			if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1901
-				$old_status = 'wpi-pending';
1902
-			}
1899
+            // Paid - Renewal (i.e when duplicating a parent invoice )
1900
+            if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1901
+                $old_status = 'wpi-pending';
1902
+            }
1903 1903
 
1904
-		}
1904
+        }
1905 1905
 
1906
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1907
-			$this->status_transition = array(
1908
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1909
-				'to'     => $new_status,
1910
-				'note'   => $note,
1911
-				'manual' => (bool) $manual_update,
1912
-			);
1906
+        if ( true === $this->object_read && $old_status !== $new_status ) {
1907
+            $this->status_transition = array(
1908
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1909
+                'to'     => $new_status,
1910
+                'note'   => $note,
1911
+                'manual' => (bool) $manual_update,
1912
+            );
1913 1913
 
1914
-			if ( $manual_update ) {
1915
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1916
-			}
1914
+            if ( $manual_update ) {
1915
+                do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1916
+            }
1917 1917
 
1918
-			$this->maybe_set_date_paid();
1918
+            $this->maybe_set_date_paid();
1919 1919
 
1920
-		}
1920
+        }
1921 1921
 
1922
-		return array(
1923
-			'from' => $old_status,
1924
-			'to'   => $new_status,
1925
-		);
1926
-	}
1922
+        return array(
1923
+            'from' => $old_status,
1924
+            'to'   => $new_status,
1925
+        );
1926
+    }
1927 1927
 
1928
-	/**
1929
-	 * Maybe set date paid.
1930
-	 *
1931
-	 * Sets the date paid variable when transitioning to the payment complete
1932
-	 * order status.
1933
-	 *
1934
-	 * @since 1.0.19
1935
-	 */
1936
-	public function maybe_set_date_paid() {
1928
+    /**
1929
+     * Maybe set date paid.
1930
+     *
1931
+     * Sets the date paid variable when transitioning to the payment complete
1932
+     * order status.
1933
+     *
1934
+     * @since 1.0.19
1935
+     */
1936
+    public function maybe_set_date_paid() {
1937 1937
 
1938
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1939
-			$this->set_date_completed( current_time( 'mysql' ) );
1940
-		}
1941
-	}
1938
+        if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1939
+            $this->set_date_completed( current_time( 'mysql' ) );
1940
+        }
1941
+    }
1942 1942
 
1943 1943
     /**
1944
-	 * Set parent invoice ID.
1945
-	 *
1946
-	 * @since 1.0.19
1947
-	 */
1948
-	public function set_parent_id( $value ) {
1949
-		if ( $value && ( $value === $this->get_id() ) ) {
1950
-			return;
1951
-		}
1952
-		$this->set_prop( 'parent_id', absint( $value ) );
1944
+     * Set parent invoice ID.
1945
+     *
1946
+     * @since 1.0.19
1947
+     */
1948
+    public function set_parent_id( $value ) {
1949
+        if ( $value && ( $value === $this->get_id() ) ) {
1950
+            return;
1951
+        }
1952
+        $this->set_prop( 'parent_id', absint( $value ) );
1953 1953
     }
1954 1954
 
1955 1955
     /**
1956
-	 * Set plugin version when the invoice was created.
1957
-	 *
1958
-	 * @since 1.0.19
1959
-	 */
1960
-	public function set_version( $value ) {
1961
-		$this->set_prop( 'version', $value );
1956
+     * Set plugin version when the invoice was created.
1957
+     *
1958
+     * @since 1.0.19
1959
+     */
1960
+    public function set_version( $value ) {
1961
+        $this->set_prop( 'version', $value );
1962 1962
     }
1963
-
1964
-    /**
1965
-	 * Set date when the invoice was created.
1966
-	 *
1967
-	 * @since 1.0.19
1968
-	 * @param string $value Value to set.
1963
+
1964
+    /**
1965
+     * Set date when the invoice was created.
1966
+     *
1967
+     * @since 1.0.19
1968
+     * @param string $value Value to set.
1969 1969
      * @return bool Whether or not the date was set.
1970
-	 */
1971
-	public function set_date_created( $value ) {
1970
+     */
1971
+    public function set_date_created( $value ) {
1972 1972
         $date = strtotime( $value );
1973 1973
 
1974 1974
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1976,19 +1976,19 @@  discard block
 block discarded – undo
1976 1976
             return true;
1977 1977
         }
1978 1978
 
1979
-		$this->set_prop( 'date_created', '' );
1980
-		return false;
1979
+        $this->set_prop( 'date_created', '' );
1980
+        return false;
1981 1981
 
1982 1982
     }
1983 1983
 
1984 1984
     /**
1985
-	 * Set date invoice due date.
1986
-	 *
1987
-	 * @since 1.0.19
1988
-	 * @param string $value Value to set.
1985
+     * Set date invoice due date.
1986
+     *
1987
+     * @since 1.0.19
1988
+     * @param string $value Value to set.
1989 1989
      * @return bool Whether or not the date was set.
1990
-	 */
1991
-	public function set_due_date( $value ) {
1990
+     */
1991
+    public function set_due_date( $value ) {
1992 1992
         $date = strtotime( $value );
1993 1993
 
1994 1994
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1996,29 +1996,29 @@  discard block
 block discarded – undo
1996 1996
             return true;
1997 1997
         }
1998 1998
 
1999
-		$this->set_prop( 'due_date', '' );
1999
+        $this->set_prop( 'due_date', '' );
2000 2000
         return false;
2001 2001
 
2002 2002
     }
2003 2003
 
2004 2004
     /**
2005
-	 * Alias of self::set_due_date().
2006
-	 *
2007
-	 * @since 1.0.19
2008
-	 * @param  string $value New name.
2009
-	 */
2010
-	public function set_date_due( $value ) {
2011
-		$this->set_due_date( $value );
2005
+     * Alias of self::set_due_date().
2006
+     *
2007
+     * @since 1.0.19
2008
+     * @param  string $value New name.
2009
+     */
2010
+    public function set_date_due( $value ) {
2011
+        $this->set_due_date( $value );
2012 2012
     }
2013 2013
 
2014 2014
     /**
2015
-	 * Set date invoice was completed.
2016
-	 *
2017
-	 * @since 1.0.19
2018
-	 * @param string $value Value to set.
2015
+     * Set date invoice was completed.
2016
+     *
2017
+     * @since 1.0.19
2018
+     * @param string $value Value to set.
2019 2019
      * @return bool Whether or not the date was set.
2020
-	 */
2021
-	public function set_completed_date( $value ) {
2020
+     */
2021
+    public function set_completed_date( $value ) {
2022 2022
         $date = strtotime( $value );
2023 2023
 
2024 2024
         if ( $date && $value !== '0000-00-00 00:00:00'  ) {
@@ -2026,29 +2026,29 @@  discard block
 block discarded – undo
2026 2026
             return true;
2027 2027
         }
2028 2028
 
2029
-		$this->set_prop( 'completed_date', '' );
2029
+        $this->set_prop( 'completed_date', '' );
2030 2030
         return false;
2031 2031
 
2032 2032
     }
2033 2033
 
2034 2034
     /**
2035
-	 * Alias of self::set_completed_date().
2036
-	 *
2037
-	 * @since 1.0.19
2038
-	 * @param  string $value New name.
2039
-	 */
2040
-	public function set_date_completed( $value ) {
2041
-		$this->set_completed_date( $value );
2035
+     * Alias of self::set_completed_date().
2036
+     *
2037
+     * @since 1.0.19
2038
+     * @param  string $value New name.
2039
+     */
2040
+    public function set_date_completed( $value ) {
2041
+        $this->set_completed_date( $value );
2042 2042
     }
2043 2043
 
2044 2044
     /**
2045
-	 * Set date when the invoice was last modified.
2046
-	 *
2047
-	 * @since 1.0.19
2048
-	 * @param string $value Value to set.
2045
+     * Set date when the invoice was last modified.
2046
+     *
2047
+     * @since 1.0.19
2048
+     * @param string $value Value to set.
2049 2049
      * @return bool Whether or not the date was set.
2050
-	 */
2051
-	public function set_date_modified( $value ) {
2050
+     */
2051
+    public function set_date_modified( $value ) {
2052 2052
         $date = strtotime( $value );
2053 2053
 
2054 2054
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2056,763 +2056,763 @@  discard block
 block discarded – undo
2056 2056
             return true;
2057 2057
         }
2058 2058
 
2059
-		$this->set_prop( 'date_modified', '' );
2059
+        $this->set_prop( 'date_modified', '' );
2060 2060
         return false;
2061 2061
 
2062 2062
     }
2063 2063
 
2064 2064
     /**
2065
-	 * Set the invoice number.
2066
-	 *
2067
-	 * @since 1.0.19
2068
-	 * @param  string $value New number.
2069
-	 */
2070
-	public function set_number( $value ) {
2065
+     * Set the invoice number.
2066
+     *
2067
+     * @since 1.0.19
2068
+     * @param  string $value New number.
2069
+     */
2070
+    public function set_number( $value ) {
2071 2071
         $number = sanitize_text_field( $value );
2072
-		$this->set_prop( 'number', $number );
2072
+        $this->set_prop( 'number', $number );
2073 2073
     }
2074 2074
 
2075 2075
     /**
2076
-	 * Set the invoice type.
2077
-	 *
2078
-	 * @since 1.0.19
2079
-	 * @param  string $value Type.
2080
-	 */
2081
-	public function set_type( $value ) {
2076
+     * Set the invoice type.
2077
+     *
2078
+     * @since 1.0.19
2079
+     * @param  string $value Type.
2080
+     */
2081
+    public function set_type( $value ) {
2082 2082
         $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
2083
-		$this->set_prop( 'type', $type );
2084
-	}
2083
+        $this->set_prop( 'type', $type );
2084
+    }
2085 2085
 
2086 2086
     /**
2087
-	 * Set the invoice post type.
2088
-	 *
2089
-	 * @since 1.0.19
2090
-	 * @param  string $value Post type.
2091
-	 */
2092
-	public function set_post_type( $value ) {
2087
+     * Set the invoice post type.
2088
+     *
2089
+     * @since 1.0.19
2090
+     * @param  string $value Post type.
2091
+     */
2092
+    public function set_post_type( $value ) {
2093 2093
         if ( getpaid_is_invoice_post_type( $value ) ) {
2094
-			$this->set_type( $value );
2094
+            $this->set_type( $value );
2095 2095
             $this->set_prop( 'post_type', $value );
2096 2096
         }
2097 2097
     }
2098 2098
 
2099 2099
     /**
2100
-	 * Set the invoice key.
2101
-	 *
2102
-	 * @since 1.0.19
2103
-	 * @param  string $value New key.
2104
-	 */
2105
-	public function set_key( $value ) {
2100
+     * Set the invoice key.
2101
+     *
2102
+     * @since 1.0.19
2103
+     * @param  string $value New key.
2104
+     */
2105
+    public function set_key( $value ) {
2106 2106
         $key = sanitize_text_field( $value );
2107
-		$this->set_prop( 'key', $key );
2107
+        $this->set_prop( 'key', $key );
2108 2108
     }
2109 2109
 
2110 2110
     /**
2111
-	 * Set the invoice mode.
2112
-	 *
2113
-	 * @since 1.0.19
2114
-	 * @param  string $value mode.
2115
-	 */
2116
-	public function set_mode( $value ) {
2111
+     * Set the invoice mode.
2112
+     *
2113
+     * @since 1.0.19
2114
+     * @param  string $value mode.
2115
+     */
2116
+    public function set_mode( $value ) {
2117 2117
         if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
2118 2118
             $this->set_prop( 'value', $value );
2119 2119
         }
2120 2120
     }
2121 2121
 
2122 2122
     /**
2123
-	 * Set the invoice path.
2124
-	 *
2125
-	 * @since 1.0.19
2126
-	 * @param  string $value path.
2127
-	 */
2128
-	public function set_path( $value ) {
2123
+     * Set the invoice path.
2124
+     *
2125
+     * @since 1.0.19
2126
+     * @param  string $value path.
2127
+     */
2128
+    public function set_path( $value ) {
2129 2129
         $this->set_prop( 'path', $value );
2130 2130
     }
2131 2131
 
2132 2132
     /**
2133
-	 * Set the invoice name.
2134
-	 *
2135
-	 * @since 1.0.19
2136
-	 * @param  string $value New name.
2137
-	 */
2138
-	public function set_name( $value ) {
2133
+     * Set the invoice name.
2134
+     *
2135
+     * @since 1.0.19
2136
+     * @param  string $value New name.
2137
+     */
2138
+    public function set_name( $value ) {
2139 2139
         $name = sanitize_text_field( $value );
2140
-		$this->set_prop( 'name', $name );
2140
+        $this->set_prop( 'name', $name );
2141 2141
     }
2142 2142
 
2143 2143
     /**
2144
-	 * Alias of self::set_name().
2145
-	 *
2146
-	 * @since 1.0.19
2147
-	 * @param  string $value New name.
2148
-	 */
2149
-	public function set_title( $value ) {
2150
-		$this->set_name( $value );
2144
+     * Alias of self::set_name().
2145
+     *
2146
+     * @since 1.0.19
2147
+     * @param  string $value New name.
2148
+     */
2149
+    public function set_title( $value ) {
2150
+        $this->set_name( $value );
2151 2151
     }
2152 2152
 
2153 2153
     /**
2154
-	 * Set the invoice description.
2155
-	 *
2156
-	 * @since 1.0.19
2157
-	 * @param  string $value New description.
2158
-	 */
2159
-	public function set_description( $value ) {
2154
+     * Set the invoice description.
2155
+     *
2156
+     * @since 1.0.19
2157
+     * @param  string $value New description.
2158
+     */
2159
+    public function set_description( $value ) {
2160 2160
         $description = wp_kses_post( $value );
2161
-		$this->set_prop( 'description', $description );
2161
+        $this->set_prop( 'description', $description );
2162
+    }
2163
+
2164
+    /**
2165
+     * Alias of self::set_description().
2166
+     *
2167
+     * @since 1.0.19
2168
+     * @param  string $value New description.
2169
+     */
2170
+    public function set_excerpt( $value ) {
2171
+        $this->set_description( $value );
2172
+    }
2173
+
2174
+    /**
2175
+     * Alias of self::set_description().
2176
+     *
2177
+     * @since 1.0.19
2178
+     * @param  string $value New description.
2179
+     */
2180
+    public function set_summary( $value ) {
2181
+        $this->set_description( $value );
2162 2182
     }
2163 2183
 
2164 2184
     /**
2165
-	 * Alias of self::set_description().
2166
-	 *
2167
-	 * @since 1.0.19
2168
-	 * @param  string $value New description.
2169
-	 */
2170
-	public function set_excerpt( $value ) {
2171
-		$this->set_description( $value );
2185
+     * Set the receiver of the invoice.
2186
+     *
2187
+     * @since 1.0.19
2188
+     * @param  int $value New author.
2189
+     */
2190
+    public function set_author( $value ) {
2191
+        $user = get_user_by( 'id', (int) $value );
2192
+
2193
+        if ( $user && $user->ID ) {
2194
+            $this->set_prop( 'author', $user->ID );
2195
+            $this->set_prop( 'email', $user->user_email );
2196
+        }
2197
+
2172 2198
     }
2173 2199
 
2174 2200
     /**
2175
-	 * Alias of self::set_description().
2176
-	 *
2177
-	 * @since 1.0.19
2178
-	 * @param  string $value New description.
2179
-	 */
2180
-	public function set_summary( $value ) {
2181
-		$this->set_description( $value );
2201
+     * Alias of self::set_author().
2202
+     *
2203
+     * @since 1.0.19
2204
+     * @param  int $value New user id.
2205
+     */
2206
+    public function set_user_id( $value ) {
2207
+        $this->set_author( $value );
2182 2208
     }
2183 2209
 
2184 2210
     /**
2185
-	 * Set the receiver of the invoice.
2186
-	 *
2187
-	 * @since 1.0.19
2188
-	 * @param  int $value New author.
2189
-	 */
2190
-	public function set_author( $value ) {
2191
-		$user = get_user_by( 'id', (int) $value );
2211
+     * Alias of self::set_author().
2212
+     *
2213
+     * @since 1.0.19
2214
+     * @param  int $value New user id.
2215
+     */
2216
+    public function set_customer_id( $value ) {
2217
+        $this->set_author( $value );
2218
+    }
2192 2219
 
2193
-		if ( $user && $user->ID ) {
2194
-			$this->set_prop( 'author', $user->ID );
2195
-			$this->set_prop( 'email', $user->user_email );
2196
-		}
2220
+    /**
2221
+     * Set the customer's ip.
2222
+     *
2223
+     * @since 1.0.19
2224
+     * @param  string $value ip address.
2225
+     */
2226
+    public function set_ip( $value ) {
2227
+        $this->set_prop( 'ip', $value );
2228
+    }
2197 2229
 
2230
+    /**
2231
+     * Alias of self::set_ip().
2232
+     *
2233
+     * @since 1.0.19
2234
+     * @param  string $value ip address.
2235
+     */
2236
+    public function set_user_ip( $value ) {
2237
+        $this->set_ip( $value );
2198 2238
     }
2199 2239
 
2200 2240
     /**
2201
-	 * Alias of self::set_author().
2202
-	 *
2203
-	 * @since 1.0.19
2204
-	 * @param  int $value New user id.
2205
-	 */
2206
-	public function set_user_id( $value ) {
2207
-		$this->set_author( $value );
2241
+     * Set the customer's first name.
2242
+     *
2243
+     * @since 1.0.19
2244
+     * @param  string $value first name.
2245
+     */
2246
+    public function set_first_name( $value ) {
2247
+        $this->set_prop( 'first_name', $value );
2208 2248
     }
2209 2249
 
2210 2250
     /**
2211
-	 * Alias of self::set_author().
2212
-	 *
2213
-	 * @since 1.0.19
2214
-	 * @param  int $value New user id.
2215
-	 */
2216
-	public function set_customer_id( $value ) {
2217
-		$this->set_author( $value );
2251
+     * Alias of self::set_first_name().
2252
+     *
2253
+     * @since 1.0.19
2254
+     * @param  string $value first name.
2255
+     */
2256
+    public function set_user_first_name( $value ) {
2257
+        $this->set_first_name( $value );
2218 2258
     }
2219 2259
 
2220 2260
     /**
2221
-	 * Set the customer's ip.
2222
-	 *
2223
-	 * @since 1.0.19
2224
-	 * @param  string $value ip address.
2225
-	 */
2226
-	public function set_ip( $value ) {
2227
-		$this->set_prop( 'ip', $value );
2261
+     * Alias of self::set_first_name().
2262
+     *
2263
+     * @since 1.0.19
2264
+     * @param  string $value first name.
2265
+     */
2266
+    public function set_customer_first_name( $value ) {
2267
+        $this->set_first_name( $value );
2228 2268
     }
2229 2269
 
2230 2270
     /**
2231
-	 * Alias of self::set_ip().
2232
-	 *
2233
-	 * @since 1.0.19
2234
-	 * @param  string $value ip address.
2235
-	 */
2236
-	public function set_user_ip( $value ) {
2237
-		$this->set_ip( $value );
2271
+     * Set the customer's last name.
2272
+     *
2273
+     * @since 1.0.19
2274
+     * @param  string $value last name.
2275
+     */
2276
+    public function set_last_name( $value ) {
2277
+        $this->set_prop( 'last_name', $value );
2238 2278
     }
2239 2279
 
2240 2280
     /**
2241
-	 * Set the customer's first name.
2242
-	 *
2243
-	 * @since 1.0.19
2244
-	 * @param  string $value first name.
2245
-	 */
2246
-	public function set_first_name( $value ) {
2247
-		$this->set_prop( 'first_name', $value );
2281
+     * Alias of self::set_last_name().
2282
+     *
2283
+     * @since 1.0.19
2284
+     * @param  string $value last name.
2285
+     */
2286
+    public function set_user_last_name( $value ) {
2287
+        $this->set_last_name( $value );
2248 2288
     }
2249 2289
 
2250 2290
     /**
2251
-	 * Alias of self::set_first_name().
2252
-	 *
2253
-	 * @since 1.0.19
2254
-	 * @param  string $value first name.
2255
-	 */
2256
-	public function set_user_first_name( $value ) {
2257
-		$this->set_first_name( $value );
2291
+     * Alias of self::set_last_name().
2292
+     *
2293
+     * @since 1.0.19
2294
+     * @param  string $value last name.
2295
+     */
2296
+    public function set_customer_last_name( $value ) {
2297
+        $this->set_last_name( $value );
2258 2298
     }
2259 2299
 
2260 2300
     /**
2261
-	 * Alias of self::set_first_name().
2262
-	 *
2263
-	 * @since 1.0.19
2264
-	 * @param  string $value first name.
2265
-	 */
2266
-	public function set_customer_first_name( $value ) {
2267
-		$this->set_first_name( $value );
2301
+     * Set the customer's phone number.
2302
+     *
2303
+     * @since 1.0.19
2304
+     * @param  string $value phone.
2305
+     */
2306
+    public function set_phone( $value ) {
2307
+        $this->set_prop( 'phone', $value );
2268 2308
     }
2269 2309
 
2270 2310
     /**
2271
-	 * Set the customer's last name.
2272
-	 *
2273
-	 * @since 1.0.19
2274
-	 * @param  string $value last name.
2275
-	 */
2276
-	public function set_last_name( $value ) {
2277
-		$this->set_prop( 'last_name', $value );
2311
+     * Alias of self::set_phone().
2312
+     *
2313
+     * @since 1.0.19
2314
+     * @param  string $value phone.
2315
+     */
2316
+    public function set_user_phone( $value ) {
2317
+        $this->set_phone( $value );
2278 2318
     }
2279 2319
 
2280 2320
     /**
2281
-	 * Alias of self::set_last_name().
2282
-	 *
2283
-	 * @since 1.0.19
2284
-	 * @param  string $value last name.
2285
-	 */
2286
-	public function set_user_last_name( $value ) {
2287
-		$this->set_last_name( $value );
2321
+     * Alias of self::set_phone().
2322
+     *
2323
+     * @since 1.0.19
2324
+     * @param  string $value phone.
2325
+     */
2326
+    public function set_customer_phone( $value ) {
2327
+        $this->set_phone( $value );
2288 2328
     }
2289 2329
 
2290 2330
     /**
2291
-	 * Alias of self::set_last_name().
2292
-	 *
2293
-	 * @since 1.0.19
2294
-	 * @param  string $value last name.
2295
-	 */
2296
-	public function set_customer_last_name( $value ) {
2297
-		$this->set_last_name( $value );
2331
+     * Alias of self::set_phone().
2332
+     *
2333
+     * @since 1.0.19
2334
+     * @param  string $value phone.
2335
+     */
2336
+    public function set_phone_number( $value ) {
2337
+        $this->set_phone( $value );
2298 2338
     }
2299 2339
 
2300 2340
     /**
2301
-	 * Set the customer's phone number.
2302
-	 *
2303
-	 * @since 1.0.19
2304
-	 * @param  string $value phone.
2305
-	 */
2306
-	public function set_phone( $value ) {
2307
-		$this->set_prop( 'phone', $value );
2341
+     * Set the customer's email address.
2342
+     *
2343
+     * @since 1.0.19
2344
+     * @param  string $value email address.
2345
+     */
2346
+    public function set_email( $value ) {
2347
+        $this->set_prop( 'email', $value );
2308 2348
     }
2309 2349
 
2310 2350
     /**
2311
-	 * Alias of self::set_phone().
2312
-	 *
2313
-	 * @since 1.0.19
2314
-	 * @param  string $value phone.
2315
-	 */
2316
-	public function set_user_phone( $value ) {
2317
-		$this->set_phone( $value );
2351
+     * Alias of self::set_email().
2352
+     *
2353
+     * @since 1.0.19
2354
+     * @param  string $value email address.
2355
+     */
2356
+    public function set_user_email( $value ) {
2357
+        $this->set_email( $value );
2318 2358
     }
2319 2359
 
2320 2360
     /**
2321
-	 * Alias of self::set_phone().
2322
-	 *
2323
-	 * @since 1.0.19
2324
-	 * @param  string $value phone.
2325
-	 */
2326
-	public function set_customer_phone( $value ) {
2327
-		$this->set_phone( $value );
2361
+     * Alias of self::set_email().
2362
+     *
2363
+     * @since 1.0.19
2364
+     * @param  string $value email address.
2365
+     */
2366
+    public function set_email_address( $value ) {
2367
+        $this->set_email( $value );
2328 2368
     }
2329 2369
 
2330 2370
     /**
2331
-	 * Alias of self::set_phone().
2332
-	 *
2333
-	 * @since 1.0.19
2334
-	 * @param  string $value phone.
2335
-	 */
2336
-	public function set_phone_number( $value ) {
2337
-		$this->set_phone( $value );
2371
+     * Alias of self::set_email().
2372
+     *
2373
+     * @since 1.0.19
2374
+     * @param  string $value email address.
2375
+     */
2376
+    public function set_customer_email( $value ) {
2377
+        $this->set_email( $value );
2338 2378
     }
2339 2379
 
2340 2380
     /**
2341
-	 * Set the customer's email address.
2342
-	 *
2343
-	 * @since 1.0.19
2344
-	 * @param  string $value email address.
2345
-	 */
2346
-	public function set_email( $value ) {
2347
-		$this->set_prop( 'email', $value );
2381
+     * Set the customer's country.
2382
+     *
2383
+     * @since 1.0.19
2384
+     * @param  string $value country.
2385
+     */
2386
+    public function set_country( $value ) {
2387
+        $this->set_prop( 'country', $value );
2348 2388
     }
2349 2389
 
2350 2390
     /**
2351
-	 * Alias of self::set_email().
2352
-	 *
2353
-	 * @since 1.0.19
2354
-	 * @param  string $value email address.
2355
-	 */
2356
-	public function set_user_email( $value ) {
2357
-		$this->set_email( $value );
2391
+     * Alias of self::set_country().
2392
+     *
2393
+     * @since 1.0.19
2394
+     * @param  string $value country.
2395
+     */
2396
+    public function set_user_country( $value ) {
2397
+        $this->set_country( $value );
2358 2398
     }
2359 2399
 
2360 2400
     /**
2361
-	 * Alias of self::set_email().
2362
-	 *
2363
-	 * @since 1.0.19
2364
-	 * @param  string $value email address.
2365
-	 */
2366
-	public function set_email_address( $value ) {
2367
-		$this->set_email( $value );
2401
+     * Alias of self::set_country().
2402
+     *
2403
+     * @since 1.0.19
2404
+     * @param  string $value country.
2405
+     */
2406
+    public function set_customer_country( $value ) {
2407
+        $this->set_country( $value );
2368 2408
     }
2369 2409
 
2370 2410
     /**
2371
-	 * Alias of self::set_email().
2372
-	 *
2373
-	 * @since 1.0.19
2374
-	 * @param  string $value email address.
2375
-	 */
2376
-	public function set_customer_email( $value ) {
2377
-		$this->set_email( $value );
2411
+     * Set the customer's state.
2412
+     *
2413
+     * @since 1.0.19
2414
+     * @param  string $value state.
2415
+     */
2416
+    public function set_state( $value ) {
2417
+        $this->set_prop( 'state', $value );
2378 2418
     }
2379 2419
 
2380 2420
     /**
2381
-	 * Set the customer's country.
2382
-	 *
2383
-	 * @since 1.0.19
2384
-	 * @param  string $value country.
2385
-	 */
2386
-	public function set_country( $value ) {
2387
-		$this->set_prop( 'country', $value );
2421
+     * Alias of self::set_state().
2422
+     *
2423
+     * @since 1.0.19
2424
+     * @param  string $value state.
2425
+     */
2426
+    public function set_user_state( $value ) {
2427
+        $this->set_state( $value );
2388 2428
     }
2389 2429
 
2390 2430
     /**
2391
-	 * Alias of self::set_country().
2392
-	 *
2393
-	 * @since 1.0.19
2394
-	 * @param  string $value country.
2395
-	 */
2396
-	public function set_user_country( $value ) {
2397
-		$this->set_country( $value );
2431
+     * Alias of self::set_state().
2432
+     *
2433
+     * @since 1.0.19
2434
+     * @param  string $value state.
2435
+     */
2436
+    public function set_customer_state( $value ) {
2437
+        $this->set_state( $value );
2398 2438
     }
2399 2439
 
2400 2440
     /**
2401
-	 * Alias of self::set_country().
2402
-	 *
2403
-	 * @since 1.0.19
2404
-	 * @param  string $value country.
2405
-	 */
2406
-	public function set_customer_country( $value ) {
2407
-		$this->set_country( $value );
2441
+     * Set the customer's city.
2442
+     *
2443
+     * @since 1.0.19
2444
+     * @param  string $value city.
2445
+     */
2446
+    public function set_city( $value ) {
2447
+        $this->set_prop( 'city', $value );
2408 2448
     }
2409 2449
 
2410 2450
     /**
2411
-	 * Set the customer's state.
2412
-	 *
2413
-	 * @since 1.0.19
2414
-	 * @param  string $value state.
2415
-	 */
2416
-	public function set_state( $value ) {
2417
-		$this->set_prop( 'state', $value );
2451
+     * Alias of self::set_city().
2452
+     *
2453
+     * @since 1.0.19
2454
+     * @param  string $value city.
2455
+     */
2456
+    public function set_user_city( $value ) {
2457
+        $this->set_city( $value );
2418 2458
     }
2419 2459
 
2420 2460
     /**
2421
-	 * Alias of self::set_state().
2422
-	 *
2423
-	 * @since 1.0.19
2424
-	 * @param  string $value state.
2425
-	 */
2426
-	public function set_user_state( $value ) {
2427
-		$this->set_state( $value );
2461
+     * Alias of self::set_city().
2462
+     *
2463
+     * @since 1.0.19
2464
+     * @param  string $value city.
2465
+     */
2466
+    public function set_customer_city( $value ) {
2467
+        $this->set_city( $value );
2428 2468
     }
2429 2469
 
2430 2470
     /**
2431
-	 * Alias of self::set_state().
2432
-	 *
2433
-	 * @since 1.0.19
2434
-	 * @param  string $value state.
2435
-	 */
2436
-	public function set_customer_state( $value ) {
2437
-		$this->set_state( $value );
2471
+     * Set the customer's zip code.
2472
+     *
2473
+     * @since 1.0.19
2474
+     * @param  string $value zip.
2475
+     */
2476
+    public function set_zip( $value ) {
2477
+        $this->set_prop( 'zip', $value );
2438 2478
     }
2439 2479
 
2440 2480
     /**
2441
-	 * Set the customer's city.
2442
-	 *
2443
-	 * @since 1.0.19
2444
-	 * @param  string $value city.
2445
-	 */
2446
-	public function set_city( $value ) {
2447
-		$this->set_prop( 'city', $value );
2481
+     * Alias of self::set_zip().
2482
+     *
2483
+     * @since 1.0.19
2484
+     * @param  string $value zip.
2485
+     */
2486
+    public function set_user_zip( $value ) {
2487
+        $this->set_zip( $value );
2448 2488
     }
2449 2489
 
2450 2490
     /**
2451
-	 * Alias of self::set_city().
2452
-	 *
2453
-	 * @since 1.0.19
2454
-	 * @param  string $value city.
2455
-	 */
2456
-	public function set_user_city( $value ) {
2457
-		$this->set_city( $value );
2491
+     * Alias of self::set_zip().
2492
+     *
2493
+     * @since 1.0.19
2494
+     * @param  string $value zip.
2495
+     */
2496
+    public function set_customer_zip( $value ) {
2497
+        $this->set_zip( $value );
2458 2498
     }
2459 2499
 
2460 2500
     /**
2461
-	 * Alias of self::set_city().
2462
-	 *
2463
-	 * @since 1.0.19
2464
-	 * @param  string $value city.
2465
-	 */
2466
-	public function set_customer_city( $value ) {
2467
-		$this->set_city( $value );
2501
+     * Set the customer's company.
2502
+     *
2503
+     * @since 1.0.19
2504
+     * @param  string $value company.
2505
+     */
2506
+    public function set_company( $value ) {
2507
+        $this->set_prop( 'company', $value );
2468 2508
     }
2469 2509
 
2470 2510
     /**
2471
-	 * Set the customer's zip code.
2472
-	 *
2473
-	 * @since 1.0.19
2474
-	 * @param  string $value zip.
2475
-	 */
2476
-	public function set_zip( $value ) {
2477
-		$this->set_prop( 'zip', $value );
2511
+     * Alias of self::set_company().
2512
+     *
2513
+     * @since 1.0.19
2514
+     * @param  string $value company.
2515
+     */
2516
+    public function set_user_company( $value ) {
2517
+        $this->set_company( $value );
2478 2518
     }
2479 2519
 
2480 2520
     /**
2481
-	 * Alias of self::set_zip().
2482
-	 *
2483
-	 * @since 1.0.19
2484
-	 * @param  string $value zip.
2485
-	 */
2486
-	public function set_user_zip( $value ) {
2487
-		$this->set_zip( $value );
2521
+     * Alias of self::set_company().
2522
+     *
2523
+     * @since 1.0.19
2524
+     * @param  string $value company.
2525
+     */
2526
+    public function set_customer_company( $value ) {
2527
+        $this->set_company( $value );
2488 2528
     }
2489 2529
 
2490 2530
     /**
2491
-	 * Alias of self::set_zip().
2492
-	 *
2493
-	 * @since 1.0.19
2494
-	 * @param  string $value zip.
2495
-	 */
2496
-	public function set_customer_zip( $value ) {
2497
-		$this->set_zip( $value );
2531
+     * Set the customer's var number.
2532
+     *
2533
+     * @since 1.0.19
2534
+     * @param  string $value var number.
2535
+     */
2536
+    public function set_vat_number( $value ) {
2537
+        $this->set_prop( 'vat_number', $value );
2498 2538
     }
2499 2539
 
2500 2540
     /**
2501
-	 * Set the customer's company.
2502
-	 *
2503
-	 * @since 1.0.19
2504
-	 * @param  string $value company.
2505
-	 */
2506
-	public function set_company( $value ) {
2507
-		$this->set_prop( 'company', $value );
2541
+     * Alias of self::set_vat_number().
2542
+     *
2543
+     * @since 1.0.19
2544
+     * @param  string $value var number.
2545
+     */
2546
+    public function set_user_vat_number( $value ) {
2547
+        $this->set_vat_number( $value );
2508 2548
     }
2509 2549
 
2510 2550
     /**
2511
-	 * Alias of self::set_company().
2512
-	 *
2513
-	 * @since 1.0.19
2514
-	 * @param  string $value company.
2515
-	 */
2516
-	public function set_user_company( $value ) {
2517
-		$this->set_company( $value );
2551
+     * Alias of self::set_vat_number().
2552
+     *
2553
+     * @since 1.0.19
2554
+     * @param  string $value var number.
2555
+     */
2556
+    public function set_customer_vat_number( $value ) {
2557
+        $this->set_vat_number( $value );
2518 2558
     }
2519 2559
 
2520 2560
     /**
2521
-	 * Alias of self::set_company().
2522
-	 *
2523
-	 * @since 1.0.19
2524
-	 * @param  string $value company.
2525
-	 */
2526
-	public function set_customer_company( $value ) {
2527
-		$this->set_company( $value );
2561
+     * Set the customer's vat rate.
2562
+     *
2563
+     * @since 1.0.19
2564
+     * @param  string $value var rate.
2565
+     */
2566
+    public function set_vat_rate( $value ) {
2567
+        $this->set_prop( 'vat_rate', $value );
2528 2568
     }
2529 2569
 
2530 2570
     /**
2531
-	 * Set the customer's var number.
2532
-	 *
2533
-	 * @since 1.0.19
2534
-	 * @param  string $value var number.
2535
-	 */
2536
-	public function set_vat_number( $value ) {
2537
-		$this->set_prop( 'vat_number', $value );
2571
+     * Alias of self::set_vat_rate().
2572
+     *
2573
+     * @since 1.0.19
2574
+     * @param  string $value var number.
2575
+     */
2576
+    public function set_user_vat_rate( $value ) {
2577
+        $this->set_vat_rate( $value );
2538 2578
     }
2539 2579
 
2540 2580
     /**
2541
-	 * Alias of self::set_vat_number().
2542
-	 *
2543
-	 * @since 1.0.19
2544
-	 * @param  string $value var number.
2545
-	 */
2546
-	public function set_user_vat_number( $value ) {
2547
-		$this->set_vat_number( $value );
2581
+     * Alias of self::set_vat_rate().
2582
+     *
2583
+     * @since 1.0.19
2584
+     * @param  string $value var number.
2585
+     */
2586
+    public function set_customer_vat_rate( $value ) {
2587
+        $this->set_vat_rate( $value );
2548 2588
     }
2549 2589
 
2550 2590
     /**
2551
-	 * Alias of self::set_vat_number().
2552
-	 *
2553
-	 * @since 1.0.19
2554
-	 * @param  string $value var number.
2555
-	 */
2556
-	public function set_customer_vat_number( $value ) {
2557
-		$this->set_vat_number( $value );
2591
+     * Set the customer's address.
2592
+     *
2593
+     * @since 1.0.19
2594
+     * @param  string $value address.
2595
+     */
2596
+    public function set_address( $value ) {
2597
+        $this->set_prop( 'address', $value );
2558 2598
     }
2559 2599
 
2560 2600
     /**
2561
-	 * Set the customer's vat rate.
2562
-	 *
2563
-	 * @since 1.0.19
2564
-	 * @param  string $value var rate.
2565
-	 */
2566
-	public function set_vat_rate( $value ) {
2567
-		$this->set_prop( 'vat_rate', $value );
2601
+     * Alias of self::set_address().
2602
+     *
2603
+     * @since 1.0.19
2604
+     * @param  string $value address.
2605
+     */
2606
+    public function set_user_address( $value ) {
2607
+        $this->set_address( $value );
2568 2608
     }
2569 2609
 
2570 2610
     /**
2571
-	 * Alias of self::set_vat_rate().
2572
-	 *
2573
-	 * @since 1.0.19
2574
-	 * @param  string $value var number.
2575
-	 */
2576
-	public function set_user_vat_rate( $value ) {
2577
-		$this->set_vat_rate( $value );
2611
+     * Alias of self::set_address().
2612
+     *
2613
+     * @since 1.0.19
2614
+     * @param  string $value address.
2615
+     */
2616
+    public function set_customer_address( $value ) {
2617
+        $this->set_address( $value );
2578 2618
     }
2579 2619
 
2580 2620
     /**
2581
-	 * Alias of self::set_vat_rate().
2582
-	 *
2583
-	 * @since 1.0.19
2584
-	 * @param  string $value var number.
2585
-	 */
2586
-	public function set_customer_vat_rate( $value ) {
2587
-		$this->set_vat_rate( $value );
2621
+     * Set whether the customer has viewed the invoice or not.
2622
+     *
2623
+     * @since 1.0.19
2624
+     * @param  int|bool $value confirmed.
2625
+     */
2626
+    public function set_is_viewed( $value ) {
2627
+        $this->set_prop( 'is_viewed', $value );
2588 2628
     }
2589 2629
 
2590 2630
     /**
2591
-	 * Set the customer's address.
2592
-	 *
2593
-	 * @since 1.0.19
2594
-	 * @param  string $value address.
2595
-	 */
2596
-	public function set_address( $value ) {
2597
-		$this->set_prop( 'address', $value );
2631
+     * Set extra email recipients.
2632
+     *
2633
+     * @since 1.0.19
2634
+     * @param  string $value email recipients.
2635
+     */
2636
+    public function set_email_cc( $value ) {
2637
+        $this->set_prop( 'email_cc', $value );
2598 2638
     }
2599 2639
 
2600 2640
     /**
2601
-	 * Alias of self::set_address().
2602
-	 *
2603
-	 * @since 1.0.19
2604
-	 * @param  string $value address.
2605
-	 */
2606
-	public function set_user_address( $value ) {
2607
-		$this->set_address( $value );
2641
+     * Set the invoice template.
2642
+     *
2643
+     * @since 1.0.19
2644
+     * @param  string $value template.
2645
+     */
2646
+    public function set_template( $value ) {
2647
+        if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2648
+            $this->set_prop( 'template', $value );
2649
+        }
2608 2650
     }
2609 2651
 
2610 2652
     /**
2611
-	 * Alias of self::set_address().
2612
-	 *
2613
-	 * @since 1.0.19
2614
-	 * @param  string $value address.
2615
-	 */
2616
-	public function set_customer_address( $value ) {
2617
-		$this->set_address( $value );
2653
+     * Set the invoice source.
2654
+     *
2655
+     * @since 1.0.19
2656
+     * @param  string $value email recipients.
2657
+     */
2658
+    public function created_via( $value ) {
2659
+        $this->set_prop( 'created_via', sanitize_text_field( $value ) );
2618 2660
     }
2619 2661
 
2620 2662
     /**
2621
-	 * Set whether the customer has viewed the invoice or not.
2622
-	 *
2623
-	 * @since 1.0.19
2624
-	 * @param  int|bool $value confirmed.
2625
-	 */
2626
-	public function set_is_viewed( $value ) {
2627
-		$this->set_prop( 'is_viewed', $value );
2628
-	}
2629
-
2630
-	/**
2631
-	 * Set extra email recipients.
2632
-	 *
2633
-	 * @since 1.0.19
2634
-	 * @param  string $value email recipients.
2635
-	 */
2636
-	public function set_email_cc( $value ) {
2637
-		$this->set_prop( 'email_cc', $value );
2638
-	}
2639
-
2640
-	/**
2641
-	 * Set the invoice template.
2642
-	 *
2643
-	 * @since 1.0.19
2644
-	 * @param  string $value template.
2645
-	 */
2646
-	public function set_template( $value ) {
2647
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2648
-			$this->set_prop( 'template', $value );
2649
-		}
2650
-	}
2651
-
2652
-	/**
2653
-	 * Set the invoice source.
2654
-	 *
2655
-	 * @since 1.0.19
2656
-	 * @param  string $value email recipients.
2657
-	 */
2658
-	public function created_via( $value ) {
2659
-		$this->set_prop( 'created_via', sanitize_text_field( $value ) );
2660
-	}
2661
-
2662
-	/**
2663
-	 * Set the customer's address confirmed status.
2664
-	 *
2665
-	 * @since 1.0.19
2666
-	 * @param  int|bool $value confirmed.
2667
-	 */
2668
-	public function set_address_confirmed( $value ) {
2669
-		$this->set_prop( 'address_confirmed', $value );
2663
+     * Set the customer's address confirmed status.
2664
+     *
2665
+     * @since 1.0.19
2666
+     * @param  int|bool $value confirmed.
2667
+     */
2668
+    public function set_address_confirmed( $value ) {
2669
+        $this->set_prop( 'address_confirmed', $value );
2670 2670
     }
2671 2671
 
2672 2672
     /**
2673
-	 * Alias of self::set_address_confirmed().
2674
-	 *
2675
-	 * @since 1.0.19
2676
-	 * @param  int|bool $value confirmed.
2677
-	 */
2678
-	public function set_user_address_confirmed( $value ) {
2679
-		$this->set_address_confirmed( $value );
2673
+     * Alias of self::set_address_confirmed().
2674
+     *
2675
+     * @since 1.0.19
2676
+     * @param  int|bool $value confirmed.
2677
+     */
2678
+    public function set_user_address_confirmed( $value ) {
2679
+        $this->set_address_confirmed( $value );
2680 2680
     }
2681 2681
 
2682 2682
     /**
2683
-	 * Alias of self::set_address_confirmed().
2684
-	 *
2685
-	 * @since 1.0.19
2686
-	 * @param  int|bool $value confirmed.
2687
-	 */
2688
-	public function set_customer_address_confirmed( $value ) {
2689
-		$this->set_address_confirmed( $value );
2683
+     * Alias of self::set_address_confirmed().
2684
+     *
2685
+     * @since 1.0.19
2686
+     * @param  int|bool $value confirmed.
2687
+     */
2688
+    public function set_customer_address_confirmed( $value ) {
2689
+        $this->set_address_confirmed( $value );
2690 2690
     }
2691 2691
 
2692 2692
     /**
2693
-	 * Set the invoice sub total.
2694
-	 *
2695
-	 * @since 1.0.19
2696
-	 * @param  float $value sub total.
2697
-	 */
2698
-	public function set_subtotal( $value ) {
2699
-		$this->set_prop( 'subtotal', $value );
2693
+     * Set the invoice sub total.
2694
+     *
2695
+     * @since 1.0.19
2696
+     * @param  float $value sub total.
2697
+     */
2698
+    public function set_subtotal( $value ) {
2699
+        $this->set_prop( 'subtotal', $value );
2700 2700
     }
2701 2701
 
2702 2702
     /**
2703
-	 * Set the invoice discount amount.
2704
-	 *
2705
-	 * @since 1.0.19
2706
-	 * @param  float $value discount total.
2707
-	 */
2708
-	public function set_total_discount( $value ) {
2709
-		$this->set_prop( 'total_discount', $value );
2703
+     * Set the invoice discount amount.
2704
+     *
2705
+     * @since 1.0.19
2706
+     * @param  float $value discount total.
2707
+     */
2708
+    public function set_total_discount( $value ) {
2709
+        $this->set_prop( 'total_discount', $value );
2710 2710
     }
2711 2711
 
2712 2712
     /**
2713
-	 * Alias of self::set_total_discount().
2714
-	 *
2715
-	 * @since 1.0.19
2716
-	 * @param  float $value discount total.
2717
-	 */
2718
-	public function set_discount( $value ) {
2719
-		$this->set_total_discount( $value );
2713
+     * Alias of self::set_total_discount().
2714
+     *
2715
+     * @since 1.0.19
2716
+     * @param  float $value discount total.
2717
+     */
2718
+    public function set_discount( $value ) {
2719
+        $this->set_total_discount( $value );
2720 2720
     }
2721 2721
 
2722 2722
     /**
2723
-	 * Set the invoice tax amount.
2724
-	 *
2725
-	 * @since 1.0.19
2726
-	 * @param  float $value tax total.
2727
-	 */
2728
-	public function set_total_tax( $value ) {
2729
-		$this->set_prop( 'total_tax', $value );
2723
+     * Set the invoice tax amount.
2724
+     *
2725
+     * @since 1.0.19
2726
+     * @param  float $value tax total.
2727
+     */
2728
+    public function set_total_tax( $value ) {
2729
+        $this->set_prop( 'total_tax', $value );
2730 2730
     }
2731 2731
 
2732 2732
     /**
2733
-	 * Alias of self::set_total_tax().
2734
-	 *
2735
-	 * @since 1.0.19
2736
-	 * @param  float $value tax total.
2737
-	 */
2738
-	public function set_tax_total( $value ) {
2739
-		$this->set_total_tax( $value );
2733
+     * Alias of self::set_total_tax().
2734
+     *
2735
+     * @since 1.0.19
2736
+     * @param  float $value tax total.
2737
+     */
2738
+    public function set_tax_total( $value ) {
2739
+        $this->set_total_tax( $value );
2740 2740
     }
2741 2741
 
2742 2742
     /**
2743
-	 * Set the invoice fees amount.
2744
-	 *
2745
-	 * @since 1.0.19
2746
-	 * @param  float $value fees total.
2747
-	 */
2748
-	public function set_total_fees( $value ) {
2749
-		$this->set_prop( 'total_fees', $value );
2743
+     * Set the invoice fees amount.
2744
+     *
2745
+     * @since 1.0.19
2746
+     * @param  float $value fees total.
2747
+     */
2748
+    public function set_total_fees( $value ) {
2749
+        $this->set_prop( 'total_fees', $value );
2750 2750
     }
2751 2751
 
2752 2752
     /**
2753
-	 * Alias of self::set_total_fees().
2754
-	 *
2755
-	 * @since 1.0.19
2756
-	 * @param  float $value fees total.
2757
-	 */
2758
-	public function set_fees_total( $value ) {
2759
-		$this->set_total_fees( $value );
2753
+     * Alias of self::set_total_fees().
2754
+     *
2755
+     * @since 1.0.19
2756
+     * @param  float $value fees total.
2757
+     */
2758
+    public function set_fees_total( $value ) {
2759
+        $this->set_total_fees( $value );
2760 2760
     }
2761 2761
 
2762 2762
     /**
2763
-	 * Set the invoice fees.
2764
-	 *
2765
-	 * @since 1.0.19
2766
-	 * @param  array $value fees.
2767
-	 */
2768
-	public function set_fees( $value ) {
2763
+     * Set the invoice fees.
2764
+     *
2765
+     * @since 1.0.19
2766
+     * @param  array $value fees.
2767
+     */
2768
+    public function set_fees( $value ) {
2769 2769
 
2770
-		if ( ! is_array( $value ) ) {
2771
-			$value = array();
2772
-		}
2770
+        if ( ! is_array( $value ) ) {
2771
+            $value = array();
2772
+        }
2773 2773
 
2774
-		$this->set_prop( 'fees', $value );
2774
+        $this->set_prop( 'fees', $value );
2775 2775
 
2776 2776
     }
2777 2777
 
2778 2778
     /**
2779
-	 * Set the invoice taxes.
2780
-	 *
2781
-	 * @since 1.0.19
2782
-	 * @param  array $value taxes.
2783
-	 */
2784
-	public function set_taxes( $value ) {
2779
+     * Set the invoice taxes.
2780
+     *
2781
+     * @since 1.0.19
2782
+     * @param  array $value taxes.
2783
+     */
2784
+    public function set_taxes( $value ) {
2785 2785
 
2786
-		if ( ! is_array( $value ) ) {
2787
-			$value = array();
2788
-		}
2786
+        if ( ! is_array( $value ) ) {
2787
+            $value = array();
2788
+        }
2789 2789
 
2790
-		$this->set_prop( 'taxes', $value );
2790
+        $this->set_prop( 'taxes', $value );
2791 2791
 
2792 2792
     }
2793 2793
 
2794 2794
     /**
2795
-	 * Set the invoice discounts.
2796
-	 *
2797
-	 * @since 1.0.19
2798
-	 * @param  array $value discounts.
2799
-	 */
2800
-	public function set_discounts( $value ) {
2795
+     * Set the invoice discounts.
2796
+     *
2797
+     * @since 1.0.19
2798
+     * @param  array $value discounts.
2799
+     */
2800
+    public function set_discounts( $value ) {
2801 2801
 
2802
-		if ( ! is_array( $value ) ) {
2803
-			$value = array();
2804
-		}
2802
+        if ( ! is_array( $value ) ) {
2803
+            $value = array();
2804
+        }
2805 2805
 
2806
-		$this->set_prop( 'discounts', $value );
2806
+        $this->set_prop( 'discounts', $value );
2807 2807
     }
2808 2808
 
2809 2809
     /**
2810
-	 * Set the invoice items.
2811
-	 *
2812
-	 * @since 1.0.19
2813
-	 * @param  GetPaid_Form_Item[] $value items.
2814
-	 */
2815
-	public function set_items( $value ) {
2810
+     * Set the invoice items.
2811
+     *
2812
+     * @since 1.0.19
2813
+     * @param  GetPaid_Form_Item[] $value items.
2814
+     */
2815
+    public function set_items( $value ) {
2816 2816
 
2817 2817
         // Remove existing items.
2818 2818
         $this->set_prop( 'items', array() );
@@ -2829,95 +2829,95 @@  discard block
 block discarded – undo
2829 2829
     }
2830 2830
 
2831 2831
     /**
2832
-	 * Set the payment form.
2833
-	 *
2834
-	 * @since 1.0.19
2835
-	 * @param  int $value payment form.
2836
-	 */
2837
-	public function set_payment_form( $value ) {
2838
-		$this->set_prop( 'payment_form', $value );
2832
+     * Set the payment form.
2833
+     *
2834
+     * @since 1.0.19
2835
+     * @param  int $value payment form.
2836
+     */
2837
+    public function set_payment_form( $value ) {
2838
+        $this->set_prop( 'payment_form', $value );
2839 2839
     }
2840 2840
 
2841 2841
     /**
2842
-	 * Set the submission id.
2843
-	 *
2844
-	 * @since 1.0.19
2845
-	 * @param  string $value submission id.
2846
-	 */
2847
-	public function set_submission_id( $value ) {
2848
-		$this->set_prop( 'submission_id', $value );
2842
+     * Set the submission id.
2843
+     *
2844
+     * @since 1.0.19
2845
+     * @param  string $value submission id.
2846
+     */
2847
+    public function set_submission_id( $value ) {
2848
+        $this->set_prop( 'submission_id', $value );
2849 2849
     }
2850 2850
 
2851 2851
     /**
2852
-	 * Set the discount code.
2853
-	 *
2854
-	 * @since 1.0.19
2855
-	 * @param  string $value discount code.
2856
-	 */
2857
-	public function set_discount_code( $value ) {
2858
-		$this->set_prop( 'discount_code', $value );
2852
+     * Set the discount code.
2853
+     *
2854
+     * @since 1.0.19
2855
+     * @param  string $value discount code.
2856
+     */
2857
+    public function set_discount_code( $value ) {
2858
+        $this->set_prop( 'discount_code', $value );
2859 2859
     }
2860 2860
 
2861 2861
     /**
2862
-	 * Set the gateway.
2863
-	 *
2864
-	 * @since 1.0.19
2865
-	 * @param  string $value gateway.
2866
-	 */
2867
-	public function set_gateway( $value ) {
2868
-		$this->set_prop( 'gateway', $value );
2862
+     * Set the gateway.
2863
+     *
2864
+     * @since 1.0.19
2865
+     * @param  string $value gateway.
2866
+     */
2867
+    public function set_gateway( $value ) {
2868
+        $this->set_prop( 'gateway', $value );
2869 2869
     }
2870 2870
 
2871 2871
     /**
2872
-	 * Set the transaction id.
2873
-	 *
2874
-	 * @since 1.0.19
2875
-	 * @param  string $value transaction id.
2876
-	 */
2877
-	public function set_transaction_id( $value ) {
2878
-		if ( ! empty( $value ) ) {
2879
-			$this->set_prop( 'transaction_id', $value );
2880
-		}
2872
+     * Set the transaction id.
2873
+     *
2874
+     * @since 1.0.19
2875
+     * @param  string $value transaction id.
2876
+     */
2877
+    public function set_transaction_id( $value ) {
2878
+        if ( ! empty( $value ) ) {
2879
+            $this->set_prop( 'transaction_id', $value );
2880
+        }
2881 2881
     }
2882 2882
 
2883 2883
     /**
2884
-	 * Set the currency id.
2885
-	 *
2886
-	 * @since 1.0.19
2887
-	 * @param  string $value currency id.
2888
-	 */
2889
-	public function set_currency( $value ) {
2890
-		$this->set_prop( 'currency', $value );
2884
+     * Set the currency id.
2885
+     *
2886
+     * @since 1.0.19
2887
+     * @param  string $value currency id.
2888
+     */
2889
+    public function set_currency( $value ) {
2890
+        $this->set_prop( 'currency', $value );
2891 2891
     }
2892 2892
 
2893
-	/**
2894
-	 * Set whether to disable taxes.
2895
-	 *
2896
-	 * @since 1.0.19
2897
-	 * @param  bool $value value.
2898
-	 */
2899
-	public function set_disable_taxes( $value ) {
2900
-		$this->set_prop( 'disable_taxes', (bool) $value );
2901
-	}
2893
+    /**
2894
+     * Set whether to disable taxes.
2895
+     *
2896
+     * @since 1.0.19
2897
+     * @param  bool $value value.
2898
+     */
2899
+    public function set_disable_taxes( $value ) {
2900
+        $this->set_prop( 'disable_taxes', (bool) $value );
2901
+    }
2902 2902
 
2903 2903
     /**
2904
-	 * Set the subscription id.
2905
-	 *
2906
-	 * @since 1.0.19
2907
-	 * @param  string $value subscription id.
2908
-	 */
2909
-	public function set_subscription_id( $value ) {
2910
-		$this->set_prop( 'subscription_id', $value );
2911
-	}
2904
+     * Set the subscription id.
2905
+     *
2906
+     * @since 1.0.19
2907
+     * @param  string $value subscription id.
2908
+     */
2909
+    public function set_subscription_id( $value ) {
2910
+        $this->set_prop( 'subscription_id', $value );
2911
+    }
2912 2912
 	
2913
-	/**
2914
-	 * Set the remote subscription id.
2915
-	 *
2916
-	 * @since 1.0.19
2917
-	 * @param  string $value subscription id.
2918
-	 */
2919
-	public function set_remote_subscription_id( $value ) {
2920
-		$this->set_prop( 'remote_subscription_id', $value );
2913
+    /**
2914
+     * Set the remote subscription id.
2915
+     *
2916
+     * @since 1.0.19
2917
+     * @param  string $value subscription id.
2918
+     */
2919
+    public function set_remote_subscription_id( $value ) {
2920
+        $this->set_prop( 'remote_subscription_id', $value );
2921 2921
     }
2922 2922
 
2923 2923
     /*
@@ -2956,24 +2956,24 @@  discard block
 block discarded – undo
2956 2956
      */
2957 2957
     public function is_taxable() {
2958 2958
         return ! $this->get_disable_taxes();
2959
-	}
2959
+    }
2960 2960
 
2961
-	/**
2962
-	 * @deprecated
2963
-	 */
2964
-	public function has_vat() {
2961
+    /**
2962
+     * @deprecated
2963
+     */
2964
+    public function has_vat() {
2965 2965
         return $this->is_taxable();
2966
-	}
2966
+    }
2967 2967
 
2968
-	/**
2969
-	 * Checks to see if the invoice requires payment.
2970
-	 */
2971
-	public function is_free() {
2968
+    /**
2969
+     * Checks to see if the invoice requires payment.
2970
+     */
2971
+    public function is_free() {
2972 2972
         $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 );
2973 2973
 
2974
-		if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2975
-			$is_free = false;
2976
-		}
2974
+        if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2975
+            $is_free = false;
2976
+        }
2977 2977
 
2978 2978
         return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2979 2979
     }
@@ -2984,46 +2984,46 @@  discard block
 block discarded – undo
2984 2984
     public function is_paid() {
2985 2985
         $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2986 2986
         return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2987
-	}
2987
+    }
2988 2988
 
2989
-	/**
2989
+    /**
2990 2990
      * Checks if the invoice needs payment.
2991 2991
      */
2992
-	public function needs_payment() {
2993
-		$needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2992
+    public function needs_payment() {
2993
+        $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2994 2994
         return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2995 2995
     }
2996 2996
   
2997
-	/**
2997
+    /**
2998 2998
      * Checks if the invoice is refunded.
2999 2999
      */
3000
-	public function is_refunded() {
3000
+    public function is_refunded() {
3001 3001
         $is_refunded = $this->has_status( 'wpi-refunded' );
3002 3002
         return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
3003
-	}
3003
+    }
3004 3004
 
3005
-	/**
3005
+    /**
3006 3006
      * Checks if the invoice is held.
3007 3007
      */
3008
-	public function is_held() {
3008
+    public function is_held() {
3009 3009
         $is_held = $this->has_status( 'wpi-onhold' );
3010 3010
         return apply_filters( 'wpinv_invoice_is_held', $is_held, $this );
3011
-	}
3011
+    }
3012 3012
 
3013
-	/**
3013
+    /**
3014 3014
      * Checks if the invoice is due.
3015 3015
      */
3016
-	public function is_due() {
3017
-		$due_date = $this->get_due_date();
3018
-		return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3019
-	}
3016
+    public function is_due() {
3017
+        $due_date = $this->get_due_date();
3018
+        return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
3019
+    }
3020 3020
 
3021
-	/**
3021
+    /**
3022 3022
      * Checks if the invoice is draft.
3023 3023
      */
3024
-	public function is_draft() {
3024
+    public function is_draft() {
3025 3025
         return $this->has_status( 'draft, auto-draft' );
3026
-	}
3026
+    }
3027 3027
 
3028 3028
     /**
3029 3029
      * Checks if the invoice has a given status.
@@ -3031,9 +3031,9 @@  discard block
 block discarded – undo
3031 3031
     public function has_status( $status ) {
3032 3032
         $status = wpinv_parse_list( $status );
3033 3033
         return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
3034
-	}
3034
+    }
3035 3035
 
3036
-	/**
3036
+    /**
3037 3037
      * Checks if the invoice is of a given type.
3038 3038
      */
3039 3039
     public function is_type( $type ) {
@@ -3056,25 +3056,25 @@  discard block
 block discarded – undo
3056 3056
      */
3057 3057
     public function has_free_trial() {
3058 3058
         return $this->is_recurring() && 0 == $this->get_initial_total();
3059
-	}
3059
+    }
3060 3060
 
3061
-	/**
3061
+    /**
3062 3062
      * @deprecated
3063 3063
      */
3064 3064
     public function is_free_trial() {
3065 3065
         $this->has_free_trial();
3066 3066
     }
3067 3067
 
3068
-	/**
3068
+    /**
3069 3069
      * Check if the initial payment if 0.
3070 3070
      *
3071 3071
      */
3072
-	public function is_initial_free() {
3072
+    public function is_initial_free() {
3073 3073
         $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
3074 3074
         return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
3075 3075
     }
3076 3076
 	
3077
-	/**
3077
+    /**
3078 3078
      * Check if the recurring item has a free trial.
3079 3079
      *
3080 3080
      */
@@ -3087,21 +3087,21 @@  discard block
 block discarded – undo
3087 3087
 
3088 3088
         $item = $this->get_recurring( true );
3089 3089
         return $item->has_free_trial();
3090
-	}
3090
+    }
3091 3091
 
3092
-	/**
3092
+    /**
3093 3093
      * Check if the free trial is a result of a discount.
3094 3094
      */
3095 3095
     public function is_free_trial_from_discount() {
3096
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
3097
-	}
3096
+        return $this->has_free_trial() && ! $this->item_has_free_trial();
3097
+    }
3098 3098
 	
3099
-	/**
3099
+    /**
3100 3100
      * @deprecated
3101 3101
      */
3102 3102
     public function discount_first_payment_only() {
3103 3103
 
3104
-		$discount = wpinv_get_discount_obj( $this->get_discount_code() );
3104
+        $discount = wpinv_get_discount_obj( $this->get_discount_code() );
3105 3105
         if ( ! $discount->exists() || ! $this->is_recurring() ) {
3106 3106
             return true;
3107 3107
         }
@@ -3126,28 +3126,28 @@  discard block
 block discarded – undo
3126 3126
      */
3127 3127
     public function add_item( $item ) {
3128 3128
 
3129
-		if ( is_array( $item ) ) {
3130
-			$item = $this->process_array_item( $item );
3131
-		}
3129
+        if ( is_array( $item ) ) {
3130
+            $item = $this->process_array_item( $item );
3131
+        }
3132 3132
 
3133
-		if ( is_numeric( $item ) ) {
3134
-			$item = new GetPaid_Form_Item( $item );
3135
-		}
3133
+        if ( is_numeric( $item ) ) {
3134
+            $item = new GetPaid_Form_Item( $item );
3135
+        }
3136 3136
 
3137 3137
         // Make sure that it is available for purchase.
3138
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3139
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3138
+        if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3139
+            return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3140 3140
         }
3141 3141
 
3142 3142
         // Do we have a recurring item?
3143
-		if ( $item->is_recurring() ) {
3143
+        if ( $item->is_recurring() ) {
3144 3144
 
3145
-			// An invoice can only contain one recurring item.
3146
-			if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3147
-				return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3148
-			}
3145
+            // An invoice can only contain one recurring item.
3146
+            if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3147
+                return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3148
+            }
3149 3149
 
3150
-			$this->recurring_item = $item->get_id();
3150
+            $this->recurring_item = $item->get_id();
3151 3151
         }
3152 3152
 
3153 3153
         // Invoice id.
@@ -3158,60 +3158,60 @@  discard block
 block discarded – undo
3158 3158
         $items[ (int) $item->get_id() ] = $item;
3159 3159
 
3160 3160
         $this->set_prop( 'items', $items );
3161
-		return true;
3162
-	}
3161
+        return true;
3162
+    }
3163 3163
 
3164
-	/**
3165
-	 * Converts an array to an item.
3166
-	 *
3167
-	 * @since 1.0.19
3168
-	 * @return GetPaid_Form_Item
3169
-	 */
3170
-	protected function process_array_item( $array ) {
3164
+    /**
3165
+     * Converts an array to an item.
3166
+     *
3167
+     * @since 1.0.19
3168
+     * @return GetPaid_Form_Item
3169
+     */
3170
+    protected function process_array_item( $array ) {
3171 3171
 
3172
-		$item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3173
-		$item    = new GetPaid_Form_Item( $item_id );
3172
+        $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3173
+        $item    = new GetPaid_Form_Item( $item_id );
3174 3174
 
3175
-		// Set item data.
3176
-		foreach ( array( 'name', 'price', 'description' ) as $key ) {
3177
-			if ( isset( $array[ "item_$key" ] ) ) {
3178
-				$method = "set_$key";
3179
-				$item->$method( $array[ "item_$key" ] );
3180
-			}
3181
-		}
3175
+        // Set item data.
3176
+        foreach ( array( 'name', 'price', 'description' ) as $key ) {
3177
+            if ( isset( $array[ "item_$key" ] ) ) {
3178
+                $method = "set_$key";
3179
+                $item->$method( $array[ "item_$key" ] );
3180
+            }
3181
+        }
3182 3182
 
3183
-		if ( isset( $array['quantity'] ) ) {
3184
-			$item->set_quantity( $array['quantity'] );
3185
-		}
3183
+        if ( isset( $array['quantity'] ) ) {
3184
+            $item->set_quantity( $array['quantity'] );
3185
+        }
3186 3186
 
3187
-		// Set item meta.
3188
-		if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3189
-			$item->set_item_meta( $array['meta'] );
3190
-		}
3187
+        // Set item meta.
3188
+        if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3189
+            $item->set_item_meta( $array['meta'] );
3190
+        }
3191 3191
 
3192
-		return $item;
3192
+        return $item;
3193 3193
 
3194
-	}
3194
+    }
3195 3195
 
3196 3196
     /**
3197
-	 * Retrieves a specific item.
3198
-	 *
3199
-	 * @since 1.0.19
3200
-	 */
3201
-	public function get_item( $item_id ) {
3202
-		$items   = $this->get_items();
3203
-		$item_id = (int) $item_id;
3204
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3197
+     * Retrieves a specific item.
3198
+     *
3199
+     * @since 1.0.19
3200
+     */
3201
+    public function get_item( $item_id ) {
3202
+        $items   = $this->get_items();
3203
+        $item_id = (int) $item_id;
3204
+        return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3205 3205
     }
3206 3206
 
3207 3207
     /**
3208
-	 * Removes a specific item.
3209
-	 *
3210
-	 * @since 1.0.19
3211
-	 */
3212
-	public function remove_item( $item_id ) {
3213
-		$items   = $this->get_items();
3214
-		$item_id = (int) $item_id;
3208
+     * Removes a specific item.
3209
+     *
3210
+     * @since 1.0.19
3211
+     */
3212
+    public function remove_item( $item_id ) {
3213
+        $items   = $this->get_items();
3214
+        $item_id = (int) $item_id;
3215 3215
 
3216 3216
         if ( $item_id == $this->recurring_item ) {
3217 3217
             $this->recurring_item = null;
@@ -3224,35 +3224,35 @@  discard block
 block discarded – undo
3224 3224
     }
3225 3225
 
3226 3226
     /**
3227
-	 * Adds a fee to the invoice.
3228
-	 *
3229
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
3230
-	 * @since 1.0.19
3231
-	 */
3227
+     * Adds a fee to the invoice.
3228
+     *
3229
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
3230
+     * @since 1.0.19
3231
+     */
3232 3232
     public function add_fee( $fee ) {
3233 3233
 
3234
-		$fees                 = $this->get_fees();
3235
-		$fees[ $fee['name'] ] = $fee;
3236
-		$this->set_prop( 'fees', $fees );
3234
+        $fees                 = $this->get_fees();
3235
+        $fees[ $fee['name'] ] = $fee;
3236
+        $this->set_prop( 'fees', $fees );
3237 3237
 
3238 3238
     }
3239 3239
 
3240 3240
     /**
3241
-	 * Retrieves a specific fee.
3242
-	 *
3243
-	 * @since 1.0.19
3244
-	 */
3245
-	public function get_fee( $fee ) {
3241
+     * Retrieves a specific fee.
3242
+     *
3243
+     * @since 1.0.19
3244
+     */
3245
+    public function get_fee( $fee ) {
3246 3246
         $fees = $this->get_fees();
3247
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3247
+        return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3248 3248
     }
3249 3249
 
3250 3250
     /**
3251
-	 * Removes a specific fee.
3252
-	 *
3253
-	 * @since 1.0.19
3254
-	 */
3255
-	public function remove_fee( $fee ) {
3251
+     * Removes a specific fee.
3252
+     *
3253
+     * @since 1.0.19
3254
+     */
3255
+    public function remove_fee( $fee ) {
3256 3256
         $fees = $this->get_fees();
3257 3257
         if ( isset( $fees[ $fee ] ) ) {
3258 3258
             unset( $fees[ $fee ] );
@@ -3260,43 +3260,43 @@  discard block
 block discarded – undo
3260 3260
         }
3261 3261
     }
3262 3262
 
3263
-	/**
3264
-	 * Adds a discount to the invoice.
3265
-	 *
3266
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
3267
-	 * @since 1.0.19
3268
-	 */
3269
-	public function add_discount( $discount ) {
3263
+    /**
3264
+     * Adds a discount to the invoice.
3265
+     *
3266
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
3267
+     * @since 1.0.19
3268
+     */
3269
+    public function add_discount( $discount ) {
3270 3270
 
3271
-		$discounts = $this->get_discounts();
3272
-		$discounts[ $discount['name'] ] = $discount;
3273
-		$this->set_prop( 'discounts', $discounts );
3271
+        $discounts = $this->get_discounts();
3272
+        $discounts[ $discount['name'] ] = $discount;
3273
+        $this->set_prop( 'discounts', $discounts );
3274 3274
 
3275
-	}
3275
+    }
3276 3276
 
3277 3277
     /**
3278
-	 * Retrieves a specific discount.
3279
-	 *
3280
-	 * @since 1.0.19
3281
-	 * @return float
3282
-	 */
3283
-	public function get_discount( $discount = false ) {
3278
+     * Retrieves a specific discount.
3279
+     *
3280
+     * @since 1.0.19
3281
+     * @return float
3282
+     */
3283
+    public function get_discount( $discount = false ) {
3284 3284
 
3285
-		// Backwards compatibilty.
3286
-		if ( empty( $discount ) ) {
3287
-			return $this->get_total_discount();
3288
-		}
3285
+        // Backwards compatibilty.
3286
+        if ( empty( $discount ) ) {
3287
+            return $this->get_total_discount();
3288
+        }
3289 3289
 
3290 3290
         $discounts = $this->get_discounts();
3291
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3291
+        return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3292 3292
     }
3293 3293
 
3294 3294
     /**
3295
-	 * Removes a specific discount.
3296
-	 *
3297
-	 * @since 1.0.19
3298
-	 */
3299
-	public function remove_discount( $discount ) {
3295
+     * Removes a specific discount.
3296
+     *
3297
+     * @since 1.0.19
3298
+     */
3299
+    public function remove_discount( $discount ) {
3300 3300
         $discounts = $this->get_discounts();
3301 3301
         if ( isset( $discounts[ $discount ] ) ) {
3302 3302
             unset( $discounts[ $discount ] );
@@ -3313,34 +3313,34 @@  discard block
 block discarded – undo
3313 3313
         if ( $this->is_taxable() ) {
3314 3314
 
3315 3315
             $taxes                 = $this->get_taxes();
3316
-			$taxes[ $tax['name'] ] = $tax;
3317
-			$this->set_prop( 'taxes', $tax );
3316
+            $taxes[ $tax['name'] ] = $tax;
3317
+            $this->set_prop( 'taxes', $tax );
3318 3318
 
3319 3319
         }
3320 3320
     }
3321 3321
 
3322 3322
     /**
3323
-	 * Retrieves a specific tax.
3324
-	 *
3325
-	 * @since 1.0.19
3326
-	 */
3327
-	public function get_tax( $tax = null ) {
3323
+     * Retrieves a specific tax.
3324
+     *
3325
+     * @since 1.0.19
3326
+     */
3327
+    public function get_tax( $tax = null ) {
3328 3328
 
3329
-		// Backwards compatility.
3330
-		if ( empty( $tax ) ) {
3331
-			return $this->get_total_tax();
3332
-		}
3329
+        // Backwards compatility.
3330
+        if ( empty( $tax ) ) {
3331
+            return $this->get_total_tax();
3332
+        }
3333 3333
 
3334 3334
         $taxes = $this->get_taxes();
3335
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3335
+        return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3336 3336
     }
3337 3337
 
3338 3338
     /**
3339
-	 * Removes a specific tax.
3340
-	 *
3341
-	 * @since 1.0.19
3342
-	 */
3343
-	public function remove_tax( $tax ) {
3339
+     * Removes a specific tax.
3340
+     *
3341
+     * @since 1.0.19
3342
+     */
3343
+    public function remove_tax( $tax ) {
3344 3344
         $taxes = $this->get_taxes();
3345 3345
         if ( isset( $taxes[ $tax ] ) ) {
3346 3346
             unset( $taxes[ $tax ] );
@@ -3349,134 +3349,134 @@  discard block
 block discarded – undo
3349 3349
     }
3350 3350
 
3351 3351
     /**
3352
-	 * Recalculates the invoice subtotal.
3353
-	 *
3354
-	 * @since 1.0.19
3355
-	 * @return float The recalculated subtotal
3356
-	 */
3357
-	public function recalculate_subtotal() {
3352
+     * Recalculates the invoice subtotal.
3353
+     *
3354
+     * @since 1.0.19
3355
+     * @return float The recalculated subtotal
3356
+     */
3357
+    public function recalculate_subtotal() {
3358 3358
         $items     = $this->get_items();
3359
-		$subtotal  = 0;
3360
-		$recurring = 0;
3359
+        $subtotal  = 0;
3360
+        $recurring = 0;
3361 3361
 
3362 3362
         foreach ( $items as $item ) {
3363
-			$subtotal  += $item->get_sub_total();
3364
-			$recurring += $item->get_recurring_sub_total();
3363
+            $subtotal  += $item->get_sub_total();
3364
+            $recurring += $item->get_recurring_sub_total();
3365 3365
         }
3366 3366
 
3367
-		$current = $this->is_renewal() ? $recurring : $subtotal;
3368
-		$this->set_subtotal( $current );
3367
+        $current = $this->is_renewal() ? $recurring : $subtotal;
3368
+        $this->set_subtotal( $current );
3369 3369
 
3370
-		$this->totals['subtotal'] = array(
3371
-			'initial'   => $subtotal,
3372
-			'recurring' => $recurring,
3373
-		);
3370
+        $this->totals['subtotal'] = array(
3371
+            'initial'   => $subtotal,
3372
+            'recurring' => $recurring,
3373
+        );
3374 3374
 
3375 3375
         return $current;
3376 3376
     }
3377 3377
 
3378 3378
     /**
3379
-	 * Recalculates the invoice discount total.
3380
-	 *
3381
-	 * @since 1.0.19
3382
-	 * @return float The recalculated discount
3383
-	 */
3384
-	public function recalculate_total_discount() {
3379
+     * Recalculates the invoice discount total.
3380
+     *
3381
+     * @since 1.0.19
3382
+     * @return float The recalculated discount
3383
+     */
3384
+    public function recalculate_total_discount() {
3385 3385
         $discounts = $this->get_discounts();
3386
-		$discount  = 0;
3387
-		$recurring = 0;
3386
+        $discount  = 0;
3387
+        $recurring = 0;
3388 3388
 
3389 3389
         foreach ( $discounts as $data ) {
3390
-			$discount  += wpinv_sanitize_amount( $data['initial_discount'] );
3391
-			$recurring += wpinv_sanitize_amount( $data['recurring_discount'] );
3392
-		}
3390
+            $discount  += wpinv_sanitize_amount( $data['initial_discount'] );
3391
+            $recurring += wpinv_sanitize_amount( $data['recurring_discount'] );
3392
+        }
3393 3393
 
3394
-		$current = $this->is_renewal() ? $recurring : $discount;
3394
+        $current = $this->is_renewal() ? $recurring : $discount;
3395 3395
 
3396
-		$this->set_total_discount( $current );
3396
+        $this->set_total_discount( $current );
3397 3397
 
3398
-		$this->totals['discount'] = array(
3399
-			'initial'   => $discount,
3400
-			'recurring' => $recurring,
3401
-		);
3398
+        $this->totals['discount'] = array(
3399
+            'initial'   => $discount,
3400
+            'recurring' => $recurring,
3401
+        );
3402 3402
 
3403
-		return $current;
3403
+        return $current;
3404 3404
 
3405 3405
     }
3406 3406
 
3407 3407
     /**
3408
-	 * Recalculates the invoice tax total.
3409
-	 *
3410
-	 * @since 1.0.19
3411
-	 * @return float The recalculated tax
3412
-	 */
3413
-	public function recalculate_total_tax() {
3408
+     * Recalculates the invoice tax total.
3409
+     *
3410
+     * @since 1.0.19
3411
+     * @return float The recalculated tax
3412
+     */
3413
+    public function recalculate_total_tax() {
3414 3414
         $taxes     = $this->get_taxes();
3415
-		$tax       = 0;
3416
-		$recurring = 0;
3415
+        $tax       = 0;
3416
+        $recurring = 0;
3417 3417
 
3418 3418
         foreach ( $taxes as $data ) {
3419
-			$tax       += wpinv_sanitize_amount( $data['initial_tax'] );
3420
-			$recurring += wpinv_sanitize_amount( $data['recurring_tax'] );
3421
-		}
3419
+            $tax       += wpinv_sanitize_amount( $data['initial_tax'] );
3420
+            $recurring += wpinv_sanitize_amount( $data['recurring_tax'] );
3421
+        }
3422 3422
 
3423
-		$current = $this->is_renewal() ? $recurring : $tax;
3424
-		$this->set_total_tax( $current );
3423
+        $current = $this->is_renewal() ? $recurring : $tax;
3424
+        $this->set_total_tax( $current );
3425 3425
 
3426
-		$this->totals['tax'] = array(
3427
-			'initial'   => $tax,
3428
-			'recurring' => $recurring,
3429
-		);
3426
+        $this->totals['tax'] = array(
3427
+            'initial'   => $tax,
3428
+            'recurring' => $recurring,
3429
+        );
3430 3430
 
3431
-		return $current;
3431
+        return $current;
3432 3432
 
3433 3433
     }
3434 3434
 
3435 3435
     /**
3436
-	 * Recalculates the invoice fees total.
3437
-	 *
3438
-	 * @since 1.0.19
3439
-	 * @return float The recalculated fee
3440
-	 */
3441
-	public function recalculate_total_fees() {
3442
-		$fees      = $this->get_fees();
3443
-		$fee       = 0;
3444
-		$recurring = 0;
3436
+     * Recalculates the invoice fees total.
3437
+     *
3438
+     * @since 1.0.19
3439
+     * @return float The recalculated fee
3440
+     */
3441
+    public function recalculate_total_fees() {
3442
+        $fees      = $this->get_fees();
3443
+        $fee       = 0;
3444
+        $recurring = 0;
3445 3445
 
3446 3446
         foreach ( $fees as $data ) {
3447
-			$fee       += wpinv_sanitize_amount( $data['initial_fee'] );
3448
-			$recurring += wpinv_sanitize_amount( $data['recurring_fee'] );
3449
-		}
3447
+            $fee       += wpinv_sanitize_amount( $data['initial_fee'] );
3448
+            $recurring += wpinv_sanitize_amount( $data['recurring_fee'] );
3449
+        }
3450 3450
 
3451
-		$current = $this->is_renewal() ? $recurring : $fee;
3452
-		$this->set_total_fees( $current );
3451
+        $current = $this->is_renewal() ? $recurring : $fee;
3452
+        $this->set_total_fees( $current );
3453 3453
 
3454
-		$this->totals['fee'] = array(
3455
-			'initial'   => $fee,
3456
-			'recurring' => $recurring,
3457
-		);
3454
+        $this->totals['fee'] = array(
3455
+            'initial'   => $fee,
3456
+            'recurring' => $recurring,
3457
+        );
3458 3458
 
3459 3459
         $this->set_total_fees( $fee );
3460 3460
         return $current;
3461 3461
     }
3462 3462
 
3463 3463
     /**
3464
-	 * Recalculates the invoice total.
3465
-	 *
3466
-	 * @since 1.0.19
3464
+     * Recalculates the invoice total.
3465
+     *
3466
+     * @since 1.0.19
3467 3467
      * @return float The invoice total
3468
-	 */
3469
-	public function recalculate_total() {
3468
+     */
3469
+    public function recalculate_total() {
3470 3470
         $this->recalculate_subtotal();
3471 3471
         $this->recalculate_total_fees();
3472 3472
         $this->recalculate_total_discount();
3473 3473
         $this->recalculate_total_tax();
3474
-		return $this->get_total();
3475
-	}
3474
+        return $this->get_total();
3475
+    }
3476 3476
 
3477
-	/**
3478
-	 * @deprecated
3479
-	 */
3477
+    /**
3478
+     * @deprecated
3479
+     */
3480 3480
     public function recalculate_totals( $temp = false ) {
3481 3481
         $this->update_items( $temp );
3482 3482
         $this->save( true );
@@ -3494,7 +3494,7 @@  discard block
 block discarded – undo
3494 3494
      * Adds a note to an invoice.
3495 3495
      *
3496 3496
      * @param string $note The note being added.
3497
-	 * @return int|false The new note's ID on success, false on failure.
3497
+     * @return int|false The new note's ID on success, false on failure.
3498 3498
      *
3499 3499
      */
3500 3500
     public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
@@ -3504,21 +3504,21 @@  discard block
 block discarded – undo
3504 3504
             return false;
3505 3505
         }
3506 3506
 
3507
-		$author       = 'System';
3508
-		$author_email = '[email protected]';
3507
+        $author       = 'System';
3508
+        $author_email = '[email protected]';
3509 3509
 
3510
-		// If this is an admin comment or it has been added by the user.
3511
-		if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3512
-			$user         = get_user_by( 'id', get_current_user_id() );
3510
+        // If this is an admin comment or it has been added by the user.
3511
+        if ( is_user_logged_in() && ( ! $system || $added_by_user ) ) {
3512
+            $user         = get_user_by( 'id', get_current_user_id() );
3513 3513
             $author       = $user->display_name;
3514 3514
             $author_email = $user->user_email;
3515
-		}
3515
+        }
3516 3516
 
3517
-		return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3517
+        return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3518 3518
 
3519
-	}
3519
+    }
3520 3520
 
3521
-	/**
3521
+    /**
3522 3522
      * Generates a unique key for the invoice.
3523 3523
      */
3524 3524
     public function generate_key( $string = '' ) {
@@ -3538,113 +3538,113 @@  discard block
 block discarded – undo
3538 3538
             $number = wpinv_get_next_invoice_number( $this->get_post_type() );
3539 3539
         }
3540 3540
 
3541
-		return wpinv_format_invoice_number( $number, $this->get_post_type() );
3542
-
3543
-	}
3544
-
3545
-	/**
3546
-	 * Handle the status transition.
3547
-	 */
3548
-	protected function status_transition() {
3549
-		$status_transition = $this->status_transition;
3550
-
3551
-		// Reset status transition variable.
3552
-		$this->status_transition = false;
3553
-
3554
-		if ( $status_transition ) {
3555
-			try {
3541
+        return wpinv_format_invoice_number( $number, $this->get_post_type() );
3556 3542
 
3557
-				// Fire a hook for the status change.
3558
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3559
-
3560
-				// @deprecated this is deprecated and will be removed in the future.
3561
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3562
-
3563
-				if ( ! empty( $status_transition['from'] ) ) {
3564
-
3565
-					/* translators: 1: old invoice status 2: new invoice status */
3566
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3567
-
3568
-					// Fire another hook.
3569
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3570
-					do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3571
-
3572
-					// @deprecated this is deprecated and will be removed in the future.
3573
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3574
-
3575
-					// Note the transition occurred.
3576
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] );
3577
-
3578
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
3579
-					if (
3580
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3581
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3582
-					) {
3583
-						do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3584
-					}
3585
-
3586
-					// Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead.
3587
-					if (
3588
-						in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3589
-						&& in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3590
-					) {
3591
-						do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition );
3592
-					}
3593
-				} else {
3594
-					/* translators: %s: new invoice status */
3595
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3596
-
3597
-					// Note the transition occurred.
3598
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3543
+    }
3599 3544
 
3600
-				}
3601
-			} catch ( Exception $e ) {
3602
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3603
-			}
3604
-		}
3605
-	}
3545
+    /**
3546
+     * Handle the status transition.
3547
+     */
3548
+    protected function status_transition() {
3549
+        $status_transition = $this->status_transition;
3550
+
3551
+        // Reset status transition variable.
3552
+        $this->status_transition = false;
3553
+
3554
+        if ( $status_transition ) {
3555
+            try {
3556
+
3557
+                // Fire a hook for the status change.
3558
+                do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this, $status_transition );
3559
+
3560
+                // @deprecated this is deprecated and will be removed in the future.
3561
+                do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3562
+
3563
+                if ( ! empty( $status_transition['from'] ) ) {
3564
+
3565
+                    /* translators: 1: old invoice status 2: new invoice status */
3566
+                    $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'], $this ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3567
+
3568
+                    // Fire another hook.
3569
+                    do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this );
3570
+                    do_action( 'getpaid_invoice_status_changed', $this, $status_transition['from'], $status_transition['to'] );
3571
+
3572
+                    // @deprecated this is deprecated and will be removed in the future.
3573
+                    do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3574
+
3575
+                    // Note the transition occurred.
3576
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), false, $status_transition['manual'] );
3577
+
3578
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
3579
+                    if (
3580
+                        in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3581
+                        && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3582
+                    ) {
3583
+                        do_action( 'getpaid_invoice_payment_status_changed', $this, $status_transition );
3584
+                    }
3585
+
3586
+                    // Work out if this was for a payment reversal, and trigger a payment_status_reversed hook instead.
3587
+                    if (
3588
+                        in_array( $status_transition['from'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3589
+                        && in_array( $status_transition['to'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded', 'wpi-onhold' ), true )
3590
+                    ) {
3591
+                        do_action( 'getpaid_invoice_payment_status_reversed', $this, $status_transition );
3592
+                    }
3593
+                } else {
3594
+                    /* translators: %s: new invoice status */
3595
+                    $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'], $this  ) );
3596
+
3597
+                    // Note the transition occurred.
3598
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3599
+
3600
+                }
3601
+            } catch ( Exception $e ) {
3602
+                $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3603
+            }
3604
+        }
3605
+    }
3606 3606
 
3607
-	/**
3608
-	 * Updates an invoice status.
3609
-	 */
3610
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3607
+    /**
3608
+     * Updates an invoice status.
3609
+     */
3610
+    public function update_status( $new_status = false, $note = '', $manual = false ) {
3611 3611
 
3612
-		// Fires before updating a status.
3613
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3612
+        // Fires before updating a status.
3613
+        do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3614 3614
 
3615
-		// Update the status.
3616
-		$this->set_status( $new_status, $note, $manual );
3615
+        // Update the status.
3616
+        $this->set_status( $new_status, $note, $manual );
3617 3617
 
3618
-		// Save the order.
3619
-		return $this->save();
3618
+        // Save the order.
3619
+        return $this->save();
3620 3620
 
3621
-	}
3621
+    }
3622 3622
 
3623
-	/**
3624
-	 * @deprecated
3625
-	 */
3626
-	public function refresh_item_ids() {
3623
+    /**
3624
+     * @deprecated
3625
+     */
3626
+    public function refresh_item_ids() {
3627 3627
         $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3628 3628
         update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3629
-	}
3629
+    }
3630 3630
 
3631
-	/**
3632
-	 * @deprecated
3633
-	 */
3634
-	public function update_items( $temp = false ) {
3631
+    /**
3632
+     * @deprecated
3633
+     */
3634
+    public function update_items( $temp = false ) {
3635 3635
 
3636
-		$this->set_items( $this->get_items() );
3636
+        $this->set_items( $this->get_items() );
3637 3637
 
3638
-		if ( ! $temp ) {
3639
-			$this->save();
3640
-		}
3638
+        if ( ! $temp ) {
3639
+            $this->save();
3640
+        }
3641 3641
 
3642 3642
         return $this;
3643
-	}
3643
+    }
3644 3644
 
3645
-	/**
3646
-	 * @deprecated
3647
-	 */
3645
+    /**
3646
+     * @deprecated
3647
+     */
3648 3648
     public function validate_discount() {
3649 3649
 
3650 3650
         $discount_code = $this->get_discount_code();
@@ -3660,97 +3660,97 @@  discard block
 block discarded – undo
3660 3660
 
3661 3661
     }
3662 3662
 
3663
-	/**
3664
-	 * Refunds an invoice.
3665
-	 */
3663
+    /**
3664
+     * Refunds an invoice.
3665
+     */
3666 3666
     public function refund() {
3667
-		$this->set_status( 'wpi-refunded' );
3667
+        $this->set_status( 'wpi-refunded' );
3668 3668
         $this->save();
3669
-	}
3669
+    }
3670 3670
 
3671
-	/**
3672
-	 * Marks an invoice as paid.
3673
-	 * 
3674
-	 * @param string $transaction_id
3675
-	 */
3671
+    /**
3672
+     * Marks an invoice as paid.
3673
+     * 
3674
+     * @param string $transaction_id
3675
+     */
3676 3676
     public function mark_paid( $transaction_id = null, $note = '' ) {
3677 3677
 
3678
-		// Set the transaction id.
3679
-		if ( empty( $transaction_id ) ) {
3680
-			$transaction_id = $this->generate_key('trans_');
3681
-		}
3678
+        // Set the transaction id.
3679
+        if ( empty( $transaction_id ) ) {
3680
+            $transaction_id = $this->generate_key('trans_');
3681
+        }
3682 3682
 
3683
-		if ( ! $this->get_transaction_id() ) {
3684
-			$this->set_transaction_id( $transaction_id );
3685
-		}
3683
+        if ( ! $this->get_transaction_id() ) {
3684
+            $this->set_transaction_id( $transaction_id );
3685
+        }
3686 3686
 
3687
-		if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3688
-			return $this->save();
3689
-		}
3687
+        if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3688
+            return $this->save();
3689
+        }
3690 3690
 
3691
-		// Set the completed date.
3692
-		$this->set_date_completed( current_time( 'mysql' ) );
3691
+        // Set the completed date.
3692
+        $this->set_date_completed( current_time( 'mysql' ) );
3693 3693
 
3694
-		// Set the new status.
3695
-		if ( $this->is_renewal() ) {
3694
+        // Set the new status.
3695
+        if ( $this->is_renewal() ) {
3696 3696
 
3697
-			$_note = sprintf(
3698
-				__( 'Renewed via %s', 'invoicing' ),
3699
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3700
-			);
3697
+            $_note = sprintf(
3698
+                __( 'Renewed via %s', 'invoicing' ),
3699
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3700
+            );
3701 3701
 
3702
-			if ( 'none' == $this->get_gateway() ) {
3703
-				$_note = $note;
3704
-			}
3702
+            if ( 'none' == $this->get_gateway() ) {
3703
+                $_note = $note;
3704
+            }
3705 3705
 
3706
-			$this->set_status( 'wpi-renewal', $_note );
3706
+            $this->set_status( 'wpi-renewal', $_note );
3707 3707
 
3708
-		} else {
3708
+        } else {
3709 3709
 
3710
-			$_note = sprintf(
3711
-				__( 'Paid via %s', 'invoicing' ),
3712
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3713
-			);
3710
+            $_note = sprintf(
3711
+                __( 'Paid via %s', 'invoicing' ),
3712
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3713
+            );
3714 3714
 
3715
-			if ( 'none' == $this->get_gateway() ) {
3716
-				$_note = $note;
3717
-			}
3715
+            if ( 'none' == $this->get_gateway() ) {
3716
+                $_note = $note;
3717
+            }
3718 3718
 
3719
-			$this->set_status( 'publish',$_note );
3719
+            $this->set_status( 'publish',$_note );
3720 3720
 
3721
-		}
3721
+        }
3722 3722
 
3723
-		// Set checkout mode.
3724
-		$mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3725
-		$this->set_mode( $mode );
3723
+        // Set checkout mode.
3724
+        $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3725
+        $this->set_mode( $mode );
3726 3726
 
3727
-		// Save the invoice.
3727
+        // Save the invoice.
3728 3728
         $this->save();
3729
-	}
3730
-
3731
-
3732
-	/**
3733
-	 * Save data to the database.
3734
-	 *
3735
-	 * @since 1.0.19
3736
-	 * @return int invoice ID
3737
-	 */
3738
-	public function save() {
3739
-		$this->maybe_set_date_paid();
3740
-		$this->maybe_set_key();
3741
-		parent::save();
3742
-		$this->clear_cache();
3743
-		$this->status_transition();
3744
-		return $this->get_id();
3745
-	}
3746
-
3747
-	/**
3729
+    }
3730
+
3731
+
3732
+    /**
3733
+     * Save data to the database.
3734
+     *
3735
+     * @since 1.0.19
3736
+     * @return int invoice ID
3737
+     */
3738
+    public function save() {
3739
+        $this->maybe_set_date_paid();
3740
+        $this->maybe_set_key();
3741
+        parent::save();
3742
+        $this->clear_cache();
3743
+        $this->status_transition();
3744
+        return $this->get_id();
3745
+    }
3746
+
3747
+    /**
3748 3748
      * Clears the subscription's cache.
3749 3749
      */
3750 3750
     public function clear_cache() {
3751
-		wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
3752
-		wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
3753
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
3754
-	}
3751
+        wp_cache_delete( $this->get_key(), 'getpaid_invoice_keys_to_invoice_ids' );
3752
+        wp_cache_delete( $this->get_number(), 'getpaid_invoice_numbers_to_invoice_ids' );
3753
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_invoice_transaction_ids_to_invoice_ids' );
3754
+    }
3755 3755
 
3756 3756
 }
Please login to merge, or discard this patch.