Passed
Push — master ( 7db120...b4ab02 )
by Brian
07:23 queued 02:27
created
includes/class-getpaid-subscriptions-query.php 1 patch
Indentation   +476 added lines, -476 removed lines patch added patch discarded remove patch
@@ -16,481 +16,481 @@
 block discarded – undo
16 16
  */
17 17
 class GetPaid_Subscriptions_Query {
18 18
 
19
-	/**
20
-	 * Query vars, after parsing
21
-	 *
22
-	 * @since 1.0.19
23
-	 * @var array
24
-	 */
25
-	public $query_vars = array();
26
-
27
-	/**
28
-	 * List of found subscriptions.
29
-	 *
30
-	 * @since 1.0.19
31
-	 * @var array
32
-	 */
33
-	private $results;
34
-
35
-	/**
36
-	 * Total number of found subscriptions for the current query
37
-	 *
38
-	 * @since 1.0.19
39
-	 * @var int
40
-	 */
41
-	private $total_subscriptions = 0;
42
-
43
-	/**
44
-	 * The SQL query used to fetch matching subscriptions.
45
-	 *
46
-	 * @since 1.0.19
47
-	 * @var string
48
-	 */
49
-	public $request;
50
-
51
-	// SQL clauses
52
-
53
-	/**
54
-	 * Contains the 'FIELDS' sql clause
55
-	 *
56
-	 * @since 1.0.19
57
-	 * @var string
58
-	 */
59
-	public $query_fields;
60
-
61
-	/**
62
-	 * Contains the 'FROM' sql clause
63
-	 *
64
-	 * @since 1.0.19
65
-	 * @var string
66
-	 */
67
-	public $query_from;
68
-
69
-	/**
70
-	 * Contains the 'WHERE' sql clause
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $query_where;
76
-
77
-	/**
78
-	 * Contains the 'ORDER BY' sql clause
79
-	 *
80
-	 * @since 1.0.19
81
-	 * @var string
82
-	 */
83
-	public $query_orderby;
84
-
85
-	/**
86
-	 * Contains the 'LIMIT' sql clause
87
-	 *
88
-	 * @since 1.0.19
89
-	 * @var string
90
-	 */
91
-	public $query_limit;
92
-
93
-	/**
94
-	 * Class constructor.
95
-	 *
96
-	 * @since 1.0.19
97
-	 *
98
-	 * @param null|string|array $query Optional. The query variables.
99
-	 */
100
-	public function __construct( $query = null ) {
101
-		if ( ! is_null( $query ) ) {
102
-			$this->prepare_query( $query );
103
-			$this->query();
104
-		}
105
-	}
106
-
107
-	/**
108
-	 * Fills in missing query variables with default values.
109
-	 *
110
-	 * @since 1.0.19
111
-	 *
112
-	 * @param  string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`.
113
-	 * @return array Complete query variables with undefined ones filled in with defaults.
114
-	 */
115
-	public static function fill_query_vars( $args ) {
116
-		$defaults = array(
117
-			'status'            => 'all',
118
-			'customer_in'       => array(),
119
-			'customer_not_in'   => array(),
120
-			'product_in'        => array(),
121
-			'product_not_in'    => array(),
122
-			'include'           => array(),
123
-			'exclude'           => array(),
124
-			'orderby'           => 'id',
125
-			'order'             => 'DESC',
126
-			'offset'            => '',
127
-			'number'            => 10,
128
-			'paged'             => 1,
129
-			'count_total'       => true,
130
-			'fields'            => 'all',
131
-		);
132
-
133
-		return wp_parse_args( $args, $defaults );
134
-	}
135
-
136
-	/**
137
-	 * Prepare the query variables.
138
-	 *
139
-	 * @since 1.0.19
140
-	 *
141
-	 * @global wpdb $wpdb WordPress database abstraction object.
142
-	 *
143
-	 * @param string|array $query {
144
-	 *     Optional. Array or string of Query parameters.
145
-	 *
146
-	 *     @type string|array $status              The subscription status to filter by. Can either be a single status or an array of statuses.
147
-	 *                                             Default is all.
148
-	 *     @type int[]        $customer_in         An array of customer ids to filter by.
149
-	 *     @type int[]        $customer_not_in     An array of customer ids whose subscriptions should be excluded.
150
-	 *     @type int[]        $product_in          An array of product ids to filter by.
151
-	 *     @type int[]        $product_not_in      An array of product ids whose subscriptions should be excluded.
152
-	 *     @type array        $date_created_query  A WP_Date_Query compatible array use to filter subscriptions by their date of creation.
153
-	 *     @type array        $date_expires_query  A WP_Date_Query compatible array use to filter subscriptions by their expiration date.
154
-	 *     @type array        $include             An array of subscription IDs to include. Default empty array.
155
-	 *     @type array        $exclude             An array of subscription IDs to exclude. Default empty array.
156
-	 *     @type string|array $orderby             Field(s) to sort the retrieved subscription by. May be a single value,
157
-	 *                                             an array of values, or a multi-dimensional array with fields as
158
-	 *                                             keys and orders ('ASC' or 'DESC') as values. Accepted values are
159
-	 *                                             'id', 'customer_id', 'frequency', 'period', 'initial_amount,
160
-	 *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
161
-	 *                                             'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ).
162
-	 *     @type string       $order               Designates ascending or descending order of subscriptions. Order values
163
-	 *                                             passed as part of an `$orderby` array take precedence over this
164
-	 *                                             parameter. Accepts 'ASC', 'DESC'. Default 'DESC'.
165
-	 *     @type int          $offset              Number of subscriptions to offset in retrieved results. Can be used in
166
-	 *                                             conjunction with pagination. Default 0.
167
-	 *     @type int          $number              Number of subscriptions to limit the query for. Can be used in
168
-	 *                                             conjunction with pagination. Value -1 (all) is supported, but
169
-	 *                                             should be used with caution on larger sites.
170
-	 *                                             Default 10.
171
-	 *     @type int          $paged               When used with number, defines the page of results to return.
172
-	 *                                             Default 1.
173
-	 *     @type bool         $count_total         Whether to count the total number of subscriptions found. If pagination
174
-	 *                                             is not needed, setting this to false can improve performance.
175
-	 *                                             Default true.
176
-	 *     @type string|array $fields              Which fields to return. Single or all fields (string), or array
177
-	 *                                             of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount,
178
-	 *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
179
-	 *                                             'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'.
180
-	 *                                             Use 'all' for all fields. Default 'all'.
181
-	 * }
182
-	 */
183
-	public function prepare_query( $query = array() ) {
184
-		global $wpdb;
185
-
186
-		if ( empty( $this->query_vars ) || ! empty( $query ) ) {
187
-			$this->query_limit = null;
188
-			$this->query_vars  = $this->fill_query_vars( $query );
189
-		}
190
-
191
-		if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
192
-			$this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
193
-		}
194
-
195
-		do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
196
-
197
-		// Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
198
-		$qv                =& $this->query_vars;
199
-		$qv                = $this->fill_query_vars( $qv );
200
-		$table             = $wpdb->prefix . 'wpinv_subscriptions';
201
-		$this->query_from  = "FROM $table";
202
-
203
-		// Prepare query fields.
204
-		$this->prepare_query_fields( $qv, $table );
205
-
206
-		// Prepare query where.
207
-		$this->prepare_query_where( $qv, $table );
208
-
209
-		// Prepare query order.
210
-		$this->prepare_query_order( $qv, $table );
211
-
212
-		// limit
213
-		if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
214
-			if ( $qv['offset'] ) {
215
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
216
-			} else {
217
-				$this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
218
-			}
219
-		}
220
-
221
-		do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
222
-	}
223
-
224
-	/**
225
-	 * Prepares the query fields.
226
-	 *
227
-	 * @since 1.0.19
228
-	 *
229
-	 * @param array $qv Query vars.
230
-	 * @param string $table Table name.
231
-	 */
232
-	protected function prepare_query_fields( &$qv, $table ) {
233
-
234
-		if ( is_array( $qv['fields'] ) ) {
235
-			$qv['fields'] = array_unique( $qv['fields'] );
236
-
237
-			$query_fields = array();
238
-			foreach ( $qv['fields'] as $field ) {
239
-				$field          = sanitize_key( $field );
240
-				$query_fields[] = "$table.`$field`";
241
-			}
242
-			$this->query_fields = implode( ',', $query_fields );
243
-		} else {
244
-			$this->query_fields = "$table.*";
245
-		}
246
-
247
-		if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
248
-			$this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
249
-		}
250
-
251
-	}
252
-
253
-	/**
254
-	 * Prepares the query where.
255
-	 *
256
-	 * @since 1.0.19
257
-	 *
258
-	 * @param array $qv Query vars.
259
-	 * @param string $table Table name.
260
-	 */
261
-	protected function prepare_query_where( &$qv, $table ) {
262
-		global $wpdb;
263
-		$this->query_where = 'WHERE 1=1';
264
-
265
-		// Status.
266
-		if ( 'all' !== $qv['status'] ) {
267
-			$statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
268
-			$prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
269
-			$this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
270
-		}
271
-
272
-		if ( ! empty( $qv['customer_in'] ) ) {
273
-			$customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
274
-			$this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
275
-		} elseif ( ! empty( $qv['customer_not_in'] ) ) {
276
-			$customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
277
-			$this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
278
-		}
279
-
280
-		if ( ! empty( $qv['product_in'] ) ) {
281
-			$product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
282
-			$this->query_where .= " AND $table.`product_id` IN ($product_in)";
283
-		} elseif ( ! empty( $qv['product_not_in'] ) ) {
284
-			$product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
285
-			$this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
286
-		}
287
-
288
-		if ( ! empty( $qv['include'] ) ) {
289
-			$include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
290
-			$this->query_where .= " AND $table.`id` IN ($include)";
291
-		} elseif ( ! empty( $qv['exclude'] ) ) {
292
-			$exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
293
-			$this->query_where .= " AND $table.`id` NOT IN ($exclude)";
294
-		}
295
-
296
-		// Date queries are allowed for the subscription creation date.
297
-		if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
298
-			$date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
299
-			$this->query_where .= $date_created_query->get_sql();
300
-		}
301
-
302
-		// Date queries are also allowed for the subscription expiration date.
303
-		if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
304
-			$date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
305
-			$this->query_where .= $date_expires_query->get_sql();
306
-		}
307
-
308
-	}
309
-
310
-	/**
311
-	 * Prepares the query order.
312
-	 *
313
-	 * @since 1.0.19
314
-	 *
315
-	 * @param array $qv Query vars.
316
-	 * @param string $table Table name.
317
-	 */
318
-	protected function prepare_query_order( &$qv, $table ) {
319
-
320
-		// sorting.
321
-		$qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
322
-		$order       = $this->parse_order( $qv['order'] );
323
-
324
-		// Default order is by 'id' (latest subscriptions).
325
-		if ( empty( $qv['orderby'] ) ) {
326
-			$qv['orderby'] = array( 'id' );
327
-		}
328
-
329
-		// 'orderby' values may be an array, comma- or space-separated list.
330
-		$ordersby      = array_filter( wpinv_parse_list(  $qv['orderby'] ) );
331
-
332
-		$orderby_array = array();
333
-		foreach ( $ordersby as $_key => $_value ) {
334
-
335
-			if ( is_int( $_key ) ) {
336
-				// Integer key means this is a flat array of 'orderby' fields.
337
-				$_orderby = $_value;
338
-				$_order   = $order;
339
-			} else {
340
-				// Non-integer key means that the key is the field and the value is ASC/DESC.
341
-				$_orderby = $_key;
342
-				$_order   = $_value;
343
-			}
344
-
345
-			$parsed = $this->parse_orderby( $_orderby, $table );
346
-
347
-			if ( $parsed ) {
348
-				$orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
349
-			}
350
-
351
-		}
352
-
353
-		// If no valid clauses were found, order by id.
354
-		if ( empty( $orderby_array ) ) {
355
-			$orderby_array[] = "id $order";
356
-		}
357
-
358
-		$this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
359
-
360
-	}
361
-
362
-	/**
363
-	 * Execute the query, with the current variables.
364
-	 *
365
-	 * @since 1.0.19
366
-	 *
367
-	 * @global wpdb $wpdb WordPress database abstraction object.
368
-	 */
369
-	public function query() {
370
-		global $wpdb;
371
-
372
-		$qv =& $this->query_vars;
373
-
374
-		// Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
375
-		// total_subscriptions property.
376
-		$this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
377
-
378
-		if ( null === $this->results ) {
379
-			$this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
380
-
381
-			if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
382
-				$this->results = $wpdb->get_results( $this->request );
383
-			} else {
384
-				$this->results = $wpdb->get_col( $this->request );
385
-			}
386
-
387
-			if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
388
-				$found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
389
-				$this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
390
-			}
391
-		}
392
-
393
-		if ( 'all' == $qv['fields'] ) {
394
-			foreach ( $this->results as $key => $subscription ) {
395
-				$this->results[ $key ] = new WPInv_Subscription( $subscription );
396
-			}
397
-		}
398
-
399
-	}
400
-
401
-	/**
402
-	 * Retrieve query variable.
403
-	 *
404
-	 * @since 1.0.19
405
-	 *
406
-	 * @param string $query_var Query variable key.
407
-	 * @return mixed
408
-	 */
409
-	public function get( $query_var ) {
410
-		if ( isset( $this->query_vars[ $query_var ] ) ) {
411
-			return $this->query_vars[ $query_var ];
412
-		}
413
-
414
-		return null;
415
-	}
416
-
417
-	/**
418
-	 * Set query variable.
419
-	 *
420
-	 * @since 1.0.19
421
-	 *
422
-	 * @param string $query_var Query variable key.
423
-	 * @param mixed $value Query variable value.
424
-	 */
425
-	public function set( $query_var, $value ) {
426
-		$this->query_vars[ $query_var ] = $value;
427
-	}
428
-
429
-	/**
430
-	 * Return the list of subscriptions.
431
-	 *
432
-	 * @since 1.0.19
433
-	 *
434
-	 * @return WPInv_Subscription[]|array Found subscriptions.
435
-	 */
436
-	public function get_results() {
437
-		return $this->results;
438
-	}
439
-
440
-	/**
441
-	 * Return the total number of subscriptions for the current query.
442
-	 *
443
-	 * @since 1.0.19
444
-	 *
445
-	 * @return int Number of total subscriptions.
446
-	 */
447
-	public function get_total() {
448
-		return $this->total_subscriptions;
449
-	}
450
-
451
-	/**
452
-	 * Parse and sanitize 'orderby' keys passed to the subscriptions query.
453
-	 *
454
-	 * @since 1.0.19
455
-	 *
456
-	 * @param string $orderby Alias for the field to order by.
457
-	 *  @param string $table The current table.
458
-	 * @return string Value to use in the ORDER clause, if `$orderby` is valid.
459
-	 */
460
-	protected function parse_orderby( $orderby, $table ) {
461
-
462
-		$_orderby = '';
463
-		if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) {
464
-			$_orderby = "$table.`$orderby`";
465
-		} elseif ( 'id' === strtolower( $orderby ) ) {
466
-			$_orderby = "$table.id";
467
-		} elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
468
-			$include     = wp_parse_id_list( $this->query_vars['include'] );
469
-			$include_sql = implode( ',', $include );
470
-			$_orderby    = "FIELD( $table.id, $include_sql )";
471
-		}
472
-
473
-		return $_orderby;
474
-	}
475
-
476
-	/**
477
-	 * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
478
-	 *
479
-	 * @since 1.0.19
480
-	 *
481
-	 * @param string $order The 'order' query variable.
482
-	 * @return string The sanitized 'order' query variable.
483
-	 */
484
-	protected function parse_order( $order ) {
485
-		if ( ! is_string( $order ) || empty( $order ) ) {
486
-			return 'DESC';
487
-		}
488
-
489
-		if ( 'ASC' === strtoupper( $order ) ) {
490
-			return 'ASC';
491
-		} else {
492
-			return 'DESC';
493
-		}
494
-	}
19
+    /**
20
+     * Query vars, after parsing
21
+     *
22
+     * @since 1.0.19
23
+     * @var array
24
+     */
25
+    public $query_vars = array();
26
+
27
+    /**
28
+     * List of found subscriptions.
29
+     *
30
+     * @since 1.0.19
31
+     * @var array
32
+     */
33
+    private $results;
34
+
35
+    /**
36
+     * Total number of found subscriptions for the current query
37
+     *
38
+     * @since 1.0.19
39
+     * @var int
40
+     */
41
+    private $total_subscriptions = 0;
42
+
43
+    /**
44
+     * The SQL query used to fetch matching subscriptions.
45
+     *
46
+     * @since 1.0.19
47
+     * @var string
48
+     */
49
+    public $request;
50
+
51
+    // SQL clauses
52
+
53
+    /**
54
+     * Contains the 'FIELDS' sql clause
55
+     *
56
+     * @since 1.0.19
57
+     * @var string
58
+     */
59
+    public $query_fields;
60
+
61
+    /**
62
+     * Contains the 'FROM' sql clause
63
+     *
64
+     * @since 1.0.19
65
+     * @var string
66
+     */
67
+    public $query_from;
68
+
69
+    /**
70
+     * Contains the 'WHERE' sql clause
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $query_where;
76
+
77
+    /**
78
+     * Contains the 'ORDER BY' sql clause
79
+     *
80
+     * @since 1.0.19
81
+     * @var string
82
+     */
83
+    public $query_orderby;
84
+
85
+    /**
86
+     * Contains the 'LIMIT' sql clause
87
+     *
88
+     * @since 1.0.19
89
+     * @var string
90
+     */
91
+    public $query_limit;
92
+
93
+    /**
94
+     * Class constructor.
95
+     *
96
+     * @since 1.0.19
97
+     *
98
+     * @param null|string|array $query Optional. The query variables.
99
+     */
100
+    public function __construct( $query = null ) {
101
+        if ( ! is_null( $query ) ) {
102
+            $this->prepare_query( $query );
103
+            $this->query();
104
+        }
105
+    }
106
+
107
+    /**
108
+     * Fills in missing query variables with default values.
109
+     *
110
+     * @since 1.0.19
111
+     *
112
+     * @param  string|array $args Query vars, as passed to `GetPaid_Subscriptions_Query`.
113
+     * @return array Complete query variables with undefined ones filled in with defaults.
114
+     */
115
+    public static function fill_query_vars( $args ) {
116
+        $defaults = array(
117
+            'status'            => 'all',
118
+            'customer_in'       => array(),
119
+            'customer_not_in'   => array(),
120
+            'product_in'        => array(),
121
+            'product_not_in'    => array(),
122
+            'include'           => array(),
123
+            'exclude'           => array(),
124
+            'orderby'           => 'id',
125
+            'order'             => 'DESC',
126
+            'offset'            => '',
127
+            'number'            => 10,
128
+            'paged'             => 1,
129
+            'count_total'       => true,
130
+            'fields'            => 'all',
131
+        );
132
+
133
+        return wp_parse_args( $args, $defaults );
134
+    }
135
+
136
+    /**
137
+     * Prepare the query variables.
138
+     *
139
+     * @since 1.0.19
140
+     *
141
+     * @global wpdb $wpdb WordPress database abstraction object.
142
+     *
143
+     * @param string|array $query {
144
+     *     Optional. Array or string of Query parameters.
145
+     *
146
+     *     @type string|array $status              The subscription status to filter by. Can either be a single status or an array of statuses.
147
+     *                                             Default is all.
148
+     *     @type int[]        $customer_in         An array of customer ids to filter by.
149
+     *     @type int[]        $customer_not_in     An array of customer ids whose subscriptions should be excluded.
150
+     *     @type int[]        $product_in          An array of product ids to filter by.
151
+     *     @type int[]        $product_not_in      An array of product ids whose subscriptions should be excluded.
152
+     *     @type array        $date_created_query  A WP_Date_Query compatible array use to filter subscriptions by their date of creation.
153
+     *     @type array        $date_expires_query  A WP_Date_Query compatible array use to filter subscriptions by their expiration date.
154
+     *     @type array        $include             An array of subscription IDs to include. Default empty array.
155
+     *     @type array        $exclude             An array of subscription IDs to exclude. Default empty array.
156
+     *     @type string|array $orderby             Field(s) to sort the retrieved subscription by. May be a single value,
157
+     *                                             an array of values, or a multi-dimensional array with fields as
158
+     *                                             keys and orders ('ASC' or 'DESC') as values. Accepted values are
159
+     *                                             'id', 'customer_id', 'frequency', 'period', 'initial_amount,
160
+     *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
161
+     *                                             'transaction_id', 'product_id', 'trial_period', 'include', 'status', 'profile_id'. Default array( 'id' ).
162
+     *     @type string       $order               Designates ascending or descending order of subscriptions. Order values
163
+     *                                             passed as part of an `$orderby` array take precedence over this
164
+     *                                             parameter. Accepts 'ASC', 'DESC'. Default 'DESC'.
165
+     *     @type int          $offset              Number of subscriptions to offset in retrieved results. Can be used in
166
+     *                                             conjunction with pagination. Default 0.
167
+     *     @type int          $number              Number of subscriptions to limit the query for. Can be used in
168
+     *                                             conjunction with pagination. Value -1 (all) is supported, but
169
+     *                                             should be used with caution on larger sites.
170
+     *                                             Default 10.
171
+     *     @type int          $paged               When used with number, defines the page of results to return.
172
+     *                                             Default 1.
173
+     *     @type bool         $count_total         Whether to count the total number of subscriptions found. If pagination
174
+     *                                             is not needed, setting this to false can improve performance.
175
+     *                                             Default true.
176
+     *     @type string|array $fields              Which fields to return. Single or all fields (string), or array
177
+     *                                             of fields. Accepts 'id', 'customer_id', 'frequency', 'period', 'initial_amount,
178
+     *                                             'recurring_amount', 'bill_times', 'parent_payment_id', 'created', 'expiration'
179
+     *                                             'transaction_id', 'product_id', 'trial_period', 'status', 'profile_id'.
180
+     *                                             Use 'all' for all fields. Default 'all'.
181
+     * }
182
+     */
183
+    public function prepare_query( $query = array() ) {
184
+        global $wpdb;
185
+
186
+        if ( empty( $this->query_vars ) || ! empty( $query ) ) {
187
+            $this->query_limit = null;
188
+            $this->query_vars  = $this->fill_query_vars( $query );
189
+        }
190
+
191
+        if ( ! empty( $this->query_vars['fields'] ) && 'all' !== $this->query_vars['fields'] ) {
192
+            $this->query_vars['fields'] = wpinv_parse_list( $this->query_vars['fields'] );
193
+        }
194
+
195
+        do_action( 'getpaid_pre_get_subscriptions', array( &$this ) );
196
+
197
+        // Ensure that query vars are filled after 'getpaid_pre_get_subscriptions'.
198
+        $qv                =& $this->query_vars;
199
+        $qv                = $this->fill_query_vars( $qv );
200
+        $table             = $wpdb->prefix . 'wpinv_subscriptions';
201
+        $this->query_from  = "FROM $table";
202
+
203
+        // Prepare query fields.
204
+        $this->prepare_query_fields( $qv, $table );
205
+
206
+        // Prepare query where.
207
+        $this->prepare_query_where( $qv, $table );
208
+
209
+        // Prepare query order.
210
+        $this->prepare_query_order( $qv, $table );
211
+
212
+        // limit
213
+        if ( isset( $qv['number'] ) && $qv['number'] > 0 ) {
214
+            if ( $qv['offset'] ) {
215
+                $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['offset'], $qv['number'] );
216
+            } else {
217
+                $this->query_limit = $wpdb->prepare( 'LIMIT %d, %d', $qv['number'] * ( $qv['paged'] - 1 ), $qv['number'] );
218
+            }
219
+        }
220
+
221
+        do_action_ref_array( 'getpaid_after_subscriptions_query', array( &$this ) );
222
+    }
223
+
224
+    /**
225
+     * Prepares the query fields.
226
+     *
227
+     * @since 1.0.19
228
+     *
229
+     * @param array $qv Query vars.
230
+     * @param string $table Table name.
231
+     */
232
+    protected function prepare_query_fields( &$qv, $table ) {
233
+
234
+        if ( is_array( $qv['fields'] ) ) {
235
+            $qv['fields'] = array_unique( $qv['fields'] );
236
+
237
+            $query_fields = array();
238
+            foreach ( $qv['fields'] as $field ) {
239
+                $field          = sanitize_key( $field );
240
+                $query_fields[] = "$table.`$field`";
241
+            }
242
+            $this->query_fields = implode( ',', $query_fields );
243
+        } else {
244
+            $this->query_fields = "$table.*";
245
+        }
246
+
247
+        if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
248
+            $this->query_fields = 'SQL_CALC_FOUND_ROWS ' . $this->query_fields;
249
+        }
250
+
251
+    }
252
+
253
+    /**
254
+     * Prepares the query where.
255
+     *
256
+     * @since 1.0.19
257
+     *
258
+     * @param array $qv Query vars.
259
+     * @param string $table Table name.
260
+     */
261
+    protected function prepare_query_where( &$qv, $table ) {
262
+        global $wpdb;
263
+        $this->query_where = 'WHERE 1=1';
264
+
265
+        // Status.
266
+        if ( 'all' !== $qv['status'] ) {
267
+            $statuses           = wpinv_clean( wpinv_parse_list( $qv['status'] ) );
268
+            $prepared_statuses  = join( ',', array_fill( 0, count( $statuses ), '%s' ) );
269
+            $this->query_where .= $wpdb->prepare( " AND $table.`status` IN ( $prepared_statuses )", $statuses );
270
+        }
271
+
272
+        if ( ! empty( $qv['customer_in'] ) ) {
273
+            $customer_in        = implode( ',', wp_parse_id_list( $qv['customer_in'] ) );
274
+            $this->query_where .= " AND $table.`customer_id` IN ($customer_in)";
275
+        } elseif ( ! empty( $qv['customer_not_in'] ) ) {
276
+            $customer_not_in    = implode( ',', wp_parse_id_list( $qv['customer_not_in'] ) );
277
+            $this->query_where .= " AND $table.`customer_id` NOT IN ($customer_not_in)";
278
+        }
279
+
280
+        if ( ! empty( $qv['product_in'] ) ) {
281
+            $product_in         = implode( ',', wp_parse_id_list( $qv['product_in'] ) );
282
+            $this->query_where .= " AND $table.`product_id` IN ($product_in)";
283
+        } elseif ( ! empty( $qv['product_not_in'] ) ) {
284
+            $product_not_in     = implode( ',', wp_parse_id_list( $qv['product_not_in'] ) );
285
+            $this->query_where .= " AND $table.`product_id` NOT IN ($product_not_in)";
286
+        }
287
+
288
+        if ( ! empty( $qv['include'] ) ) {
289
+            $include            = implode( ',', wp_parse_id_list( $qv['include'] ) );
290
+            $this->query_where .= " AND $table.`id` IN ($include)";
291
+        } elseif ( ! empty( $qv['exclude'] ) ) {
292
+            $exclude            = implode( ',', wp_parse_id_list( $qv['exclude'] ) );
293
+            $this->query_where .= " AND $table.`id` NOT IN ($exclude)";
294
+        }
295
+
296
+        // Date queries are allowed for the subscription creation date.
297
+        if ( ! empty( $qv['date_created_query'] ) && is_array( $qv['date_created_query'] ) ) {
298
+            $date_created_query = new WP_Date_Query( $qv['date_created_query'], "$table.created" );
299
+            $this->query_where .= $date_created_query->get_sql();
300
+        }
301
+
302
+        // Date queries are also allowed for the subscription expiration date.
303
+        if ( ! empty( $qv['date_expires_query'] ) && is_array( $qv['date_expires_query'] ) ) {
304
+            $date_expires_query = new WP_Date_Query( $qv['date_expires_query'], "$table.expiration" );
305
+            $this->query_where .= $date_expires_query->get_sql();
306
+        }
307
+
308
+    }
309
+
310
+    /**
311
+     * Prepares the query order.
312
+     *
313
+     * @since 1.0.19
314
+     *
315
+     * @param array $qv Query vars.
316
+     * @param string $table Table name.
317
+     */
318
+    protected function prepare_query_order( &$qv, $table ) {
319
+
320
+        // sorting.
321
+        $qv['order'] = isset( $qv['order'] ) ? strtoupper( $qv['order'] ) : '';
322
+        $order       = $this->parse_order( $qv['order'] );
323
+
324
+        // Default order is by 'id' (latest subscriptions).
325
+        if ( empty( $qv['orderby'] ) ) {
326
+            $qv['orderby'] = array( 'id' );
327
+        }
328
+
329
+        // 'orderby' values may be an array, comma- or space-separated list.
330
+        $ordersby      = array_filter( wpinv_parse_list(  $qv['orderby'] ) );
331
+
332
+        $orderby_array = array();
333
+        foreach ( $ordersby as $_key => $_value ) {
334
+
335
+            if ( is_int( $_key ) ) {
336
+                // Integer key means this is a flat array of 'orderby' fields.
337
+                $_orderby = $_value;
338
+                $_order   = $order;
339
+            } else {
340
+                // Non-integer key means that the key is the field and the value is ASC/DESC.
341
+                $_orderby = $_key;
342
+                $_order   = $_value;
343
+            }
344
+
345
+            $parsed = $this->parse_orderby( $_orderby, $table );
346
+
347
+            if ( $parsed ) {
348
+                $orderby_array[] = $parsed . ' ' . $this->parse_order( $_order );
349
+            }
350
+
351
+        }
352
+
353
+        // If no valid clauses were found, order by id.
354
+        if ( empty( $orderby_array ) ) {
355
+            $orderby_array[] = "id $order";
356
+        }
357
+
358
+        $this->query_orderby = 'ORDER BY ' . implode( ', ', $orderby_array );
359
+
360
+    }
361
+
362
+    /**
363
+     * Execute the query, with the current variables.
364
+     *
365
+     * @since 1.0.19
366
+     *
367
+     * @global wpdb $wpdb WordPress database abstraction object.
368
+     */
369
+    public function query() {
370
+        global $wpdb;
371
+
372
+        $qv =& $this->query_vars;
373
+
374
+        // Return a non-null value to bypass the default GetPaid subscriptions query and remember to set the
375
+        // total_subscriptions property.
376
+        $this->results = apply_filters_ref_array( 'getpaid_subscriptions_pre_query', array( null, &$this ) );
377
+
378
+        if ( null === $this->results ) {
379
+            $this->request = "SELECT $this->query_fields $this->query_from $this->query_where $this->query_orderby $this->query_limit";
380
+
381
+            if ( ( is_array( $qv['fields'] ) && 1 != count( $qv['fields'] ) ) || 'all' == $qv['fields'] ) {
382
+                $this->results = $wpdb->get_results( $this->request );
383
+            } else {
384
+                $this->results = $wpdb->get_col( $this->request );
385
+            }
386
+
387
+            if ( isset( $qv['count_total'] ) && $qv['count_total'] ) {
388
+                $found_subscriptions_query = apply_filters( 'getpaid_found_subscriptions_query', 'SELECT FOUND_ROWS()', $this );
389
+                $this->total_subscriptions   = (int) $wpdb->get_var( $found_subscriptions_query );
390
+            }
391
+        }
392
+
393
+        if ( 'all' == $qv['fields'] ) {
394
+            foreach ( $this->results as $key => $subscription ) {
395
+                $this->results[ $key ] = new WPInv_Subscription( $subscription );
396
+            }
397
+        }
398
+
399
+    }
400
+
401
+    /**
402
+     * Retrieve query variable.
403
+     *
404
+     * @since 1.0.19
405
+     *
406
+     * @param string $query_var Query variable key.
407
+     * @return mixed
408
+     */
409
+    public function get( $query_var ) {
410
+        if ( isset( $this->query_vars[ $query_var ] ) ) {
411
+            return $this->query_vars[ $query_var ];
412
+        }
413
+
414
+        return null;
415
+    }
416
+
417
+    /**
418
+     * Set query variable.
419
+     *
420
+     * @since 1.0.19
421
+     *
422
+     * @param string $query_var Query variable key.
423
+     * @param mixed $value Query variable value.
424
+     */
425
+    public function set( $query_var, $value ) {
426
+        $this->query_vars[ $query_var ] = $value;
427
+    }
428
+
429
+    /**
430
+     * Return the list of subscriptions.
431
+     *
432
+     * @since 1.0.19
433
+     *
434
+     * @return WPInv_Subscription[]|array Found subscriptions.
435
+     */
436
+    public function get_results() {
437
+        return $this->results;
438
+    }
439
+
440
+    /**
441
+     * Return the total number of subscriptions for the current query.
442
+     *
443
+     * @since 1.0.19
444
+     *
445
+     * @return int Number of total subscriptions.
446
+     */
447
+    public function get_total() {
448
+        return $this->total_subscriptions;
449
+    }
450
+
451
+    /**
452
+     * Parse and sanitize 'orderby' keys passed to the subscriptions query.
453
+     *
454
+     * @since 1.0.19
455
+     *
456
+     * @param string $orderby Alias for the field to order by.
457
+     *  @param string $table The current table.
458
+     * @return string Value to use in the ORDER clause, if `$orderby` is valid.
459
+     */
460
+    protected function parse_orderby( $orderby, $table ) {
461
+
462
+        $_orderby = '';
463
+        if ( in_array( $orderby, array( 'customer_id', 'frequency', 'period', 'initial_amount', 'recurring_amount', 'bill_times', 'transaction_id', 'parent_payment_id', 'product_id', 'created', 'expiration', 'trial_period', 'status', 'profile_id' ) ) ) {
464
+            $_orderby = "$table.`$orderby`";
465
+        } elseif ( 'id' === strtolower( $orderby ) ) {
466
+            $_orderby = "$table.id";
467
+        } elseif ( 'include' === $orderby && ! empty( $this->query_vars['include'] ) ) {
468
+            $include     = wp_parse_id_list( $this->query_vars['include'] );
469
+            $include_sql = implode( ',', $include );
470
+            $_orderby    = "FIELD( $table.id, $include_sql )";
471
+        }
472
+
473
+        return $_orderby;
474
+    }
475
+
476
+    /**
477
+     * Parse an 'order' query variable and cast it to ASC or DESC as necessary.
478
+     *
479
+     * @since 1.0.19
480
+     *
481
+     * @param string $order The 'order' query variable.
482
+     * @return string The sanitized 'order' query variable.
483
+     */
484
+    protected function parse_order( $order ) {
485
+        if ( ! is_string( $order ) || empty( $order ) ) {
486
+            return 'DESC';
487
+        }
488
+
489
+        if ( 'ASC' === strtoupper( $order ) ) {
490
+            return 'ASC';
491
+        } else {
492
+            return 'DESC';
493
+        }
494
+    }
495 495
 
496 496
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-data-store.php 1 patch
Indentation   +181 added lines, -181 removed lines patch added patch discarded remove patch
@@ -11,186 +11,186 @@
 block discarded – undo
11 11
  */
12 12
 class GetPaid_Data_Store {
13 13
 
14
-	/**
15
-	 * Contains an instance of the data store class that we are working with.
16
-	 *
17
-	 * @var GetPaid_Data_Store
18
-	 */
19
-	private $instance = null;
20
-
21
-	/**
22
-	 * Contains an array of default supported data stores.
23
-	 * Format of object name => class name.
24
-	 * Example: 'item' => 'GetPaid_Item_Data_Store'
25
-	 * You can also pass something like item-<type> for item stores and
26
-	 * that type will be used first when available, if a store is requested like
27
-	 * this and doesn't exist, then the store would fall back to 'item'.
28
-	 * Ran through `getpaid_data_stores`.
29
-	 *
30
-	 * @var array
31
-	 */
32
-	private $stores = array(
33
-		'item'         => 'GetPaid_Item_Data_Store',
34
-		'payment_form' => 'GetPaid_Payment_Form_Data_Store',
35
-		'discount'     => 'GetPaid_Discount_Data_Store',
36
-		'invoice'      => 'GetPaid_Invoice_Data_Store',
37
-		'subscription' => 'GetPaid_Subscription_Data_Store',
38
-	);
39
-
40
-	/**
41
-	 * Contains the name of the current data store's class name.
42
-	 *
43
-	 * @var string
44
-	 */
45
-	private $current_class_name = '';
46
-
47
-	/**
48
-	 * The object type this store works with.
49
-	 *
50
-	 * @var string
51
-	 */
52
-	private $object_type = '';
53
-
54
-	/**
55
-	 * Tells GetPaid_Data_Store which object
56
-	 * store we want to work with.
57
-	 *
58
-	 * @param string $object_type Name of object.
59
-	 */
60
-	public function __construct( $object_type ) {
61
-		$this->object_type = $object_type;
62
-		$this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
63
-
64
-		// If this object type can't be found, check to see if we can load one
65
-		// level up (so if item-type isn't found, we try item).
66
-		if ( ! array_key_exists( $object_type, $this->stores ) ) {
67
-			$pieces      = explode( '-', $object_type );
68
-			$object_type = $pieces[0];
69
-		}
70
-
71
-		if ( array_key_exists( $object_type, $this->stores ) ) {
72
-			$store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
73
-			if ( is_object( $store ) ) {
74
-				$this->current_class_name = get_class( $store );
75
-				$this->instance           = $store;
76
-			} else {
77
-				if ( ! class_exists( $store ) ) {
78
-					throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) );
79
-				}
80
-				$this->current_class_name = $store;
81
-				$this->instance           = new $store();
82
-			}
83
-		} else {
84
-			throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
85
-		}
86
-	}
87
-
88
-	/**
89
-	 * Only store the object type to avoid serializing the data store instance.
90
-	 *
91
-	 * @return array
92
-	 */
93
-	public function __sleep() {
94
-		return array( 'object_type' );
95
-	}
96
-
97
-	/**
98
-	 * Re-run the constructor with the object type.
99
-	 *
100
-	 * @throws Exception When validation fails.
101
-	 */
102
-	public function __wakeup() {
103
-		$this->__construct( $this->object_type );
104
-	}
105
-
106
-	/**
107
-	 * Loads a data store.
108
-	 *
109
-	 * @param string $object_type Name of object.
110
-	 *
111
-	 * @since 1.0.19
112
-	 * @throws Exception When validation fails.
113
-	 * @return GetPaid_Data_Store
114
-	 */
115
-	public static function load( $object_type ) {
116
-		return new GetPaid_Data_Store( $object_type );
117
-	}
118
-
119
-	/**
120
-	 * Returns the class name of the current data store.
121
-	 *
122
-	 * @since 1.0.19
123
-	 * @return string
124
-	 */
125
-	public function get_current_class_name() {
126
-		return $this->current_class_name;
127
-	}
128
-
129
-	/**
130
-	 * Returns the object type of the current data store.
131
-	 *
132
-	 * @since 1.0.19
133
-	 * @return string
134
-	 */
135
-	public function get_object_type() {
136
-		return $this->object_type;
137
-	}
138
-
139
-	/**
140
-	 * Reads an object from the data store.
141
-	 *
142
-	 * @since 1.0.19
143
-	 * @param GetPaid_Data $data GetPaid data instance.
144
-	 */
145
-	public function read( &$data ) {
146
-		$this->instance->read( $data );
147
-	}
148
-
149
-	/**
150
-	 * Create an object in the data store.
151
-	 *
152
-	 * @since 1.0.19
153
-	 * @param GetPaid_Data $data GetPaid data instance.
154
-	 */
155
-	public function create( &$data ) {
156
-		$this->instance->create( $data );
157
-	}
158
-
159
-	/**
160
-	 * Update an object in the data store.
161
-	 *
162
-	 * @since 1.0.19
163
-	 * @param GetPaid_Data $data GetPaid data instance.
164
-	 */
165
-	public function update( &$data ) {
166
-		$this->instance->update( $data );
167
-	}
168
-
169
-	/**
170
-	 * Delete an object from the data store.
171
-	 *
172
-	 * @since 1.0.19
173
-	 * @param GetPaid_Data $data GetPaid data instance.
174
-	 * @param array   $args Array of args to pass to the delete method.
175
-	 */
176
-	public function delete( &$data, $args = array() ) {
177
-		$this->instance->delete( $data, $args );
178
-	}
179
-
180
-	/**
181
-	 * Data stores can define additional function. This passes
182
-	 * through to the instance if that function exists.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param string $method     Method.
186
-	 * @return mixed
187
-	 */
188
-	public function __call( $method, $parameters ) {
189
-		if ( is_callable( array( $this->instance, $method ) ) ) {
190
-			$object     = array_shift( $parameters );
191
-			$parameters = array_merge( array( &$object ), $parameters );
192
-			return call_user_func_array( array( $this->instance, $method ), $parameters );
193
-		}
194
-	}
14
+    /**
15
+     * Contains an instance of the data store class that we are working with.
16
+     *
17
+     * @var GetPaid_Data_Store
18
+     */
19
+    private $instance = null;
20
+
21
+    /**
22
+     * Contains an array of default supported data stores.
23
+     * Format of object name => class name.
24
+     * Example: 'item' => 'GetPaid_Item_Data_Store'
25
+     * You can also pass something like item-<type> for item stores and
26
+     * that type will be used first when available, if a store is requested like
27
+     * this and doesn't exist, then the store would fall back to 'item'.
28
+     * Ran through `getpaid_data_stores`.
29
+     *
30
+     * @var array
31
+     */
32
+    private $stores = array(
33
+        'item'         => 'GetPaid_Item_Data_Store',
34
+        'payment_form' => 'GetPaid_Payment_Form_Data_Store',
35
+        'discount'     => 'GetPaid_Discount_Data_Store',
36
+        'invoice'      => 'GetPaid_Invoice_Data_Store',
37
+        'subscription' => 'GetPaid_Subscription_Data_Store',
38
+    );
39
+
40
+    /**
41
+     * Contains the name of the current data store's class name.
42
+     *
43
+     * @var string
44
+     */
45
+    private $current_class_name = '';
46
+
47
+    /**
48
+     * The object type this store works with.
49
+     *
50
+     * @var string
51
+     */
52
+    private $object_type = '';
53
+
54
+    /**
55
+     * Tells GetPaid_Data_Store which object
56
+     * store we want to work with.
57
+     *
58
+     * @param string $object_type Name of object.
59
+     */
60
+    public function __construct( $object_type ) {
61
+        $this->object_type = $object_type;
62
+        $this->stores      = apply_filters( 'getpaid_data_stores', $this->stores );
63
+
64
+        // If this object type can't be found, check to see if we can load one
65
+        // level up (so if item-type isn't found, we try item).
66
+        if ( ! array_key_exists( $object_type, $this->stores ) ) {
67
+            $pieces      = explode( '-', $object_type );
68
+            $object_type = $pieces[0];
69
+        }
70
+
71
+        if ( array_key_exists( $object_type, $this->stores ) ) {
72
+            $store = apply_filters( 'getpaid_' . $object_type . '_data_store', $this->stores[ $object_type ] );
73
+            if ( is_object( $store ) ) {
74
+                $this->current_class_name = get_class( $store );
75
+                $this->instance           = $store;
76
+            } else {
77
+                if ( ! class_exists( $store ) ) {
78
+                    throw new Exception( __( 'Data store class does not exist.', 'invoicing' ) );
79
+                }
80
+                $this->current_class_name = $store;
81
+                $this->instance           = new $store();
82
+            }
83
+        } else {
84
+            throw new Exception( __( 'Invalid data store.', 'invoicing' ) );
85
+        }
86
+    }
87
+
88
+    /**
89
+     * Only store the object type to avoid serializing the data store instance.
90
+     *
91
+     * @return array
92
+     */
93
+    public function __sleep() {
94
+        return array( 'object_type' );
95
+    }
96
+
97
+    /**
98
+     * Re-run the constructor with the object type.
99
+     *
100
+     * @throws Exception When validation fails.
101
+     */
102
+    public function __wakeup() {
103
+        $this->__construct( $this->object_type );
104
+    }
105
+
106
+    /**
107
+     * Loads a data store.
108
+     *
109
+     * @param string $object_type Name of object.
110
+     *
111
+     * @since 1.0.19
112
+     * @throws Exception When validation fails.
113
+     * @return GetPaid_Data_Store
114
+     */
115
+    public static function load( $object_type ) {
116
+        return new GetPaid_Data_Store( $object_type );
117
+    }
118
+
119
+    /**
120
+     * Returns the class name of the current data store.
121
+     *
122
+     * @since 1.0.19
123
+     * @return string
124
+     */
125
+    public function get_current_class_name() {
126
+        return $this->current_class_name;
127
+    }
128
+
129
+    /**
130
+     * Returns the object type of the current data store.
131
+     *
132
+     * @since 1.0.19
133
+     * @return string
134
+     */
135
+    public function get_object_type() {
136
+        return $this->object_type;
137
+    }
138
+
139
+    /**
140
+     * Reads an object from the data store.
141
+     *
142
+     * @since 1.0.19
143
+     * @param GetPaid_Data $data GetPaid data instance.
144
+     */
145
+    public function read( &$data ) {
146
+        $this->instance->read( $data );
147
+    }
148
+
149
+    /**
150
+     * Create an object in the data store.
151
+     *
152
+     * @since 1.0.19
153
+     * @param GetPaid_Data $data GetPaid data instance.
154
+     */
155
+    public function create( &$data ) {
156
+        $this->instance->create( $data );
157
+    }
158
+
159
+    /**
160
+     * Update an object in the data store.
161
+     *
162
+     * @since 1.0.19
163
+     * @param GetPaid_Data $data GetPaid data instance.
164
+     */
165
+    public function update( &$data ) {
166
+        $this->instance->update( $data );
167
+    }
168
+
169
+    /**
170
+     * Delete an object from the data store.
171
+     *
172
+     * @since 1.0.19
173
+     * @param GetPaid_Data $data GetPaid data instance.
174
+     * @param array   $args Array of args to pass to the delete method.
175
+     */
176
+    public function delete( &$data, $args = array() ) {
177
+        $this->instance->delete( $data, $args );
178
+    }
179
+
180
+    /**
181
+     * Data stores can define additional function. This passes
182
+     * through to the instance if that function exists.
183
+     *
184
+     * @since 1.0.19
185
+     * @param string $method     Method.
186
+     * @return mixed
187
+     */
188
+    public function __call( $method, $parameters ) {
189
+        if ( is_callable( array( $this->instance, $method ) ) ) {
190
+            $object     = array_shift( $parameters );
191
+            $parameters = array_merge( array( &$object ), $parameters );
192
+            return call_user_func_array( array( $this->instance, $method ), $parameters );
193
+        }
194
+    }
195 195
 
196 196
 }
Please login to merge, or discard this patch.
includes/data-stores/class-getpaid-subscription-data-store.php 1 patch
Indentation   +178 added lines, -178 removed lines patch added patch discarded remove patch
@@ -5,7 +5,7 @@  discard block
 block discarded – undo
5 5
  *
6 6
  */
7 7
 if ( ! defined( 'ABSPATH' ) ) {
8
-	exit;
8
+    exit;
9 9
 }
10 10
 
11 11
 /**
@@ -15,193 +15,193 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Subscription_Data_Store {
17 17
 
18
-	/**
19
-	 * A map of database fields to data types.
20
-	 *
21
-	 * @since 1.0.19
22
-	 * @var array
23
-	 */
24
-	protected $database_fields_to_data_type = array(
25
-		'id'                => '%d',
26
-		'customer_id'       => '%d',
27
-		'frequency'         => '%d',
28
-		'period'            => '%s',
29
-		'initial_amount'    => '%s',
30
-		'recurring_amount'  => '%s',
31
-		'bill_times'        => '%d',
32
-		'transaction_id'    => '%s',
33
-		'parent_payment_id' => '%d',
34
-		'product_id'        => '%d',
35
-		'created'           => '%s',
36
-		'expiration'        => '%s',
37
-		'trial_period'      => '%s',
38
-		'status'            => '%s',
39
-		'profile_id'        => '%s',
40
-	);
41
-
42
-	/*
18
+    /**
19
+     * A map of database fields to data types.
20
+     *
21
+     * @since 1.0.19
22
+     * @var array
23
+     */
24
+    protected $database_fields_to_data_type = array(
25
+        'id'                => '%d',
26
+        'customer_id'       => '%d',
27
+        'frequency'         => '%d',
28
+        'period'            => '%s',
29
+        'initial_amount'    => '%s',
30
+        'recurring_amount'  => '%s',
31
+        'bill_times'        => '%d',
32
+        'transaction_id'    => '%s',
33
+        'parent_payment_id' => '%d',
34
+        'product_id'        => '%d',
35
+        'created'           => '%s',
36
+        'expiration'        => '%s',
37
+        'trial_period'      => '%s',
38
+        'status'            => '%s',
39
+        'profile_id'        => '%s',
40
+    );
41
+
42
+    /*
43 43
 	|--------------------------------------------------------------------------
44 44
 	| CRUD Methods
45 45
 	|--------------------------------------------------------------------------
46 46
 	*/
47 47
 
48
-	/**
49
-	 * Method to create a new subscription in the database.
50
-	 *
51
-	 * @param WPInv_Subscription $subscription Subscription object.
52
-	 */
53
-	public function create( &$subscription ) {
54
-		global $wpdb;
55
-
56
-		$values  = array();
57
-		$formats = array();
58
-
59
-		$fields = $this->database_fields_to_data_type;
60
-		unset( $fields['id'] );
61
-
62
-		foreach ( $fields as $key => $format ) {
63
-			$method     = "get_$key";
64
-			$values[]   = $subscription->$method( 'edit' );
65
-			$formats[]  = $format;
66
-		}
67
-
68
-		$result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats );
69
-
70
-		if ( $result ) {
71
-			$subscription->set_id( $wpdb->insert_id );
72
-			$subscription->apply_changes();
73
-			$subscription->clear_cache();
74
-			do_action( 'getpaid_new_subscription', $subscription );
75
-			return true;
76
-		}
77
-
78
-		return false;
79
-	}
80
-
81
-	/**
82
-	 * Method to read a subscription from the database.
83
-	 *
84
-	 * @param WPInv_Subscription $subscription Subscription object.
85
-	 *
86
-	 */
87
-	public function read( &$subscription ) {
88
-		global $wpdb;
89
-
90
-		$subscription->set_defaults();
91
-
92
-		if ( ! $subscription->get_id() ) {
93
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
94
-			$subscription->set_id( 0 );
95
-			return false;
96
-		}
97
-
98
-		// Maybe retrieve from the cache.
99
-		$raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
100
-
101
-		// If not found, retrieve from the db.
102
-		if ( false === $raw_subscription ) {
103
-
104
-			$raw_subscription = $wpdb->get_row(
105
-				$wpdb->prepare(
106
-					"SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d",
107
-					$subscription->get_id()
108
-				)
109
-			);
110
-
111
-			// Update the cache with our data
112
-			wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
113
-
114
-		}
115
-
116
-		if ( ! $raw_subscription ) {
117
-			$subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
118
-			return false;
119
-		}
120
-
121
-		foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
122
-			$method     = "set_$key";
123
-			$subscription->$method( $raw_subscription->$key );
124
-		}
125
-
126
-		$subscription->set_object_read( true );
127
-		do_action( 'getpaid_read_subscription', $subscription );
128
-
129
-	}
130
-
131
-	/**
132
-	 * Method to update a subscription in the database.
133
-	 *
134
-	 * @param WPInv_Subscription $subscription Subscription object.
135
-	 */
136
-	public function update( &$subscription ) {
137
-		global $wpdb;
138
-
139
-		if ( null === $subscription->get_date_created( 'edit' ) ) {
140
-			$subscription->set_date_created(  current_time('mysql') );
141
-		}
142
-
143
-		$changes = $subscription->get_changes();
144
-		$values  = array();
145
-		$format  = array();
146
-
147
-		foreach ( $this->database_fields_to_data_type as $key => $format ) {
148
-			if ( array_key_exists( $key, $changes ) ) {
149
-				$method     = "get_$key";
150
-				$values[]   = $subscription->$method( 'edit' );
151
-				$formats[]  = $format;
152
-			}
153
-		}
154
-
155
-		if ( empty( $values ) ) {
156
-			return;
157
-		}
158
-
159
-		$wpdb->update(
160
-			$wpdb->prefix . 'wpinv_subscriptions',
161
-			$values,
162
-			array(
163
-				'id' => $subscription->get_id(),
164
-			),
165
-			$formats
166
-		);
167
-
168
-		// Apply the changes.
169
-		$subscription->apply_changes();
170
-
171
-		// Delete cache.
172
-		$subscription->clear_cache();
173
-
174
-		// Fire a hook.
175
-		do_action( 'getpaid_update_subscription', $subscription->get_id(), $subscription );
176
-
177
-	}
178
-
179
-	/**
180
-	 * Method to delete a subscription from the database.
181
-	 *
182
-	 * @param WPInv_Subscription $subscription
183
-	 */
184
-	public function delete( &$subscription ) {
185
-		global $wpdb;
186
-
187
-		$wpdb->query(
188
-			$wpdb->prepare(
189
-				"DELETE FROM {$wpdb->prefix}getpaid_subscriptions
48
+    /**
49
+     * Method to create a new subscription in the database.
50
+     *
51
+     * @param WPInv_Subscription $subscription Subscription object.
52
+     */
53
+    public function create( &$subscription ) {
54
+        global $wpdb;
55
+
56
+        $values  = array();
57
+        $formats = array();
58
+
59
+        $fields = $this->database_fields_to_data_type;
60
+        unset( $fields['id'] );
61
+
62
+        foreach ( $fields as $key => $format ) {
63
+            $method     = "get_$key";
64
+            $values[]   = $subscription->$method( 'edit' );
65
+            $formats[]  = $format;
66
+        }
67
+
68
+        $result = $wpdb->insert( $wpdb->prefix . 'wpinv_subscriptions', $fields, $formats );
69
+
70
+        if ( $result ) {
71
+            $subscription->set_id( $wpdb->insert_id );
72
+            $subscription->apply_changes();
73
+            $subscription->clear_cache();
74
+            do_action( 'getpaid_new_subscription', $subscription );
75
+            return true;
76
+        }
77
+
78
+        return false;
79
+    }
80
+
81
+    /**
82
+     * Method to read a subscription from the database.
83
+     *
84
+     * @param WPInv_Subscription $subscription Subscription object.
85
+     *
86
+     */
87
+    public function read( &$subscription ) {
88
+        global $wpdb;
89
+
90
+        $subscription->set_defaults();
91
+
92
+        if ( ! $subscription->get_id() ) {
93
+            $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
94
+            $subscription->set_id( 0 );
95
+            return false;
96
+        }
97
+
98
+        // Maybe retrieve from the cache.
99
+        $raw_subscription = wp_cache_get( $subscription->get_id(), 'getpaid_subscriptions' );
100
+
101
+        // If not found, retrieve from the db.
102
+        if ( false === $raw_subscription ) {
103
+
104
+            $raw_subscription = $wpdb->get_row(
105
+                $wpdb->prepare(
106
+                    "SELECT * FROM {$wpdb->prefix}wpinv_subscriptions WHERE id = %d",
107
+                    $subscription->get_id()
108
+                )
109
+            );
110
+
111
+            // Update the cache with our data
112
+            wp_cache_set( $subscription->get_id(), $raw_subscription, 'getpaid_subscriptions' );
113
+
114
+        }
115
+
116
+        if ( ! $raw_subscription ) {
117
+            $subscription->last_error = __( 'Invalid subscription ID.', 'invoicing' );
118
+            return false;
119
+        }
120
+
121
+        foreach ( array_keys( $this->database_fields_to_data_type ) as $key ) {
122
+            $method     = "set_$key";
123
+            $subscription->$method( $raw_subscription->$key );
124
+        }
125
+
126
+        $subscription->set_object_read( true );
127
+        do_action( 'getpaid_read_subscription', $subscription );
128
+
129
+    }
130
+
131
+    /**
132
+     * Method to update a subscription in the database.
133
+     *
134
+     * @param WPInv_Subscription $subscription Subscription object.
135
+     */
136
+    public function update( &$subscription ) {
137
+        global $wpdb;
138
+
139
+        if ( null === $subscription->get_date_created( 'edit' ) ) {
140
+            $subscription->set_date_created(  current_time('mysql') );
141
+        }
142
+
143
+        $changes = $subscription->get_changes();
144
+        $values  = array();
145
+        $format  = array();
146
+
147
+        foreach ( $this->database_fields_to_data_type as $key => $format ) {
148
+            if ( array_key_exists( $key, $changes ) ) {
149
+                $method     = "get_$key";
150
+                $values[]   = $subscription->$method( 'edit' );
151
+                $formats[]  = $format;
152
+            }
153
+        }
154
+
155
+        if ( empty( $values ) ) {
156
+            return;
157
+        }
158
+
159
+        $wpdb->update(
160
+            $wpdb->prefix . 'wpinv_subscriptions',
161
+            $values,
162
+            array(
163
+                'id' => $subscription->get_id(),
164
+            ),
165
+            $formats
166
+        );
167
+
168
+        // Apply the changes.
169
+        $subscription->apply_changes();
170
+
171
+        // Delete cache.
172
+        $subscription->clear_cache();
173
+
174
+        // Fire a hook.
175
+        do_action( 'getpaid_update_subscription', $subscription->get_id(), $subscription );
176
+
177
+    }
178
+
179
+    /**
180
+     * Method to delete a subscription from the database.
181
+     *
182
+     * @param WPInv_Subscription $subscription
183
+     */
184
+    public function delete( &$subscription ) {
185
+        global $wpdb;
186
+
187
+        $wpdb->query(
188
+            $wpdb->prepare(
189
+                "DELETE FROM {$wpdb->prefix}getpaid_subscriptions
190 190
 				WHERE id = %d",
191
-				$subscription->get_id()
192
-			)
193
-		);
191
+                $subscription->get_id()
192
+            )
193
+        );
194 194
 
195
-		// Delete cache.
196
-		$subscription->clear_cache();
195
+        // Delete cache.
196
+        $subscription->clear_cache();
197 197
 
198
-		// Fire a hook.
199
-		do_action( 'getpaid_delete_subscription', $subscription->get_id(), $subscription );
198
+        // Fire a hook.
199
+        do_action( 'getpaid_delete_subscription', $subscription->get_id(), $subscription );
200 200
 
201
-		$subscription->set_id( 0 );
202
-	}
201
+        $subscription->set_id( 0 );
202
+    }
203 203
 
204
-	/*
204
+    /*
205 205
 	|--------------------------------------------------------------------------
206 206
 	| Additional Methods
207 207
 	|--------------------------------------------------------------------------
Please login to merge, or discard this patch.
includes/wpinv-subscription.php 1 patch
Indentation   +948 added lines, -948 removed lines patch added patch discarded remove patch
@@ -15,127 +15,127 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class WPInv_Subscription extends GetPaid_Data {
17 17
 
18
-	/**
19
-	 * Which data store to load.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	protected $data_store_name = 'subscription';
24
-
25
-	/**
26
-	 * This is the name of this object type.
27
-	 *
28
-	 * @var string
29
-	 */
30
-	protected $object_type = 'subscription';
31
-
32
-	/**
33
-	 * Item Data array. This is the core item data exposed in APIs.
34
-	 *
35
-	 * @since 1.0.19
36
-	 * @var array
37
-	 */
38
-	protected $data = array(
39
-		'customer_id'       => 0,
40
-		'frequency'         => 1,
41
-		'period'            => 'D',
42
-		'initial_amount'    => null,
43
-		'recurring_amount'  => null,
44
-		'bill_times'        => 0,
45
-		'transaction_id'    => '',
46
-		'parent_payment_id' => null,
47
-		'product_id'        => 0,
48
-		'created'           => '0000-00-00 00:00:00',
49
-		'expiration'        => '0000-00-00 00:00:00',
50
-		'trial_period'      => null,
51
-		'status'            => 'pending',
52
-		'profile_id'        => '',
53
-		'gateway'           => '',
54
-		'customer'          => '',
55
-	);
56
-
57
-	/**
58
-	 * Stores the status transition information.
59
-	 *
60
-	 * @since 1.0.19
61
-	 * @var bool
62
-	 */
63
-	protected $status_transition = false;
64
-
65
-	private $subs_db;
66
-
67
-	/**
68
-	 * Get the subscription if ID is passed, otherwise the subscription is new and empty.
69
-	 *
70
-	 * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
71
-	 * @param  bool $deprecated
72
-	 */
73
-	function __construct( $subscription = 0, $deprecated = false ) {
74
-
75
-		parent::__construct( $subscription );
76
-
77
-		if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
78
-			$this->set_id( $subscription );
79
-		} elseif ( $subscription instanceof self ) {
80
-			$this->set_id( $subscription->get_id() );
81
-		} elseif ( ! empty( $subscription->id ) ) {
82
-			$this->set_id( $subscription->id );
83
-		} elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
84
-			$this->set_id( $subscription_id );
85
-		} else {
86
-			$this->set_object_read( true );
87
-		}
88
-
89
-		// Load the datastore.
90
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
91
-
92
-		if ( $this->get_id() > 0 ) {
93
-			$this->data_store->read( $this );
94
-		}
95
-
96
-	}
97
-
98
-	/**
99
-	 * Given an invoice id, profile id, transaction id, it returns the subscription's id.
100
-	 *
101
-	 *
102
-	 * @static
103
-	 * @param string $value
104
-	 * @param string $field Either invoice_id, transaction_id or profile_id.
105
-	 * @since 1.0.19
106
-	 * @return int
107
-	 */
108
-	public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
18
+    /**
19
+     * Which data store to load.
20
+     *
21
+     * @var string
22
+     */
23
+    protected $data_store_name = 'subscription';
24
+
25
+    /**
26
+     * This is the name of this object type.
27
+     *
28
+     * @var string
29
+     */
30
+    protected $object_type = 'subscription';
31
+
32
+    /**
33
+     * Item Data array. This is the core item data exposed in APIs.
34
+     *
35
+     * @since 1.0.19
36
+     * @var array
37
+     */
38
+    protected $data = array(
39
+        'customer_id'       => 0,
40
+        'frequency'         => 1,
41
+        'period'            => 'D',
42
+        'initial_amount'    => null,
43
+        'recurring_amount'  => null,
44
+        'bill_times'        => 0,
45
+        'transaction_id'    => '',
46
+        'parent_payment_id' => null,
47
+        'product_id'        => 0,
48
+        'created'           => '0000-00-00 00:00:00',
49
+        'expiration'        => '0000-00-00 00:00:00',
50
+        'trial_period'      => null,
51
+        'status'            => 'pending',
52
+        'profile_id'        => '',
53
+        'gateway'           => '',
54
+        'customer'          => '',
55
+    );
56
+
57
+    /**
58
+     * Stores the status transition information.
59
+     *
60
+     * @since 1.0.19
61
+     * @var bool
62
+     */
63
+    protected $status_transition = false;
64
+
65
+    private $subs_db;
66
+
67
+    /**
68
+     * Get the subscription if ID is passed, otherwise the subscription is new and empty.
69
+     *
70
+     * @param  int|string|object|WPInv_Subscription $subscription Subscription id, profile_id, or object to read.
71
+     * @param  bool $deprecated
72
+     */
73
+    function __construct( $subscription = 0, $deprecated = false ) {
74
+
75
+        parent::__construct( $subscription );
76
+
77
+        if ( ! $deprecated && ! empty( $subscription ) && is_numeric( $subscription ) ) {
78
+            $this->set_id( $subscription );
79
+        } elseif ( $subscription instanceof self ) {
80
+            $this->set_id( $subscription->get_id() );
81
+        } elseif ( ! empty( $subscription->id ) ) {
82
+            $this->set_id( $subscription->id );
83
+        } elseif ( $deprecated && $subscription_id = self::get_subscription_id_by_field( $subscription, 'profile_id' ) ) {
84
+            $this->set_id( $subscription_id );
85
+        } else {
86
+            $this->set_object_read( true );
87
+        }
88
+
89
+        // Load the datastore.
90
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
91
+
92
+        if ( $this->get_id() > 0 ) {
93
+            $this->data_store->read( $this );
94
+        }
95
+
96
+    }
97
+
98
+    /**
99
+     * Given an invoice id, profile id, transaction id, it returns the subscription's id.
100
+     *
101
+     *
102
+     * @static
103
+     * @param string $value
104
+     * @param string $field Either invoice_id, transaction_id or profile_id.
105
+     * @since 1.0.19
106
+     * @return int
107
+     */
108
+    public static function get_subscription_id_by_field( $value, $field = 'profile_id' ) {
109 109
         global $wpdb;
110 110
 
111
-		// Trim the value.
112
-		$value = trim( $value );
111
+        // Trim the value.
112
+        $value = trim( $value );
113 113
 
114
-		if ( empty( $value ) ) {
115
-			return 0;
116
-		}
114
+        if ( empty( $value ) ) {
115
+            return 0;
116
+        }
117 117
 
118
-		if ( 'invoice_id' == $field ) {
119
-			$field = 'parent_payment_id';
120
-		}
118
+        if ( 'invoice_id' == $field ) {
119
+            $field = 'parent_payment_id';
120
+        }
121 121
 
122 122
         // Valid fields.
123 123
         $fields = array(
124
-			'parent_payment_id',
125
-			'transaction_id',
126
-			'profile_id'
127
-		);
128
-
129
-		// Ensure a field has been passed.
130
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
131
-			return 0;
132
-		}
133
-
134
-		// Maybe retrieve from the cache.
135
-		$subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
136
-		if ( ! empty( $subscription_id ) ) {
137
-			return $subscription_id;
138
-		}
124
+            'parent_payment_id',
125
+            'transaction_id',
126
+            'profile_id'
127
+        );
128
+
129
+        // Ensure a field has been passed.
130
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
131
+            return 0;
132
+        }
133
+
134
+        // Maybe retrieve from the cache.
135
+        $subscription_id   = wp_cache_get( $value, "getpaid_subscription_{$field}s_to_subscription_ids" );
136
+        if ( ! empty( $subscription_id ) ) {
137
+            return $subscription_id;
138
+        }
139 139
 
140 140
         // Fetch from the db.
141 141
         $table            = $wpdb->prefix . 'wpinv_subscriptions';
@@ -143,34 +143,34 @@  discard block
 block discarded – undo
143 143
             $wpdb->prepare( "SELECT `id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
144 144
         );
145 145
 
146
-		if ( empty( $subscription_id ) ) {
147
-			return 0;
148
-		}
146
+        if ( empty( $subscription_id ) ) {
147
+            return 0;
148
+        }
149 149
 
150
-		// Update the cache with our data.
151
-		wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
150
+        // Update the cache with our data.
151
+        wp_cache_set( $value, $subscription_id, "getpaid_subscription_{$field}s_to_subscription_ids" );
152 152
 
153
-		return $subscription_id;
154
-	}
153
+        return $subscription_id;
154
+    }
155 155
 
156
-	/**
156
+    /**
157 157
      * Clears the subscription's cache.
158 158
      */
159 159
     public function clear_cache() {
160
-		wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
161
-		wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
162
-		wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
163
-		wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
164
-	}
160
+        wp_cache_delete( $this->get_parent_payment_id(), 'getpaid_subscription_parent_payment_ids_to_subscription_ids' );
161
+        wp_cache_delete( $this->get_transaction_id(), 'getpaid_subscription_transaction_ids_to_subscription_ids' );
162
+        wp_cache_delete( $this->get_profile_id(), 'getpaid_subscription_profile_ids_to_subscription_ids' );
163
+        wp_cache_delete( $this->get_id(), 'getpaid_subscriptions' );
164
+    }
165 165
 
166
-	/**
166
+    /**
167 167
      * Checks if a subscription key is set.
168 168
      */
169 169
     public function _isset( $key ) {
170 170
         return isset( $this->data[$key] ) || method_exists( $this, "get_$key" );
171
-	}
171
+    }
172 172
 
173
-	/*
173
+    /*
174 174
 	|--------------------------------------------------------------------------
175 175
 	| CRUD methods
176 176
 	|--------------------------------------------------------------------------
@@ -179,57 +179,57 @@  discard block
 block discarded – undo
179 179
 	|
180 180
     */
181 181
 
182
-	/*
182
+    /*
183 183
 	|--------------------------------------------------------------------------
184 184
 	| Getters
185 185
 	|--------------------------------------------------------------------------
186 186
 	*/
187 187
 
188
-	/**
189
-	 * Get customer id.
190
-	 *
191
-	 * @since 1.0.19
192
-	 * @param  string $context View or edit context.
193
-	 * @return int
194
-	 */
195
-	public function get_customer_id( $context = 'view' ) {
196
-		return (int) $this->get_prop( 'customer_id', $context );
197
-	}
198
-
199
-	/**
200
-	 * Get customer information.
201
-	 *
202
-	 * @since 1.0.19
203
-	 * @param  string $context View or edit context.
204
-	 * @return WP_User|false WP_User object on success, false on failure.
205
-	 */
206
-	public function get_customer( $context = 'view' ) {
207
-		return get_userdata( $this->get_customer_id( $context ) );
208
-	}
209
-
210
-	/**
211
-	 * Get parent invoice id.
212
-	 *
213
-	 * @since 1.0.19
214
-	 * @param  string $context View or edit context.
215
-	 * @return int
216
-	 */
217
-	public function get_parent_invoice_id( $context = 'view' ) {
218
-		return (int) $this->get_prop( 'parent_payment_id', $context );
219
-	}
220
-
221
-	/**
222
-	 * Alias for self::get_parent_invoice_id().
223
-	 *
224
-	 * @since 1.0.19
225
-	 * @param  string $context View or edit context.
226
-	 * @return int
227
-	 */
188
+    /**
189
+     * Get customer id.
190
+     *
191
+     * @since 1.0.19
192
+     * @param  string $context View or edit context.
193
+     * @return int
194
+     */
195
+    public function get_customer_id( $context = 'view' ) {
196
+        return (int) $this->get_prop( 'customer_id', $context );
197
+    }
198
+
199
+    /**
200
+     * Get customer information.
201
+     *
202
+     * @since 1.0.19
203
+     * @param  string $context View or edit context.
204
+     * @return WP_User|false WP_User object on success, false on failure.
205
+     */
206
+    public function get_customer( $context = 'view' ) {
207
+        return get_userdata( $this->get_customer_id( $context ) );
208
+    }
209
+
210
+    /**
211
+     * Get parent invoice id.
212
+     *
213
+     * @since 1.0.19
214
+     * @param  string $context View or edit context.
215
+     * @return int
216
+     */
217
+    public function get_parent_invoice_id( $context = 'view' ) {
218
+        return (int) $this->get_prop( 'parent_payment_id', $context );
219
+    }
220
+
221
+    /**
222
+     * Alias for self::get_parent_invoice_id().
223
+     *
224
+     * @since 1.0.19
225
+     * @param  string $context View or edit context.
226
+     * @return int
227
+     */
228 228
     public function get_parent_payment_id( $context = 'view' ) {
229 229
         return $this->get_parent_invoice_id( $context );
230
-	}
230
+    }
231 231
 
232
-	/**
232
+    /**
233 233
      * Alias for self::get_parent_invoice_id().
234 234
      *
235 235
      * @since  1.0.0
@@ -239,390 +239,390 @@  discard block
 block discarded – undo
239 239
         return $this->get_parent_invoice_id( $context );
240 240
     }
241 241
 
242
-	/**
243
-	 * Get parent invoice.
244
-	 *
245
-	 * @since 1.0.19
246
-	 * @param  string $context View or edit context.
247
-	 * @return WPInv_Invoice
248
-	 */
249
-	public function get_parent_invoice( $context = 'view' ) {
250
-		return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
251
-	}
252
-
253
-	/**
254
-	 * Alias for self::get_parent_invoice().
255
-	 *
256
-	 * @since 1.0.19
257
-	 * @param  string $context View or edit context.
258
-	 * @return WPInv_Invoice
259
-	 */
242
+    /**
243
+     * Get parent invoice.
244
+     *
245
+     * @since 1.0.19
246
+     * @param  string $context View or edit context.
247
+     * @return WPInv_Invoice
248
+     */
249
+    public function get_parent_invoice( $context = 'view' ) {
250
+        return new WPInv_Invoice( $this->get_parent_invoice_id( $context ) );
251
+    }
252
+
253
+    /**
254
+     * Alias for self::get_parent_invoice().
255
+     *
256
+     * @since 1.0.19
257
+     * @param  string $context View or edit context.
258
+     * @return WPInv_Invoice
259
+     */
260 260
     public function get_parent_payment( $context = 'view' ) {
261 261
         return $this->get_parent_invoice( $context );
262
-	}
263
-
264
-	/**
265
-	 * Get subscription's product id.
266
-	 *
267
-	 * @since 1.0.19
268
-	 * @param  string $context View or edit context.
269
-	 * @return int
270
-	 */
271
-	public function get_product_id( $context = 'view' ) {
272
-		return (int) $this->get_prop( 'product_id', $context );
273
-	}
274
-
275
-	/**
276
-	 * Get the subscription product.
277
-	 *
278
-	 * @since 1.0.19
279
-	 * @param  string $context View or edit context.
280
-	 * @return WPInv_Item
281
-	 */
282
-	public function get_product( $context = 'view' ) {
283
-		return new WPInv_Item( $this->get_product_id( $context ) );
284
-	}
285
-
286
-	/**
287
-	 * Get parent invoice's gateway.
288
-	 *
289
-	 * Here for backwards compatibility.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return string
294
-	 */
295
-	public function get_gateway( $context = 'view' ) {
296
-		return $this->get_parent_invoice( $context )->get_gateway();
297
-	}
298
-
299
-	/**
300
-	 * Get the period of a renewal.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return string
305
-	 */
306
-	public function get_period( $context = 'view' ) {
307
-		return $this->get_prop( 'period', $context );
308
-	}
309
-
310
-	/**
311
-	 * Get number of periods each renewal is valid for.
312
-	 *
313
-	 * @since 1.0.19
314
-	 * @param  string $context View or edit context.
315
-	 * @return int
316
-	 */
317
-	public function get_frequency( $context = 'view' ) {
318
-		return (int) $this->get_prop( 'frequency', $context );
319
-	}
320
-
321
-	/**
322
-	 * Get the initial amount for the subscription.
323
-	 *
324
-	 * @since 1.0.19
325
-	 * @param  string $context View or edit context.
326
-	 * @return float
327
-	 */
328
-	public function get_initial_amount( $context = 'view' ) {
329
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
330
-	}
331
-
332
-	/**
333
-	 * Get the recurring amount for the subscription.
334
-	 *
335
-	 * @since 1.0.19
336
-	 * @param  string $context View or edit context.
337
-	 * @return float
338
-	 */
339
-	public function get_recurring_amount( $context = 'view' ) {
340
-		return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
341
-	}
342
-
343
-	/**
344
-	 * Get number of times that this subscription can be renewed.
345
-	 *
346
-	 * @since 1.0.19
347
-	 * @param  string $context View or edit context.
348
-	 * @return int
349
-	 */
350
-	public function get_bill_times( $context = 'view' ) {
351
-		return (int) $this->get_prop( 'bill_times', $context );
352
-	}
353
-
354
-	/**
355
-	 * Get transaction id of this subscription's parent invoice.
356
-	 *
357
-	 * @since 1.0.19
358
-	 * @param  string $context View or edit context.
359
-	 * @return string
360
-	 */
361
-	public function get_transaction_id( $context = 'view' ) {
362
-		return $this->get_prop( 'transaction_id', $context );
363
-	}
364
-
365
-	/**
366
-	 * Get the date that the subscription was created.
367
-	 *
368
-	 * @since 1.0.19
369
-	 * @param  string $context View or edit context.
370
-	 * @return string
371
-	 */
372
-	public function get_created( $context = 'view' ) {
373
-		return $this->get_prop( 'created', $context );
374
-	}
375
-
376
-	/**
377
-	 * Alias for self::get_created().
378
-	 *
379
-	 * @since 1.0.19
380
-	 * @param  string $context View or edit context.
381
-	 * @return string
382
-	 */
383
-	public function get_date_created( $context = 'view' ) {
384
-		return $this->get_created( $context );
385
-	}
386
-
387
-	/**
388
-	 * Retrieves the creation date in a timestamp
389
-	 *
390
-	 * @since  1.0.0
391
-	 * @return int
392
-	 */
393
-	public function get_time_created() {
394
-		$created = $this->get_date_created();
395
-		return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
396
-	}
397
-
398
-	/**
399
-	 * Get GMT date when the subscription was created.
400
-	 *
401
-	 * @since 1.0.19
402
-	 * @param  string $context View or edit context.
403
-	 * @return string
404
-	 */
405
-	public function get_date_created_gmt( $context = 'view' ) {
262
+    }
263
+
264
+    /**
265
+     * Get subscription's product id.
266
+     *
267
+     * @since 1.0.19
268
+     * @param  string $context View or edit context.
269
+     * @return int
270
+     */
271
+    public function get_product_id( $context = 'view' ) {
272
+        return (int) $this->get_prop( 'product_id', $context );
273
+    }
274
+
275
+    /**
276
+     * Get the subscription product.
277
+     *
278
+     * @since 1.0.19
279
+     * @param  string $context View or edit context.
280
+     * @return WPInv_Item
281
+     */
282
+    public function get_product( $context = 'view' ) {
283
+        return new WPInv_Item( $this->get_product_id( $context ) );
284
+    }
285
+
286
+    /**
287
+     * Get parent invoice's gateway.
288
+     *
289
+     * Here for backwards compatibility.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return string
294
+     */
295
+    public function get_gateway( $context = 'view' ) {
296
+        return $this->get_parent_invoice( $context )->get_gateway();
297
+    }
298
+
299
+    /**
300
+     * Get the period of a renewal.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return string
305
+     */
306
+    public function get_period( $context = 'view' ) {
307
+        return $this->get_prop( 'period', $context );
308
+    }
309
+
310
+    /**
311
+     * Get number of periods each renewal is valid for.
312
+     *
313
+     * @since 1.0.19
314
+     * @param  string $context View or edit context.
315
+     * @return int
316
+     */
317
+    public function get_frequency( $context = 'view' ) {
318
+        return (int) $this->get_prop( 'frequency', $context );
319
+    }
320
+
321
+    /**
322
+     * Get the initial amount for the subscription.
323
+     *
324
+     * @since 1.0.19
325
+     * @param  string $context View or edit context.
326
+     * @return float
327
+     */
328
+    public function get_initial_amount( $context = 'view' ) {
329
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'initial_amount', $context ) );
330
+    }
331
+
332
+    /**
333
+     * Get the recurring amount for the subscription.
334
+     *
335
+     * @since 1.0.19
336
+     * @param  string $context View or edit context.
337
+     * @return float
338
+     */
339
+    public function get_recurring_amount( $context = 'view' ) {
340
+        return (float) wpinv_sanitize_amount( $this->get_prop( 'recurring_amount', $context ) );
341
+    }
342
+
343
+    /**
344
+     * Get number of times that this subscription can be renewed.
345
+     *
346
+     * @since 1.0.19
347
+     * @param  string $context View or edit context.
348
+     * @return int
349
+     */
350
+    public function get_bill_times( $context = 'view' ) {
351
+        return (int) $this->get_prop( 'bill_times', $context );
352
+    }
353
+
354
+    /**
355
+     * Get transaction id of this subscription's parent invoice.
356
+     *
357
+     * @since 1.0.19
358
+     * @param  string $context View or edit context.
359
+     * @return string
360
+     */
361
+    public function get_transaction_id( $context = 'view' ) {
362
+        return $this->get_prop( 'transaction_id', $context );
363
+    }
364
+
365
+    /**
366
+     * Get the date that the subscription was created.
367
+     *
368
+     * @since 1.0.19
369
+     * @param  string $context View or edit context.
370
+     * @return string
371
+     */
372
+    public function get_created( $context = 'view' ) {
373
+        return $this->get_prop( 'created', $context );
374
+    }
375
+
376
+    /**
377
+     * Alias for self::get_created().
378
+     *
379
+     * @since 1.0.19
380
+     * @param  string $context View or edit context.
381
+     * @return string
382
+     */
383
+    public function get_date_created( $context = 'view' ) {
384
+        return $this->get_created( $context );
385
+    }
386
+
387
+    /**
388
+     * Retrieves the creation date in a timestamp
389
+     *
390
+     * @since  1.0.0
391
+     * @return int
392
+     */
393
+    public function get_time_created() {
394
+        $created = $this->get_date_created();
395
+        return empty( $created ) ? current_time( 'timestamp' ) : strtotime( $created, current_time( 'timestamp' ) );
396
+    }
397
+
398
+    /**
399
+     * Get GMT date when the subscription was created.
400
+     *
401
+     * @since 1.0.19
402
+     * @param  string $context View or edit context.
403
+     * @return string
404
+     */
405
+    public function get_date_created_gmt( $context = 'view' ) {
406 406
         $date = $this->get_date_created( $context );
407 407
 
408 408
         if ( $date ) {
409 409
             $date = get_gmt_from_date( $date );
410 410
         }
411
-		return $date;
412
-	}
413
-
414
-	/**
415
-	 * Get the date that the subscription will renew.
416
-	 *
417
-	 * @since 1.0.19
418
-	 * @param  string $context View or edit context.
419
-	 * @return string
420
-	 */
421
-	public function get_next_renewal_date( $context = 'view' ) {
422
-		return $this->get_prop( 'expiration', $context );
423
-	}
424
-
425
-	/**
426
-	 * Alias for self::get_next_renewal_date().
427
-	 *
428
-	 * @since 1.0.19
429
-	 * @param  string $context View or edit context.
430
-	 * @return string
431
-	 */
432
-	public function get_expiration( $context = 'view' ) {
433
-		return $this->get_next_renewal_date( $context );
434
-	}
435
-
436
-	/**
437
-	 * Retrieves the expiration date in a timestamp
438
-	 *
439
-	 * @since  1.0.0
440
-	 * @return int
441
-	 */
442
-	public function get_expiration_time() {
443
-		$expiration = $this->get_expiration();
444
-
445
-		if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
446
-			return current_time( 'timestamp' );
447
-		}
448
-
449
-		$expiration = strtotime( $expiration, current_time( 'timestamp' ) );
450
-		return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
451
-	}
452
-
453
-	/**
454
-	 * Get GMT date when the subscription will renew.
455
-	 *
456
-	 * @since 1.0.19
457
-	 * @param  string $context View or edit context.
458
-	 * @return string
459
-	 */
460
-	public function get_next_renewal_date_gmt( $context = 'view' ) {
411
+        return $date;
412
+    }
413
+
414
+    /**
415
+     * Get the date that the subscription will renew.
416
+     *
417
+     * @since 1.0.19
418
+     * @param  string $context View or edit context.
419
+     * @return string
420
+     */
421
+    public function get_next_renewal_date( $context = 'view' ) {
422
+        return $this->get_prop( 'expiration', $context );
423
+    }
424
+
425
+    /**
426
+     * Alias for self::get_next_renewal_date().
427
+     *
428
+     * @since 1.0.19
429
+     * @param  string $context View or edit context.
430
+     * @return string
431
+     */
432
+    public function get_expiration( $context = 'view' ) {
433
+        return $this->get_next_renewal_date( $context );
434
+    }
435
+
436
+    /**
437
+     * Retrieves the expiration date in a timestamp
438
+     *
439
+     * @since  1.0.0
440
+     * @return int
441
+     */
442
+    public function get_expiration_time() {
443
+        $expiration = $this->get_expiration();
444
+
445
+        if ( empty( $expiration ) || '0000-00-00 00:00:00' == $expiration ) {
446
+            return current_time( 'timestamp' );
447
+        }
448
+
449
+        $expiration = strtotime( $expiration, current_time( 'timestamp' ) );
450
+        return $expiration < current_time( 'timestamp' ) ? current_time( 'timestamp' ) : $expiration;
451
+    }
452
+
453
+    /**
454
+     * Get GMT date when the subscription will renew.
455
+     *
456
+     * @since 1.0.19
457
+     * @param  string $context View or edit context.
458
+     * @return string
459
+     */
460
+    public function get_next_renewal_date_gmt( $context = 'view' ) {
461 461
         $date = $this->get_next_renewal_date( $context );
462 462
 
463 463
         if ( $date ) {
464 464
             $date = get_gmt_from_date( $date );
465 465
         }
466
-		return $date;
467
-	}
468
-
469
-	/**
470
-	 * Get the subscription's trial period.
471
-	 *
472
-	 * @since 1.0.19
473
-	 * @param  string $context View or edit context.
474
-	 * @return string
475
-	 */
476
-	public function get_trial_period( $context = 'view' ) {
477
-		return $this->get_prop( 'trial_period', $context );
478
-	}
479
-
480
-	/**
481
-	 * Get the subscription's status.
482
-	 *
483
-	 * @since 1.0.19
484
-	 * @param  string $context View or edit context.
485
-	 * @return string
486
-	 */
487
-	public function get_status( $context = 'view' ) {
488
-		return $this->get_prop( 'status', $context );
489
-	}
490
-
491
-	/**
492
-	 * Get the subscription's profile id.
493
-	 *
494
-	 * @since 1.0.19
495
-	 * @param  string $context View or edit context.
496
-	 * @return string
497
-	 */
498
-	public function get_profile_id( $context = 'view' ) {
499
-		return $this->get_prop( 'profile_id', $context );
500
-	}
501
-
502
-	/*
466
+        return $date;
467
+    }
468
+
469
+    /**
470
+     * Get the subscription's trial period.
471
+     *
472
+     * @since 1.0.19
473
+     * @param  string $context View or edit context.
474
+     * @return string
475
+     */
476
+    public function get_trial_period( $context = 'view' ) {
477
+        return $this->get_prop( 'trial_period', $context );
478
+    }
479
+
480
+    /**
481
+     * Get the subscription's status.
482
+     *
483
+     * @since 1.0.19
484
+     * @param  string $context View or edit context.
485
+     * @return string
486
+     */
487
+    public function get_status( $context = 'view' ) {
488
+        return $this->get_prop( 'status', $context );
489
+    }
490
+
491
+    /**
492
+     * Get the subscription's profile id.
493
+     *
494
+     * @since 1.0.19
495
+     * @param  string $context View or edit context.
496
+     * @return string
497
+     */
498
+    public function get_profile_id( $context = 'view' ) {
499
+        return $this->get_prop( 'profile_id', $context );
500
+    }
501
+
502
+    /*
503 503
 	|--------------------------------------------------------------------------
504 504
 	| Setters
505 505
 	|--------------------------------------------------------------------------
506 506
 	*/
507 507
 
508
-	/**
509
-	 * Set customer id.
510
-	 *
511
-	 * @since 1.0.19
512
-	 * @param  int $value The customer's id.
513
-	 */
514
-	public function set_customer_id( $value ) {
515
-		$this->set_prop( 'customer_id', (int) $value );
516
-	}
517
-
518
-	/**
519
-	 * Set parent invoice id.
520
-	 *
521
-	 * @since 1.0.19
522
-	 * @param  int $value The parent invoice id.
523
-	 */
524
-	public function set_parent_invoice_id( $value ) {
525
-		$this->set_prop( 'parent_payment_id', (int) $value );
526
-	}
527
-
528
-	/**
529
-	 * Alias for self::set_parent_invoice_id().
530
-	 *
531
-	 * @since 1.0.19
532
-	 * @param  int $value The parent invoice id.
533
-	 */
508
+    /**
509
+     * Set customer id.
510
+     *
511
+     * @since 1.0.19
512
+     * @param  int $value The customer's id.
513
+     */
514
+    public function set_customer_id( $value ) {
515
+        $this->set_prop( 'customer_id', (int) $value );
516
+    }
517
+
518
+    /**
519
+     * Set parent invoice id.
520
+     *
521
+     * @since 1.0.19
522
+     * @param  int $value The parent invoice id.
523
+     */
524
+    public function set_parent_invoice_id( $value ) {
525
+        $this->set_prop( 'parent_payment_id', (int) $value );
526
+    }
527
+
528
+    /**
529
+     * Alias for self::set_parent_invoice_id().
530
+     *
531
+     * @since 1.0.19
532
+     * @param  int $value The parent invoice id.
533
+     */
534 534
     public function set_parent_payment_id( $value ) {
535 535
         $this->set_parent_invoice_id( $value );
536
-	}
536
+    }
537 537
 
538
-	/**
538
+    /**
539 539
      * Alias for self::set_parent_invoice_id().
540 540
      *
541 541
      * @since 1.0.19
542
-	 * @param  int $value The parent invoice id.
542
+     * @param  int $value The parent invoice id.
543 543
      */
544 544
     public function set_original_payment_id( $value ) {
545 545
         $this->set_parent_invoice_id( $value );
546
-	}
547
-
548
-	/**
549
-	 * Set subscription's product id.
550
-	 *
551
-	 * @since 1.0.19
552
-	 * @param  int $value The subscription product id.
553
-	 */
554
-	public function set_product_id( $value ) {
555
-		$this->set_prop( 'product_id', (int) $value );
556
-	}
557
-
558
-	/**
559
-	 * Set the period of a renewal.
560
-	 *
561
-	 * @since 1.0.19
562
-	 * @param  string $value The renewal period.
563
-	 */
564
-	public function set_period( $value ) {
565
-		$this->set_prop( 'period', $value );
566
-	}
567
-
568
-	/**
569
-	 * Set number of periods each renewal is valid for.
570
-	 *
571
-	 * @since 1.0.19
572
-	 * @param  int $value The subscription frequency.
573
-	 */
574
-	public function set_frequency( $value ) {
575
-		$value = empty( $value ) ? 1 : (int) $value;
576
-		$this->set_prop( 'frequency', absint( $value ) );
577
-	}
578
-
579
-	/**
580
-	 * Set the initial amount for the subscription.
581
-	 *
582
-	 * @since 1.0.19
583
-	 * @param  float $value The initial subcription amount.
584
-	 */
585
-	public function set_initial_amount( $value ) {
586
-		$this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
587
-	}
588
-
589
-	/**
590
-	 * Set the recurring amount for the subscription.
591
-	 *
592
-	 * @since 1.0.19
593
-	 * @param  float $value The recurring subcription amount.
594
-	 */
595
-	public function set_recurring_amount( $value ) {
596
-		$this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
597
-	}
598
-
599
-	/**
600
-	 * Set number of times that this subscription can be renewed.
601
-	 *
602
-	 * @since 1.0.19
603
-	 * @param  int $value Bill times.
604
-	 */
605
-	public function set_bill_times( $value ) {
606
-		$this->set_prop( 'bill_times', (int) $value );
607
-	}
608
-
609
-	/**
610
-	 * Get transaction id of this subscription's parent invoice.
611
-	 *
612
-	 * @since 1.0.19
613
-	 * @param string $value Bill times.
614
-	 */
615
-	public function set_transaction_id( $value ) {
616
-		$this->set_prop( 'transaction_id', $value );
617
-	}
618
-
619
-	/**
620
-	 * Set date when this subscription started.
621
-	 *
622
-	 * @since 1.0.19
623
-	 * @param string $value strtotime compliant date.
624
-	 */
625
-	public function set_created( $value ) {
546
+    }
547
+
548
+    /**
549
+     * Set subscription's product id.
550
+     *
551
+     * @since 1.0.19
552
+     * @param  int $value The subscription product id.
553
+     */
554
+    public function set_product_id( $value ) {
555
+        $this->set_prop( 'product_id', (int) $value );
556
+    }
557
+
558
+    /**
559
+     * Set the period of a renewal.
560
+     *
561
+     * @since 1.0.19
562
+     * @param  string $value The renewal period.
563
+     */
564
+    public function set_period( $value ) {
565
+        $this->set_prop( 'period', $value );
566
+    }
567
+
568
+    /**
569
+     * Set number of periods each renewal is valid for.
570
+     *
571
+     * @since 1.0.19
572
+     * @param  int $value The subscription frequency.
573
+     */
574
+    public function set_frequency( $value ) {
575
+        $value = empty( $value ) ? 1 : (int) $value;
576
+        $this->set_prop( 'frequency', absint( $value ) );
577
+    }
578
+
579
+    /**
580
+     * Set the initial amount for the subscription.
581
+     *
582
+     * @since 1.0.19
583
+     * @param  float $value The initial subcription amount.
584
+     */
585
+    public function set_initial_amount( $value ) {
586
+        $this->set_prop( 'initial_amount', wpinv_sanitize_amount( $value ) );
587
+    }
588
+
589
+    /**
590
+     * Set the recurring amount for the subscription.
591
+     *
592
+     * @since 1.0.19
593
+     * @param  float $value The recurring subcription amount.
594
+     */
595
+    public function set_recurring_amount( $value ) {
596
+        $this->set_prop( 'recurring_amount', wpinv_sanitize_amount( $value ) );
597
+    }
598
+
599
+    /**
600
+     * Set number of times that this subscription can be renewed.
601
+     *
602
+     * @since 1.0.19
603
+     * @param  int $value Bill times.
604
+     */
605
+    public function set_bill_times( $value ) {
606
+        $this->set_prop( 'bill_times', (int) $value );
607
+    }
608
+
609
+    /**
610
+     * Get transaction id of this subscription's parent invoice.
611
+     *
612
+     * @since 1.0.19
613
+     * @param string $value Bill times.
614
+     */
615
+    public function set_transaction_id( $value ) {
616
+        $this->set_prop( 'transaction_id', $value );
617
+    }
618
+
619
+    /**
620
+     * Set date when this subscription started.
621
+     *
622
+     * @since 1.0.19
623
+     * @param string $value strtotime compliant date.
624
+     */
625
+    public function set_created( $value ) {
626 626
         $date = strtotime( $value );
627 627
 
628 628
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -630,94 +630,94 @@  discard block
 block discarded – undo
630 630
             return;
631 631
         }
632 632
 
633
-		$this->set_prop( 'created', '' );
633
+        $this->set_prop( 'created', '' );
634 634
 
635
-	}
635
+    }
636 636
 
637
-	/**
638
-	 * Alias for self::set_created().
639
-	 *
640
-	 * @since 1.0.19
641
-	 * @param string $value strtotime compliant date.
642
-	 */
643
-	public function set_date_created( $value ) {
644
-		$this->set_created( $value );
637
+    /**
638
+     * Alias for self::set_created().
639
+     *
640
+     * @since 1.0.19
641
+     * @param string $value strtotime compliant date.
642
+     */
643
+    public function set_date_created( $value ) {
644
+        $this->set_created( $value );
645 645
     }
646 646
 
647
-	/**
648
-	 * Set the date that the subscription will renew.
649
-	 *
650
-	 * @since 1.0.19
651
-	 * @param string $value strtotime compliant date.
652
-	 */
653
-	public function set_next_renewal_date( $value ) {
654
-		$date = strtotime( $value );
647
+    /**
648
+     * Set the date that the subscription will renew.
649
+     *
650
+     * @since 1.0.19
651
+     * @param string $value strtotime compliant date.
652
+     */
653
+    public function set_next_renewal_date( $value ) {
654
+        $date = strtotime( $value );
655 655
 
656 656
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
657 657
             $this->set_prop( 'expiration', date( 'Y-m-d H:i:s', $date ) );
658 658
             return;
659
-		}
660
-
661
-		$this->set_prop( 'expiration', '' );
662
-
663
-	}
664
-
665
-	/**
666
-	 * Alias for self::set_next_renewal_date().
667
-	 *
668
-	 * @since 1.0.19
669
-	 * @param string $value strtotime compliant date.
670
-	 */
671
-	public function set_expiration( $value ) {
672
-		$this->set_next_renewal_date( $value );
673
-    }
674
-
675
-	/**
676
-	 * Set the subscription's trial period.
677
-	 *
678
-	 * @since 1.0.19
679
-	 * @param string $value trial period e.g 1 year.
680
-	 */
681
-	public function set_trial_period( $value ) {
682
-		$this->set_prop( 'trial_period', $value );
683
-	}
684
-
685
-	/**
686
-	 * Set the subscription's status.
687
-	 *
688
-	 * @since 1.0.19
689
-	 * @param string $new_status    New subscription status.
690
-	 */
691
-	public function set_status( $new_status ) {
692
-
693
-		// Abort if this is not a valid status;
694
-		if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
695
-			return;
696
-		}
697
-
698
-		$old_status = $this->get_status();
699
-		$this->set_prop( 'status', $new_status );
700
-
701
-		if ( true === $this->object_read && $old_status !== $new_status ) {
702
-			$this->status_transition = array(
703
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
704
-				'to'     => $new_status,
705
-			);
706
-		}
707
-
708
-	}
709
-
710
-	/**
711
-	 * Set the subscription's (remote) profile id.
712
-	 *
713
-	 * @since 1.0.19
714
-	 * @param  string $value the remote profile id.
715
-	 */
716
-	public function set_profile_id( $value ) {
717
-		$this->set_prop( 'profile_id', $value );
718
-	}
719
-
720
-	/*
659
+        }
660
+
661
+        $this->set_prop( 'expiration', '' );
662
+
663
+    }
664
+
665
+    /**
666
+     * Alias for self::set_next_renewal_date().
667
+     *
668
+     * @since 1.0.19
669
+     * @param string $value strtotime compliant date.
670
+     */
671
+    public function set_expiration( $value ) {
672
+        $this->set_next_renewal_date( $value );
673
+    }
674
+
675
+    /**
676
+     * Set the subscription's trial period.
677
+     *
678
+     * @since 1.0.19
679
+     * @param string $value trial period e.g 1 year.
680
+     */
681
+    public function set_trial_period( $value ) {
682
+        $this->set_prop( 'trial_period', $value );
683
+    }
684
+
685
+    /**
686
+     * Set the subscription's status.
687
+     *
688
+     * @since 1.0.19
689
+     * @param string $new_status    New subscription status.
690
+     */
691
+    public function set_status( $new_status ) {
692
+
693
+        // Abort if this is not a valid status;
694
+        if ( ! array_key_exists( $new_status, getpaid_get_subscription_statuses() ) ) {
695
+            return;
696
+        }
697
+
698
+        $old_status = $this->get_status();
699
+        $this->set_prop( 'status', $new_status );
700
+
701
+        if ( true === $this->object_read && $old_status !== $new_status ) {
702
+            $this->status_transition = array(
703
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
704
+                'to'     => $new_status,
705
+            );
706
+        }
707
+
708
+    }
709
+
710
+    /**
711
+     * Set the subscription's (remote) profile id.
712
+     *
713
+     * @since 1.0.19
714
+     * @param  string $value the remote profile id.
715
+     */
716
+    public function set_profile_id( $value ) {
717
+        $this->set_prop( 'profile_id', $value );
718
+    }
719
+
720
+    /*
721 721
 	|--------------------------------------------------------------------------
722 722
 	| Boolean methods
723 723
 	|--------------------------------------------------------------------------
@@ -726,45 +726,45 @@  discard block
 block discarded – undo
726 726
 	|
727 727
 	*/
728 728
 
729
-	/**
729
+    /**
730 730
      * Checks if the subscription has a given status.
731
-	 *
732
-	 * @param string|array String or array of strings to check for.
733
-	 * @return bool
731
+     *
732
+     * @param string|array String or array of strings to check for.
733
+     * @return bool
734 734
      */
735 735
     public function has_status( $status ) {
736 736
         return in_array( $this->get_status(), wpinv_parse_list( $status ) );
737
-	}
737
+    }
738 738
 
739
-	/**
739
+    /**
740 740
      * Checks if the subscription has a trial period.
741
-	 *
742
-	 * @return bool
741
+     *
742
+     * @return bool
743 743
      */
744 744
     public function has_trial_period() {
745
-		$period = $this->get_trial_period();
745
+        $period = $this->get_trial_period();
746 746
         return ! empty( $period );
747
-	}
748
-
749
-	/**
750
-	 * Is the subscription active?
751
-	 *
752
-	 * @return bool
753
-	 */
754
-	public function is_active() {
755
-		return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' );
756
-	}
757
-
758
-	/**
759
-	 * Is the subscription expired?
760
-	 *
761
-	 * @return bool
762
-	 */
763
-	public function is_expired() {
764
-		return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
765
-	}
766
-
767
-	/*
747
+    }
748
+
749
+    /**
750
+     * Is the subscription active?
751
+     *
752
+     * @return bool
753
+     */
754
+    public function is_active() {
755
+        return $this->has_status( 'active trialling' ) && $this->get_expiration_time() > current_time( 'mysql' );
756
+    }
757
+
758
+    /**
759
+     * Is the subscription expired?
760
+     *
761
+     * @return bool
762
+     */
763
+    public function is_expired() {
764
+        return $this->has_status( 'expired' ) || ( $this->has_status( 'active cancelled trialling' ) && $this->get_expiration_time() < current_time( 'mysql' ) );
765
+    }
766
+
767
+    /*
768 768
 	|--------------------------------------------------------------------------
769 769
 	| Additional methods
770 770
 	|--------------------------------------------------------------------------
@@ -773,27 +773,27 @@  discard block
 block discarded – undo
773 773
 	|
774 774
 	*/
775 775
 
776
-	/**
777
-	 * Backwards compatibilty.
778
-	 */
779
-	public function create( $data = array() ) {
776
+    /**
777
+     * Backwards compatibilty.
778
+     */
779
+    public function create( $data = array() ) {
780 780
 
781
-		// Set the properties.
782
-		if ( is_array( $data ) ) {
783
-			$this->set_props( $data );
784
-		}
781
+        // Set the properties.
782
+        if ( is_array( $data ) ) {
783
+            $this->set_props( $data );
784
+        }
785 785
 
786
-		// Save the item.
787
-		return $this->save();
786
+        // Save the item.
787
+        return $this->save();
788 788
 
789
-	}
789
+    }
790 790
 
791
-	/**
792
-	 * Backwards compatibilty.
793
-	 */
794
-	public function update( $args = array() ) {
795
-		return $this->create( $args );
796
-	}
791
+    /**
792
+     * Backwards compatibilty.
793
+     */
794
+    public function update( $args = array() ) {
795
+        return $this->create( $args );
796
+    }
797 797
 
798 798
     /**
799 799
      * Retrieve renewal payments for a subscription
@@ -803,15 +803,15 @@  discard block
 block discarded – undo
803 803
      */
804 804
     public function get_child_payments() {
805 805
         return get_posts(
806
-			array(
807
-            	'post_parent'    => $this->get_parent_payment_id(),
808
-            	'numberposts'    => -1,
809
-            	'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
810
-            	'orderby'        => 'ID',
811
-            	'order'          => 'DESC',
812
-            	'post_type'      => 'wpi_invoice'
813
-			)
814
-		);
806
+            array(
807
+                'post_parent'    => $this->get_parent_payment_id(),
808
+                'numberposts'    => -1,
809
+                'post_status'    => array( 'publish', 'wpi-processing', 'wpi-renewal' ),
810
+                'orderby'        => 'ID',
811
+                'order'          => 'DESC',
812
+                'post_type'      => 'wpi_invoice'
813
+            )
814
+        );
815 815
     }
816 816
 
817 817
     /**
@@ -821,16 +821,16 @@  discard block
 block discarded – undo
821 821
      * @return int
822 822
      */
823 823
     public function get_total_payments() {
824
-		global $wpdb;
824
+        global $wpdb;
825 825
 
826
-		$count = $wpdb->get_var(
827
-			$wpdb->prepare(
828
-				"SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
829
-				$this->get_parent_invoice_id()
830
-			)
831
-		);
826
+        $count = $wpdb->get_var(
827
+            $wpdb->prepare(
828
+                "SELECT COUNT(ID) FROM $wpdb->posts WHERE post_parent=%d AND post_status IN ( 'publish', 'wpi-processing', 'wpi-renewal' )",
829
+                $this->get_parent_invoice_id()
830
+            )
831
+        );
832 832
 
833
-		// Maybe include parent invoice.
833
+        // Maybe include parent invoice.
834 834
         if ( ! $this->has_status( 'pending' ) ) {
835 835
             $count++;
836 836
         }
@@ -859,57 +859,57 @@  discard block
 block discarded – undo
859 859
      *
860 860
      * @since  2.4
861 861
      * @param  array $args Array of values for the payment, including amount and transaction ID
862
-	 * @param  WPInv_Invoice $invoice If adding an existing invoice.
862
+     * @param  WPInv_Invoice $invoice If adding an existing invoice.
863 863
      * @return bool
864 864
      */
865 865
     public function add_payment( $args = array(), $invoice = false ) {
866 866
 
867
-		// Process each payment once.
867
+        // Process each payment once.
868 868
         if ( ! empty( $args['transaction_id'] ) && $this->payment_exists( $args['transaction_id'] ) ) {
869 869
             return false;
870 870
         }
871 871
 
872
-		// Are we creating a new invoice?
873
-		if ( empty( $invoice ) ) {
874
-			$invoice = $this->create_payment();
872
+        // Are we creating a new invoice?
873
+        if ( empty( $invoice ) ) {
874
+            $invoice = $this->create_payment();
875 875
 
876
-			if ( empty( $invoice ) ) {
877
-				return false;
878
-			}
876
+            if ( empty( $invoice ) ) {
877
+                return false;
878
+            }
879 879
 
880
-			$invoice->set_status( 'wpi-renewal' );
880
+            $invoice->set_status( 'wpi-renewal' );
881 881
 
882
-		}
882
+        }
883 883
 
884
-		// Maybe set a transaction id.
885
-		if ( ! empty( $args['transaction_id'] ) ) {
886
-			$invoice->set_transaction_id( $args['transaction_id'] );
887
-		}
884
+        // Maybe set a transaction id.
885
+        if ( ! empty( $args['transaction_id'] ) ) {
886
+            $invoice->set_transaction_id( $args['transaction_id'] );
887
+        }
888 888
 
889
-		// Set the completed date.
890
-		$invoice->set_completed_date( current_time( 'mysql' ) );
889
+        // Set the completed date.
890
+        $invoice->set_completed_date( current_time( 'mysql' ) );
891 891
 
892
-		// And the gateway.
893
-		if ( ! empty( $args['gateway'] ) ) {
894
-			$invoice->set_gateway( $args['gateway'] );
895
-		}
892
+        // And the gateway.
893
+        if ( ! empty( $args['gateway'] ) ) {
894
+            $invoice->set_gateway( $args['gateway'] );
895
+        }
896 896
 
897
-		$invoice->save();
897
+        $invoice->save();
898 898
 
899
-		if ( ! $invoice->get_id() ) {
900
-			return 0;
901
-		}
899
+        if ( ! $invoice->get_id() ) {
900
+            return 0;
901
+        }
902 902
 
903
-		do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
904
-		do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
903
+        do_action( 'getpaid_after_create_subscription_renewal_invoice', $invoice, $this );
904
+        do_action( 'wpinv_recurring_add_subscription_payment', $invoice, $this );
905 905
         do_action( 'wpinv_recurring_record_payment', $invoice->get_id(), $this->get_parent_invoice_id(), $invoice->get_recurring_total(), $invoice->get_transaction_id() );
906 906
 
907 907
         update_post_meta( $invoice->get_id(), '_wpinv_subscription_id', $this->id );
908 908
 
909 909
         return $invoice->get_id();
910
-	}
910
+    }
911 911
 
912
-	/**
912
+    /**
913 913
      * Creates a new invoice and returns it.
914 914
      *
915 915
      * @since  1.0.19
@@ -917,103 +917,103 @@  discard block
 block discarded – undo
917 917
      */
918 918
     public function create_payment() {
919 919
 
920
-		$parent_invoice = $this->get_parent_payment();
921
-
922
-		if ( ! $parent_invoice->get_id() ) {
923
-			return false;
924
-		}
925
-
926
-		// Duplicate the parent invoice.
927
-		$invoice = new WPInv_Invoice();
928
-		$invoice->set_props( $parent_invoice->get_data() );
929
-		$invoice->set_id( 0 );
930
-		$invoice->set_parent_id( $parent_invoice->get_id() );
931
-		$invoice->set_transaction_id( '' );
932
-		$invoice->set_key( $invoice->generate_key( 'renewal_' ) );
933
-		$invoice->set_number( '' );
934
-		$invoice->set_completed_date( '' );
935
-		$invoice->set_status( 'wpi-pending' );
936
-		$invoice->recalculate_total();
937
-		$invoice->save();
938
-
939
-		return $invoice->get_id() ? $invoice : false;
940
-    }
941
-
942
-	/**
943
-	 * Renews or completes a subscription
944
-	 *
945
-	 * @since  1.0.0
946
-	 * @return int The subscription's id
947
-	 */
948
-	public function renew() {
949
-
950
-		// Complete subscription if applicable
951
-		if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) {
952
-			return $this->complete();
953
-		}
954
-
955
-		// Calculate new expiration
956
-		$frequency      = $this->get_frequency();
957
-		$period         = $this->get_period();
958
-		$new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
959
-
960
-		$this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
961
-		$this->set_status( 'active' );
962
-		return $this->save();
963
-
964
-		do_action( 'getpaid_subscription_renewed', $this );
965
-
966
-	}
967
-
968
-	/**
969
-	 * Marks a subscription as completed
970
-	 *
971
-	 * Subscription is completed when the number of payments matches the billing_times field
972
-	 *
973
-	 * @since  1.0.0
974
-	 * @return int|bool Subscription id or false if the subscription is cancelled.
975
-	 */
976
-	public function complete() {
977
-
978
-		// Only mark a subscription as complete if it's not already cancelled.
979
-		if ( $this->has_status( 'cancelled' ) ) {
980
-			return false;
981
-		}
982
-
983
-		$this->set_status( 'completed' );
984
-		return $this->save();
985
-
986
-	}
987
-
988
-	/**
989
-	 * Marks a subscription as expired
990
-	 *
991
-	 * @since  1.0.0
992
-	 * @param  bool $check_expiration
993
-	 * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
994
-	 */
995
-	public function expire( $check_expiration = false ) {
996
-
997
-		if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
998
-			// Do not mark as expired since real expiration date is in the future
999
-			return false;
1000
-		}
1001
-
1002
-		$this->set_status( 'expired' );
1003
-		return $this->save();
1004
-
1005
-	}
1006
-
1007
-	/**
1008
-	 * Marks a subscription as failing
1009
-	 *
1010
-	 * @since  2.4.2
1011
-	 * @return int Subscription id.
1012
-	 */
1013
-	public function failing() {
1014
-		$this->set_status( 'failing' );
1015
-		return $this->save();
1016
-	}
920
+        $parent_invoice = $this->get_parent_payment();
921
+
922
+        if ( ! $parent_invoice->get_id() ) {
923
+            return false;
924
+        }
925
+
926
+        // Duplicate the parent invoice.
927
+        $invoice = new WPInv_Invoice();
928
+        $invoice->set_props( $parent_invoice->get_data() );
929
+        $invoice->set_id( 0 );
930
+        $invoice->set_parent_id( $parent_invoice->get_id() );
931
+        $invoice->set_transaction_id( '' );
932
+        $invoice->set_key( $invoice->generate_key( 'renewal_' ) );
933
+        $invoice->set_number( '' );
934
+        $invoice->set_completed_date( '' );
935
+        $invoice->set_status( 'wpi-pending' );
936
+        $invoice->recalculate_total();
937
+        $invoice->save();
938
+
939
+        return $invoice->get_id() ? $invoice : false;
940
+    }
941
+
942
+    /**
943
+     * Renews or completes a subscription
944
+     *
945
+     * @since  1.0.0
946
+     * @return int The subscription's id
947
+     */
948
+    public function renew() {
949
+
950
+        // Complete subscription if applicable
951
+        if ( $this->get_bill_times() > 0 && $this->get_times_billed() >= $this->get_bill_times() ) {
952
+            return $this->complete();
953
+        }
954
+
955
+        // Calculate new expiration
956
+        $frequency      = $this->get_frequency();
957
+        $period         = $this->get_period();
958
+        $new_expiration = strtotime( "+ $frequency $period", $this->get_expiration_time() );
959
+
960
+        $this->set_expiration( date( 'Y-m-d H:i:s',$new_expiration ) );
961
+        $this->set_status( 'active' );
962
+        return $this->save();
963
+
964
+        do_action( 'getpaid_subscription_renewed', $this );
965
+
966
+    }
967
+
968
+    /**
969
+     * Marks a subscription as completed
970
+     *
971
+     * Subscription is completed when the number of payments matches the billing_times field
972
+     *
973
+     * @since  1.0.0
974
+     * @return int|bool Subscription id or false if the subscription is cancelled.
975
+     */
976
+    public function complete() {
977
+
978
+        // Only mark a subscription as complete if it's not already cancelled.
979
+        if ( $this->has_status( 'cancelled' ) ) {
980
+            return false;
981
+        }
982
+
983
+        $this->set_status( 'completed' );
984
+        return $this->save();
985
+
986
+    }
987
+
988
+    /**
989
+     * Marks a subscription as expired
990
+     *
991
+     * @since  1.0.0
992
+     * @param  bool $check_expiration
993
+     * @return int|bool Subscription id or false if $check_expiration is true and expiration date is in the future.
994
+     */
995
+    public function expire( $check_expiration = false ) {
996
+
997
+        if ( $check_expiration && $this->get_expiration_time() > current_time( 'timestamp' ) ) {
998
+            // Do not mark as expired since real expiration date is in the future
999
+            return false;
1000
+        }
1001
+
1002
+        $this->set_status( 'expired' );
1003
+        return $this->save();
1004
+
1005
+    }
1006
+
1007
+    /**
1008
+     * Marks a subscription as failing
1009
+     *
1010
+     * @since  2.4.2
1011
+     * @return int Subscription id.
1012
+     */
1013
+    public function failing() {
1014
+        $this->set_status( 'failing' );
1015
+        return $this->save();
1016
+    }
1017 1017
 
1018 1018
     /**
1019 1019
      * Marks a subscription as cancelled
@@ -1022,19 +1022,19 @@  discard block
 block discarded – undo
1022 1022
      * @return int Subscription id.
1023 1023
      */
1024 1024
     public function cancel() {
1025
-		$this->set_status( 'cancelled' );
1026
-		return $this->save();
1025
+        $this->set_status( 'cancelled' );
1026
+        return $this->save();
1027 1027
     }
1028 1028
 
1029
-	/**
1030
-	 * Determines if a subscription can be cancelled both locally and with a payment processor.
1031
-	 *
1032
-	 * @since  1.0.0
1033
-	 * @return bool
1034
-	 */
1035
-	public function can_cancel() {
1036
-		return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1037
-	}
1029
+    /**
1030
+     * Determines if a subscription can be cancelled both locally and with a payment processor.
1031
+     *
1032
+     * @since  1.0.0
1033
+     * @return bool
1034
+     */
1035
+    public function can_cancel() {
1036
+        return apply_filters( 'wpinv_subscription_can_cancel', $this->has_status( $this->get_cancellable_statuses() ), $this );
1037
+    }
1038 1038
 
1039 1039
     /**
1040 1040
      * Returns an array of subscription statuses that can be cancelled
@@ -1047,82 +1047,82 @@  discard block
 block discarded – undo
1047 1047
         return apply_filters( 'wpinv_recurring_cancellable_statuses', array( 'active', 'trialling', 'failing' ) );
1048 1048
     }
1049 1049
 
1050
-	/**
1051
-	 * Retrieves the URL to cancel subscription
1052
-	 *
1053
-	 * @since  1.0.0
1054
-	 * @return string
1055
-	 */
1056
-	public function get_cancel_url() {
1057
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' );
1058
-		return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1059
-	}
1060
-
1061
-	/**
1062
-	 * Determines if subscription can be manually renewed
1063
-	 *
1064
-	 * This method is filtered by payment gateways in order to return true on subscriptions
1065
-	 * that can be renewed manually
1066
-	 *
1067
-	 * @since  2.5
1068
-	 * @return bool
1069
-	 */
1070
-	public function can_renew() {
1071
-		return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1072
-	}
1073
-
1074
-	/**
1075
-	 * Retrieves the URL to renew a subscription
1076
-	 *
1077
-	 * @since  2.5
1078
-	 * @return string
1079
-	 */
1080
-	public function get_renew_url() {
1081
-		$url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' );
1082
-		return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1083
-	}
1084
-
1085
-	/**
1086
-	 * Determines if subscription can have their payment method updated
1087
-	 *
1088
-	 * @since  1.0.0
1089
-	 * @return bool
1090
-	 */
1091
-	public function can_update() {
1092
-		return apply_filters( 'wpinv_subscription_can_update', false, $this );
1093
-	}
1094
-
1095
-	/**
1096
-	 * Retrieves the URL to update subscription
1097
-	 *
1098
-	 * @since  1.0.0
1099
-	 * @return string
1100
-	 */
1101
-	public function get_update_url() {
1102
-		$url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1103
-		return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1104
-	}
1105
-
1106
-	/**
1107
-	 * Retrieves the subscription status label
1108
-	 *
1109
-	 * @since  1.0.0
1110
-	 * @return string
1111
-	 */
1112
-	public function get_status_label() {
1113
-		return getpaid_get_subscription_status_label( $this->get_status() );
1114
-	}
1115
-
1116
-	/**
1117
-	 * Retrieves the subscription status class
1118
-	 *
1119
-	 * @since  1.0.19
1120
-	 * @return string
1121
-	 */
1122
-	public function get_status_class() {
1123
-		$statuses = getpaid_get_subscription_status_classes();
1124
-		return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1125
-	}
1050
+    /**
1051
+     * Retrieves the URL to cancel subscription
1052
+     *
1053
+     * @since  1.0.0
1054
+     * @return string
1055
+     */
1056
+    public function get_cancel_url() {
1057
+        $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'cancel_subscription', 'sub_id' => $this->get_id() ) ), 'wpinv-recurring-cancel' );
1058
+        return apply_filters( 'wpinv_subscription_cancel_url', $url, $this );
1059
+    }
1060
+
1061
+    /**
1062
+     * Determines if subscription can be manually renewed
1063
+     *
1064
+     * This method is filtered by payment gateways in order to return true on subscriptions
1065
+     * that can be renewed manually
1066
+     *
1067
+     * @since  2.5
1068
+     * @return bool
1069
+     */
1070
+    public function can_renew() {
1071
+        return apply_filters( 'wpinv_subscription_can_renew', true, $this );
1072
+    }
1073
+
1074
+    /**
1075
+     * Retrieves the URL to renew a subscription
1076
+     *
1077
+     * @since  2.5
1078
+     * @return string
1079
+     */
1080
+    public function get_renew_url() {
1081
+        $url = wp_nonce_url( add_query_arg( array( 'wpinv_action' => 'renew_subscription', 'sub_id' => $this->get_id ) ), 'wpinv-recurring-renew' );
1082
+        return apply_filters( 'wpinv_subscription_renew_url', $url, $this );
1083
+    }
1084
+
1085
+    /**
1086
+     * Determines if subscription can have their payment method updated
1087
+     *
1088
+     * @since  1.0.0
1089
+     * @return bool
1090
+     */
1091
+    public function can_update() {
1092
+        return apply_filters( 'wpinv_subscription_can_update', false, $this );
1093
+    }
1094
+
1095
+    /**
1096
+     * Retrieves the URL to update subscription
1097
+     *
1098
+     * @since  1.0.0
1099
+     * @return string
1100
+     */
1101
+    public function get_update_url() {
1102
+        $url = add_query_arg( array( 'action' => 'update', 'subscription_id' => $this->get_id() ) );
1103
+        return apply_filters( 'wpinv_subscription_update_url', $url, $this );
1104
+    }
1105
+
1106
+    /**
1107
+     * Retrieves the subscription status label
1108
+     *
1109
+     * @since  1.0.0
1110
+     * @return string
1111
+     */
1112
+    public function get_status_label() {
1113
+        return getpaid_get_subscription_status_label( $this->get_status() );
1114
+    }
1115
+
1116
+    /**
1117
+     * Retrieves the subscription status class
1118
+     *
1119
+     * @since  1.0.19
1120
+     * @return string
1121
+     */
1122
+    public function get_status_class() {
1123
+        $statuses = getpaid_get_subscription_status_classes();
1124
+        return isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : 'text-white bg-secondary';
1125
+    }
1126 1126
 
1127 1127
     /**
1128 1128
      * Retrieves the subscription status label
@@ -1132,11 +1132,11 @@  discard block
 block discarded – undo
1132 1132
      */
1133 1133
     public function get_status_label_html() {
1134 1134
 
1135
-		$status_label = sanitize_text_field( $this->get_status_label() );
1136
-		$class        = sanitize_html_class( $this->get_status_class() );
1137
-		$status       = sanitize_html_class( $this->get_status_label() );
1135
+        $status_label = sanitize_text_field( $this->get_status_label() );
1136
+        $class        = sanitize_html_class( $this->get_status_class() );
1137
+        $status       = sanitize_html_class( $this->get_status_label() );
1138 1138
 
1139
-		"<span class='bsui'><small class='d-inline-block py-1 px-2 rounded $class $status'>$status_label</small></span>";
1139
+        "<span class='bsui'><small class='d-inline-block py-1 px-2 rounded $class $status'>$status_label</small></span>";
1140 1140
     }
1141 1141
 
1142 1142
     /**
@@ -1147,63 +1147,63 @@  discard block
 block discarded – undo
1147 1147
      * @return bool
1148 1148
      */
1149 1149
     public function payment_exists( $txn_id = '' ) {
1150
-		$invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1150
+        $invoice_id = WPInv_Invoice::get_invoice_id_by_field( $txn_id, 'transaction_id' );
1151 1151
         return ! empty( $invoice_id );
1152
-	}
1153
-
1154
-	/**
1155
-	 * Handle the status transition.
1156
-	 */
1157
-	protected function status_transition() {
1158
-		$status_transition = $this->status_transition;
1159
-
1160
-		// Reset status transition variable.
1161
-		$this->status_transition = false;
1162
-
1163
-		if ( $status_transition ) {
1164
-			try {
1165
-
1166
-				// Fire a hook for the status change.
1167
-				do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1168
-				do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1169
-
1170
-				if ( ! empty( $status_transition['from'] ) ) {
1171
-
1172
-					/* translators: 1: old subscription status 2: new subscription status */
1173
-					$transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1174
-
1175
-					// Fire another hook.
1176
-					do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1177
-					do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
1178
-
1179
-					// Note the transition occurred.
1180
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1181
-
1182
-				} else {
1183
-					/* translators: %s: new invoice status */
1184
-					$transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1185
-
1186
-					// Note the transition occurred.
1187
-					$this->get_parent_payment()->add_note( $transition_note, false, false, true );
1188
-
1189
-				}
1190
-			} catch ( Exception $e ) {
1191
-				$this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1192
-			}
1193
-		}
1194
-
1195
-	}
1196
-
1197
-	/**
1198
-	 * Save data to the database.
1199
-	 *
1200
-	 * @since 1.0.19
1201
-	 * @return int subscription ID
1202
-	 */
1203
-	public function save() {
1204
-		parent::save();
1205
-		$this->status_transition();
1206
-		return $this->get_id();
1207
-	}
1152
+    }
1153
+
1154
+    /**
1155
+     * Handle the status transition.
1156
+     */
1157
+    protected function status_transition() {
1158
+        $status_transition = $this->status_transition;
1159
+
1160
+        // Reset status transition variable.
1161
+        $this->status_transition = false;
1162
+
1163
+        if ( $status_transition ) {
1164
+            try {
1165
+
1166
+                // Fire a hook for the status change.
1167
+                do_action( 'wpinv_subscription_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
1168
+                do_action( 'getpaid_subscription_' . $status_transition['to'], $this, $status_transition );
1169
+
1170
+                if ( ! empty( $status_transition['from'] ) ) {
1171
+
1172
+                    /* translators: 1: old subscription status 2: new subscription status */
1173
+                    $transition_note = sprintf( __( 'Subscription status changed from %1$s to %2$s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['from'] ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1174
+
1175
+                    // Fire another hook.
1176
+                    do_action( 'getpaid_subscription_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
1177
+                    do_action( 'getpaid_subscription_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
1178
+
1179
+                    // Note the transition occurred.
1180
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1181
+
1182
+                } else {
1183
+                    /* translators: %s: new invoice status */
1184
+                    $transition_note = sprintf( __( 'Subscription status set to %s.', 'invoicing' ), getpaid_get_subscription_status_label( $status_transition['to'] ) );
1185
+
1186
+                    // Note the transition occurred.
1187
+                    $this->get_parent_payment()->add_note( $transition_note, false, false, true );
1188
+
1189
+                }
1190
+            } catch ( Exception $e ) {
1191
+                $this->get_parent_payment()->add_note( __( 'Error during subscription status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
1192
+            }
1193
+        }
1194
+
1195
+    }
1196
+
1197
+    /**
1198
+     * Save data to the database.
1199
+     *
1200
+     * @since 1.0.19
1201
+     * @return int subscription ID
1202
+     */
1203
+    public function save() {
1204
+        parent::save();
1205
+        $this->status_transition();
1206
+        return $this->get_id();
1207
+    }
1208 1208
 
1209 1209
 }
Please login to merge, or discard this patch.
includes/class-wpinv-invoice.php 1 patch
Indentation   +2235 added lines, -2235 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,20 +79,20 @@  discard block
 block discarded – undo
79 79
         'transaction_id'       => '',
80 80
         'currency'             => '',
81 81
         'disable_taxes'        => false,
82
-		'subscription_id'      => null,
83
-		'is_viewed'            => false,
84
-		'email_cc'             => '',
85
-		'template'             => 'quantity', // hours, amount only
82
+        'subscription_id'      => null,
83
+        'is_viewed'            => false,
84
+        'email_cc'             => '',
85
+        'template'             => 'quantity', // hours, amount only
86 86
     );
87 87
 
88 88
     /**
89
-	 * Stores meta in cache for future reads.
90
-	 *
91
-	 * A group must be set to to enable caching.
92
-	 *
93
-	 * @var string
94
-	 */
95
-	protected $cache_group = 'getpaid_invoices';
89
+     * Stores meta in cache for future reads.
90
+     *
91
+     * A group must be set to to enable caching.
92
+     *
93
+     * @var string
94
+     */
95
+    protected $cache_group = 'getpaid_invoices';
96 96
 
97 97
     /**
98 98
      * Stores a reference to the original WP_Post object
@@ -106,104 +106,104 @@  discard block
 block discarded – undo
106 106
      *
107 107
      * @var int
108 108
      */
109
-	protected $recurring_item = null;
109
+    protected $recurring_item = null;
110 110
 
111
-	/**
111
+    /**
112 112
      * Stores an array of item totals.
113
-	 *
114
-	 * e.g $totals['discount'] = array(
115
-	 * 		'initial'   => 10,
116
-	 * 		'recurring' => 10,
117
-	 * )
113
+     *
114
+     * e.g $totals['discount'] = array(
115
+     * 		'initial'   => 10,
116
+     * 		'recurring' => 10,
117
+     * )
118 118
      *
119 119
      * @var array
120 120
      */
121
-	protected $totals = array();
121
+    protected $totals = array();
122 122
 
123
-	/**
124
-	 * Stores the status transition information.
125
-	 *
126
-	 * @since 1.0.19
127
-	 * @var bool
128
-	 */
129
-	protected $status_transition = false;
123
+    /**
124
+     * Stores the status transition information.
125
+     *
126
+     * @since 1.0.19
127
+     * @var bool
128
+     */
129
+    protected $status_transition = false;
130 130
 
131 131
     /**
132
-	 * Get the invoice if ID is passed, otherwise the invoice is new and empty.
133
-	 *
134
-	 * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
135
-	 */
132
+     * Get the invoice if ID is passed, otherwise the invoice is new and empty.
133
+     *
134
+     * @param  int|string|object|WPInv_Invoice|WPInv_Legacy_Invoice|WP_Post $invoice Invoice id, key, transaction id, number or object to read.
135
+     */
136 136
     public function __construct( $invoice = false ) {
137 137
 
138 138
         parent::__construct( $invoice );
139 139
 
140
-		if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
141
-			$this->set_id( $invoice );
142
-		} elseif ( $invoice instanceof self ) {
143
-			$this->set_id( $invoice->get_id() );
144
-		} elseif ( ! empty( $invoice->ID ) ) {
145
-			$this->set_id( $invoice->ID );
146
-		} elseif ( is_array( $invoice ) ) {
147
-			$this->set_props( $invoice );
148
-
149
-			if ( isset( $invoice['ID'] ) ) {
150
-				$this->set_id( $invoice['ID'] );
151
-			}
152
-
153
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
154
-			$this->set_id( $invoice_id );
155
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
156
-			$this->set_id( $invoice_id );
157
-		} elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
158
-			$this->set_id( $invoice_id );
159
-		}else {
160
-			$this->set_object_read( true );
161
-		}
140
+        if ( ! empty( $invoice ) && is_numeric( $invoice ) && getpaid_is_invoice_post_type( get_post_type( $invoice ) ) ) {
141
+            $this->set_id( $invoice );
142
+        } elseif ( $invoice instanceof self ) {
143
+            $this->set_id( $invoice->get_id() );
144
+        } elseif ( ! empty( $invoice->ID ) ) {
145
+            $this->set_id( $invoice->ID );
146
+        } elseif ( is_array( $invoice ) ) {
147
+            $this->set_props( $invoice );
148
+
149
+            if ( isset( $invoice['ID'] ) ) {
150
+                $this->set_id( $invoice['ID'] );
151
+            }
152
+
153
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'key' ) ) {
154
+            $this->set_id( $invoice_id );
155
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'number' ) ) {
156
+            $this->set_id( $invoice_id );
157
+        } elseif ( is_scalar( $invoice ) && $invoice_id = self::get_invoice_id_by_field( $invoice, 'transaction_id' ) ) {
158
+            $this->set_id( $invoice_id );
159
+        }else {
160
+            $this->set_object_read( true );
161
+        }
162 162
 
163 163
         // Load the datastore.
164
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
164
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
165 165
 
166
-		if ( $this->get_id() > 0 ) {
166
+        if ( $this->get_id() > 0 ) {
167 167
             $this->post = get_post( $this->get_id() );
168 168
             $this->ID   = $this->get_id();
169
-			$this->data_store->read( $this );
169
+            $this->data_store->read( $this );
170 170
         }
171 171
 
172 172
     }
173 173
 
174 174
     /**
175
-	 * Given an invoice key/number, it returns its id.
176
-	 *
177
-	 *
178
-	 * @static
179
-	 * @param string $value The invoice key or number
180
-	 * @param string $field Either key, transaction_id or number.
181
-	 * @since 1.0.15
182
-	 * @return int
183
-	 */
184
-	public static function get_invoice_id_by_field( $value, $field = 'key' ) {
175
+     * Given an invoice key/number, it returns its id.
176
+     *
177
+     *
178
+     * @static
179
+     * @param string $value The invoice key or number
180
+     * @param string $field Either key, transaction_id or number.
181
+     * @since 1.0.15
182
+     * @return int
183
+     */
184
+    public static function get_invoice_id_by_field( $value, $field = 'key' ) {
185 185
         global $wpdb;
186 186
 
187
-		// Trim the value.
188
-		$value = trim( $value );
187
+        // Trim the value.
188
+        $value = trim( $value );
189 189
 
190
-		if ( empty( $value ) ) {
191
-			return 0;
192
-		}
190
+        if ( empty( $value ) ) {
191
+            return 0;
192
+        }
193 193
 
194 194
         // Valid fields.
195 195
         $fields = array( 'key', 'number', 'transaction_id' );
196 196
 
197
-		// Ensure a field has been passed.
198
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
199
-			return 0;
200
-		}
197
+        // Ensure a field has been passed.
198
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
199
+            return 0;
200
+        }
201 201
 
202
-		// Maybe retrieve from the cache.
203
-		$invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
204
-		if ( ! empty( $invoice_id ) ) {
205
-			return $invoice_id;
206
-		}
202
+        // Maybe retrieve from the cache.
203
+        $invoice_id   = wp_cache_get( $value, "getpaid_invoice_{$field}s_to_invoice_ids" );
204
+        if ( ! empty( $invoice_id ) ) {
205
+            return $invoice_id;
206
+        }
207 207
 
208 208
         // Fetch from the db.
209 209
         $table       = $wpdb->prefix . 'getpaid_invoices';
@@ -211,14 +211,14 @@  discard block
 block discarded – undo
211 211
             $wpdb->prepare( "SELECT `post_id` FROM $table WHERE `$field`=%s LIMIT 1", $value )
212 212
         );
213 213
 
214
-		if ( empty( $invoice_id ) ) {
215
-			return 0;
216
-		}
214
+        if ( empty( $invoice_id ) ) {
215
+            return 0;
216
+        }
217 217
 
218
-		// Update the cache with our data
219
-		wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
218
+        // Update the cache with our data
219
+        wp_cache_set( $value, $invoice_id, "getpaid_invoice_{$field}s_to_invoice_ids" );
220 220
 
221
-		return $invoice_id;
221
+        return $invoice_id;
222 222
     }
223 223
 
224 224
     /**
@@ -244,73 +244,73 @@  discard block
 block discarded – undo
244 244
     */
245 245
 
246 246
     /**
247
-	 * Get parent invoice ID.
248
-	 *
249
-	 * @since 1.0.19
250
-	 * @param  string $context View or edit context.
251
-	 * @return int
252
-	 */
253
-	public function get_parent_id( $context = 'view' ) {
254
-		return (int) $this->get_prop( 'parent_id', $context );
247
+     * Get parent invoice ID.
248
+     *
249
+     * @since 1.0.19
250
+     * @param  string $context View or edit context.
251
+     * @return int
252
+     */
253
+    public function get_parent_id( $context = 'view' ) {
254
+        return (int) $this->get_prop( 'parent_id', $context );
255 255
     }
256 256
 
257 257
     /**
258
-	 * Get parent invoice.
259
-	 *
260
-	 * @since 1.0.19
261
-	 * @return WPInv_Invoice
262
-	 */
258
+     * Get parent invoice.
259
+     *
260
+     * @since 1.0.19
261
+     * @return WPInv_Invoice
262
+     */
263 263
     public function get_parent_payment() {
264 264
         return new WPInv_Invoice( $this->get_parent_id() );
265 265
     }
266 266
 
267 267
     /**
268
-	 * Alias for self::get_parent_payment().
269
-	 *
270
-	 * @since 1.0.19
271
-	 * @return WPInv_Invoice
272
-	 */
268
+     * Alias for self::get_parent_payment().
269
+     *
270
+     * @since 1.0.19
271
+     * @return WPInv_Invoice
272
+     */
273 273
     public function get_parent() {
274 274
         return $this->get_parent_payment();
275 275
     }
276 276
 
277 277
     /**
278
-	 * Get invoice status.
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @param  string $context View or edit context.
282
-	 * @return string
283
-	 */
284
-	public function get_status( $context = 'view' ) {
285
-		return $this->get_prop( 'status', $context );
286
-	}
278
+     * Get invoice status.
279
+     *
280
+     * @since 1.0.19
281
+     * @param  string $context View or edit context.
282
+     * @return string
283
+     */
284
+    public function get_status( $context = 'view' ) {
285
+        return $this->get_prop( 'status', $context );
286
+    }
287 287
 	
288
-	/**
289
-	 * Retrieves an array of possible invoice statuses.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @return array
293
-	 */
294
-	public function get_all_statuses() {
295
-
296
-		$statuses = wpinv_get_invoice_statuses( true, true, $this );
297
-
298
-		// For backwards compatibility.
299
-		if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
288
+    /**
289
+     * Retrieves an array of possible invoice statuses.
290
+     *
291
+     * @since 1.0.19
292
+     * @return array
293
+     */
294
+    public function get_all_statuses() {
295
+
296
+        $statuses = wpinv_get_invoice_statuses( true, true, $this );
297
+
298
+        // For backwards compatibility.
299
+        if ( $this->is_quote() && class_exists( 'Wpinv_Quotes_Shared' ) ) {
300 300
             $statuses = Wpinv_Quotes_Shared::wpinv_get_quote_statuses();
301
-		}
301
+        }
302 302
 
303
-		return $statuses;
303
+        return $statuses;
304 304
     }
305 305
 
306 306
     /**
307
-	 * Get invoice status nice name.
308
-	 *
309
-	 * @since 1.0.19
310
-	 * @return string
311
-	 */
307
+     * Get invoice status nice name.
308
+     *
309
+     * @since 1.0.19
310
+     * @return string
311
+     */
312 312
     public function get_status_nicename() {
313
-		$statuses = $this->get_all_statuses();
313
+        $statuses = $this->get_all_statuses();
314 314
 
315 315
         $status = isset( $statuses[ $this->get_status() ] ) ? $statuses[ $this->get_status() ] : $this->get_status();
316 316
 
@@ -318,20 +318,20 @@  discard block
 block discarded – undo
318 318
     }
319 319
 
320 320
     /**
321
-	 * Get plugin version when the invoice was created.
322
-	 *
323
-	 * @since 1.0.19
324
-	 * @param  string $context View or edit context.
325
-	 * @return string
326
-	 */
327
-	public function get_version( $context = 'view' ) {
328
-		return $this->get_prop( 'version', $context );
329
-	}
321
+     * Get plugin version when the invoice was created.
322
+     *
323
+     * @since 1.0.19
324
+     * @param  string $context View or edit context.
325
+     * @return string
326
+     */
327
+    public function get_version( $context = 'view' ) {
328
+        return $this->get_prop( 'version', $context );
329
+    }
330 330
 
331
-	/**
332
-	 * @deprecated
333
-	 */
334
-	public function get_invoice_date( $formatted = true ) {
331
+    /**
332
+     * @deprecated
333
+     */
334
+    public function get_invoice_date( $formatted = true ) {
335 335
         $date_completed = $this->get_date_completed();
336 336
         $invoice_date   = $date_completed != '0000-00-00 00:00:00' ? $date_completed : '';
337 337
 
@@ -348,187 +348,187 @@  discard block
 block discarded – undo
348 348
     }
349 349
 
350 350
     /**
351
-	 * Get date when the invoice was created.
352
-	 *
353
-	 * @since 1.0.19
354
-	 * @param  string $context View or edit context.
355
-	 * @return string
356
-	 */
357
-	public function get_date_created( $context = 'view' ) {
358
-		return $this->get_prop( 'date_created', $context );
359
-	}
351
+     * Get date when the invoice was created.
352
+     *
353
+     * @since 1.0.19
354
+     * @param  string $context View or edit context.
355
+     * @return string
356
+     */
357
+    public function get_date_created( $context = 'view' ) {
358
+        return $this->get_prop( 'date_created', $context );
359
+    }
360 360
 	
361
-	/**
362
-	 * Alias for self::get_date_created().
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param  string $context View or edit context.
366
-	 * @return string
367
-	 */
368
-	public function get_created_date( $context = 'view' ) {
369
-		return $this->get_date_created( $context );
370
-    }
371
-
372
-    /**
373
-	 * Get GMT date when the invoice was created.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $context View or edit context.
377
-	 * @return string
378
-	 */
379
-	public function get_date_created_gmt( $context = 'view' ) {
361
+    /**
362
+     * Alias for self::get_date_created().
363
+     *
364
+     * @since 1.0.19
365
+     * @param  string $context View or edit context.
366
+     * @return string
367
+     */
368
+    public function get_created_date( $context = 'view' ) {
369
+        return $this->get_date_created( $context );
370
+    }
371
+
372
+    /**
373
+     * Get GMT date when the invoice was created.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $context View or edit context.
377
+     * @return string
378
+     */
379
+    public function get_date_created_gmt( $context = 'view' ) {
380 380
         $date = $this->get_date_created( $context );
381 381
 
382 382
         if ( $date ) {
383 383
             $date = get_gmt_from_date( $date );
384 384
         }
385
-		return $date;
385
+        return $date;
386 386
     }
387 387
 
388 388
     /**
389
-	 * Get date when the invoice was last modified.
390
-	 *
391
-	 * @since 1.0.19
392
-	 * @param  string $context View or edit context.
393
-	 * @return string
394
-	 */
395
-	public function get_date_modified( $context = 'view' ) {
396
-		return $this->get_prop( 'date_modified', $context );
397
-	}
389
+     * Get date when the invoice was last modified.
390
+     *
391
+     * @since 1.0.19
392
+     * @param  string $context View or edit context.
393
+     * @return string
394
+     */
395
+    public function get_date_modified( $context = 'view' ) {
396
+        return $this->get_prop( 'date_modified', $context );
397
+    }
398 398
 
399
-	/**
400
-	 * Alias for self::get_date_modified().
401
-	 *
402
-	 * @since 1.0.19
403
-	 * @param  string $context View or edit context.
404
-	 * @return string
405
-	 */
406
-	public function get_modified_date( $context = 'view' ) {
407
-		return $this->get_date_modified( $context );
399
+    /**
400
+     * Alias for self::get_date_modified().
401
+     *
402
+     * @since 1.0.19
403
+     * @param  string $context View or edit context.
404
+     * @return string
405
+     */
406
+    public function get_modified_date( $context = 'view' ) {
407
+        return $this->get_date_modified( $context );
408 408
     }
409 409
 
410 410
     /**
411
-	 * Get GMT date when the invoice was last modified.
412
-	 *
413
-	 * @since 1.0.19
414
-	 * @param  string $context View or edit context.
415
-	 * @return string
416
-	 */
417
-	public function get_date_modified_gmt( $context = 'view' ) {
411
+     * Get GMT date when the invoice was last modified.
412
+     *
413
+     * @since 1.0.19
414
+     * @param  string $context View or edit context.
415
+     * @return string
416
+     */
417
+    public function get_date_modified_gmt( $context = 'view' ) {
418 418
         $date = $this->get_date_modified( $context );
419 419
 
420 420
         if ( $date ) {
421 421
             $date = get_gmt_from_date( $date );
422 422
         }
423
-		return $date;
423
+        return $date;
424 424
     }
425 425
 
426 426
     /**
427
-	 * Get the invoice due date.
428
-	 *
429
-	 * @since 1.0.19
430
-	 * @param  string $context View or edit context.
431
-	 * @return string
432
-	 */
433
-	public function get_due_date( $context = 'view' ) {
434
-		return $this->get_prop( 'due_date', $context );
427
+     * Get the invoice due date.
428
+     *
429
+     * @since 1.0.19
430
+     * @param  string $context View or edit context.
431
+     * @return string
432
+     */
433
+    public function get_due_date( $context = 'view' ) {
434
+        return $this->get_prop( 'due_date', $context );
435 435
     }
436 436
 
437 437
     /**
438
-	 * Alias for self::get_due_date().
439
-	 *
440
-	 * @since 1.0.19
441
-	 * @param  string $context View or edit context.
442
-	 * @return string
443
-	 */
444
-	public function get_date_due( $context = 'view' ) {
445
-		return $this->get_due_date( $context );
438
+     * Alias for self::get_due_date().
439
+     *
440
+     * @since 1.0.19
441
+     * @param  string $context View or edit context.
442
+     * @return string
443
+     */
444
+    public function get_date_due( $context = 'view' ) {
445
+        return $this->get_due_date( $context );
446 446
     }
447 447
 
448 448
     /**
449
-	 * Get the invoice GMT due date.
450
-	 *
451
-	 * @since 1.0.19
452
-	 * @param  string $context View or edit context.
453
-	 * @return string
454
-	 */
455
-	public function get_due_date_gmt( $context = 'view' ) {
449
+     * Get the invoice GMT due date.
450
+     *
451
+     * @since 1.0.19
452
+     * @param  string $context View or edit context.
453
+     * @return string
454
+     */
455
+    public function get_due_date_gmt( $context = 'view' ) {
456 456
         $date = $this->get_due_date( $context );
457 457
 
458 458
         if ( $date ) {
459 459
             $date = get_gmt_from_date( $date );
460 460
         }
461
-		return $date;
461
+        return $date;
462 462
     }
463 463
 
464 464
     /**
465
-	 * Alias for self::get_due_date_gmt().
466
-	 *
467
-	 * @since 1.0.19
468
-	 * @param  string $context View or edit context.
469
-	 * @return string
470
-	 */
471
-	public function get_gmt_date_due( $context = 'view' ) {
472
-		return $this->get_due_date_gmt( $context );
465
+     * Alias for self::get_due_date_gmt().
466
+     *
467
+     * @since 1.0.19
468
+     * @param  string $context View or edit context.
469
+     * @return string
470
+     */
471
+    public function get_gmt_date_due( $context = 'view' ) {
472
+        return $this->get_due_date_gmt( $context );
473 473
     }
474 474
 
475 475
     /**
476
-	 * Get date when the invoice was completed.
477
-	 *
478
-	 * @since 1.0.19
479
-	 * @param  string $context View or edit context.
480
-	 * @return string
481
-	 */
482
-	public function get_completed_date( $context = 'view' ) {
483
-		return $this->get_prop( 'completed_date', $context );
476
+     * Get date when the invoice was completed.
477
+     *
478
+     * @since 1.0.19
479
+     * @param  string $context View or edit context.
480
+     * @return string
481
+     */
482
+    public function get_completed_date( $context = 'view' ) {
483
+        return $this->get_prop( 'completed_date', $context );
484 484
     }
485 485
 
486 486
     /**
487
-	 * Alias for self::get_completed_date().
488
-	 *
489
-	 * @since 1.0.19
490
-	 * @param  string $context View or edit context.
491
-	 * @return string
492
-	 */
493
-	public function get_date_completed( $context = 'view' ) {
494
-		return $this->get_completed_date( $context );
487
+     * Alias for self::get_completed_date().
488
+     *
489
+     * @since 1.0.19
490
+     * @param  string $context View or edit context.
491
+     * @return string
492
+     */
493
+    public function get_date_completed( $context = 'view' ) {
494
+        return $this->get_completed_date( $context );
495 495
     }
496 496
 
497 497
     /**
498
-	 * Get GMT date when the invoice was was completed.
499
-	 *
500
-	 * @since 1.0.19
501
-	 * @param  string $context View or edit context.
502
-	 * @return string
503
-	 */
504
-	public function get_completed_date_gmt( $context = 'view' ) {
498
+     * Get GMT date when the invoice was was completed.
499
+     *
500
+     * @since 1.0.19
501
+     * @param  string $context View or edit context.
502
+     * @return string
503
+     */
504
+    public function get_completed_date_gmt( $context = 'view' ) {
505 505
         $date = $this->get_completed_date( $context );
506 506
 
507 507
         if ( $date ) {
508 508
             $date = get_gmt_from_date( $date );
509 509
         }
510
-		return $date;
510
+        return $date;
511 511
     }
512 512
 
513 513
     /**
514
-	 * Alias for self::get_completed_date_gmt().
515
-	 *
516
-	 * @since 1.0.19
517
-	 * @param  string $context View or edit context.
518
-	 * @return string
519
-	 */
520
-	public function get_gmt_completed_date( $context = 'view' ) {
521
-		return $this->get_completed_date_gmt( $context );
514
+     * Alias for self::get_completed_date_gmt().
515
+     *
516
+     * @since 1.0.19
517
+     * @param  string $context View or edit context.
518
+     * @return string
519
+     */
520
+    public function get_gmt_completed_date( $context = 'view' ) {
521
+        return $this->get_completed_date_gmt( $context );
522 522
     }
523 523
 
524 524
     /**
525
-	 * Get the invoice number.
526
-	 *
527
-	 * @since 1.0.19
528
-	 * @param  string $context View or edit context.
529
-	 * @return string
530
-	 */
531
-	public function get_number( $context = 'view' ) {
525
+     * Get the invoice number.
526
+     *
527
+     * @since 1.0.19
528
+     * @param  string $context View or edit context.
529
+     * @return string
530
+     */
531
+    public function get_number( $context = 'view' ) {
532 532
         $number = $this->get_prop( 'number', $context );
533 533
 
534 534
         if ( empty( $number ) ) {
@@ -536,17 +536,17 @@  discard block
 block discarded – undo
536 536
             $this->set_number( $number );
537 537
         }
538 538
 
539
-		return $number;
539
+        return $number;
540 540
     }
541 541
 
542 542
     /**
543
-	 * Get the invoice key.
544
-	 *
545
-	 * @since 1.0.19
546
-	 * @param  string $context View or edit context.
547
-	 * @return string
548
-	 */
549
-	public function get_key( $context = 'view' ) {
543
+     * Get the invoice key.
544
+     *
545
+     * @since 1.0.19
546
+     * @param  string $context View or edit context.
547
+     * @return string
548
+     */
549
+    public function get_key( $context = 'view' ) {
550 550
         $key = $this->get_prop( 'key', $context );
551 551
 
552 552
         if ( empty( $key ) ) {
@@ -554,24 +554,24 @@  discard block
 block discarded – undo
554 554
             $this->set_key( $key );
555 555
         }
556 556
 
557
-		return $key;
557
+        return $key;
558 558
     }
559 559
 
560 560
     /**
561
-	 * Get the invoice type.
562
-	 *
563
-	 * @since 1.0.19
564
-	 * @param  string $context View or edit context.
565
-	 * @return string
566
-	 */
567
-	public function get_type( $context = 'view' ) {
561
+     * Get the invoice type.
562
+     *
563
+     * @since 1.0.19
564
+     * @param  string $context View or edit context.
565
+     * @return string
566
+     */
567
+    public function get_type( $context = 'view' ) {
568 568
         return $this->get_prop( 'type', $context );
569
-	}
569
+    }
570 570
 
571
-	/**
572
-	 * @deprecated
573
-	 */
574
-	public function get_invoice_quote_type( $post_id ) {
571
+    /**
572
+     * @deprecated
573
+     */
574
+    public function get_invoice_quote_type( $post_id ) {
575 575
         if ( empty( $post_id ) ) {
576 576
             return '';
577 577
         }
@@ -588,35 +588,35 @@  discard block
 block discarded – undo
588 588
     }
589 589
 
590 590
     /**
591
-	 * Get the invoice post type.
592
-	 *
593
-	 * @since 1.0.19
594
-	 * @param  string $context View or edit context.
595
-	 * @return string
596
-	 */
597
-	public function get_post_type( $context = 'view' ) {
591
+     * Get the invoice post type.
592
+     *
593
+     * @since 1.0.19
594
+     * @param  string $context View or edit context.
595
+     * @return string
596
+     */
597
+    public function get_post_type( $context = 'view' ) {
598 598
         return $this->get_prop( 'post_type', $context );
599 599
     }
600 600
 
601 601
     /**
602
-	 * Get the invoice mode.
603
-	 *
604
-	 * @since 1.0.19
605
-	 * @param  string $context View or edit context.
606
-	 * @return string
607
-	 */
608
-	public function get_mode( $context = 'view' ) {
602
+     * Get the invoice mode.
603
+     *
604
+     * @since 1.0.19
605
+     * @param  string $context View or edit context.
606
+     * @return string
607
+     */
608
+    public function get_mode( $context = 'view' ) {
609 609
         return $this->get_prop( 'mode', $context );
610 610
     }
611 611
 
612 612
     /**
613
-	 * Get the invoice path.
614
-	 *
615
-	 * @since 1.0.19
616
-	 * @param  string $context View or edit context.
617
-	 * @return string
618
-	 */
619
-	public function get_path( $context = 'view' ) {
613
+     * Get the invoice path.
614
+     *
615
+     * @since 1.0.19
616
+     * @param  string $context View or edit context.
617
+     * @return string
618
+     */
619
+    public function get_path( $context = 'view' ) {
620 620
         $path = $this->get_prop( 'path', $context );
621 621
 
622 622
         if ( empty( $path ) ) {
@@ -624,73 +624,73 @@  discard block
 block discarded – undo
624 624
             $path   = sanitize_title( $prefix . $this->get_id() );
625 625
         }
626 626
 
627
-		return $path;
627
+        return $path;
628 628
     }
629 629
 
630 630
     /**
631
-	 * Get the invoice name/title.
632
-	 *
633
-	 * @since 1.0.19
634
-	 * @param  string $context View or edit context.
635
-	 * @return string
636
-	 */
637
-	public function get_name( $context = 'view' ) {
631
+     * Get the invoice name/title.
632
+     *
633
+     * @since 1.0.19
634
+     * @param  string $context View or edit context.
635
+     * @return string
636
+     */
637
+    public function get_name( $context = 'view' ) {
638 638
         $name = $this->get_prop( 'title', $context );
639 639
 
640
-		return empty( $name ) ? $this->get_number( $context ) : $name;
640
+        return empty( $name ) ? $this->get_number( $context ) : $name;
641 641
     }
642 642
 
643 643
     /**
644
-	 * Alias of self::get_name().
645
-	 *
646
-	 * @since 1.0.19
647
-	 * @param  string $context View or edit context.
648
-	 * @return string
649
-	 */
650
-	public function get_title( $context = 'view' ) {
651
-		return $this->get_name( $context );
644
+     * Alias of self::get_name().
645
+     *
646
+     * @since 1.0.19
647
+     * @param  string $context View or edit context.
648
+     * @return string
649
+     */
650
+    public function get_title( $context = 'view' ) {
651
+        return $this->get_name( $context );
652 652
     }
653 653
 
654 654
     /**
655
-	 * Get the invoice description.
656
-	 *
657
-	 * @since 1.0.19
658
-	 * @param  string $context View or edit context.
659
-	 * @return string
660
-	 */
661
-	public function get_description( $context = 'view' ) {
662
-		return $this->get_prop( 'description', $context );
655
+     * Get the invoice description.
656
+     *
657
+     * @since 1.0.19
658
+     * @param  string $context View or edit context.
659
+     * @return string
660
+     */
661
+    public function get_description( $context = 'view' ) {
662
+        return $this->get_prop( 'description', $context );
663 663
     }
664 664
 
665 665
     /**
666
-	 * Alias of self::get_description().
667
-	 *
668
-	 * @since 1.0.19
669
-	 * @param  string $context View or edit context.
670
-	 * @return string
671
-	 */
672
-	public function get_excerpt( $context = 'view' ) {
673
-		return $this->get_description( $context );
666
+     * Alias of self::get_description().
667
+     *
668
+     * @since 1.0.19
669
+     * @param  string $context View or edit context.
670
+     * @return string
671
+     */
672
+    public function get_excerpt( $context = 'view' ) {
673
+        return $this->get_description( $context );
674 674
     }
675 675
 
676 676
     /**
677
-	 * Alias of self::get_description().
678
-	 *
679
-	 * @since 1.0.19
680
-	 * @param  string $context View or edit context.
681
-	 * @return string
682
-	 */
683
-	public function get_summary( $context = 'view' ) {
684
-		return $this->get_description( $context );
677
+     * Alias of self::get_description().
678
+     *
679
+     * @since 1.0.19
680
+     * @param  string $context View or edit context.
681
+     * @return string
682
+     */
683
+    public function get_summary( $context = 'view' ) {
684
+        return $this->get_description( $context );
685 685
     }
686 686
 
687 687
     /**
688
-	 * Returns the user info.
689
-	 *
690
-	 * @since 1.0.19
688
+     * Returns the user info.
689
+     *
690
+     * @since 1.0.19
691 691
      * @param  string $context View or edit context.
692
-	 * @return array
693
-	 */
692
+     * @return array
693
+     */
694 694
     public function get_user_info( $context = 'view' ) {
695 695
 
696 696
         $user_info = array(
@@ -707,605 +707,605 @@  discard block
 block discarded – undo
707 707
             'company'    => $this->get_company( $context ),
708 708
             'vat_number' => $this->get_vat_number( $context ),
709 709
             'discount'   => $this->get_discount_code( $context ),
710
-		);
710
+        );
711 711
 
712
-		return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
712
+        return apply_filters( 'wpinv_user_info', $user_info, $this->get_id(), $this );
713 713
 
714 714
     }
715 715
 
716 716
     /**
717
-	 * Get the customer id.
718
-	 *
719
-	 * @since 1.0.19
720
-	 * @param  string $context View or edit context.
721
-	 * @return int
722
-	 */
723
-	public function get_author( $context = 'view' ) {
724
-		return (int) $this->get_prop( 'author', $context );
717
+     * Get the customer id.
718
+     *
719
+     * @since 1.0.19
720
+     * @param  string $context View or edit context.
721
+     * @return int
722
+     */
723
+    public function get_author( $context = 'view' ) {
724
+        return (int) $this->get_prop( 'author', $context );
725 725
     }
726 726
 
727 727
     /**
728
-	 * Alias of self::get_author().
729
-	 *
730
-	 * @since 1.0.19
731
-	 * @param  string $context View or edit context.
732
-	 * @return int
733
-	 */
734
-	public function get_user_id( $context = 'view' ) {
735
-		return $this->get_author( $context );
728
+     * Alias of self::get_author().
729
+     *
730
+     * @since 1.0.19
731
+     * @param  string $context View or edit context.
732
+     * @return int
733
+     */
734
+    public function get_user_id( $context = 'view' ) {
735
+        return $this->get_author( $context );
736 736
     }
737 737
 
738
-     /**
739
-	 * Alias of self::get_author().
740
-	 *
741
-	 * @since 1.0.19
742
-	 * @param  string $context View or edit context.
743
-	 * @return int
744
-	 */
745
-	public function get_customer_id( $context = 'view' ) {
746
-		return $this->get_author( $context );
738
+        /**
739
+         * Alias of self::get_author().
740
+         *
741
+         * @since 1.0.19
742
+         * @param  string $context View or edit context.
743
+         * @return int
744
+         */
745
+    public function get_customer_id( $context = 'view' ) {
746
+        return $this->get_author( $context );
747 747
     }
748 748
 
749 749
     /**
750
-	 * Get the customer's ip.
751
-	 *
752
-	 * @since 1.0.19
753
-	 * @param  string $context View or edit context.
754
-	 * @return string
755
-	 */
756
-	public function get_ip( $context = 'view' ) {
757
-		return $this->get_prop( 'user_ip', $context );
750
+     * Get the customer's ip.
751
+     *
752
+     * @since 1.0.19
753
+     * @param  string $context View or edit context.
754
+     * @return string
755
+     */
756
+    public function get_ip( $context = 'view' ) {
757
+        return $this->get_prop( 'user_ip', $context );
758 758
     }
759 759
 
760 760
     /**
761
-	 * Alias of self::get_ip().
762
-	 *
763
-	 * @since 1.0.19
764
-	 * @param  string $context View or edit context.
765
-	 * @return string
766
-	 */
767
-	public function get_user_ip( $context = 'view' ) {
768
-		return $this->get_ip( $context );
761
+     * Alias of self::get_ip().
762
+     *
763
+     * @since 1.0.19
764
+     * @param  string $context View or edit context.
765
+     * @return string
766
+     */
767
+    public function get_user_ip( $context = 'view' ) {
768
+        return $this->get_ip( $context );
769 769
     }
770 770
 
771
-     /**
772
-	 * Alias of self::get_ip().
773
-	 *
774
-	 * @since 1.0.19
775
-	 * @param  string $context View or edit context.
776
-	 * @return string
777
-	 */
778
-	public function get_customer_ip( $context = 'view' ) {
779
-		return $this->get_ip( $context );
771
+        /**
772
+         * Alias of self::get_ip().
773
+         *
774
+         * @since 1.0.19
775
+         * @param  string $context View or edit context.
776
+         * @return string
777
+         */
778
+    public function get_customer_ip( $context = 'view' ) {
779
+        return $this->get_ip( $context );
780 780
     }
781 781
 
782 782
     /**
783
-	 * Get the customer's first name.
784
-	 *
785
-	 * @since 1.0.19
786
-	 * @param  string $context View or edit context.
787
-	 * @return string
788
-	 */
789
-	public function get_first_name( $context = 'view' ) {
790
-		return $this->get_prop( 'first_name', $context );
783
+     * Get the customer's first name.
784
+     *
785
+     * @since 1.0.19
786
+     * @param  string $context View or edit context.
787
+     * @return string
788
+     */
789
+    public function get_first_name( $context = 'view' ) {
790
+        return $this->get_prop( 'first_name', $context );
791 791
     }
792 792
 
793 793
     /**
794
-	 * Alias of self::get_first_name().
795
-	 *
796
-	 * @since 1.0.19
797
-	 * @param  string $context View or edit context.
798
-	 * @return int
799
-	 */
800
-	public function get_user_first_name( $context = 'view' ) {
801
-		return $this->get_first_name( $context );
794
+     * Alias of self::get_first_name().
795
+     *
796
+     * @since 1.0.19
797
+     * @param  string $context View or edit context.
798
+     * @return int
799
+     */
800
+    public function get_user_first_name( $context = 'view' ) {
801
+        return $this->get_first_name( $context );
802 802
     }
803 803
 
804
-     /**
805
-	 * Alias of self::get_first_name().
806
-	 *
807
-	 * @since 1.0.19
808
-	 * @param  string $context View or edit context.
809
-	 * @return int
810
-	 */
811
-	public function get_customer_first_name( $context = 'view' ) {
812
-		return $this->get_first_name( $context );
804
+        /**
805
+         * Alias of self::get_first_name().
806
+         *
807
+         * @since 1.0.19
808
+         * @param  string $context View or edit context.
809
+         * @return int
810
+         */
811
+    public function get_customer_first_name( $context = 'view' ) {
812
+        return $this->get_first_name( $context );
813 813
     }
814 814
 
815 815
     /**
816
-	 * Get the customer's last name.
817
-	 *
818
-	 * @since 1.0.19
819
-	 * @param  string $context View or edit context.
820
-	 * @return string
821
-	 */
822
-	public function get_last_name( $context = 'view' ) {
823
-		return $this->get_prop( 'last_name', $context );
816
+     * Get the customer's last name.
817
+     *
818
+     * @since 1.0.19
819
+     * @param  string $context View or edit context.
820
+     * @return string
821
+     */
822
+    public function get_last_name( $context = 'view' ) {
823
+        return $this->get_prop( 'last_name', $context );
824 824
     }
825 825
 
826 826
     /**
827
-	 * Alias of self::get_last_name().
828
-	 *
829
-	 * @since 1.0.19
830
-	 * @param  string $context View or edit context.
831
-	 * @return int
832
-	 */
833
-	public function get_user_last_name( $context = 'view' ) {
834
-		return $this->get_last_name( $context );
827
+     * Alias of self::get_last_name().
828
+     *
829
+     * @since 1.0.19
830
+     * @param  string $context View or edit context.
831
+     * @return int
832
+     */
833
+    public function get_user_last_name( $context = 'view' ) {
834
+        return $this->get_last_name( $context );
835 835
     }
836 836
 
837 837
     /**
838
-	 * Alias of self::get_last_name().
839
-	 *
840
-	 * @since 1.0.19
841
-	 * @param  string $context View or edit context.
842
-	 * @return int
843
-	 */
844
-	public function get_customer_last_name( $context = 'view' ) {
845
-		return $this->get_last_name( $context );
838
+     * Alias of self::get_last_name().
839
+     *
840
+     * @since 1.0.19
841
+     * @param  string $context View or edit context.
842
+     * @return int
843
+     */
844
+    public function get_customer_last_name( $context = 'view' ) {
845
+        return $this->get_last_name( $context );
846 846
     }
847 847
 
848 848
     /**
849
-	 * Get the customer's full name.
850
-	 *
851
-	 * @since 1.0.19
852
-	 * @param  string $context View or edit context.
853
-	 * @return string
854
-	 */
855
-	public function get_full_name( $context = 'view' ) {
856
-		return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
849
+     * Get the customer's full name.
850
+     *
851
+     * @since 1.0.19
852
+     * @param  string $context View or edit context.
853
+     * @return string
854
+     */
855
+    public function get_full_name( $context = 'view' ) {
856
+        return trim( $this->get_first_name( $context ) . ' ' . $this->get_last_name( $context ) );
857 857
     }
858 858
 
859 859
     /**
860
-	 * Alias of self::get_full_name().
861
-	 *
862
-	 * @since 1.0.19
863
-	 * @param  string $context View or edit context.
864
-	 * @return int
865
-	 */
866
-	public function get_user_full_name( $context = 'view' ) {
867
-		return $this->get_full_name( $context );
860
+     * Alias of self::get_full_name().
861
+     *
862
+     * @since 1.0.19
863
+     * @param  string $context View or edit context.
864
+     * @return int
865
+     */
866
+    public function get_user_full_name( $context = 'view' ) {
867
+        return $this->get_full_name( $context );
868 868
     }
869 869
 
870 870
     /**
871
-	 * Alias of self::get_full_name().
872
-	 *
873
-	 * @since 1.0.19
874
-	 * @param  string $context View or edit context.
875
-	 * @return int
876
-	 */
877
-	public function get_customer_full_name( $context = 'view' ) {
878
-		return $this->get_full_name( $context );
871
+     * Alias of self::get_full_name().
872
+     *
873
+     * @since 1.0.19
874
+     * @param  string $context View or edit context.
875
+     * @return int
876
+     */
877
+    public function get_customer_full_name( $context = 'view' ) {
878
+        return $this->get_full_name( $context );
879 879
     }
880 880
 
881 881
     /**
882
-	 * Get the customer's phone number.
883
-	 *
884
-	 * @since 1.0.19
885
-	 * @param  string $context View or edit context.
886
-	 * @return string
887
-	 */
888
-	public function get_phone( $context = 'view' ) {
889
-		return $this->get_prop( 'phone', $context );
882
+     * Get the customer's phone number.
883
+     *
884
+     * @since 1.0.19
885
+     * @param  string $context View or edit context.
886
+     * @return string
887
+     */
888
+    public function get_phone( $context = 'view' ) {
889
+        return $this->get_prop( 'phone', $context );
890 890
     }
891 891
 
892 892
     /**
893
-	 * Alias of self::get_phone().
894
-	 *
895
-	 * @since 1.0.19
896
-	 * @param  string $context View or edit context.
897
-	 * @return int
898
-	 */
899
-	public function get_phone_number( $context = 'view' ) {
900
-		return $this->get_phone( $context );
893
+     * Alias of self::get_phone().
894
+     *
895
+     * @since 1.0.19
896
+     * @param  string $context View or edit context.
897
+     * @return int
898
+     */
899
+    public function get_phone_number( $context = 'view' ) {
900
+        return $this->get_phone( $context );
901 901
     }
902 902
 
903 903
     /**
904
-	 * Alias of self::get_phone().
905
-	 *
906
-	 * @since 1.0.19
907
-	 * @param  string $context View or edit context.
908
-	 * @return int
909
-	 */
910
-	public function get_user_phone( $context = 'view' ) {
911
-		return $this->get_phone( $context );
904
+     * Alias of self::get_phone().
905
+     *
906
+     * @since 1.0.19
907
+     * @param  string $context View or edit context.
908
+     * @return int
909
+     */
910
+    public function get_user_phone( $context = 'view' ) {
911
+        return $this->get_phone( $context );
912 912
     }
913 913
 
914 914
     /**
915
-	 * Alias of self::get_phone().
916
-	 *
917
-	 * @since 1.0.19
918
-	 * @param  string $context View or edit context.
919
-	 * @return int
920
-	 */
921
-	public function get_customer_phone( $context = 'view' ) {
922
-		return $this->get_phone( $context );
915
+     * Alias of self::get_phone().
916
+     *
917
+     * @since 1.0.19
918
+     * @param  string $context View or edit context.
919
+     * @return int
920
+     */
921
+    public function get_customer_phone( $context = 'view' ) {
922
+        return $this->get_phone( $context );
923 923
     }
924 924
 
925 925
     /**
926
-	 * Get the customer's email address.
927
-	 *
928
-	 * @since 1.0.19
929
-	 * @param  string $context View or edit context.
930
-	 * @return string
931
-	 */
932
-	public function get_email( $context = 'view' ) {
933
-		return $this->get_prop( 'email', $context );
926
+     * Get the customer's email address.
927
+     *
928
+     * @since 1.0.19
929
+     * @param  string $context View or edit context.
930
+     * @return string
931
+     */
932
+    public function get_email( $context = 'view' ) {
933
+        return $this->get_prop( 'email', $context );
934 934
     }
935 935
 
936 936
     /**
937
-	 * Alias of self::get_email().
938
-	 *
939
-	 * @since 1.0.19
940
-	 * @param  string $context View or edit context.
941
-	 * @return string
942
-	 */
943
-	public function get_email_address( $context = 'view' ) {
944
-		return $this->get_email( $context );
937
+     * Alias of self::get_email().
938
+     *
939
+     * @since 1.0.19
940
+     * @param  string $context View or edit context.
941
+     * @return string
942
+     */
943
+    public function get_email_address( $context = 'view' ) {
944
+        return $this->get_email( $context );
945 945
     }
946 946
 
947 947
     /**
948
-	 * Alias of self::get_email().
949
-	 *
950
-	 * @since 1.0.19
951
-	 * @param  string $context View or edit context.
952
-	 * @return int
953
-	 */
954
-	public function get_user_email( $context = 'view' ) {
955
-		return $this->get_email( $context );
948
+     * Alias of self::get_email().
949
+     *
950
+     * @since 1.0.19
951
+     * @param  string $context View or edit context.
952
+     * @return int
953
+     */
954
+    public function get_user_email( $context = 'view' ) {
955
+        return $this->get_email( $context );
956 956
     }
957 957
 
958 958
     /**
959
-	 * Alias of self::get_email().
960
-	 *
961
-	 * @since 1.0.19
962
-	 * @param  string $context View or edit context.
963
-	 * @return int
964
-	 */
965
-	public function get_customer_email( $context = 'view' ) {
966
-		return $this->get_email( $context );
959
+     * Alias of self::get_email().
960
+     *
961
+     * @since 1.0.19
962
+     * @param  string $context View or edit context.
963
+     * @return int
964
+     */
965
+    public function get_customer_email( $context = 'view' ) {
966
+        return $this->get_email( $context );
967 967
     }
968 968
 
969 969
     /**
970
-	 * Get the customer's country.
971
-	 *
972
-	 * @since 1.0.19
973
-	 * @param  string $context View or edit context.
974
-	 * @return string
975
-	 */
976
-	public function get_country( $context = 'view' ) {
977
-		$country = $this->get_prop( 'country', $context );
978
-		return empty( $country ) ? wpinv_get_default_country() : $country;
970
+     * Get the customer's country.
971
+     *
972
+     * @since 1.0.19
973
+     * @param  string $context View or edit context.
974
+     * @return string
975
+     */
976
+    public function get_country( $context = 'view' ) {
977
+        $country = $this->get_prop( 'country', $context );
978
+        return empty( $country ) ? wpinv_get_default_country() : $country;
979 979
     }
980 980
 
981 981
     /**
982
-	 * Alias of self::get_country().
983
-	 *
984
-	 * @since 1.0.19
985
-	 * @param  string $context View or edit context.
986
-	 * @return int
987
-	 */
988
-	public function get_user_country( $context = 'view' ) {
989
-		return $this->get_country( $context );
982
+     * Alias of self::get_country().
983
+     *
984
+     * @since 1.0.19
985
+     * @param  string $context View or edit context.
986
+     * @return int
987
+     */
988
+    public function get_user_country( $context = 'view' ) {
989
+        return $this->get_country( $context );
990 990
     }
991 991
 
992 992
     /**
993
-	 * Alias of self::get_country().
994
-	 *
995
-	 * @since 1.0.19
996
-	 * @param  string $context View or edit context.
997
-	 * @return int
998
-	 */
999
-	public function get_customer_country( $context = 'view' ) {
1000
-		return $this->get_country( $context );
993
+     * Alias of self::get_country().
994
+     *
995
+     * @since 1.0.19
996
+     * @param  string $context View or edit context.
997
+     * @return int
998
+     */
999
+    public function get_customer_country( $context = 'view' ) {
1000
+        return $this->get_country( $context );
1001 1001
     }
1002 1002
 
1003 1003
     /**
1004
-	 * Get the customer's state.
1005
-	 *
1006
-	 * @since 1.0.19
1007
-	 * @param  string $context View or edit context.
1008
-	 * @return string
1009
-	 */
1010
-	public function get_state( $context = 'view' ) {
1011
-		$state = $this->get_prop( 'state', $context );
1012
-		return empty( $state ) ? wpinv_get_default_state() : $state;
1004
+     * Get the customer's state.
1005
+     *
1006
+     * @since 1.0.19
1007
+     * @param  string $context View or edit context.
1008
+     * @return string
1009
+     */
1010
+    public function get_state( $context = 'view' ) {
1011
+        $state = $this->get_prop( 'state', $context );
1012
+        return empty( $state ) ? wpinv_get_default_state() : $state;
1013 1013
     }
1014 1014
 
1015 1015
     /**
1016
-	 * Alias of self::get_state().
1017
-	 *
1018
-	 * @since 1.0.19
1019
-	 * @param  string $context View or edit context.
1020
-	 * @return int
1021
-	 */
1022
-	public function get_user_state( $context = 'view' ) {
1023
-		return $this->get_state( $context );
1016
+     * Alias of self::get_state().
1017
+     *
1018
+     * @since 1.0.19
1019
+     * @param  string $context View or edit context.
1020
+     * @return int
1021
+     */
1022
+    public function get_user_state( $context = 'view' ) {
1023
+        return $this->get_state( $context );
1024 1024
     }
1025 1025
 
1026 1026
     /**
1027
-	 * Alias of self::get_state().
1028
-	 *
1029
-	 * @since 1.0.19
1030
-	 * @param  string $context View or edit context.
1031
-	 * @return int
1032
-	 */
1033
-	public function get_customer_state( $context = 'view' ) {
1034
-		return $this->get_state( $context );
1027
+     * Alias of self::get_state().
1028
+     *
1029
+     * @since 1.0.19
1030
+     * @param  string $context View or edit context.
1031
+     * @return int
1032
+     */
1033
+    public function get_customer_state( $context = 'view' ) {
1034
+        return $this->get_state( $context );
1035 1035
     }
1036 1036
 
1037 1037
     /**
1038
-	 * Get the customer's city.
1039
-	 *
1040
-	 * @since 1.0.19
1041
-	 * @param  string $context View or edit context.
1042
-	 * @return string
1043
-	 */
1044
-	public function get_city( $context = 'view' ) {
1045
-		return $this->get_prop( 'city', $context );
1038
+     * Get the customer's city.
1039
+     *
1040
+     * @since 1.0.19
1041
+     * @param  string $context View or edit context.
1042
+     * @return string
1043
+     */
1044
+    public function get_city( $context = 'view' ) {
1045
+        return $this->get_prop( 'city', $context );
1046 1046
     }
1047 1047
 
1048 1048
     /**
1049
-	 * Alias of self::get_city().
1050
-	 *
1051
-	 * @since 1.0.19
1052
-	 * @param  string $context View or edit context.
1053
-	 * @return string
1054
-	 */
1055
-	public function get_user_city( $context = 'view' ) {
1056
-		return $this->get_city( $context );
1049
+     * Alias of self::get_city().
1050
+     *
1051
+     * @since 1.0.19
1052
+     * @param  string $context View or edit context.
1053
+     * @return string
1054
+     */
1055
+    public function get_user_city( $context = 'view' ) {
1056
+        return $this->get_city( $context );
1057 1057
     }
1058 1058
 
1059 1059
     /**
1060
-	 * Alias of self::get_city().
1061
-	 *
1062
-	 * @since 1.0.19
1063
-	 * @param  string $context View or edit context.
1064
-	 * @return string
1065
-	 */
1066
-	public function get_customer_city( $context = 'view' ) {
1067
-		return $this->get_city( $context );
1060
+     * Alias of self::get_city().
1061
+     *
1062
+     * @since 1.0.19
1063
+     * @param  string $context View or edit context.
1064
+     * @return string
1065
+     */
1066
+    public function get_customer_city( $context = 'view' ) {
1067
+        return $this->get_city( $context );
1068 1068
     }
1069 1069
 
1070 1070
     /**
1071
-	 * Get the customer's zip.
1072
-	 *
1073
-	 * @since 1.0.19
1074
-	 * @param  string $context View or edit context.
1075
-	 * @return string
1076
-	 */
1077
-	public function get_zip( $context = 'view' ) {
1078
-		return $this->get_prop( 'zip', $context );
1071
+     * Get the customer's zip.
1072
+     *
1073
+     * @since 1.0.19
1074
+     * @param  string $context View or edit context.
1075
+     * @return string
1076
+     */
1077
+    public function get_zip( $context = 'view' ) {
1078
+        return $this->get_prop( 'zip', $context );
1079 1079
     }
1080 1080
 
1081 1081
     /**
1082
-	 * Alias of self::get_zip().
1083
-	 *
1084
-	 * @since 1.0.19
1085
-	 * @param  string $context View or edit context.
1086
-	 * @return string
1087
-	 */
1088
-	public function get_user_zip( $context = 'view' ) {
1089
-		return $this->get_zip( $context );
1082
+     * Alias of self::get_zip().
1083
+     *
1084
+     * @since 1.0.19
1085
+     * @param  string $context View or edit context.
1086
+     * @return string
1087
+     */
1088
+    public function get_user_zip( $context = 'view' ) {
1089
+        return $this->get_zip( $context );
1090 1090
     }
1091 1091
 
1092 1092
     /**
1093
-	 * Alias of self::get_zip().
1094
-	 *
1095
-	 * @since 1.0.19
1096
-	 * @param  string $context View or edit context.
1097
-	 * @return string
1098
-	 */
1099
-	public function get_customer_zip( $context = 'view' ) {
1100
-		return $this->get_zip( $context );
1093
+     * Alias of self::get_zip().
1094
+     *
1095
+     * @since 1.0.19
1096
+     * @param  string $context View or edit context.
1097
+     * @return string
1098
+     */
1099
+    public function get_customer_zip( $context = 'view' ) {
1100
+        return $this->get_zip( $context );
1101 1101
     }
1102 1102
 
1103 1103
     /**
1104
-	 * Get the customer's company.
1105
-	 *
1106
-	 * @since 1.0.19
1107
-	 * @param  string $context View or edit context.
1108
-	 * @return string
1109
-	 */
1110
-	public function get_company( $context = 'view' ) {
1111
-		return $this->get_prop( 'company', $context );
1104
+     * Get the customer's company.
1105
+     *
1106
+     * @since 1.0.19
1107
+     * @param  string $context View or edit context.
1108
+     * @return string
1109
+     */
1110
+    public function get_company( $context = 'view' ) {
1111
+        return $this->get_prop( 'company', $context );
1112 1112
     }
1113 1113
 
1114 1114
     /**
1115
-	 * Alias of self::get_company().
1116
-	 *
1117
-	 * @since 1.0.19
1118
-	 * @param  string $context View or edit context.
1119
-	 * @return string
1120
-	 */
1121
-	public function get_user_company( $context = 'view' ) {
1122
-		return $this->get_company( $context );
1115
+     * Alias of self::get_company().
1116
+     *
1117
+     * @since 1.0.19
1118
+     * @param  string $context View or edit context.
1119
+     * @return string
1120
+     */
1121
+    public function get_user_company( $context = 'view' ) {
1122
+        return $this->get_company( $context );
1123 1123
     }
1124 1124
 
1125 1125
     /**
1126
-	 * Alias of self::get_company().
1127
-	 *
1128
-	 * @since 1.0.19
1129
-	 * @param  string $context View or edit context.
1130
-	 * @return string
1131
-	 */
1132
-	public function get_customer_company( $context = 'view' ) {
1133
-		return $this->get_company( $context );
1126
+     * Alias of self::get_company().
1127
+     *
1128
+     * @since 1.0.19
1129
+     * @param  string $context View or edit context.
1130
+     * @return string
1131
+     */
1132
+    public function get_customer_company( $context = 'view' ) {
1133
+        return $this->get_company( $context );
1134 1134
     }
1135 1135
 
1136 1136
     /**
1137
-	 * Get the customer's vat number.
1138
-	 *
1139
-	 * @since 1.0.19
1140
-	 * @param  string $context View or edit context.
1141
-	 * @return string
1142
-	 */
1143
-	public function get_vat_number( $context = 'view' ) {
1144
-		return $this->get_prop( 'vat_number', $context );
1137
+     * Get the customer's vat number.
1138
+     *
1139
+     * @since 1.0.19
1140
+     * @param  string $context View or edit context.
1141
+     * @return string
1142
+     */
1143
+    public function get_vat_number( $context = 'view' ) {
1144
+        return $this->get_prop( 'vat_number', $context );
1145 1145
     }
1146 1146
 
1147 1147
     /**
1148
-	 * Alias of self::get_vat_number().
1149
-	 *
1150
-	 * @since 1.0.19
1151
-	 * @param  string $context View or edit context.
1152
-	 * @return string
1153
-	 */
1154
-	public function get_user_vat_number( $context = 'view' ) {
1155
-		return $this->get_vat_number( $context );
1148
+     * Alias of self::get_vat_number().
1149
+     *
1150
+     * @since 1.0.19
1151
+     * @param  string $context View or edit context.
1152
+     * @return string
1153
+     */
1154
+    public function get_user_vat_number( $context = 'view' ) {
1155
+        return $this->get_vat_number( $context );
1156 1156
     }
1157 1157
 
1158 1158
     /**
1159
-	 * Alias of self::get_vat_number().
1160
-	 *
1161
-	 * @since 1.0.19
1162
-	 * @param  string $context View or edit context.
1163
-	 * @return string
1164
-	 */
1165
-	public function get_customer_vat_number( $context = 'view' ) {
1166
-		return $this->get_vat_number( $context );
1167
-    }
1168
-
1159
+     * Alias of self::get_vat_number().
1160
+     *
1161
+     * @since 1.0.19
1162
+     * @param  string $context View or edit context.
1163
+     * @return string
1164
+     */
1165
+    public function get_customer_vat_number( $context = 'view' ) {
1166
+        return $this->get_vat_number( $context );
1167
+    }
1168
+
1169
+    /**
1170
+     * Get the customer's vat rate.
1171
+     *
1172
+     * @since 1.0.19
1173
+     * @param  string $context View or edit context.
1174
+     * @return string
1175
+     */
1176
+    public function get_vat_rate( $context = 'view' ) {
1177
+        return $this->get_prop( 'vat_rate', $context );
1178
+    }
1179
+
1180
+    /**
1181
+     * Alias of self::get_vat_rate().
1182
+     *
1183
+     * @since 1.0.19
1184
+     * @param  string $context View or edit context.
1185
+     * @return string
1186
+     */
1187
+    public function get_user_vat_rate( $context = 'view' ) {
1188
+        return $this->get_vat_rate( $context );
1189
+    }
1190
+
1191
+    /**
1192
+     * Alias of self::get_vat_rate().
1193
+     *
1194
+     * @since 1.0.19
1195
+     * @param  string $context View or edit context.
1196
+     * @return string
1197
+     */
1198
+    public function get_customer_vat_rate( $context = 'view' ) {
1199
+        return $this->get_vat_rate( $context );
1200
+    }
1201
+
1169 1202
     /**
1170
-	 * Get the customer's vat rate.
1171
-	 *
1172
-	 * @since 1.0.19
1173
-	 * @param  string $context View or edit context.
1174
-	 * @return string
1175
-	 */
1176
-	public function get_vat_rate( $context = 'view' ) {
1177
-		return $this->get_prop( 'vat_rate', $context );
1203
+     * Get the customer's address.
1204
+     *
1205
+     * @since 1.0.19
1206
+     * @param  string $context View or edit context.
1207
+     * @return string
1208
+     */
1209
+    public function get_address( $context = 'view' ) {
1210
+        return $this->get_prop( 'address', $context );
1178 1211
     }
1179 1212
 
1180 1213
     /**
1181
-	 * Alias of self::get_vat_rate().
1182
-	 *
1183
-	 * @since 1.0.19
1184
-	 * @param  string $context View or edit context.
1185
-	 * @return string
1186
-	 */
1187
-	public function get_user_vat_rate( $context = 'view' ) {
1188
-		return $this->get_vat_rate( $context );
1214
+     * Alias of self::get_address().
1215
+     *
1216
+     * @since 1.0.19
1217
+     * @param  string $context View or edit context.
1218
+     * @return string
1219
+     */
1220
+    public function get_user_address( $context = 'view' ) {
1221
+        return $this->get_address( $context );
1189 1222
     }
1190 1223
 
1191 1224
     /**
1192
-	 * Alias of self::get_vat_rate().
1193
-	 *
1194
-	 * @since 1.0.19
1195
-	 * @param  string $context View or edit context.
1196
-	 * @return string
1197
-	 */
1198
-	public function get_customer_vat_rate( $context = 'view' ) {
1199
-		return $this->get_vat_rate( $context );
1225
+     * Alias of self::get_address().
1226
+     *
1227
+     * @since 1.0.19
1228
+     * @param  string $context View or edit context.
1229
+     * @return string
1230
+     */
1231
+    public function get_customer_address( $context = 'view' ) {
1232
+        return $this->get_address( $context );
1233
+    }
1234
+
1235
+    /**
1236
+     * Get whether the customer has viewed the invoice or not.
1237
+     *
1238
+     * @since 1.0.19
1239
+     * @param  string $context View or edit context.
1240
+     * @return bool
1241
+     */
1242
+    public function get_is_viewed( $context = 'view' ) {
1243
+        return (bool) $this->get_prop( 'is_viewed', $context );
1200 1244
     }
1201 1245
 
1202 1246
     /**
1203
-	 * Get the customer's address.
1204
-	 *
1205
-	 * @since 1.0.19
1206
-	 * @param  string $context View or edit context.
1207
-	 * @return string
1208
-	 */
1209
-	public function get_address( $context = 'view' ) {
1210
-		return $this->get_prop( 'address', $context );
1211
-    }
1212
-
1213
-    /**
1214
-	 * Alias of self::get_address().
1215
-	 *
1216
-	 * @since 1.0.19
1217
-	 * @param  string $context View or edit context.
1218
-	 * @return string
1219
-	 */
1220
-	public function get_user_address( $context = 'view' ) {
1221
-		return $this->get_address( $context );
1222
-    }
1223
-
1224
-    /**
1225
-	 * Alias of self::get_address().
1226
-	 *
1227
-	 * @since 1.0.19
1228
-	 * @param  string $context View or edit context.
1229
-	 * @return string
1230
-	 */
1231
-	public function get_customer_address( $context = 'view' ) {
1232
-		return $this->get_address( $context );
1233
-    }
1234
-
1235
-    /**
1236
-	 * Get whether the customer has viewed the invoice or not.
1237
-	 *
1238
-	 * @since 1.0.19
1239
-	 * @param  string $context View or edit context.
1240
-	 * @return bool
1241
-	 */
1242
-	public function get_is_viewed( $context = 'view' ) {
1243
-		return (bool) $this->get_prop( 'is_viewed', $context );
1244
-	}
1245
-
1246
-	/**
1247
-	 * Get other recipients for invoice communications.
1248
-	 *
1249
-	 * @since 1.0.19
1250
-	 * @param  string $context View or edit context.
1251
-	 * @return bool
1252
-	 */
1253
-	public function get_email_cc( $context = 'view' ) {
1254
-		return $this->get_prop( 'email_cc', $context );
1255
-	}
1256
-
1257
-	/**
1258
-	 * Get invoice template.
1259
-	 *
1260
-	 * @since 1.0.19
1261
-	 * @param  string $context View or edit context.
1262
-	 * @return bool
1263
-	 */
1264
-	public function get_template( $context = 'view' ) {
1265
-		return $this->get_prop( 'template', $context );
1266
-	}
1267
-
1268
-	/**
1269
-	 * Get whether the customer has confirmed their address.
1270
-	 *
1271
-	 * @since 1.0.19
1272
-	 * @param  string $context View or edit context.
1273
-	 * @return bool
1274
-	 */
1275
-	public function get_address_confirmed( $context = 'view' ) {
1276
-		return (bool) $this->get_prop( 'address_confirmed', $context );
1277
-    }
1278
-
1279
-    /**
1280
-	 * Alias of self::get_address_confirmed().
1281
-	 *
1282
-	 * @since 1.0.19
1283
-	 * @param  string $context View or edit context.
1284
-	 * @return bool
1285
-	 */
1286
-	public function get_user_address_confirmed( $context = 'view' ) {
1287
-		return $this->get_address_confirmed( $context );
1288
-    }
1289
-
1290
-    /**
1291
-	 * Alias of self::get_address().
1292
-	 *
1293
-	 * @since 1.0.19
1294
-	 * @param  string $context View or edit context.
1295
-	 * @return bool
1296
-	 */
1297
-	public function get_customer_address_confirmed( $context = 'view' ) {
1298
-		return $this->get_address_confirmed( $context );
1299
-    }
1300
-
1301
-    /**
1302
-	 * Get the invoice subtotal.
1303
-	 *
1304
-	 * @since 1.0.19
1305
-	 * @param  string $context View or edit context.
1306
-	 * @return float
1307
-	 */
1308
-	public function get_subtotal( $context = 'view' ) {
1247
+     * Get other recipients for invoice communications.
1248
+     *
1249
+     * @since 1.0.19
1250
+     * @param  string $context View or edit context.
1251
+     * @return bool
1252
+     */
1253
+    public function get_email_cc( $context = 'view' ) {
1254
+        return $this->get_prop( 'email_cc', $context );
1255
+    }
1256
+
1257
+    /**
1258
+     * Get invoice template.
1259
+     *
1260
+     * @since 1.0.19
1261
+     * @param  string $context View or edit context.
1262
+     * @return bool
1263
+     */
1264
+    public function get_template( $context = 'view' ) {
1265
+        return $this->get_prop( 'template', $context );
1266
+    }
1267
+
1268
+    /**
1269
+     * Get whether the customer has confirmed their address.
1270
+     *
1271
+     * @since 1.0.19
1272
+     * @param  string $context View or edit context.
1273
+     * @return bool
1274
+     */
1275
+    public function get_address_confirmed( $context = 'view' ) {
1276
+        return (bool) $this->get_prop( 'address_confirmed', $context );
1277
+    }
1278
+
1279
+    /**
1280
+     * Alias of self::get_address_confirmed().
1281
+     *
1282
+     * @since 1.0.19
1283
+     * @param  string $context View or edit context.
1284
+     * @return bool
1285
+     */
1286
+    public function get_user_address_confirmed( $context = 'view' ) {
1287
+        return $this->get_address_confirmed( $context );
1288
+    }
1289
+
1290
+    /**
1291
+     * Alias of self::get_address().
1292
+     *
1293
+     * @since 1.0.19
1294
+     * @param  string $context View or edit context.
1295
+     * @return bool
1296
+     */
1297
+    public function get_customer_address_confirmed( $context = 'view' ) {
1298
+        return $this->get_address_confirmed( $context );
1299
+    }
1300
+
1301
+    /**
1302
+     * Get the invoice subtotal.
1303
+     *
1304
+     * @since 1.0.19
1305
+     * @param  string $context View or edit context.
1306
+     * @return float
1307
+     */
1308
+    public function get_subtotal( $context = 'view' ) {
1309 1309
         $subtotal = (float) $this->get_prop( 'subtotal', $context );
1310 1310
 
1311 1311
         // Backwards compatibility.
@@ -1317,165 +1317,165 @@  discard block
 block discarded – undo
1317 1317
     }
1318 1318
 
1319 1319
     /**
1320
-	 * Get the invoice discount total.
1321
-	 *
1322
-	 * @since 1.0.19
1323
-	 * @param  string $context View or edit context.
1324
-	 * @return float
1325
-	 */
1326
-	public function get_total_discount( $context = 'view' ) {
1327
-		return (float) $this->get_prop( 'total_discount', $context );
1320
+     * Get the invoice discount total.
1321
+     *
1322
+     * @since 1.0.19
1323
+     * @param  string $context View or edit context.
1324
+     * @return float
1325
+     */
1326
+    public function get_total_discount( $context = 'view' ) {
1327
+        return (float) $this->get_prop( 'total_discount', $context );
1328 1328
     }
1329 1329
 
1330 1330
     /**
1331
-	 * Get the invoice tax total.
1332
-	 *
1333
-	 * @since 1.0.19
1334
-	 * @param  string $context View or edit context.
1335
-	 * @return float
1336
-	 */
1337
-	public function get_total_tax( $context = 'view' ) {
1338
-		return (float) $this->get_prop( 'total_tax', $context );
1339
-	}
1331
+     * Get the invoice tax total.
1332
+     *
1333
+     * @since 1.0.19
1334
+     * @param  string $context View or edit context.
1335
+     * @return float
1336
+     */
1337
+    public function get_total_tax( $context = 'view' ) {
1338
+        return (float) $this->get_prop( 'total_tax', $context );
1339
+    }
1340 1340
 
1341
-	/**
1342
-	 * @deprecated
1343
-	 */
1344
-	public function get_final_tax( $currency = false ) {
1345
-		$tax = $this->get_total_tax();
1341
+    /**
1342
+     * @deprecated
1343
+     */
1344
+    public function get_final_tax( $currency = false ) {
1345
+        $tax = $this->get_total_tax();
1346 1346
 
1347 1347
         if ( $currency ) {
1348
-			return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1348
+            return wpinv_price( wpinv_format_amount( $tax, NULL, false ), $this->get_currency() );
1349 1349
         }
1350 1350
 
1351 1351
         return $tax;
1352 1352
     }
1353 1353
 
1354 1354
     /**
1355
-	 * Get the invoice fees total.
1356
-	 *
1357
-	 * @since 1.0.19
1358
-	 * @param  string $context View or edit context.
1359
-	 * @return float
1360
-	 */
1361
-	public function get_total_fees( $context = 'view' ) {
1362
-		return (float) $this->get_prop( 'total_fees', $context );
1355
+     * Get the invoice fees total.
1356
+     *
1357
+     * @since 1.0.19
1358
+     * @param  string $context View or edit context.
1359
+     * @return float
1360
+     */
1361
+    public function get_total_fees( $context = 'view' ) {
1362
+        return (float) $this->get_prop( 'total_fees', $context );
1363 1363
     }
1364 1364
 
1365 1365
     /**
1366
-	 * Alias for self::get_total_fees().
1367
-	 *
1368
-	 * @since 1.0.19
1369
-	 * @param  string $context View or edit context.
1370
-	 * @return float
1371
-	 */
1372
-	public function get_fees_total( $context = 'view' ) {
1373
-		return $this->get_total_fees( $context );
1366
+     * Alias for self::get_total_fees().
1367
+     *
1368
+     * @since 1.0.19
1369
+     * @param  string $context View or edit context.
1370
+     * @return float
1371
+     */
1372
+    public function get_fees_total( $context = 'view' ) {
1373
+        return $this->get_total_fees( $context );
1374 1374
     }
1375 1375
 
1376 1376
     /**
1377
-	 * Get the invoice total.
1378
-	 *
1379
-	 * @since 1.0.19
1377
+     * Get the invoice total.
1378
+     *
1379
+     * @since 1.0.19
1380 1380
      * @return float
1381
-	 */
1382
-	public function get_total() {
1383
-		$total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1384
-		return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1385
-	}
1381
+     */
1382
+    public function get_total() {
1383
+        $total = $this->is_renewal() ? $this->get_recurring_total() : $this->get_initial_total();
1384
+        return apply_filters( 'getpaid_get_invoice_total_amount', $total, $this  );
1385
+    }
1386 1386
 	
1387
-	/**
1388
-	 * Get the invoice totals.
1389
-	 *
1390
-	 * @since 1.0.19
1387
+    /**
1388
+     * Get the invoice totals.
1389
+     *
1390
+     * @since 1.0.19
1391 1391
      * @return float
1392
-	 */
1393
-	public function get_totals() {
1394
-		return $this->totals;
1392
+     */
1393
+    public function get_totals() {
1394
+        return $this->totals;
1395 1395
     }
1396 1396
 
1397 1397
     /**
1398
-	 * Get the initial invoice total.
1399
-	 *
1400
-	 * @since 1.0.19
1398
+     * Get the initial invoice total.
1399
+     *
1400
+     * @since 1.0.19
1401 1401
      * @param  string $context View or edit context.
1402 1402
      * @return float
1403
-	 */
1403
+     */
1404 1404
     public function get_initial_total() {
1405 1405
 
1406
-		if ( empty( $this->totals ) ) {
1407
-			$this->recalculate_total();
1408
-		}
1406
+        if ( empty( $this->totals ) ) {
1407
+            $this->recalculate_total();
1408
+        }
1409 1409
 
1410
-		$tax      = $this->totals['tax']['initial'];
1411
-		$fee      = $this->totals['fee']['initial'];
1412
-		$discount = $this->totals['discount']['initial'];
1413
-		$subtotal = $this->totals['subtotal']['initial'];
1414
-		$total    = $tax + $fee - $discount + $subtotal;
1410
+        $tax      = $this->totals['tax']['initial'];
1411
+        $fee      = $this->totals['fee']['initial'];
1412
+        $discount = $this->totals['discount']['initial'];
1413
+        $subtotal = $this->totals['subtotal']['initial'];
1414
+        $total    = $tax + $fee - $discount + $subtotal;
1415 1415
 
1416
-		if ( 0 > $total ) {
1417
-			$total = 0;
1418
-		}
1416
+        if ( 0 > $total ) {
1417
+            $total = 0;
1418
+        }
1419 1419
 
1420 1420
         return apply_filters( 'wpinv_get_initial_invoice_total', $total, $this );
1421
-	}
1421
+    }
1422 1422
 
1423
-	/**
1424
-	 * Get the recurring invoice total.
1425
-	 *
1426
-	 * @since 1.0.19
1423
+    /**
1424
+     * Get the recurring invoice total.
1425
+     *
1426
+     * @since 1.0.19
1427 1427
      * @param  string $context View or edit context.
1428 1428
      * @return float
1429
-	 */
1429
+     */
1430 1430
     public function get_recurring_total() {
1431 1431
 
1432
-		if ( empty( $this->totals ) ) {
1433
-			$this->recalculate_total();
1434
-		}
1432
+        if ( empty( $this->totals ) ) {
1433
+            $this->recalculate_total();
1434
+        }
1435 1435
 
1436
-		$tax      = $this->totals['tax']['recurring'];
1437
-		$fee      = $this->totals['fee']['recurring'];
1438
-		$discount = $this->totals['discount']['recurring'];
1439
-		$subtotal = $this->totals['subtotal']['recurring'];
1440
-		$total    = $tax + $fee - $discount + $subtotal;
1436
+        $tax      = $this->totals['tax']['recurring'];
1437
+        $fee      = $this->totals['fee']['recurring'];
1438
+        $discount = $this->totals['discount']['recurring'];
1439
+        $subtotal = $this->totals['subtotal']['recurring'];
1440
+        $total    = $tax + $fee - $discount + $subtotal;
1441 1441
 
1442
-		if ( 0 > $total ) {
1443
-			$total = 0;
1444
-		}
1442
+        if ( 0 > $total ) {
1443
+            $total = 0;
1444
+        }
1445 1445
 
1446 1446
         return apply_filters( 'wpinv_get_recurring_invoice_total', $total, $this );
1447
-	}
1447
+    }
1448 1448
 
1449
-	/**
1450
-	 * Returns recurring payment details.
1451
-	 *
1452
-	 * @since 1.0.19
1449
+    /**
1450
+     * Returns recurring payment details.
1451
+     *
1452
+     * @since 1.0.19
1453 1453
      * @param  string $field Optionally provide a field to return.
1454
-	 * @param string $currency Whether to include the currency.
1454
+     * @param string $currency Whether to include the currency.
1455 1455
      * @return float
1456
-	 */
1456
+     */
1457 1457
     public function get_recurring_details( $field = '', $currency = false ) {
1458 1458
 
1459
-		// Maybe recalculate totals.
1460
-		if ( empty( $this->totals ) ) {
1461
-			$this->recalculate_total();
1462
-		}
1459
+        // Maybe recalculate totals.
1460
+        if ( empty( $this->totals ) ) {
1461
+            $this->recalculate_total();
1462
+        }
1463 1463
 
1464
-		// Prepare recurring totals.
1464
+        // Prepare recurring totals.
1465 1465
         $data = apply_filters(
1466
-			'wpinv_get_invoice_recurring_details',
1467
-			array(
1468
-				'cart_details' => $this->get_cart_details(),
1469
-				'subtotal'     => $this->totals['subtotal']['recurring'],
1470
-				'discount'     => $this->totals['discount']['recurring'],
1471
-				'tax'          => $this->totals['tax']['recurring'],
1472
-				'fee'          => $this->totals['fee']['recurring'],
1473
-				'total'        => $this->get_recurring_total(),
1474
-			),
1475
-			$this,
1476
-			$field,
1477
-			$currency
1478
-		);
1466
+            'wpinv_get_invoice_recurring_details',
1467
+            array(
1468
+                'cart_details' => $this->get_cart_details(),
1469
+                'subtotal'     => $this->totals['subtotal']['recurring'],
1470
+                'discount'     => $this->totals['discount']['recurring'],
1471
+                'tax'          => $this->totals['tax']['recurring'],
1472
+                'fee'          => $this->totals['fee']['recurring'],
1473
+                'total'        => $this->get_recurring_total(),
1474
+            ),
1475
+            $this,
1476
+            $field,
1477
+            $currency
1478
+        );
1479 1479
 
1480 1480
         if ( isset( $data[$field] ) ) {
1481 1481
             return ( $currency ? wpinv_price( $data[$field], $this->get_currency() ) : $data[$field] );
@@ -1485,145 +1485,145 @@  discard block
 block discarded – undo
1485 1485
     }
1486 1486
 
1487 1487
     /**
1488
-	 * Get the invoice fees.
1489
-	 *
1490
-	 * @since 1.0.19
1491
-	 * @param  string $context View or edit context.
1492
-	 * @return array
1493
-	 */
1494
-	public function get_fees( $context = 'view' ) {
1495
-		return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1488
+     * Get the invoice fees.
1489
+     *
1490
+     * @since 1.0.19
1491
+     * @param  string $context View or edit context.
1492
+     * @return array
1493
+     */
1494
+    public function get_fees( $context = 'view' ) {
1495
+        return wpinv_parse_list( $this->get_prop( 'fees', $context ) );
1496 1496
     }
1497 1497
 
1498 1498
     /**
1499
-	 * Get the invoice discounts.
1500
-	 *
1501
-	 * @since 1.0.19
1502
-	 * @param  string $context View or edit context.
1503
-	 * @return array
1504
-	 */
1505
-	public function get_discounts( $context = 'view' ) {
1506
-		return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1499
+     * Get the invoice discounts.
1500
+     *
1501
+     * @since 1.0.19
1502
+     * @param  string $context View or edit context.
1503
+     * @return array
1504
+     */
1505
+    public function get_discounts( $context = 'view' ) {
1506
+        return wpinv_parse_list( $this->get_prop( 'discounts', $context ) );
1507 1507
     }
1508 1508
 
1509 1509
     /**
1510
-	 * Get the invoice taxes.
1511
-	 *
1512
-	 * @since 1.0.19
1513
-	 * @param  string $context View or edit context.
1514
-	 * @return array
1515
-	 */
1516
-	public function get_taxes( $context = 'view' ) {
1517
-		return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1510
+     * Get the invoice taxes.
1511
+     *
1512
+     * @since 1.0.19
1513
+     * @param  string $context View or edit context.
1514
+     * @return array
1515
+     */
1516
+    public function get_taxes( $context = 'view' ) {
1517
+        return wpinv_parse_list( $this->get_prop( 'taxes', $context ) );
1518 1518
     }
1519 1519
 
1520 1520
     /**
1521
-	 * Get the invoice items.
1522
-	 *
1523
-	 * @since 1.0.19
1524
-	 * @param  string $context View or edit context.
1525
-	 * @return GetPaid_Form_Item[]
1526
-	 */
1527
-	public function get_items( $context = 'view' ) {
1521
+     * Get the invoice items.
1522
+     *
1523
+     * @since 1.0.19
1524
+     * @param  string $context View or edit context.
1525
+     * @return GetPaid_Form_Item[]
1526
+     */
1527
+    public function get_items( $context = 'view' ) {
1528 1528
         return $this->get_prop( 'items', $context );
1529 1529
     }
1530 1530
 
1531 1531
     /**
1532
-	 * Get the invoice's payment form.
1533
-	 *
1534
-	 * @since 1.0.19
1535
-	 * @param  string $context View or edit context.
1536
-	 * @return int
1537
-	 */
1538
-	public function get_payment_form( $context = 'view' ) {
1539
-		return intval( $this->get_prop( 'payment_form', $context ) );
1532
+     * Get the invoice's payment form.
1533
+     *
1534
+     * @since 1.0.19
1535
+     * @param  string $context View or edit context.
1536
+     * @return int
1537
+     */
1538
+    public function get_payment_form( $context = 'view' ) {
1539
+        return intval( $this->get_prop( 'payment_form', $context ) );
1540 1540
     }
1541 1541
 
1542 1542
     /**
1543
-	 * Get the invoice's submission id.
1544
-	 *
1545
-	 * @since 1.0.19
1546
-	 * @param  string $context View or edit context.
1547
-	 * @return string
1548
-	 */
1549
-	public function get_submission_id( $context = 'view' ) {
1550
-		return $this->get_prop( 'submission_id', $context );
1543
+     * Get the invoice's submission id.
1544
+     *
1545
+     * @since 1.0.19
1546
+     * @param  string $context View or edit context.
1547
+     * @return string
1548
+     */
1549
+    public function get_submission_id( $context = 'view' ) {
1550
+        return $this->get_prop( 'submission_id', $context );
1551 1551
     }
1552 1552
 
1553 1553
     /**
1554
-	 * Get the invoice's discount code.
1555
-	 *
1556
-	 * @since 1.0.19
1557
-	 * @param  string $context View or edit context.
1558
-	 * @return string
1559
-	 */
1560
-	public function get_discount_code( $context = 'view' ) {
1561
-		return $this->get_prop( 'discount_code', $context );
1554
+     * Get the invoice's discount code.
1555
+     *
1556
+     * @since 1.0.19
1557
+     * @param  string $context View or edit context.
1558
+     * @return string
1559
+     */
1560
+    public function get_discount_code( $context = 'view' ) {
1561
+        return $this->get_prop( 'discount_code', $context );
1562 1562
     }
1563 1563
 
1564 1564
     /**
1565
-	 * Get the invoice's gateway.
1566
-	 *
1567
-	 * @since 1.0.19
1568
-	 * @param  string $context View or edit context.
1569
-	 * @return string
1570
-	 */
1571
-	public function get_gateway( $context = 'view' ) {
1572
-		return $this->get_prop( 'gateway', $context );
1565
+     * Get the invoice's gateway.
1566
+     *
1567
+     * @since 1.0.19
1568
+     * @param  string $context View or edit context.
1569
+     * @return string
1570
+     */
1571
+    public function get_gateway( $context = 'view' ) {
1572
+        return $this->get_prop( 'gateway', $context );
1573 1573
     }
1574 1574
 
1575 1575
     /**
1576
-	 * Get the invoice's gateway display title.
1577
-	 *
1578
-	 * @since 1.0.19
1579
-	 * @return string
1580
-	 */
1576
+     * Get the invoice's gateway display title.
1577
+     *
1578
+     * @since 1.0.19
1579
+     * @return string
1580
+     */
1581 1581
     public function get_gateway_title() {
1582 1582
         $title =  wpinv_get_gateway_checkout_label( $this->get_gateway() );
1583 1583
         return apply_filters( 'wpinv_gateway_title', $title, $this->get_id(), $this );
1584 1584
     }
1585 1585
 
1586 1586
     /**
1587
-	 * Get the invoice's transaction id.
1588
-	 *
1589
-	 * @since 1.0.19
1590
-	 * @param  string $context View or edit context.
1591
-	 * @return string
1592
-	 */
1593
-	public function get_transaction_id( $context = 'view' ) {
1594
-		return $this->get_prop( 'transaction_id', $context );
1587
+     * Get the invoice's transaction id.
1588
+     *
1589
+     * @since 1.0.19
1590
+     * @param  string $context View or edit context.
1591
+     * @return string
1592
+     */
1593
+    public function get_transaction_id( $context = 'view' ) {
1594
+        return $this->get_prop( 'transaction_id', $context );
1595 1595
     }
1596 1596
 
1597 1597
     /**
1598
-	 * Get the invoice's currency.
1599
-	 *
1600
-	 * @since 1.0.19
1601
-	 * @param  string $context View or edit context.
1602
-	 * @return string
1603
-	 */
1604
-	public function get_currency( $context = 'view' ) {
1598
+     * Get the invoice's currency.
1599
+     *
1600
+     * @since 1.0.19
1601
+     * @param  string $context View or edit context.
1602
+     * @return string
1603
+     */
1604
+    public function get_currency( $context = 'view' ) {
1605 1605
         $currency = $this->get_prop( 'currency', $context );
1606 1606
         return empty( $currency ) ? wpinv_get_currency() : $currency;
1607 1607
     }
1608 1608
 
1609 1609
     /**
1610
-	 * Checks if we are charging taxes for this invoice.
1611
-	 *
1612
-	 * @since 1.0.19
1613
-	 * @param  string $context View or edit context.
1614
-	 * @return bool
1615
-	 */
1616
-	public function get_disable_taxes( $context = 'view' ) {
1610
+     * Checks if we are charging taxes for this invoice.
1611
+     *
1612
+     * @since 1.0.19
1613
+     * @param  string $context View or edit context.
1614
+     * @return bool
1615
+     */
1616
+    public function get_disable_taxes( $context = 'view' ) {
1617 1617
         return (bool) $this->get_prop( 'disable_taxes', $context );
1618 1618
     }
1619 1619
 
1620 1620
     /**
1621
-	 * Retrieves the remote subscription id for an invoice.
1622
-	 *
1623
-	 * @since 1.0.19
1624
-	 * @param  string $context View or edit context.
1625
-	 * @return int
1626
-	 */
1621
+     * Retrieves the remote subscription id for an invoice.
1622
+     *
1623
+     * @since 1.0.19
1624
+     * @param  string $context View or edit context.
1625
+     * @return int
1626
+     */
1627 1627
     public function get_subscription_id( $context = 'view' ) {
1628 1628
         $subscription_id = $this->get_prop( 'subscription_id', $context );
1629 1629
 
@@ -1636,12 +1636,12 @@  discard block
 block discarded – undo
1636 1636
     }
1637 1637
 
1638 1638
     /**
1639
-	 * Retrieves the payment meta for an invoice.
1640
-	 *
1641
-	 * @since 1.0.19
1642
-	 * @param  string $context View or edit context.
1643
-	 * @return array
1644
-	 */
1639
+     * Retrieves the payment meta for an invoice.
1640
+     *
1641
+     * @since 1.0.19
1642
+     * @param  string $context View or edit context.
1643
+     * @return array
1644
+     */
1645 1645
     public function get_payment_meta( $context = 'view' ) {
1646 1646
 
1647 1647
         return array(
@@ -1661,11 +1661,11 @@  discard block
 block discarded – undo
1661 1661
     }
1662 1662
 
1663 1663
     /**
1664
-	 * Retrieves the cart details for an invoice.
1665
-	 *
1666
-	 * @since 1.0.19
1667
-	 * @return array
1668
-	 */
1664
+     * Retrieves the cart details for an invoice.
1665
+     *
1666
+     * @since 1.0.19
1667
+     * @return array
1668
+     */
1669 1669
     public function get_cart_details() {
1670 1670
         $items        = $this->get_items();
1671 1671
         $cart_details = array();
@@ -1675,16 +1675,16 @@  discard block
 block discarded – undo
1675 1675
         }
1676 1676
 
1677 1677
         return $cart_details;
1678
-	}
1678
+    }
1679 1679
 
1680
-	/**
1681
-	 * Retrieves the recurring item.
1682
-	 *
1683
-	 * @return null|GetPaid_Form_Item|int
1684
-	 */
1685
-	public function get_recurring( $object = false ) {
1680
+    /**
1681
+     * Retrieves the recurring item.
1682
+     *
1683
+     * @return null|GetPaid_Form_Item|int
1684
+     */
1685
+    public function get_recurring( $object = false ) {
1686 1686
 
1687
-		// Are we returning an object?
1687
+        // Are we returning an object?
1688 1688
         if ( $object ) {
1689 1689
             return $this->get_item( $this->recurring_item );
1690 1690
         }
@@ -1692,100 +1692,100 @@  discard block
 block discarded – undo
1692 1692
         return $this->recurring_item;
1693 1693
     }
1694 1694
 
1695
-	/**
1696
-	 * Retrieves the subscription name.
1697
-	 *
1698
-	 * @since 1.0.19
1699
-	 * @return string
1700
-	 */
1701
-	public function get_subscription_name() {
1695
+    /**
1696
+     * Retrieves the subscription name.
1697
+     *
1698
+     * @since 1.0.19
1699
+     * @return string
1700
+     */
1701
+    public function get_subscription_name() {
1702 1702
 
1703
-		// Retrieve the recurring name
1703
+        // Retrieve the recurring name
1704 1704
         $item = $this->get_recurring( true );
1705 1705
 
1706
-		// Abort if it does not exist.
1706
+        // Abort if it does not exist.
1707 1707
         if ( empty( $item ) ) {
1708 1708
             return '';
1709 1709
         }
1710 1710
 
1711
-		// Return the item name.
1711
+        // Return the item name.
1712 1712
         return apply_filters( 'wpinv_invoice_get_subscription_name', $item->get_name(), $this );
1713
-	}
1714
-
1715
-	/**
1716
-	 * Retrieves the view url.
1717
-	 *
1718
-	 * @since 1.0.19
1719
-	 * @return string
1720
-	 */
1721
-	public function get_view_url() {
1713
+    }
1714
+
1715
+    /**
1716
+     * Retrieves the view url.
1717
+     *
1718
+     * @since 1.0.19
1719
+     * @return string
1720
+     */
1721
+    public function get_view_url() {
1722 1722
         $invoice_url = get_permalink( $this->get_id() );
1723
-		$invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1723
+        $invoice_url = add_query_arg( 'invoice_key', $this->get_key(), $invoice_url );
1724 1724
         return apply_filters( 'wpinv_get_view_url', $invoice_url, $this );
1725
-	}
1725
+    }
1726 1726
 
1727
-	/**
1728
-	 * Retrieves the payment url.
1729
-	 *
1730
-	 * @since 1.0.19
1731
-	 * @return string
1732
-	 */
1733
-	public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1727
+    /**
1728
+     * Retrieves the payment url.
1729
+     *
1730
+     * @since 1.0.19
1731
+     * @return string
1732
+     */
1733
+    public function get_checkout_payment_url( $deprecated = false, $secret = false ) {
1734 1734
 
1735
-		// Retrieve the checkout url.
1735
+        // Retrieve the checkout url.
1736 1736
         $pay_url = wpinv_get_checkout_uri();
1737 1737
 
1738
-		// Maybe force ssl.
1738
+        // Maybe force ssl.
1739 1739
         if ( is_ssl() ) {
1740 1740
             $pay_url = str_replace( 'http:', 'https:', $pay_url );
1741 1741
         }
1742 1742
 
1743
-		// Add the invoice key.
1744
-		$pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1743
+        // Add the invoice key.
1744
+        $pay_url = add_query_arg( 'invoice_key', $this->get_key(), $pay_url );
1745 1745
 
1746
-		// (Maybe?) add a secret
1746
+        // (Maybe?) add a secret
1747 1747
         if ( $secret ) {
1748 1748
             $pay_url = add_query_arg( array( '_wpipay' => md5( $this->get_user_id() . '::' . $this->get_email() . '::' . $this->get_key() ) ), $pay_url );
1749 1749
         }
1750 1750
 
1751 1751
         return apply_filters( 'wpinv_get_checkout_payment_url', $pay_url, $this, $deprecated, $secret );
1752
-	}
1752
+    }
1753 1753
 	
1754
-	/**
1755
-	 * Retrieves the receipt url.
1756
-	 *
1757
-	 * @since 1.0.19
1758
-	 * @return string
1759
-	 */
1760
-	public function get_receipt_url() {
1761
-
1762
-		// Retrieve the checkout url.
1754
+    /**
1755
+     * Retrieves the receipt url.
1756
+     *
1757
+     * @since 1.0.19
1758
+     * @return string
1759
+     */
1760
+    public function get_receipt_url() {
1761
+
1762
+        // Retrieve the checkout url.
1763 1763
         $receipt_url = wpinv_get_success_page_uri();
1764 1764
 
1765
-		// Maybe force ssl.
1765
+        // Maybe force ssl.
1766 1766
         if ( is_ssl() ) {
1767 1767
             $receipt_url = str_replace( 'http:', 'https:', $receipt_url );
1768 1768
         }
1769 1769
 
1770
-		// Add the invoice key.
1771
-		$receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1770
+        // Add the invoice key.
1771
+        $receipt_url = add_query_arg( 'invoice_key', $this->get_key(), $receipt_url );
1772 1772
 
1773 1773
         return apply_filters( 'getpaid_get_invoice_receipt_url', $receipt_url, $this );
1774 1774
     }
1775 1775
 
1776 1776
     /**
1777
-	 * Magic method for accessing invoice properties.
1778
-	 *
1779
-	 * @since 1.0.15
1780
-	 * @access public
1781
-	 *
1782
-	 * @param string $key Discount data to retrieve
1783
-	 * @param  string $context View or edit context.
1784
-	 * @return mixed Value of the given invoice property (if set).
1785
-	 */
1786
-	public function get( $key, $context = 'view' ) {
1777
+     * Magic method for accessing invoice properties.
1778
+     *
1779
+     * @since 1.0.15
1780
+     * @access public
1781
+     *
1782
+     * @param string $key Discount data to retrieve
1783
+     * @param  string $context View or edit context.
1784
+     * @return mixed Value of the given invoice property (if set).
1785
+     */
1786
+    public function get( $key, $context = 'view' ) {
1787 1787
         return $this->get_prop( $key, $context );
1788
-	}
1788
+    }
1789 1789
 
1790 1790
     /*
1791 1791
 	|--------------------------------------------------------------------------
@@ -1798,130 +1798,130 @@  discard block
 block discarded – undo
1798 1798
     */
1799 1799
 
1800 1800
     /**
1801
-	 * Magic method for setting invoice properties.
1802
-	 *
1803
-	 * @since 1.0.19
1804
-	 * @access public
1805
-	 *
1806
-	 * @param string $key Discount data to retrieve
1807
-	 * @param  mixed $value new value.
1808
-	 * @return mixed Value of the given invoice property (if set).
1809
-	 */
1810
-	public function set( $key, $value ) {
1801
+     * Magic method for setting invoice properties.
1802
+     *
1803
+     * @since 1.0.19
1804
+     * @access public
1805
+     *
1806
+     * @param string $key Discount data to retrieve
1807
+     * @param  mixed $value new value.
1808
+     * @return mixed Value of the given invoice property (if set).
1809
+     */
1810
+    public function set( $key, $value ) {
1811 1811
 
1812 1812
         $setter = "set_$key";
1813 1813
         if ( is_callable( array( $this, $setter ) ) ) {
1814 1814
             $this->{$setter}( $value );
1815 1815
         }
1816 1816
 
1817
-	}
1817
+    }
1818 1818
 
1819
-	/**
1820
-	 * Sets item status.
1821
-	 *
1822
-	 * @since 1.0.19
1823
-	 * @param string $new_status    New status.
1824
-	 * @param string $note          Optional note to add.
1825
-	 * @param bool   $manual_update Is this a manual status change?.
1826
-	 * @return array details of change.
1827
-	 */
1828
-	public function set_status( $new_status, $note = '', $manual_update = false ) {
1829
-		$old_status = $this->get_status();
1819
+    /**
1820
+     * Sets item status.
1821
+     *
1822
+     * @since 1.0.19
1823
+     * @param string $new_status    New status.
1824
+     * @param string $note          Optional note to add.
1825
+     * @param bool   $manual_update Is this a manual status change?.
1826
+     * @return array details of change.
1827
+     */
1828
+    public function set_status( $new_status, $note = '', $manual_update = false ) {
1829
+        $old_status = $this->get_status();
1830 1830
 
1831
-		$statuses = $this->get_all_statuses();
1831
+        $statuses = $this->get_all_statuses();
1832 1832
 
1833
-		if ( isset( $statuses[ 'draft' ] ) ) {
1834
-			unset( $statuses[ 'draft' ] );
1835
-		}
1833
+        if ( isset( $statuses[ 'draft' ] ) ) {
1834
+            unset( $statuses[ 'draft' ] );
1835
+        }
1836 1836
 
1837
-		$this->set_prop( 'status', $new_status );
1837
+        $this->set_prop( 'status', $new_status );
1838 1838
 
1839
-		// If setting the status, ensure it's set to a valid status.
1840
-		if ( true === $this->object_read ) {
1839
+        // If setting the status, ensure it's set to a valid status.
1840
+        if ( true === $this->object_read ) {
1841 1841
 
1842
-			// Only allow valid new status.
1843
-			if ( ! array_key_exists( $new_status, $statuses ) ) {
1844
-				$new_status = 'wpi-pending';
1845
-			}
1842
+            // Only allow valid new status.
1843
+            if ( ! array_key_exists( $new_status, $statuses ) ) {
1844
+                $new_status = 'wpi-pending';
1845
+            }
1846 1846
 
1847
-			// If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1848
-			if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1849
-				$old_status = 'wpi-pending';
1850
-			}
1847
+            // If the old status is set but unknown (e.g. draft) assume its pending for action usage.
1848
+            if ( $old_status && ! array_key_exists( $new_status, $statuses ) ) {
1849
+                $old_status = 'wpi-pending';
1850
+            }
1851 1851
 
1852
-			// Paid - Renewal (i.e when duplicating a parent invoice )
1853
-			if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1854
-				$old_status = 'wpi-pending';
1855
-			}
1852
+            // Paid - Renewal (i.e when duplicating a parent invoice )
1853
+            if ( $new_status == 'wpi-pending' && $old_status == 'publish' && ! $this->get_id() ) {
1854
+                $old_status = 'wpi-pending';
1855
+            }
1856 1856
 
1857
-		}
1857
+        }
1858 1858
 
1859
-		if ( true === $this->object_read && $old_status !== $new_status ) {
1860
-			$this->status_transition = array(
1861
-				'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1862
-				'to'     => $new_status,
1863
-				'note'   => $note,
1864
-				'manual' => (bool) $manual_update,
1865
-			);
1859
+        if ( true === $this->object_read && $old_status !== $new_status ) {
1860
+            $this->status_transition = array(
1861
+                'from'   => ! empty( $this->status_transition['from'] ) ? $this->status_transition['from'] : $old_status,
1862
+                'to'     => $new_status,
1863
+                'note'   => $note,
1864
+                'manual' => (bool) $manual_update,
1865
+            );
1866 1866
 
1867
-			if ( $manual_update ) {
1868
-				do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1869
-			}
1867
+            if ( $manual_update ) {
1868
+                do_action( 'getpaid_' . $this->object_type .'_edit_status', $this->get_id(), $new_status );
1869
+            }
1870 1870
 
1871
-			$this->maybe_set_date_paid();
1871
+            $this->maybe_set_date_paid();
1872 1872
 
1873
-		}
1873
+        }
1874 1874
 
1875
-		return array(
1876
-			'from' => $old_status,
1877
-			'to'   => $new_status,
1878
-		);
1879
-	}
1875
+        return array(
1876
+            'from' => $old_status,
1877
+            'to'   => $new_status,
1878
+        );
1879
+    }
1880 1880
 
1881
-	/**
1882
-	 * Maybe set date paid.
1883
-	 *
1884
-	 * Sets the date paid variable when transitioning to the payment complete
1885
-	 * order status.
1886
-	 *
1887
-	 * @since 1.0.19
1888
-	 */
1889
-	public function maybe_set_date_paid() {
1881
+    /**
1882
+     * Maybe set date paid.
1883
+     *
1884
+     * Sets the date paid variable when transitioning to the payment complete
1885
+     * order status.
1886
+     *
1887
+     * @since 1.0.19
1888
+     */
1889
+    public function maybe_set_date_paid() {
1890 1890
 
1891
-		if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1892
-			$this->set_date_completed( current_time( 'mysql' ) );
1893
-		}
1894
-	}
1891
+        if ( ! $this->get_date_completed( 'edit' ) && $this->is_paid() ) {
1892
+            $this->set_date_completed( current_time( 'mysql' ) );
1893
+        }
1894
+    }
1895 1895
 
1896 1896
     /**
1897
-	 * Set parent invoice ID.
1898
-	 *
1899
-	 * @since 1.0.19
1900
-	 */
1901
-	public function set_parent_id( $value ) {
1902
-		if ( $value && ( $value === $this->get_id() ) ) {
1903
-			return;
1904
-		}
1905
-		$this->set_prop( 'parent_id', absint( $value ) );
1897
+     * Set parent invoice ID.
1898
+     *
1899
+     * @since 1.0.19
1900
+     */
1901
+    public function set_parent_id( $value ) {
1902
+        if ( $value && ( $value === $this->get_id() ) ) {
1903
+            return;
1904
+        }
1905
+        $this->set_prop( 'parent_id', absint( $value ) );
1906 1906
     }
1907 1907
 
1908 1908
     /**
1909
-	 * Set plugin version when the invoice was created.
1910
-	 *
1911
-	 * @since 1.0.19
1912
-	 */
1913
-	public function set_version( $value ) {
1914
-		$this->set_prop( 'version', $value );
1909
+     * Set plugin version when the invoice was created.
1910
+     *
1911
+     * @since 1.0.19
1912
+     */
1913
+    public function set_version( $value ) {
1914
+        $this->set_prop( 'version', $value );
1915 1915
     }
1916
-
1917
-    /**
1918
-	 * Set date when the invoice was created.
1919
-	 *
1920
-	 * @since 1.0.19
1921
-	 * @param string $value Value to set.
1916
+
1917
+    /**
1918
+     * Set date when the invoice was created.
1919
+     *
1920
+     * @since 1.0.19
1921
+     * @param string $value Value to set.
1922 1922
      * @return bool Whether or not the date was set.
1923
-	 */
1924
-	public function set_date_created( $value ) {
1923
+     */
1924
+    public function set_date_created( $value ) {
1925 1925
         $date = strtotime( $value );
1926 1926
 
1927 1927
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1934,13 +1934,13 @@  discard block
 block discarded – undo
1934 1934
     }
1935 1935
 
1936 1936
     /**
1937
-	 * Set date invoice due date.
1938
-	 *
1939
-	 * @since 1.0.19
1940
-	 * @param string $value Value to set.
1937
+     * Set date invoice due date.
1938
+     *
1939
+     * @since 1.0.19
1940
+     * @param string $value Value to set.
1941 1941
      * @return bool Whether or not the date was set.
1942
-	 */
1943
-	public function set_due_date( $value ) {
1942
+     */
1943
+    public function set_due_date( $value ) {
1944 1944
         $date = strtotime( $value );
1945 1945
 
1946 1946
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -1948,29 +1948,29 @@  discard block
 block discarded – undo
1948 1948
             return true;
1949 1949
         }
1950 1950
 
1951
-		$this->set_prop( 'due_date', '' );
1951
+        $this->set_prop( 'due_date', '' );
1952 1952
         return false;
1953 1953
 
1954 1954
     }
1955 1955
 
1956 1956
     /**
1957
-	 * Alias of self::set_due_date().
1958
-	 *
1959
-	 * @since 1.0.19
1960
-	 * @param  string $value New name.
1961
-	 */
1962
-	public function set_date_due( $value ) {
1963
-		$this->set_due_date( $value );
1957
+     * Alias of self::set_due_date().
1958
+     *
1959
+     * @since 1.0.19
1960
+     * @param  string $value New name.
1961
+     */
1962
+    public function set_date_due( $value ) {
1963
+        $this->set_due_date( $value );
1964 1964
     }
1965 1965
 
1966 1966
     /**
1967
-	 * Set date invoice was completed.
1968
-	 *
1969
-	 * @since 1.0.19
1970
-	 * @param string $value Value to set.
1967
+     * Set date invoice was completed.
1968
+     *
1969
+     * @since 1.0.19
1970
+     * @param string $value Value to set.
1971 1971
      * @return bool Whether or not the date was set.
1972
-	 */
1973
-	public function set_completed_date( $value ) {
1972
+     */
1973
+    public function set_completed_date( $value ) {
1974 1974
         $date = strtotime( $value );
1975 1975
 
1976 1976
         if ( $date && $value !== '0000-00-00 00:00:00'  ) {
@@ -1978,29 +1978,29 @@  discard block
 block discarded – undo
1978 1978
             return true;
1979 1979
         }
1980 1980
 
1981
-		$this->set_prop( 'completed_date', '' );
1981
+        $this->set_prop( 'completed_date', '' );
1982 1982
         return false;
1983 1983
 
1984 1984
     }
1985 1985
 
1986 1986
     /**
1987
-	 * Alias of self::set_completed_date().
1988
-	 *
1989
-	 * @since 1.0.19
1990
-	 * @param  string $value New name.
1991
-	 */
1992
-	public function set_date_completed( $value ) {
1993
-		$this->set_completed_date( $value );
1987
+     * Alias of self::set_completed_date().
1988
+     *
1989
+     * @since 1.0.19
1990
+     * @param  string $value New name.
1991
+     */
1992
+    public function set_date_completed( $value ) {
1993
+        $this->set_completed_date( $value );
1994 1994
     }
1995 1995
 
1996 1996
     /**
1997
-	 * Set date when the invoice was last modified.
1998
-	 *
1999
-	 * @since 1.0.19
2000
-	 * @param string $value Value to set.
1997
+     * Set date when the invoice was last modified.
1998
+     *
1999
+     * @since 1.0.19
2000
+     * @param string $value Value to set.
2001 2001
      * @return bool Whether or not the date was set.
2002
-	 */
2003
-	public function set_date_modified( $value ) {
2002
+     */
2003
+    public function set_date_modified( $value ) {
2004 2004
         $date = strtotime( $value );
2005 2005
 
2006 2006
         if ( $date && $value !== '0000-00-00 00:00:00' ) {
@@ -2008,706 +2008,706 @@  discard block
 block discarded – undo
2008 2008
             return true;
2009 2009
         }
2010 2010
 
2011
-		$this->set_prop( 'date_modified', '' );
2011
+        $this->set_prop( 'date_modified', '' );
2012 2012
         return false;
2013 2013
 
2014 2014
     }
2015 2015
 
2016 2016
     /**
2017
-	 * Set the invoice number.
2018
-	 *
2019
-	 * @since 1.0.19
2020
-	 * @param  string $value New number.
2021
-	 */
2022
-	public function set_number( $value ) {
2017
+     * Set the invoice number.
2018
+     *
2019
+     * @since 1.0.19
2020
+     * @param  string $value New number.
2021
+     */
2022
+    public function set_number( $value ) {
2023 2023
         $number = sanitize_text_field( $value );
2024
-		$this->set_prop( 'number', $number );
2024
+        $this->set_prop( 'number', $number );
2025 2025
     }
2026 2026
 
2027 2027
     /**
2028
-	 * Set the invoice type.
2029
-	 *
2030
-	 * @since 1.0.19
2031
-	 * @param  string $value Type.
2032
-	 */
2033
-	public function set_type( $value ) {
2028
+     * Set the invoice type.
2029
+     *
2030
+     * @since 1.0.19
2031
+     * @param  string $value Type.
2032
+     */
2033
+    public function set_type( $value ) {
2034 2034
         $type = sanitize_text_field( str_replace( 'wpi_', '', $value ) );
2035
-		$this->set_prop( 'type', $type );
2036
-	}
2035
+        $this->set_prop( 'type', $type );
2036
+    }
2037 2037
 
2038 2038
     /**
2039
-	 * Set the invoice post type.
2040
-	 *
2041
-	 * @since 1.0.19
2042
-	 * @param  string $value Post type.
2043
-	 */
2044
-	public function set_post_type( $value ) {
2039
+     * Set the invoice post type.
2040
+     *
2041
+     * @since 1.0.19
2042
+     * @param  string $value Post type.
2043
+     */
2044
+    public function set_post_type( $value ) {
2045 2045
         if ( getpaid_is_invoice_post_type( $value ) ) {
2046
-			$this->set_type( $value );
2046
+            $this->set_type( $value );
2047 2047
             $this->set_prop( 'post_type', $value );
2048 2048
         }
2049 2049
     }
2050 2050
 
2051 2051
     /**
2052
-	 * Set the invoice key.
2053
-	 *
2054
-	 * @since 1.0.19
2055
-	 * @param  string $value New key.
2056
-	 */
2057
-	public function set_key( $value ) {
2052
+     * Set the invoice key.
2053
+     *
2054
+     * @since 1.0.19
2055
+     * @param  string $value New key.
2056
+     */
2057
+    public function set_key( $value ) {
2058 2058
         $key = sanitize_text_field( $value );
2059
-		$this->set_prop( 'key', $key );
2059
+        $this->set_prop( 'key', $key );
2060 2060
     }
2061 2061
 
2062 2062
     /**
2063
-	 * Set the invoice mode.
2064
-	 *
2065
-	 * @since 1.0.19
2066
-	 * @param  string $value mode.
2067
-	 */
2068
-	public function set_mode( $value ) {
2063
+     * Set the invoice mode.
2064
+     *
2065
+     * @since 1.0.19
2066
+     * @param  string $value mode.
2067
+     */
2068
+    public function set_mode( $value ) {
2069 2069
         if ( ! in_array( $value, array( 'live', 'test' ) ) ) {
2070 2070
             $this->set_prop( 'value', $value );
2071 2071
         }
2072 2072
     }
2073 2073
 
2074 2074
     /**
2075
-	 * Set the invoice path.
2076
-	 *
2077
-	 * @since 1.0.19
2078
-	 * @param  string $value path.
2079
-	 */
2080
-	public function set_path( $value ) {
2075
+     * Set the invoice path.
2076
+     *
2077
+     * @since 1.0.19
2078
+     * @param  string $value path.
2079
+     */
2080
+    public function set_path( $value ) {
2081 2081
         $this->set_prop( 'path', $value );
2082 2082
     }
2083 2083
 
2084 2084
     /**
2085
-	 * Set the invoice name.
2086
-	 *
2087
-	 * @since 1.0.19
2088
-	 * @param  string $value New name.
2089
-	 */
2090
-	public function set_name( $value ) {
2085
+     * Set the invoice name.
2086
+     *
2087
+     * @since 1.0.19
2088
+     * @param  string $value New name.
2089
+     */
2090
+    public function set_name( $value ) {
2091 2091
         $name = sanitize_text_field( $value );
2092
-		$this->set_prop( 'name', $name );
2092
+        $this->set_prop( 'name', $name );
2093 2093
     }
2094 2094
 
2095 2095
     /**
2096
-	 * Alias of self::set_name().
2097
-	 *
2098
-	 * @since 1.0.19
2099
-	 * @param  string $value New name.
2100
-	 */
2101
-	public function set_title( $value ) {
2102
-		$this->set_name( $value );
2096
+     * Alias of self::set_name().
2097
+     *
2098
+     * @since 1.0.19
2099
+     * @param  string $value New name.
2100
+     */
2101
+    public function set_title( $value ) {
2102
+        $this->set_name( $value );
2103 2103
     }
2104 2104
 
2105 2105
     /**
2106
-	 * Set the invoice description.
2107
-	 *
2108
-	 * @since 1.0.19
2109
-	 * @param  string $value New description.
2110
-	 */
2111
-	public function set_description( $value ) {
2106
+     * Set the invoice description.
2107
+     *
2108
+     * @since 1.0.19
2109
+     * @param  string $value New description.
2110
+     */
2111
+    public function set_description( $value ) {
2112 2112
         $description = wp_kses_post( $value );
2113
-		return $this->set_prop( 'description', $description );
2113
+        return $this->set_prop( 'description', $description );
2114 2114
     }
2115 2115
 
2116 2116
     /**
2117
-	 * Alias of self::set_description().
2118
-	 *
2119
-	 * @since 1.0.19
2120
-	 * @param  string $value New description.
2121
-	 */
2122
-	public function set_excerpt( $value ) {
2123
-		$this->set_description( $value );
2117
+     * Alias of self::set_description().
2118
+     *
2119
+     * @since 1.0.19
2120
+     * @param  string $value New description.
2121
+     */
2122
+    public function set_excerpt( $value ) {
2123
+        $this->set_description( $value );
2124 2124
     }
2125 2125
 
2126 2126
     /**
2127
-	 * Alias of self::set_description().
2128
-	 *
2129
-	 * @since 1.0.19
2130
-	 * @param  string $value New description.
2131
-	 */
2132
-	public function set_summary( $value ) {
2133
-		$this->set_description( $value );
2127
+     * Alias of self::set_description().
2128
+     *
2129
+     * @since 1.0.19
2130
+     * @param  string $value New description.
2131
+     */
2132
+    public function set_summary( $value ) {
2133
+        $this->set_description( $value );
2134 2134
     }
2135 2135
 
2136 2136
     /**
2137
-	 * Set the receiver of the invoice.
2138
-	 *
2139
-	 * @since 1.0.19
2140
-	 * @param  int $value New author.
2141
-	 */
2142
-	public function set_author( $value ) {
2143
-		$user = get_user_by( 'id', (int) $value );
2137
+     * Set the receiver of the invoice.
2138
+     *
2139
+     * @since 1.0.19
2140
+     * @param  int $value New author.
2141
+     */
2142
+    public function set_author( $value ) {
2143
+        $user = get_user_by( 'id', (int) $value );
2144 2144
 
2145
-		if ( $user && $user->ID ) {
2146
-			$this->set_prop( 'author', $user->ID );
2147
-			$this->set_prop( 'email', $user->user_email );
2148
-		}
2145
+        if ( $user && $user->ID ) {
2146
+            $this->set_prop( 'author', $user->ID );
2147
+            $this->set_prop( 'email', $user->user_email );
2148
+        }
2149 2149
 		
2150 2150
     }
2151 2151
 
2152 2152
     /**
2153
-	 * Alias of self::set_author().
2154
-	 *
2155
-	 * @since 1.0.19
2156
-	 * @param  int $value New user id.
2157
-	 */
2158
-	public function set_user_id( $value ) {
2159
-		$this->set_author( $value );
2153
+     * Alias of self::set_author().
2154
+     *
2155
+     * @since 1.0.19
2156
+     * @param  int $value New user id.
2157
+     */
2158
+    public function set_user_id( $value ) {
2159
+        $this->set_author( $value );
2160
+    }
2161
+
2162
+    /**
2163
+     * Alias of self::set_author().
2164
+     *
2165
+     * @since 1.0.19
2166
+     * @param  int $value New user id.
2167
+     */
2168
+    public function set_customer_id( $value ) {
2169
+        $this->set_author( $value );
2170
+    }
2171
+
2172
+    /**
2173
+     * Set the customer's ip.
2174
+     *
2175
+     * @since 1.0.19
2176
+     * @param  string $value ip address.
2177
+     */
2178
+    public function set_ip( $value ) {
2179
+        $this->set_prop( 'ip', $value );
2160 2180
     }
2161 2181
 
2162 2182
     /**
2163
-	 * Alias of self::set_author().
2164
-	 *
2165
-	 * @since 1.0.19
2166
-	 * @param  int $value New user id.
2167
-	 */
2168
-	public function set_customer_id( $value ) {
2169
-		$this->set_author( $value );
2183
+     * Alias of self::set_ip().
2184
+     *
2185
+     * @since 1.0.19
2186
+     * @param  string $value ip address.
2187
+     */
2188
+    public function set_user_ip( $value ) {
2189
+        $this->set_ip( $value );
2170 2190
     }
2171 2191
 
2172 2192
     /**
2173
-	 * Set the customer's ip.
2174
-	 *
2175
-	 * @since 1.0.19
2176
-	 * @param  string $value ip address.
2177
-	 */
2178
-	public function set_ip( $value ) {
2179
-		$this->set_prop( 'ip', $value );
2193
+     * Set the customer's first name.
2194
+     *
2195
+     * @since 1.0.19
2196
+     * @param  string $value first name.
2197
+     */
2198
+    public function set_first_name( $value ) {
2199
+        $this->set_prop( 'first_name', $value );
2180 2200
     }
2181 2201
 
2182 2202
     /**
2183
-	 * Alias of self::set_ip().
2184
-	 *
2185
-	 * @since 1.0.19
2186
-	 * @param  string $value ip address.
2187
-	 */
2188
-	public function set_user_ip( $value ) {
2189
-		$this->set_ip( $value );
2203
+     * Alias of self::set_first_name().
2204
+     *
2205
+     * @since 1.0.19
2206
+     * @param  string $value first name.
2207
+     */
2208
+    public function set_user_first_name( $value ) {
2209
+        $this->set_first_name( $value );
2190 2210
     }
2191 2211
 
2192 2212
     /**
2193
-	 * Set the customer's first name.
2194
-	 *
2195
-	 * @since 1.0.19
2196
-	 * @param  string $value first name.
2197
-	 */
2198
-	public function set_first_name( $value ) {
2199
-		$this->set_prop( 'first_name', $value );
2213
+     * Alias of self::set_first_name().
2214
+     *
2215
+     * @since 1.0.19
2216
+     * @param  string $value first name.
2217
+     */
2218
+    public function set_customer_first_name( $value ) {
2219
+        $this->set_first_name( $value );
2200 2220
     }
2201 2221
 
2202 2222
     /**
2203
-	 * Alias of self::set_first_name().
2204
-	 *
2205
-	 * @since 1.0.19
2206
-	 * @param  string $value first name.
2207
-	 */
2208
-	public function set_user_first_name( $value ) {
2209
-		$this->set_first_name( $value );
2223
+     * Set the customer's last name.
2224
+     *
2225
+     * @since 1.0.19
2226
+     * @param  string $value last name.
2227
+     */
2228
+    public function set_last_name( $value ) {
2229
+        $this->set_prop( 'last_name', $value );
2210 2230
     }
2211 2231
 
2212 2232
     /**
2213
-	 * Alias of self::set_first_name().
2214
-	 *
2215
-	 * @since 1.0.19
2216
-	 * @param  string $value first name.
2217
-	 */
2218
-	public function set_customer_first_name( $value ) {
2219
-		$this->set_first_name( $value );
2233
+     * Alias of self::set_last_name().
2234
+     *
2235
+     * @since 1.0.19
2236
+     * @param  string $value last name.
2237
+     */
2238
+    public function set_user_last_name( $value ) {
2239
+        $this->set_last_name( $value );
2220 2240
     }
2221 2241
 
2222 2242
     /**
2223
-	 * Set the customer's last name.
2224
-	 *
2225
-	 * @since 1.0.19
2226
-	 * @param  string $value last name.
2227
-	 */
2228
-	public function set_last_name( $value ) {
2229
-		$this->set_prop( 'last_name', $value );
2243
+     * Alias of self::set_last_name().
2244
+     *
2245
+     * @since 1.0.19
2246
+     * @param  string $value last name.
2247
+     */
2248
+    public function set_customer_last_name( $value ) {
2249
+        $this->set_last_name( $value );
2230 2250
     }
2231 2251
 
2232 2252
     /**
2233
-	 * Alias of self::set_last_name().
2234
-	 *
2235
-	 * @since 1.0.19
2236
-	 * @param  string $value last name.
2237
-	 */
2238
-	public function set_user_last_name( $value ) {
2239
-		$this->set_last_name( $value );
2253
+     * Set the customer's phone number.
2254
+     *
2255
+     * @since 1.0.19
2256
+     * @param  string $value phone.
2257
+     */
2258
+    public function set_phone( $value ) {
2259
+        $this->set_prop( 'phone', $value );
2240 2260
     }
2241 2261
 
2242 2262
     /**
2243
-	 * Alias of self::set_last_name().
2244
-	 *
2245
-	 * @since 1.0.19
2246
-	 * @param  string $value last name.
2247
-	 */
2248
-	public function set_customer_last_name( $value ) {
2249
-		$this->set_last_name( $value );
2263
+     * Alias of self::set_phone().
2264
+     *
2265
+     * @since 1.0.19
2266
+     * @param  string $value phone.
2267
+     */
2268
+    public function set_user_phone( $value ) {
2269
+        $this->set_phone( $value );
2270
+    }
2271
+
2272
+    /**
2273
+     * Alias of self::set_phone().
2274
+     *
2275
+     * @since 1.0.19
2276
+     * @param  string $value phone.
2277
+     */
2278
+    public function set_customer_phone( $value ) {
2279
+        $this->set_phone( $value );
2250 2280
     }
2251 2281
 
2252 2282
     /**
2253
-	 * Set the customer's phone number.
2254
-	 *
2255
-	 * @since 1.0.19
2256
-	 * @param  string $value phone.
2257
-	 */
2258
-	public function set_phone( $value ) {
2259
-		$this->set_prop( 'phone', $value );
2283
+     * Alias of self::set_phone().
2284
+     *
2285
+     * @since 1.0.19
2286
+     * @param  string $value phone.
2287
+     */
2288
+    public function set_phone_number( $value ) {
2289
+        $this->set_phone( $value );
2260 2290
     }
2261 2291
 
2262 2292
     /**
2263
-	 * Alias of self::set_phone().
2264
-	 *
2265
-	 * @since 1.0.19
2266
-	 * @param  string $value phone.
2267
-	 */
2268
-	public function set_user_phone( $value ) {
2269
-		$this->set_phone( $value );
2293
+     * Set the customer's email address.
2294
+     *
2295
+     * @since 1.0.19
2296
+     * @param  string $value email address.
2297
+     */
2298
+    public function set_email( $value ) {
2299
+        $this->set_prop( 'email', $value );
2270 2300
     }
2271 2301
 
2272 2302
     /**
2273
-	 * Alias of self::set_phone().
2274
-	 *
2275
-	 * @since 1.0.19
2276
-	 * @param  string $value phone.
2277
-	 */
2278
-	public function set_customer_phone( $value ) {
2279
-		$this->set_phone( $value );
2303
+     * Alias of self::set_email().
2304
+     *
2305
+     * @since 1.0.19
2306
+     * @param  string $value email address.
2307
+     */
2308
+    public function set_user_email( $value ) {
2309
+        $this->set_email( $value );
2280 2310
     }
2281 2311
 
2282 2312
     /**
2283
-	 * Alias of self::set_phone().
2284
-	 *
2285
-	 * @since 1.0.19
2286
-	 * @param  string $value phone.
2287
-	 */
2288
-	public function set_phone_number( $value ) {
2289
-		$this->set_phone( $value );
2313
+     * Alias of self::set_email().
2314
+     *
2315
+     * @since 1.0.19
2316
+     * @param  string $value email address.
2317
+     */
2318
+    public function set_email_address( $value ) {
2319
+        $this->set_email( $value );
2290 2320
     }
2291 2321
 
2292 2322
     /**
2293
-	 * Set the customer's email address.
2294
-	 *
2295
-	 * @since 1.0.19
2296
-	 * @param  string $value email address.
2297
-	 */
2298
-	public function set_email( $value ) {
2299
-		$this->set_prop( 'email', $value );
2323
+     * Alias of self::set_email().
2324
+     *
2325
+     * @since 1.0.19
2326
+     * @param  string $value email address.
2327
+     */
2328
+    public function set_customer_email( $value ) {
2329
+        $this->set_email( $value );
2300 2330
     }
2301 2331
 
2302 2332
     /**
2303
-	 * Alias of self::set_email().
2304
-	 *
2305
-	 * @since 1.0.19
2306
-	 * @param  string $value email address.
2307
-	 */
2308
-	public function set_user_email( $value ) {
2309
-		$this->set_email( $value );
2333
+     * Set the customer's country.
2334
+     *
2335
+     * @since 1.0.19
2336
+     * @param  string $value country.
2337
+     */
2338
+    public function set_country( $value ) {
2339
+        $this->set_prop( 'country', $value );
2310 2340
     }
2311 2341
 
2312 2342
     /**
2313
-	 * Alias of self::set_email().
2314
-	 *
2315
-	 * @since 1.0.19
2316
-	 * @param  string $value email address.
2317
-	 */
2318
-	public function set_email_address( $value ) {
2319
-		$this->set_email( $value );
2343
+     * Alias of self::set_country().
2344
+     *
2345
+     * @since 1.0.19
2346
+     * @param  string $value country.
2347
+     */
2348
+    public function set_user_country( $value ) {
2349
+        $this->set_country( $value );
2320 2350
     }
2321 2351
 
2322 2352
     /**
2323
-	 * Alias of self::set_email().
2324
-	 *
2325
-	 * @since 1.0.19
2326
-	 * @param  string $value email address.
2327
-	 */
2328
-	public function set_customer_email( $value ) {
2329
-		$this->set_email( $value );
2353
+     * Alias of self::set_country().
2354
+     *
2355
+     * @since 1.0.19
2356
+     * @param  string $value country.
2357
+     */
2358
+    public function set_customer_country( $value ) {
2359
+        $this->set_country( $value );
2330 2360
     }
2331 2361
 
2332 2362
     /**
2333
-	 * Set the customer's country.
2334
-	 *
2335
-	 * @since 1.0.19
2336
-	 * @param  string $value country.
2337
-	 */
2338
-	public function set_country( $value ) {
2339
-		$this->set_prop( 'country', $value );
2363
+     * Set the customer's state.
2364
+     *
2365
+     * @since 1.0.19
2366
+     * @param  string $value state.
2367
+     */
2368
+    public function set_state( $value ) {
2369
+        $this->set_prop( 'state', $value );
2340 2370
     }
2341 2371
 
2342 2372
     /**
2343
-	 * Alias of self::set_country().
2344
-	 *
2345
-	 * @since 1.0.19
2346
-	 * @param  string $value country.
2347
-	 */
2348
-	public function set_user_country( $value ) {
2349
-		$this->set_country( $value );
2373
+     * Alias of self::set_state().
2374
+     *
2375
+     * @since 1.0.19
2376
+     * @param  string $value state.
2377
+     */
2378
+    public function set_user_state( $value ) {
2379
+        $this->set_state( $value );
2350 2380
     }
2351 2381
 
2352 2382
     /**
2353
-	 * Alias of self::set_country().
2354
-	 *
2355
-	 * @since 1.0.19
2356
-	 * @param  string $value country.
2357
-	 */
2358
-	public function set_customer_country( $value ) {
2359
-		$this->set_country( $value );
2383
+     * Alias of self::set_state().
2384
+     *
2385
+     * @since 1.0.19
2386
+     * @param  string $value state.
2387
+     */
2388
+    public function set_customer_state( $value ) {
2389
+        $this->set_state( $value );
2360 2390
     }
2361 2391
 
2362 2392
     /**
2363
-	 * Set the customer's state.
2364
-	 *
2365
-	 * @since 1.0.19
2366
-	 * @param  string $value state.
2367
-	 */
2368
-	public function set_state( $value ) {
2369
-		$this->set_prop( 'state', $value );
2393
+     * Set the customer's city.
2394
+     *
2395
+     * @since 1.0.19
2396
+     * @param  string $value city.
2397
+     */
2398
+    public function set_city( $value ) {
2399
+        $this->set_prop( 'city', $value );
2370 2400
     }
2371 2401
 
2372 2402
     /**
2373
-	 * Alias of self::set_state().
2374
-	 *
2375
-	 * @since 1.0.19
2376
-	 * @param  string $value state.
2377
-	 */
2378
-	public function set_user_state( $value ) {
2379
-		$this->set_state( $value );
2403
+     * Alias of self::set_city().
2404
+     *
2405
+     * @since 1.0.19
2406
+     * @param  string $value city.
2407
+     */
2408
+    public function set_user_city( $value ) {
2409
+        $this->set_city( $value );
2380 2410
     }
2381 2411
 
2382 2412
     /**
2383
-	 * Alias of self::set_state().
2384
-	 *
2385
-	 * @since 1.0.19
2386
-	 * @param  string $value state.
2387
-	 */
2388
-	public function set_customer_state( $value ) {
2389
-		$this->set_state( $value );
2413
+     * Alias of self::set_city().
2414
+     *
2415
+     * @since 1.0.19
2416
+     * @param  string $value city.
2417
+     */
2418
+    public function set_customer_city( $value ) {
2419
+        $this->set_city( $value );
2390 2420
     }
2391 2421
 
2392 2422
     /**
2393
-	 * Set the customer's city.
2394
-	 *
2395
-	 * @since 1.0.19
2396
-	 * @param  string $value city.
2397
-	 */
2398
-	public function set_city( $value ) {
2399
-		$this->set_prop( 'city', $value );
2423
+     * Set the customer's zip code.
2424
+     *
2425
+     * @since 1.0.19
2426
+     * @param  string $value zip.
2427
+     */
2428
+    public function set_zip( $value ) {
2429
+        $this->set_prop( 'zip', $value );
2400 2430
     }
2401 2431
 
2402 2432
     /**
2403
-	 * Alias of self::set_city().
2404
-	 *
2405
-	 * @since 1.0.19
2406
-	 * @param  string $value city.
2407
-	 */
2408
-	public function set_user_city( $value ) {
2409
-		$this->set_city( $value );
2433
+     * Alias of self::set_zip().
2434
+     *
2435
+     * @since 1.0.19
2436
+     * @param  string $value zip.
2437
+     */
2438
+    public function set_user_zip( $value ) {
2439
+        $this->set_zip( $value );
2410 2440
     }
2411 2441
 
2412 2442
     /**
2413
-	 * Alias of self::set_city().
2414
-	 *
2415
-	 * @since 1.0.19
2416
-	 * @param  string $value city.
2417
-	 */
2418
-	public function set_customer_city( $value ) {
2419
-		$this->set_city( $value );
2443
+     * Alias of self::set_zip().
2444
+     *
2445
+     * @since 1.0.19
2446
+     * @param  string $value zip.
2447
+     */
2448
+    public function set_customer_zip( $value ) {
2449
+        $this->set_zip( $value );
2420 2450
     }
2421 2451
 
2422 2452
     /**
2423
-	 * Set the customer's zip code.
2424
-	 *
2425
-	 * @since 1.0.19
2426
-	 * @param  string $value zip.
2427
-	 */
2428
-	public function set_zip( $value ) {
2429
-		$this->set_prop( 'zip', $value );
2453
+     * Set the customer's company.
2454
+     *
2455
+     * @since 1.0.19
2456
+     * @param  string $value company.
2457
+     */
2458
+    public function set_company( $value ) {
2459
+        $this->set_prop( 'company', $value );
2430 2460
     }
2431 2461
 
2432 2462
     /**
2433
-	 * Alias of self::set_zip().
2434
-	 *
2435
-	 * @since 1.0.19
2436
-	 * @param  string $value zip.
2437
-	 */
2438
-	public function set_user_zip( $value ) {
2439
-		$this->set_zip( $value );
2463
+     * Alias of self::set_company().
2464
+     *
2465
+     * @since 1.0.19
2466
+     * @param  string $value company.
2467
+     */
2468
+    public function set_user_company( $value ) {
2469
+        $this->set_company( $value );
2440 2470
     }
2441 2471
 
2442 2472
     /**
2443
-	 * Alias of self::set_zip().
2444
-	 *
2445
-	 * @since 1.0.19
2446
-	 * @param  string $value zip.
2447
-	 */
2448
-	public function set_customer_zip( $value ) {
2449
-		$this->set_zip( $value );
2473
+     * Alias of self::set_company().
2474
+     *
2475
+     * @since 1.0.19
2476
+     * @param  string $value company.
2477
+     */
2478
+    public function set_customer_company( $value ) {
2479
+        $this->set_company( $value );
2450 2480
     }
2451 2481
 
2452 2482
     /**
2453
-	 * Set the customer's company.
2454
-	 *
2455
-	 * @since 1.0.19
2456
-	 * @param  string $value company.
2457
-	 */
2458
-	public function set_company( $value ) {
2459
-		$this->set_prop( 'company', $value );
2483
+     * Set the customer's var number.
2484
+     *
2485
+     * @since 1.0.19
2486
+     * @param  string $value var number.
2487
+     */
2488
+    public function set_vat_number( $value ) {
2489
+        $this->set_prop( 'vat_number', $value );
2460 2490
     }
2461 2491
 
2462 2492
     /**
2463
-	 * Alias of self::set_company().
2464
-	 *
2465
-	 * @since 1.0.19
2466
-	 * @param  string $value company.
2467
-	 */
2468
-	public function set_user_company( $value ) {
2469
-		$this->set_company( $value );
2493
+     * Alias of self::set_vat_number().
2494
+     *
2495
+     * @since 1.0.19
2496
+     * @param  string $value var number.
2497
+     */
2498
+    public function set_user_vat_number( $value ) {
2499
+        $this->set_vat_number( $value );
2470 2500
     }
2471 2501
 
2472 2502
     /**
2473
-	 * Alias of self::set_company().
2474
-	 *
2475
-	 * @since 1.0.19
2476
-	 * @param  string $value company.
2477
-	 */
2478
-	public function set_customer_company( $value ) {
2479
-		$this->set_company( $value );
2503
+     * Alias of self::set_vat_number().
2504
+     *
2505
+     * @since 1.0.19
2506
+     * @param  string $value var number.
2507
+     */
2508
+    public function set_customer_vat_number( $value ) {
2509
+        $this->set_vat_number( $value );
2480 2510
     }
2481 2511
 
2482 2512
     /**
2483
-	 * Set the customer's var number.
2484
-	 *
2485
-	 * @since 1.0.19
2486
-	 * @param  string $value var number.
2487
-	 */
2488
-	public function set_vat_number( $value ) {
2489
-		$this->set_prop( 'vat_number', $value );
2513
+     * Set the customer's vat rate.
2514
+     *
2515
+     * @since 1.0.19
2516
+     * @param  string $value var rate.
2517
+     */
2518
+    public function set_vat_rate( $value ) {
2519
+        $this->set_prop( 'vat_rate', $value );
2490 2520
     }
2491 2521
 
2492 2522
     /**
2493
-	 * Alias of self::set_vat_number().
2494
-	 *
2495
-	 * @since 1.0.19
2496
-	 * @param  string $value var number.
2497
-	 */
2498
-	public function set_user_vat_number( $value ) {
2499
-		$this->set_vat_number( $value );
2523
+     * Alias of self::set_vat_rate().
2524
+     *
2525
+     * @since 1.0.19
2526
+     * @param  string $value var number.
2527
+     */
2528
+    public function set_user_vat_rate( $value ) {
2529
+        $this->set_vat_rate( $value );
2500 2530
     }
2501 2531
 
2502 2532
     /**
2503
-	 * Alias of self::set_vat_number().
2504
-	 *
2505
-	 * @since 1.0.19
2506
-	 * @param  string $value var number.
2507
-	 */
2508
-	public function set_customer_vat_number( $value ) {
2509
-		$this->set_vat_number( $value );
2533
+     * Alias of self::set_vat_rate().
2534
+     *
2535
+     * @since 1.0.19
2536
+     * @param  string $value var number.
2537
+     */
2538
+    public function set_customer_vat_rate( $value ) {
2539
+        $this->set_vat_rate( $value );
2510 2540
     }
2511 2541
 
2512 2542
     /**
2513
-	 * Set the customer's vat rate.
2514
-	 *
2515
-	 * @since 1.0.19
2516
-	 * @param  string $value var rate.
2517
-	 */
2518
-	public function set_vat_rate( $value ) {
2519
-		$this->set_prop( 'vat_rate', $value );
2543
+     * Set the customer's address.
2544
+     *
2545
+     * @since 1.0.19
2546
+     * @param  string $value address.
2547
+     */
2548
+    public function set_address( $value ) {
2549
+        $this->set_prop( 'address', $value );
2520 2550
     }
2521 2551
 
2522 2552
     /**
2523
-	 * Alias of self::set_vat_rate().
2524
-	 *
2525
-	 * @since 1.0.19
2526
-	 * @param  string $value var number.
2527
-	 */
2528
-	public function set_user_vat_rate( $value ) {
2529
-		$this->set_vat_rate( $value );
2553
+     * Alias of self::set_address().
2554
+     *
2555
+     * @since 1.0.19
2556
+     * @param  string $value address.
2557
+     */
2558
+    public function set_user_address( $value ) {
2559
+        $this->set_address( $value );
2530 2560
     }
2531 2561
 
2532 2562
     /**
2533
-	 * Alias of self::set_vat_rate().
2534
-	 *
2535
-	 * @since 1.0.19
2536
-	 * @param  string $value var number.
2537
-	 */
2538
-	public function set_customer_vat_rate( $value ) {
2539
-		$this->set_vat_rate( $value );
2563
+     * Alias of self::set_address().
2564
+     *
2565
+     * @since 1.0.19
2566
+     * @param  string $value address.
2567
+     */
2568
+    public function set_customer_address( $value ) {
2569
+        $this->set_address( $value );
2540 2570
     }
2541 2571
 
2542 2572
     /**
2543
-	 * Set the customer's address.
2544
-	 *
2545
-	 * @since 1.0.19
2546
-	 * @param  string $value address.
2547
-	 */
2548
-	public function set_address( $value ) {
2549
-		$this->set_prop( 'address', $value );
2573
+     * Set whether the customer has viewed the invoice or not.
2574
+     *
2575
+     * @since 1.0.19
2576
+     * @param  int|bool $value confirmed.
2577
+     */
2578
+    public function set_is_viewed( $value ) {
2579
+        $this->set_prop( 'is_viewed', $value );
2550 2580
     }
2551 2581
 
2552 2582
     /**
2553
-	 * Alias of self::set_address().
2554
-	 *
2555
-	 * @since 1.0.19
2556
-	 * @param  string $value address.
2557
-	 */
2558
-	public function set_user_address( $value ) {
2559
-		$this->set_address( $value );
2583
+     * Set extra email recipients.
2584
+     *
2585
+     * @since 1.0.19
2586
+     * @param  string $value email recipients.
2587
+     */
2588
+    public function set_email_cc( $value ) {
2589
+        $this->set_prop( 'email_cc', $value );
2560 2590
     }
2561 2591
 
2562 2592
     /**
2563
-	 * Alias of self::set_address().
2564
-	 *
2565
-	 * @since 1.0.19
2566
-	 * @param  string $value address.
2567
-	 */
2568
-	public function set_customer_address( $value ) {
2569
-		$this->set_address( $value );
2593
+     * Set the invoice template.
2594
+     *
2595
+     * @since 1.0.19
2596
+     * @param  string $value email recipients.
2597
+     */
2598
+    public function set_template( $value ) {
2599
+        if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2600
+            $this->set_prop( 'template', $value );
2601
+        }
2570 2602
     }
2571 2603
 
2572 2604
     /**
2573
-	 * Set whether the customer has viewed the invoice or not.
2574
-	 *
2575
-	 * @since 1.0.19
2576
-	 * @param  int|bool $value confirmed.
2577
-	 */
2578
-	public function set_is_viewed( $value ) {
2579
-		$this->set_prop( 'is_viewed', $value );
2580
-	}
2581
-
2582
-	/**
2583
-	 * Set extra email recipients.
2584
-	 *
2585
-	 * @since 1.0.19
2586
-	 * @param  string $value email recipients.
2587
-	 */
2588
-	public function set_email_cc( $value ) {
2589
-		$this->set_prop( 'email_cc', $value );
2590
-	}
2591
-
2592
-	/**
2593
-	 * Set the invoice template.
2594
-	 *
2595
-	 * @since 1.0.19
2596
-	 * @param  string $value email recipients.
2597
-	 */
2598
-	public function set_template( $value ) {
2599
-		if ( in_array( $value, array( 'quantity', 'hours', 'amount' ) ) ) {
2600
-			$this->set_prop( 'template', $value );
2601
-		}
2602
-	}
2603
-
2604
-	/**
2605
-	 * Set the customer's address confirmed status.
2606
-	 *
2607
-	 * @since 1.0.19
2608
-	 * @param  int|bool $value confirmed.
2609
-	 */
2610
-	public function set_address_confirmed( $value ) {
2611
-		$this->set_prop( 'address_confirmed', $value );
2605
+     * Set the customer's address confirmed status.
2606
+     *
2607
+     * @since 1.0.19
2608
+     * @param  int|bool $value confirmed.
2609
+     */
2610
+    public function set_address_confirmed( $value ) {
2611
+        $this->set_prop( 'address_confirmed', $value );
2612 2612
     }
2613 2613
 
2614 2614
     /**
2615
-	 * Alias of self::set_address_confirmed().
2616
-	 *
2617
-	 * @since 1.0.19
2618
-	 * @param  int|bool $value confirmed.
2619
-	 */
2620
-	public function set_user_address_confirmed( $value ) {
2621
-		$this->set_address_confirmed( $value );
2615
+     * Alias of self::set_address_confirmed().
2616
+     *
2617
+     * @since 1.0.19
2618
+     * @param  int|bool $value confirmed.
2619
+     */
2620
+    public function set_user_address_confirmed( $value ) {
2621
+        $this->set_address_confirmed( $value );
2622 2622
     }
2623 2623
 
2624 2624
     /**
2625
-	 * Alias of self::set_address_confirmed().
2626
-	 *
2627
-	 * @since 1.0.19
2628
-	 * @param  int|bool $value confirmed.
2629
-	 */
2630
-	public function set_customer_address_confirmed( $value ) {
2631
-		$this->set_address_confirmed( $value );
2625
+     * Alias of self::set_address_confirmed().
2626
+     *
2627
+     * @since 1.0.19
2628
+     * @param  int|bool $value confirmed.
2629
+     */
2630
+    public function set_customer_address_confirmed( $value ) {
2631
+        $this->set_address_confirmed( $value );
2632 2632
     }
2633 2633
 
2634 2634
     /**
2635
-	 * Set the invoice sub total.
2636
-	 *
2637
-	 * @since 1.0.19
2638
-	 * @param  float $value sub total.
2639
-	 */
2640
-	public function set_subtotal( $value ) {
2641
-		$this->set_prop( 'subtotal', $value );
2635
+     * Set the invoice sub total.
2636
+     *
2637
+     * @since 1.0.19
2638
+     * @param  float $value sub total.
2639
+     */
2640
+    public function set_subtotal( $value ) {
2641
+        $this->set_prop( 'subtotal', $value );
2642 2642
     }
2643 2643
 
2644 2644
     /**
2645
-	 * Set the invoice discount amount.
2646
-	 *
2647
-	 * @since 1.0.19
2648
-	 * @param  float $value discount total.
2649
-	 */
2650
-	public function set_total_discount( $value ) {
2651
-		$this->set_prop( 'total_discount', $value );
2645
+     * Set the invoice discount amount.
2646
+     *
2647
+     * @since 1.0.19
2648
+     * @param  float $value discount total.
2649
+     */
2650
+    public function set_total_discount( $value ) {
2651
+        $this->set_prop( 'total_discount', $value );
2652 2652
     }
2653 2653
 
2654 2654
     /**
2655
-	 * Alias of self::set_total_discount().
2656
-	 *
2657
-	 * @since 1.0.19
2658
-	 * @param  float $value discount total.
2659
-	 */
2660
-	public function set_discount( $value ) {
2661
-		$this->set_total_discount( $value );
2655
+     * Alias of self::set_total_discount().
2656
+     *
2657
+     * @since 1.0.19
2658
+     * @param  float $value discount total.
2659
+     */
2660
+    public function set_discount( $value ) {
2661
+        $this->set_total_discount( $value );
2662 2662
     }
2663 2663
 
2664 2664
     /**
2665
-	 * Set the invoice tax amount.
2666
-	 *
2667
-	 * @since 1.0.19
2668
-	 * @param  float $value tax total.
2669
-	 */
2670
-	public function set_total_tax( $value ) {
2671
-		$this->set_prop( 'total_tax', $value );
2665
+     * Set the invoice tax amount.
2666
+     *
2667
+     * @since 1.0.19
2668
+     * @param  float $value tax total.
2669
+     */
2670
+    public function set_total_tax( $value ) {
2671
+        $this->set_prop( 'total_tax', $value );
2672 2672
     }
2673 2673
 
2674 2674
     /**
2675
-	 * Alias of self::set_total_tax().
2676
-	 *
2677
-	 * @since 1.0.19
2678
-	 * @param  float $value tax total.
2679
-	 */
2680
-	public function set_tax_total( $value ) {
2681
-		$this->set_total_tax( $value );
2675
+     * Alias of self::set_total_tax().
2676
+     *
2677
+     * @since 1.0.19
2678
+     * @param  float $value tax total.
2679
+     */
2680
+    public function set_tax_total( $value ) {
2681
+        $this->set_total_tax( $value );
2682 2682
     }
2683 2683
 
2684 2684
     /**
2685
-	 * Set the invoice fees amount.
2686
-	 *
2687
-	 * @since 1.0.19
2688
-	 * @param  float $value fees total.
2689
-	 */
2690
-	public function set_total_fees( $value ) {
2691
-		$this->set_prop( 'total_fees', $value );
2685
+     * Set the invoice fees amount.
2686
+     *
2687
+     * @since 1.0.19
2688
+     * @param  float $value fees total.
2689
+     */
2690
+    public function set_total_fees( $value ) {
2691
+        $this->set_prop( 'total_fees', $value );
2692 2692
     }
2693 2693
 
2694 2694
     /**
2695
-	 * Alias of self::set_total_fees().
2696
-	 *
2697
-	 * @since 1.0.19
2698
-	 * @param  float $value fees total.
2699
-	 */
2700
-	public function set_fees_total( $value ) {
2701
-		$this->set_total_fees( $value );
2695
+     * Alias of self::set_total_fees().
2696
+     *
2697
+     * @since 1.0.19
2698
+     * @param  float $value fees total.
2699
+     */
2700
+    public function set_fees_total( $value ) {
2701
+        $this->set_total_fees( $value );
2702 2702
     }
2703 2703
 
2704 2704
     /**
2705
-	 * Set the invoice fees.
2706
-	 *
2707
-	 * @since 1.0.19
2708
-	 * @param  array $value fees.
2709
-	 */
2710
-	public function set_fees( $value ) {
2705
+     * Set the invoice fees.
2706
+     *
2707
+     * @since 1.0.19
2708
+     * @param  array $value fees.
2709
+     */
2710
+    public function set_fees( $value ) {
2711 2711
 
2712 2712
         $this->set_prop( 'fees', array() );
2713 2713
 
@@ -2725,23 +2725,23 @@  discard block
 block discarded – undo
2725 2725
     }
2726 2726
 
2727 2727
     /**
2728
-	 * Set the invoice taxes.
2729
-	 *
2730
-	 * @since 1.0.19
2731
-	 * @param  array $value taxes.
2732
-	 */
2733
-	public function set_taxes( $value ) {
2734
-		$this->set_prop( 'taxes', $value );
2728
+     * Set the invoice taxes.
2729
+     *
2730
+     * @since 1.0.19
2731
+     * @param  array $value taxes.
2732
+     */
2733
+    public function set_taxes( $value ) {
2734
+        $this->set_prop( 'taxes', $value );
2735 2735
     }
2736 2736
 
2737 2737
     /**
2738
-	 * Set the invoice discounts.
2739
-	 *
2740
-	 * @since 1.0.19
2741
-	 * @param  array $value discounts.
2742
-	 */
2743
-	public function set_discounts( $value ) {
2744
-		$this->set_prop( 'discounts', array() );
2738
+     * Set the invoice discounts.
2739
+     *
2740
+     * @since 1.0.19
2741
+     * @param  array $value discounts.
2742
+     */
2743
+    public function set_discounts( $value ) {
2744
+        $this->set_prop( 'discounts', array() );
2745 2745
 
2746 2746
         // Ensure that we have an array.
2747 2747
         if ( ! is_array( $value ) ) {
@@ -2756,12 +2756,12 @@  discard block
 block discarded – undo
2756 2756
     }
2757 2757
 
2758 2758
     /**
2759
-	 * Set the invoice items.
2760
-	 *
2761
-	 * @since 1.0.19
2762
-	 * @param  GetPaid_Form_Item[] $value items.
2763
-	 */
2764
-	public function set_items( $value ) {
2759
+     * Set the invoice items.
2760
+     *
2761
+     * @since 1.0.19
2762
+     * @param  GetPaid_Form_Item[] $value items.
2763
+     */
2764
+    public function set_items( $value ) {
2765 2765
 
2766 2766
         // Remove existing items.
2767 2767
         $this->set_prop( 'items', array() );
@@ -2778,85 +2778,85 @@  discard block
 block discarded – undo
2778 2778
     }
2779 2779
 
2780 2780
     /**
2781
-	 * Set the payment form.
2782
-	 *
2783
-	 * @since 1.0.19
2784
-	 * @param  int $value payment form.
2785
-	 */
2786
-	public function set_payment_form( $value ) {
2787
-		$this->set_prop( 'payment_form', $value );
2781
+     * Set the payment form.
2782
+     *
2783
+     * @since 1.0.19
2784
+     * @param  int $value payment form.
2785
+     */
2786
+    public function set_payment_form( $value ) {
2787
+        $this->set_prop( 'payment_form', $value );
2788 2788
     }
2789 2789
 
2790 2790
     /**
2791
-	 * Set the submission id.
2792
-	 *
2793
-	 * @since 1.0.19
2794
-	 * @param  string $value submission id.
2795
-	 */
2796
-	public function set_submission_id( $value ) {
2797
-		$this->set_prop( 'submission_id', $value );
2791
+     * Set the submission id.
2792
+     *
2793
+     * @since 1.0.19
2794
+     * @param  string $value submission id.
2795
+     */
2796
+    public function set_submission_id( $value ) {
2797
+        $this->set_prop( 'submission_id', $value );
2798 2798
     }
2799 2799
 
2800 2800
     /**
2801
-	 * Set the discount code.
2802
-	 *
2803
-	 * @since 1.0.19
2804
-	 * @param  string $value discount code.
2805
-	 */
2806
-	public function set_discount_code( $value ) {
2807
-		$this->set_prop( 'discount_code', $value );
2801
+     * Set the discount code.
2802
+     *
2803
+     * @since 1.0.19
2804
+     * @param  string $value discount code.
2805
+     */
2806
+    public function set_discount_code( $value ) {
2807
+        $this->set_prop( 'discount_code', $value );
2808 2808
     }
2809 2809
 
2810 2810
     /**
2811
-	 * Set the gateway.
2812
-	 *
2813
-	 * @since 1.0.19
2814
-	 * @param  string $value gateway.
2815
-	 */
2816
-	public function set_gateway( $value ) {
2817
-		$this->set_prop( 'gateway', $value );
2811
+     * Set the gateway.
2812
+     *
2813
+     * @since 1.0.19
2814
+     * @param  string $value gateway.
2815
+     */
2816
+    public function set_gateway( $value ) {
2817
+        $this->set_prop( 'gateway', $value );
2818 2818
     }
2819 2819
 
2820 2820
     /**
2821
-	 * Set the transaction id.
2822
-	 *
2823
-	 * @since 1.0.19
2824
-	 * @param  string $value transaction id.
2825
-	 */
2826
-	public function set_transaction_id( $value ) {
2827
-		if ( ! empty( $value ) ) {
2828
-			$this->set_prop( 'transaction_id', $value );
2829
-		}
2821
+     * Set the transaction id.
2822
+     *
2823
+     * @since 1.0.19
2824
+     * @param  string $value transaction id.
2825
+     */
2826
+    public function set_transaction_id( $value ) {
2827
+        if ( ! empty( $value ) ) {
2828
+            $this->set_prop( 'transaction_id', $value );
2829
+        }
2830 2830
     }
2831 2831
 
2832 2832
     /**
2833
-	 * Set the currency id.
2834
-	 *
2835
-	 * @since 1.0.19
2836
-	 * @param  string $value currency id.
2837
-	 */
2838
-	public function set_currency( $value ) {
2839
-		$this->set_prop( 'currency', $value );
2833
+     * Set the currency id.
2834
+     *
2835
+     * @since 1.0.19
2836
+     * @param  string $value currency id.
2837
+     */
2838
+    public function set_currency( $value ) {
2839
+        $this->set_prop( 'currency', $value );
2840 2840
     }
2841 2841
 
2842
-	/**
2843
-	 * Set whether to disable taxes.
2844
-	 *
2845
-	 * @since 1.0.19
2846
-	 * @param  bool $value value.
2847
-	 */
2848
-	public function set_disable_taxes( $value ) {
2849
-		$this->set_prop( 'disable_taxes', (bool) $value );
2850
-	}
2842
+    /**
2843
+     * Set whether to disable taxes.
2844
+     *
2845
+     * @since 1.0.19
2846
+     * @param  bool $value value.
2847
+     */
2848
+    public function set_disable_taxes( $value ) {
2849
+        $this->set_prop( 'disable_taxes', (bool) $value );
2850
+    }
2851 2851
 
2852 2852
     /**
2853
-	 * Set the subscription id.
2854
-	 *
2855
-	 * @since 1.0.19
2856
-	 * @param  string $value subscription id.
2857
-	 */
2858
-	public function set_subscription_id( $value ) {
2859
-		$this->set_prop( 'subscription_id', $value );
2853
+     * Set the subscription id.
2854
+     *
2855
+     * @since 1.0.19
2856
+     * @param  string $value subscription id.
2857
+     */
2858
+    public function set_subscription_id( $value ) {
2859
+        $this->set_prop( 'subscription_id', $value );
2860 2860
     }
2861 2861
 
2862 2862
     /*
@@ -2895,12 +2895,12 @@  discard block
 block discarded – undo
2895 2895
      */
2896 2896
     public function is_taxable() {
2897 2897
         return ! $this->get_disable_taxes();
2898
-	}
2898
+    }
2899 2899
 
2900
-	/**
2901
-	 * @deprecated
2902
-	 */
2903
-	public function has_vat() {
2900
+    /**
2901
+     * @deprecated
2902
+     */
2903
+    public function has_vat() {
2904 2904
         global $wpinv_euvat, $wpi_country;
2905 2905
 
2906 2906
         $requires_vat = false;
@@ -2911,17 +2911,17 @@  discard block
 block discarded – undo
2911 2911
         }
2912 2912
 
2913 2913
         return apply_filters( 'wpinv_invoice_has_vat', $requires_vat, $this );
2914
-	}
2914
+    }
2915 2915
 
2916
-	/**
2917
-	 * Checks to see if the invoice requires payment.
2918
-	 */
2919
-	public function is_free() {
2916
+    /**
2917
+     * Checks to see if the invoice requires payment.
2918
+     */
2919
+    public function is_free() {
2920 2920
         $is_free = ( (float) wpinv_round_amount( $this->get_initial_total() ) == 0 );
2921 2921
 
2922
-		if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2923
-			$is_free = false;
2924
-		}
2922
+        if ( $this->is_recurring() && $this->get_recurring_total() > 0 ) {
2923
+            $is_free = false;
2924
+        }
2925 2925
 
2926 2926
         return apply_filters( 'wpinv_invoice_is_free', $is_free, $this );
2927 2927
     }
@@ -2932,46 +2932,46 @@  discard block
 block discarded – undo
2932 2932
     public function is_paid() {
2933 2933
         $is_paid = $this->has_status( array( 'publish', 'wpi-processing', 'wpi-renewal' ) );
2934 2934
         return apply_filters( 'wpinv_invoice_is_paid', $is_paid, $this );
2935
-	}
2935
+    }
2936 2936
 
2937
-	/**
2937
+    /**
2938 2938
      * Checks if the invoice needs payment.
2939 2939
      */
2940
-	public function needs_payment() {
2941
-		$needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2940
+    public function needs_payment() {
2941
+        $needs_payment = ! $this->is_paid() && ! $this->is_refunded() && ! $this->is_free();
2942 2942
         return apply_filters( 'wpinv_needs_payment', $needs_payment, $this );
2943 2943
     }
2944 2944
 
2945
-	/**
2945
+    /**
2946 2946
      * Checks if the invoice is refunded.
2947 2947
      */
2948
-	public function is_refunded() {
2948
+    public function is_refunded() {
2949 2949
         $is_refunded = $this->has_status( 'wpi-refunded' );
2950 2950
         return apply_filters( 'wpinv_invoice_is_refunded', $is_refunded, $this );
2951
-	}
2951
+    }
2952 2952
 
2953
-	/**
2953
+    /**
2954 2954
      * Checks if the invoice is held.
2955 2955
      */
2956
-	public function is_held() {
2956
+    public function is_held() {
2957 2957
         $is_held = $this->has_status( 'wpi-onhold' );
2958 2958
         return apply_filters( 'wpinv_invoice_is_held', $is_held, $this );
2959
-	}
2959
+    }
2960 2960
 
2961
-	/**
2961
+    /**
2962 2962
      * Checks if the invoice is due.
2963 2963
      */
2964
-	public function is_due() {
2965
-		$due_date = $this->get_due_date();
2966
-		return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
2967
-	}
2964
+    public function is_due() {
2965
+        $due_date = $this->get_due_date();
2966
+        return empty( $due_date ) ? false : current_time( 'timestamp' ) > strtotime( $due_date );
2967
+    }
2968 2968
 
2969
-	/**
2969
+    /**
2970 2970
      * Checks if the invoice is draft.
2971 2971
      */
2972
-	public function is_draft() {
2972
+    public function is_draft() {
2973 2973
         return $this->has_status( 'draft, auto-draft' );
2974
-	}
2974
+    }
2975 2975
 
2976 2976
     /**
2977 2977
      * Checks if the invoice has a given status.
@@ -2979,9 +2979,9 @@  discard block
 block discarded – undo
2979 2979
     public function has_status( $status ) {
2980 2980
         $status = wpinv_parse_list( $status );
2981 2981
         return apply_filters( 'wpinv_has_status', in_array( $this->get_status(), $status ), $status );
2982
-	}
2982
+    }
2983 2983
 
2984
-	/**
2984
+    /**
2985 2985
      * Checks if the invoice is of a given type.
2986 2986
      */
2987 2987
     public function is_type( $type ) {
@@ -3004,25 +3004,25 @@  discard block
 block discarded – undo
3004 3004
      */
3005 3005
     public function has_free_trial() {
3006 3006
         return $this->is_recurring() && 0 == $this->get_initial_total();
3007
-	}
3007
+    }
3008 3008
 
3009
-	/**
3009
+    /**
3010 3010
      * @deprecated
3011 3011
      */
3012 3012
     public function is_free_trial() {
3013 3013
         $this->has_free_trial();
3014 3014
     }
3015 3015
 
3016
-	/**
3016
+    /**
3017 3017
      * Check if the initial payment if 0.
3018 3018
      *
3019 3019
      */
3020
-	public function is_initial_free() {
3020
+    public function is_initial_free() {
3021 3021
         $is_initial_free = ! ( (float) wpinv_round_amount( $this->get_initial_total() ) > 0 );
3022 3022
         return apply_filters( 'wpinv_invoice_is_initial_free', $is_initial_free, $this->get_cart_details(), $this );
3023 3023
     }
3024 3024
 	
3025
-	/**
3025
+    /**
3026 3026
      * Check if the recurring item has a free trial.
3027 3027
      *
3028 3028
      */
@@ -3035,21 +3035,21 @@  discard block
 block discarded – undo
3035 3035
 
3036 3036
         $item = $this->get_recurring( true );
3037 3037
         return $item->has_free_trial();
3038
-	}
3038
+    }
3039 3039
 
3040
-	/**
3040
+    /**
3041 3041
      * Check if the free trial is a result of a discount.
3042 3042
      */
3043 3043
     public function is_free_trial_from_discount() {
3044
-		return $this->has_free_trial() && ! $this->item_has_free_trial();
3045
-	}
3044
+        return $this->has_free_trial() && ! $this->item_has_free_trial();
3045
+    }
3046 3046
 	
3047
-	/**
3047
+    /**
3048 3048
      * @deprecated
3049 3049
      */
3050 3050
     public function discount_first_payment_only() {
3051 3051
 
3052
-		$discount_code = $this->get_discount_code();
3052
+        $discount_code = $this->get_discount_code();
3053 3053
         if ( empty( $this->discount_code ) || ! $this->is_recurring() ) {
3054 3054
             return true;
3055 3055
         }
@@ -3080,28 +3080,28 @@  discard block
 block discarded – undo
3080 3080
      */
3081 3081
     public function add_item( $item ) {
3082 3082
 
3083
-		if ( is_array( $item ) ) {
3084
-			$item = $this->process_array_item( $item );
3085
-		}
3083
+        if ( is_array( $item ) ) {
3084
+            $item = $this->process_array_item( $item );
3085
+        }
3086 3086
 
3087
-		if ( is_numeric( $item ) ) {
3088
-			$item = new GetPaid_Form_Item( $item );
3089
-		}
3087
+        if ( is_numeric( $item ) ) {
3088
+            $item = new GetPaid_Form_Item( $item );
3089
+        }
3090 3090
 
3091 3091
         // Make sure that it is available for purchase.
3092
-		if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3093
-			return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3092
+        if ( $item->get_id() > 0 && ! $item->can_purchase() ) {
3093
+            return new WP_Error( 'invalid_item', __( 'This item is not available for purchase', 'invoicing' ) );
3094 3094
         }
3095 3095
 
3096 3096
         // Do we have a recurring item?
3097
-		if ( $item->is_recurring() ) {
3097
+        if ( $item->is_recurring() ) {
3098 3098
 
3099
-			// An invoice can only contain one recurring item.
3100
-			if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3101
-				return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3102
-			}
3099
+            // An invoice can only contain one recurring item.
3100
+            if ( ! empty( $this->recurring_item  && $this->recurring_item != (int) $item->get_id() ) ) {
3101
+                return new WP_Error( 'recurring_item', __( 'An invoice can only contain one recurring item', 'invoicing' ) );
3102
+            }
3103 3103
 
3104
-			$this->recurring_item = $item->get_id();
3104
+            $this->recurring_item = $item->get_id();
3105 3105
         }
3106 3106
 
3107 3107
         // Invoice id.
@@ -3112,60 +3112,60 @@  discard block
 block discarded – undo
3112 3112
         $items[ (int) $item->get_id() ] = $item;
3113 3113
 
3114 3114
         $this->set_prop( 'items', $items );
3115
-		return true;
3116
-	}
3115
+        return true;
3116
+    }
3117 3117
 	
3118
-	/**
3119
-	 * Converts an array to an item.
3120
-	 *
3121
-	 * @since 1.0.19
3122
-	 * @return GetPaid_Form_Item
3123
-	 */
3124
-	protected function process_array_item( $array ) {
3125
-
3126
-		$item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3127
-		$item    = new GetPaid_Form_Item( $item_id );
3128
-
3129
-		// Set item data.
3130
-		foreach( array( 'name', 'price', 'description' ) as $key ) {
3131
-			if ( isset( $array[ "item_$key" ] ) ) {
3132
-				$method = "set_$key";
3133
-				$item->$method( $array[ "item_$key" ] );
3134
-			}
3135
-		}
3136
-
3137
-		if ( isset( $array['quantity'] ) ) {
3138
-			$item->set_quantity( $array['quantity'] );
3139
-		}
3140
-
3141
-		// Set item meta.
3142
-		if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3143
-			$item->set_item_meta( $array['meta'] );
3144
-		}
3145
-
3146
-		return $item;
3147
-
3148
-	}
3149
-
3150
-    /**
3151
-	 * Retrieves a specific item.
3152
-	 *
3153
-	 * @since 1.0.19
3154
-	 */
3155
-	public function get_item( $item_id ) {
3156
-		$items   = $this->get_items();
3157
-		$item_id = (int) $item_id;
3158
-		return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3159
-    }
3160
-
3161
-    /**
3162
-	 * Removes a specific item.
3163
-	 *
3164
-	 * @since 1.0.19
3165
-	 */
3166
-	public function remove_item( $item_id ) {
3167
-		$items   = $this->get_items();
3168
-		$item_id = (int) $item_id;
3118
+    /**
3119
+     * Converts an array to an item.
3120
+     *
3121
+     * @since 1.0.19
3122
+     * @return GetPaid_Form_Item
3123
+     */
3124
+    protected function process_array_item( $array ) {
3125
+
3126
+        $item_id = isset( $array['item_id'] ) ? $array['item_id'] : 0;
3127
+        $item    = new GetPaid_Form_Item( $item_id );
3128
+
3129
+        // Set item data.
3130
+        foreach( array( 'name', 'price', 'description' ) as $key ) {
3131
+            if ( isset( $array[ "item_$key" ] ) ) {
3132
+                $method = "set_$key";
3133
+                $item->$method( $array[ "item_$key" ] );
3134
+            }
3135
+        }
3136
+
3137
+        if ( isset( $array['quantity'] ) ) {
3138
+            $item->set_quantity( $array['quantity'] );
3139
+        }
3140
+
3141
+        // Set item meta.
3142
+        if ( isset( $array['meta'] ) && is_array( $array['meta'] ) ) {
3143
+            $item->set_item_meta( $array['meta'] );
3144
+        }
3145
+
3146
+        return $item;
3147
+
3148
+    }
3149
+
3150
+    /**
3151
+     * Retrieves a specific item.
3152
+     *
3153
+     * @since 1.0.19
3154
+     */
3155
+    public function get_item( $item_id ) {
3156
+        $items   = $this->get_items();
3157
+        $item_id = (int) $item_id;
3158
+        return ( ! empty( $item_id ) && isset( $items[ $item_id ] ) ) ? $items[ $item_id ] : null;
3159
+    }
3160
+
3161
+    /**
3162
+     * Removes a specific item.
3163
+     *
3164
+     * @since 1.0.19
3165
+     */
3166
+    public function remove_item( $item_id ) {
3167
+        $items   = $this->get_items();
3168
+        $item_id = (int) $item_id;
3169 3169
 
3170 3170
         if ( $item_id == $this->recurring_item ) {
3171 3171
             $this->recurring_item = null;
@@ -3192,38 +3192,38 @@  discard block
 block discarded – undo
3192 3192
         if ( isset( $fees[ $fee ] ) && isset( $fees[ $fee ]['amount'] ) ) {
3193 3193
 
3194 3194
             $amount = $fees[ $fee ]['amount'] += $amount;
3195
-			$fees[ $fee ] = array(
3196
-				'amount'    => $amount,
3195
+            $fees[ $fee ] = array(
3196
+                'amount'    => $amount,
3197 3197
                 'recurring' => (bool) $recurring,
3198 3198
             );
3199 3199
 
3200
-		} else {
3201
-			$fees[ $fee ] = array(
3200
+        } else {
3201
+            $fees[ $fee ] = array(
3202 3202
                 'amount'    => $amount,
3203 3203
                 'recurring' => (bool) $recurring,
3204 3204
             );
3205
-		}
3205
+        }
3206 3206
 
3207 3207
         $this->set_prop( 'fees', $fee );
3208 3208
 
3209 3209
     }
3210 3210
 
3211 3211
     /**
3212
-	 * Retrieves a specific fee.
3213
-	 *
3214
-	 * @since 1.0.19
3215
-	 */
3216
-	public function get_fee( $fee ) {
3212
+     * Retrieves a specific fee.
3213
+     *
3214
+     * @since 1.0.19
3215
+     */
3216
+    public function get_fee( $fee ) {
3217 3217
         $fees = $this->get_fees();
3218
-		return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3218
+        return isset( $fees[ $fee ] ) ? $fees[ $fee ] : null;
3219 3219
     }
3220 3220
 
3221 3221
     /**
3222
-	 * Removes a specific fee.
3223
-	 *
3224
-	 * @since 1.0.19
3225
-	 */
3226
-	public function remove_fee( $fee ) {
3222
+     * Removes a specific fee.
3223
+     *
3224
+     * @since 1.0.19
3225
+     */
3226
+    public function remove_fee( $fee ) {
3227 3227
         $fees = $this->get_fees();
3228 3228
         if ( isset( $fees[ $fee ] ) ) {
3229 3229
             unset( $fees[ $fee ] );
@@ -3246,44 +3246,44 @@  discard block
 block discarded – undo
3246 3246
         if ( isset( $discounts[ $discount ] ) && isset( $discounts[ $discount ]['amount'] ) ) {
3247 3247
 
3248 3248
             $amount = $discounts[ $discount ]['amount'] += $amount;
3249
-			$discounts[ $discount ] = array(
3249
+            $discounts[ $discount ] = array(
3250 3250
                 'amount'    => $amount,
3251 3251
                 'recurring' => (bool) $recurring,
3252 3252
             );
3253 3253
 
3254
-		} else {
3255
-			$discounts[ $discount ] = array(
3254
+        } else {
3255
+            $discounts[ $discount ] = array(
3256 3256
                 'amount'    => $amount,
3257 3257
                 'recurring' => (bool) $recurring,
3258 3258
             );
3259
-		}
3259
+        }
3260 3260
 
3261 3261
         $this->set_prop( 'discounts', $discount );
3262 3262
 
3263 3263
     }
3264 3264
 
3265 3265
     /**
3266
-	 * Retrieves a specific discount.
3267
-	 *
3268
-	 * @since 1.0.19
3269
-	 */
3270
-	public function get_discount( $discount = false ) {
3266
+     * Retrieves a specific discount.
3267
+     *
3268
+     * @since 1.0.19
3269
+     */
3270
+    public function get_discount( $discount = false ) {
3271 3271
 
3272
-		// Backwards compatibilty.
3273
-		if ( empty( $discount ) ) {
3274
-			return $this->get_total_discount();
3275
-		}
3272
+        // Backwards compatibilty.
3273
+        if ( empty( $discount ) ) {
3274
+            return $this->get_total_discount();
3275
+        }
3276 3276
 
3277 3277
         $discounts = $this->get_discounts();
3278
-		return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3278
+        return isset( $discounts[ $discount ] ) ? $discounts[ $discount ] : null;
3279 3279
     }
3280 3280
 
3281 3281
     /**
3282
-	 * Removes a specific discount.
3283
-	 *
3284
-	 * @since 1.0.19
3285
-	 */
3286
-	public function remove_discount( $discount ) {
3282
+     * Removes a specific discount.
3283
+     *
3284
+     * @since 1.0.19
3285
+     */
3286
+    public function remove_discount( $discount ) {
3287 3287
         $discounts = $this->get_discounts();
3288 3288
         if ( isset( $discounts[ $discount ] ) ) {
3289 3289
             unset( $discounts[ $discount ] );
@@ -3309,44 +3309,44 @@  discard block
 block discarded – undo
3309 3309
         if ( isset( $taxes[ $tax ] ) && isset( $taxes[ $tax ]['amount'] ) ) {
3310 3310
 
3311 3311
             $amount = $taxes[ $tax ]['amount'] += $amount;
3312
-			$taxes[ $tax ] = array(
3312
+            $taxes[ $tax ] = array(
3313 3313
                 'amount'    => $amount,
3314 3314
                 'recurring' => (bool) $recurring,
3315 3315
             );
3316 3316
 
3317
-		} else {
3318
-			$taxes[ $tax ] = array(
3317
+        } else {
3318
+            $taxes[ $tax ] = array(
3319 3319
                 'amount'    => $amount,
3320 3320
                 'recurring' => (bool) $recurring,
3321 3321
             );
3322
-		}
3322
+        }
3323 3323
 
3324 3324
         $this->set_prop( 'taxes', $tax );
3325 3325
 
3326 3326
     }
3327 3327
 
3328 3328
     /**
3329
-	 * Retrieves a specific tax.
3330
-	 *
3331
-	 * @since 1.0.19
3332
-	 */
3333
-	public function get_tax( $tax = null ) {
3329
+     * Retrieves a specific tax.
3330
+     *
3331
+     * @since 1.0.19
3332
+     */
3333
+    public function get_tax( $tax = null ) {
3334 3334
 
3335
-		// Backwards compatility.
3336
-		if ( empty( $tax ) ) {
3337
-			return $this->get_total_tax();
3338
-		}
3335
+        // Backwards compatility.
3336
+        if ( empty( $tax ) ) {
3337
+            return $this->get_total_tax();
3338
+        }
3339 3339
 
3340 3340
         $taxes = $this->get_taxes();
3341
-		return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3341
+        return isset( $taxes[ $tax ] ) ? $taxes[ $tax ] : null;
3342 3342
     }
3343 3343
 
3344 3344
     /**
3345
-	 * Removes a specific tax.
3346
-	 *
3347
-	 * @since 1.0.19
3348
-	 */
3349
-	public function remove_tax( $tax ) {
3345
+     * Removes a specific tax.
3346
+     *
3347
+     * @since 1.0.19
3348
+     */
3349
+    public function remove_tax( $tax ) {
3350 3350
         $taxes = $this->get_discounts();
3351 3351
         if ( isset( $taxes[ $tax ] ) ) {
3352 3352
             unset( $taxes[ $tax ] );
@@ -3355,160 +3355,160 @@  discard block
 block discarded – undo
3355 3355
     }
3356 3356
 
3357 3357
     /**
3358
-	 * Recalculates the invoice subtotal.
3359
-	 *
3360
-	 * @since 1.0.19
3361
-	 * @return float The recalculated subtotal
3362
-	 */
3363
-	public function recalculate_subtotal() {
3358
+     * Recalculates the invoice subtotal.
3359
+     *
3360
+     * @since 1.0.19
3361
+     * @return float The recalculated subtotal
3362
+     */
3363
+    public function recalculate_subtotal() {
3364 3364
         $items     = $this->get_items();
3365
-		$subtotal  = 0;
3366
-		$recurring = 0;
3365
+        $subtotal  = 0;
3366
+        $recurring = 0;
3367 3367
 
3368 3368
         foreach ( $items as $item ) {
3369
-			$subtotal  += $item->get_sub_total();
3370
-			$recurring += $item->get_recurring_sub_total();
3369
+            $subtotal  += $item->get_sub_total();
3370
+            $recurring += $item->get_recurring_sub_total();
3371 3371
         }
3372 3372
 
3373
-		if ( $this->is_renewal() ) {
3374
-			$this->set_subtotal( $recurring );
3375
-		} else {
3376
-			$this->set_subtotal( $subtotal );
3377
-		}
3373
+        if ( $this->is_renewal() ) {
3374
+            $this->set_subtotal( $recurring );
3375
+        } else {
3376
+            $this->set_subtotal( $subtotal );
3377
+        }
3378 3378
 
3379
-		$this->totals['subtotal'] = array(
3380
-			'initial'   => $subtotal,
3381
-			'recurring' => $recurring,
3382
-		);
3379
+        $this->totals['subtotal'] = array(
3380
+            'initial'   => $subtotal,
3381
+            'recurring' => $recurring,
3382
+        );
3383 3383
 
3384 3384
         return $this->is_renewal() ? $recurring : $subtotal;
3385 3385
     }
3386 3386
 
3387 3387
     /**
3388
-	 * Recalculates the invoice discount total.
3389
-	 *
3390
-	 * @since 1.0.19
3391
-	 * @return float The recalculated discount
3392
-	 */
3393
-	public function recalculate_total_discount() {
3388
+     * Recalculates the invoice discount total.
3389
+     *
3390
+     * @since 1.0.19
3391
+     * @return float The recalculated discount
3392
+     */
3393
+    public function recalculate_total_discount() {
3394 3394
         $discounts = $this->get_discounts();
3395
-		$discount  = 0;
3396
-		$recurring = 0;
3395
+        $discount  = 0;
3396
+        $recurring = 0;
3397 3397
 
3398 3398
         foreach ( $discounts as $data ) {
3399 3399
 
3400
-			if ( $data['recurring'] ) {
3401
-				$recurring += $data['amount'];
3402
-			} else {
3403
-				$discount += $data['amount'];
3404
-			}
3400
+            if ( $data['recurring'] ) {
3401
+                $recurring += $data['amount'];
3402
+            } else {
3403
+                $discount += $data['amount'];
3404
+            }
3405 3405
 
3406
-		}
3406
+        }
3407 3407
 
3408
-		if ( $this->is_renewal() ) {
3409
-			$this->set_total_discount( $recurring );
3410
-		} else {
3411
-			$this->set_total_discount( $discount );
3412
-		}
3408
+        if ( $this->is_renewal() ) {
3409
+            $this->set_total_discount( $recurring );
3410
+        } else {
3411
+            $this->set_total_discount( $discount );
3412
+        }
3413 3413
 
3414
-		$this->totals['discount'] = array(
3415
-			'initial'   => $discount,
3416
-			'recurring' => $recurring,
3417
-		);
3414
+        $this->totals['discount'] = array(
3415
+            'initial'   => $discount,
3416
+            'recurring' => $recurring,
3417
+        );
3418 3418
 
3419
-		return $this->is_renewal() ? $recurring : $discount;
3419
+        return $this->is_renewal() ? $recurring : $discount;
3420 3420
 
3421 3421
     }
3422 3422
 
3423 3423
     /**
3424
-	 * Recalculates the invoice tax total.
3425
-	 *
3426
-	 * @since 1.0.19
3427
-	 * @return float The recalculated tax
3428
-	 */
3429
-	public function recalculate_total_tax() {
3424
+     * Recalculates the invoice tax total.
3425
+     *
3426
+     * @since 1.0.19
3427
+     * @return float The recalculated tax
3428
+     */
3429
+    public function recalculate_total_tax() {
3430 3430
         $taxes     = $this->get_taxes();
3431
-		$tax       = 0;
3432
-		$recurring = 0;
3431
+        $tax       = 0;
3432
+        $recurring = 0;
3433 3433
 
3434 3434
         foreach ( $taxes as $data ) {
3435 3435
 
3436
-			if ( $data['recurring'] ) {
3437
-				$recurring += $data['amount'];
3438
-			} else {
3439
-				$tax += $data['amount'];
3440
-			}
3436
+            if ( $data['recurring'] ) {
3437
+                $recurring += $data['amount'];
3438
+            } else {
3439
+                $tax += $data['amount'];
3440
+            }
3441 3441
 
3442
-		}
3442
+        }
3443 3443
 
3444
-		if ( $this->is_renewal() ) {
3445
-			$this->set_total_tax( $recurring );
3446
-		} else {
3447
-			$this->set_total_tax( $tax );
3448
-		}
3444
+        if ( $this->is_renewal() ) {
3445
+            $this->set_total_tax( $recurring );
3446
+        } else {
3447
+            $this->set_total_tax( $tax );
3448
+        }
3449 3449
 
3450
-		$this->totals['tax'] = array(
3451
-			'initial'   => $tax,
3452
-			'recurring' => $recurring,
3453
-		);
3450
+        $this->totals['tax'] = array(
3451
+            'initial'   => $tax,
3452
+            'recurring' => $recurring,
3453
+        );
3454 3454
 
3455
-		return $this->is_renewal() ? $recurring : $tax;
3455
+        return $this->is_renewal() ? $recurring : $tax;
3456 3456
 
3457 3457
     }
3458 3458
 
3459 3459
     /**
3460
-	 * Recalculates the invoice fees total.
3461
-	 *
3462
-	 * @since 1.0.19
3463
-	 * @return float The recalculated fee
3464
-	 */
3465
-	public function recalculate_total_fees() {
3466
-		$fees      = $this->get_fees();
3467
-		$fee       = 0;
3468
-		$recurring = 0;
3460
+     * Recalculates the invoice fees total.
3461
+     *
3462
+     * @since 1.0.19
3463
+     * @return float The recalculated fee
3464
+     */
3465
+    public function recalculate_total_fees() {
3466
+        $fees      = $this->get_fees();
3467
+        $fee       = 0;
3468
+        $recurring = 0;
3469 3469
 
3470 3470
         foreach ( $fees as $data ) {
3471 3471
 
3472
-			if ( $data['recurring'] ) {
3473
-				$recurring += $data['amount'];
3474
-			} else {
3475
-				$fee += $data['amount'];
3476
-			}
3472
+            if ( $data['recurring'] ) {
3473
+                $recurring += $data['amount'];
3474
+            } else {
3475
+                $fee += $data['amount'];
3476
+            }
3477 3477
 
3478
-		}
3478
+        }
3479 3479
 
3480 3480
         if ( $this->is_renewal() ) {
3481
-			$this->set_total_fees( $recurring );
3482
-		} else {
3483
-			$this->set_total_fees( $fee );
3484
-		}
3481
+            $this->set_total_fees( $recurring );
3482
+        } else {
3483
+            $this->set_total_fees( $fee );
3484
+        }
3485 3485
 
3486
-		$this->totals['fee'] = array(
3487
-			'initial'   => $fee,
3488
-			'recurring' => $recurring,
3489
-		);
3486
+        $this->totals['fee'] = array(
3487
+            'initial'   => $fee,
3488
+            'recurring' => $recurring,
3489
+        );
3490 3490
 
3491 3491
         $this->set_total_fees( $fee );
3492 3492
         return $this->is_renewal() ? $recurring : $fee;
3493 3493
     }
3494 3494
 
3495 3495
     /**
3496
-	 * Recalculates the invoice total.
3497
-	 *
3498
-	 * @since 1.0.19
3496
+     * Recalculates the invoice total.
3497
+     *
3498
+     * @since 1.0.19
3499 3499
      * @return float The invoice total
3500
-	 */
3501
-	public function recalculate_total() {
3500
+     */
3501
+    public function recalculate_total() {
3502 3502
         $this->recalculate_subtotal();
3503 3503
         $this->recalculate_total_fees();
3504 3504
         $this->recalculate_total_discount();
3505 3505
         $this->recalculate_total_tax();
3506
-		return $this->get_total();
3507
-	}
3506
+        return $this->get_total();
3507
+    }
3508 3508
 
3509
-	/**
3510
-	 * @deprecated
3511
-	 */
3509
+    /**
3510
+     * @deprecated
3511
+     */
3512 3512
     public function recalculate_totals( $temp = false ) {
3513 3513
         $this->update_items( $temp );
3514 3514
         $this->save( true );
@@ -3526,7 +3526,7 @@  discard block
 block discarded – undo
3526 3526
      * Adds a note to an invoice.
3527 3527
      *
3528 3528
      * @param string $note The note being added.
3529
-	 * @return int|false The new note's ID on success, false on failure.
3529
+     * @return int|false The new note's ID on success, false on failure.
3530 3530
      *
3531 3531
      */
3532 3532
     public function add_note( $note = '', $customer_type = false, $added_by_user = false, $system = false ) {
@@ -3536,23 +3536,23 @@  discard block
 block discarded – undo
3536 3536
             return false;
3537 3537
         }
3538 3538
 
3539
-		// If this is an admin comment or it has been added by the user.
3540
-		if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) {
3541
-			$user         = get_user_by( 'id', get_current_user_id() );
3539
+        // If this is an admin comment or it has been added by the user.
3540
+        if ( is_user_logged_in() && ( wpinv_current_user_can_manage_invoicing() || $added_by_user ) ) {
3541
+            $user         = get_user_by( 'id', get_current_user_id() );
3542 3542
             $author       = $user->display_name;
3543 3543
             $author_email = $user->user_email;
3544
-		} 
3544
+        } 
3545 3545
 
3546
-		if ( $system ) {
3547
-			$author       = 'System';
3546
+        if ( $system ) {
3547
+            $author       = 'System';
3548 3548
             $author_email = '[email protected]';
3549
-		}
3549
+        }
3550 3550
 
3551
-		return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3551
+        return getpaid_notes()->add_invoice_note( $this, $note, $author, $author_email, $customer_type );
3552 3552
 
3553
-	}
3553
+    }
3554 3554
 
3555
-	/**
3555
+    /**
3556 3556
      * Generates a unique key for the invoice.
3557 3557
      */
3558 3558
     public function generate_key( $string = '' ) {
@@ -3572,106 +3572,106 @@  discard block
 block discarded – undo
3572 3572
             $number = wpinv_get_next_invoice_number( $this->post_type );
3573 3573
         }
3574 3574
 
3575
-		$number = wpinv_format_invoice_number( $number, $this->post_type );
3575
+        $number = wpinv_format_invoice_number( $number, $this->post_type );
3576 3576
 
3577
-		return $number;
3578
-	}
3577
+        return $number;
3578
+    }
3579 3579
 
3580
-	/**
3581
-	 * Handle the status transition.
3582
-	 */
3583
-	protected function status_transition() {
3584
-		$status_transition = $this->status_transition;
3580
+    /**
3581
+     * Handle the status transition.
3582
+     */
3583
+    protected function status_transition() {
3584
+        $status_transition = $this->status_transition;
3585 3585
 
3586
-		// Reset status transition variable.
3587
-		$this->status_transition = false;
3586
+        // Reset status transition variable.
3587
+        $this->status_transition = false;
3588 3588
 
3589
-		if ( $status_transition ) {
3590
-			try {
3589
+        if ( $status_transition ) {
3590
+            try {
3591 3591
 
3592
-				// Fire a hook for the status change.
3593
-				do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3592
+                // Fire a hook for the status change.
3593
+                do_action( 'getpaid_invoice_status_' . $status_transition['to'], $this->get_id(), $this, $status_transition );
3594 3594
 
3595
-				// @deprecated this is deprecated and will be removed in the future.
3596
-				do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3595
+                // @deprecated this is deprecated and will be removed in the future.
3596
+                do_action( 'wpinv_status_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3597 3597
 
3598
-				if ( ! empty( $status_transition['from'] ) ) {
3598
+                if ( ! empty( $status_transition['from'] ) ) {
3599 3599
 
3600
-					/* translators: 1: old invoice status 2: new invoice status */
3601
-					$transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3600
+                    /* translators: 1: old invoice status 2: new invoice status */
3601
+                    $transition_note = sprintf( __( 'Status changed from %1$s to %2$s.', 'invoicing' ), wpinv_status_nicename( $status_transition['from'] ), wpinv_status_nicename( $status_transition['to'] ) );
3602 3602
 
3603
-					// Fire another hook.
3604
-					do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3605
-					do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3603
+                    // Fire another hook.
3604
+                    do_action( 'getpaid_invoice_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $this );
3605
+                    do_action( 'getpaid_invoice_status_changed', $this->get_id(), $status_transition['from'], $status_transition['to'], $this );
3606 3606
 
3607
-					// @deprecated this is deprecated and will be removed in the future.
3608
-					do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3607
+                    // @deprecated this is deprecated and will be removed in the future.
3608
+                    do_action( 'wpinv_status_' . $status_transition['from'] . '_to_' . $status_transition['to'], $this->get_id(), $status_transition['from'] );
3609 3609
 
3610
-					// Note the transition occurred.
3611
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3610
+                    // Note the transition occurred.
3611
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3612 3612
 
3613
-					// Work out if this was for a payment, and trigger a payment_status hook instead.
3614
-					if (
3615
-						in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true )
3616
-						&& in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3617
-					) {
3618
-						do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3619
-					}
3620
-				} else {
3621
-					/* translators: %s: new invoice status */
3622
-					$transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3613
+                    // Work out if this was for a payment, and trigger a payment_status hook instead.
3614
+                    if (
3615
+                        in_array( $status_transition['from'], array( 'wpi-cancelled', 'wpi-pending', 'wpi-failed', 'wpi-refunded' ), true )
3616
+                        && in_array( $status_transition['to'], array( 'publish', 'wpi-processing', 'wpi-renewal' ), true )
3617
+                    ) {
3618
+                        do_action( 'getpaid_invoice_payment_status_changed', $this->get_id(), $this, $status_transition );
3619
+                    }
3620
+                } else {
3621
+                    /* translators: %s: new invoice status */
3622
+                    $transition_note = sprintf( __( 'Status set to %s.', 'invoicing' ), wpinv_status_nicename( $status_transition['to'] ) );
3623 3623
 
3624
-					// Note the transition occurred.
3625
-					$this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3624
+                    // Note the transition occurred.
3625
+                    $this->add_note( trim( $status_transition['note'] . ' ' . $transition_note ), 0, $status_transition['manual'] );
3626 3626
 
3627
-				}
3628
-			} catch ( Exception $e ) {
3629
-				$this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3630
-			}
3631
-		}
3632
-	}
3627
+                }
3628
+            } catch ( Exception $e ) {
3629
+                $this->add_note( __( 'Error during status transition.', 'invoicing' ) . ' ' . $e->getMessage() );
3630
+            }
3631
+        }
3632
+    }
3633 3633
 
3634
-	/**
3635
-	 * Updates an invoice status.
3636
-	 */
3637
-	public function update_status( $new_status = false, $note = '', $manual = false ) {
3634
+    /**
3635
+     * Updates an invoice status.
3636
+     */
3637
+    public function update_status( $new_status = false, $note = '', $manual = false ) {
3638 3638
 
3639
-		// Fires before updating a status.
3640
-		do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3639
+        // Fires before updating a status.
3640
+        do_action( 'wpinv_before_invoice_status_change', $this->get_id(), $new_status, $this->get_status( 'edit' ) );
3641 3641
 
3642
-		// Update the status.
3643
-		$this->set_status( $new_status, $note, $manual );
3642
+        // Update the status.
3643
+        $this->set_status( $new_status, $note, $manual );
3644 3644
 
3645
-		// Save the order.
3646
-		return $this->save();
3645
+        // Save the order.
3646
+        return $this->save();
3647 3647
 
3648
-	}
3648
+    }
3649 3649
 
3650
-	/**
3651
-	 * @deprecated
3652
-	 */
3653
-	public function refresh_item_ids() {
3650
+    /**
3651
+     * @deprecated
3652
+     */
3653
+    public function refresh_item_ids() {
3654 3654
         $item_ids = implode( ',', array_unique( array_keys( $this->get_items() ) ) );
3655 3655
         update_post_meta( $this->get_id(), '_wpinv_item_ids', $item_ids );
3656
-	}
3656
+    }
3657 3657
 
3658
-	/**
3659
-	 * @deprecated
3660
-	 */
3661
-	public function update_items( $temp = false ) {
3658
+    /**
3659
+     * @deprecated
3660
+     */
3661
+    public function update_items( $temp = false ) {
3662 3662
 
3663
-		$this->set_items( $this->get_items() );
3663
+        $this->set_items( $this->get_items() );
3664 3664
 
3665
-		if ( ! $temp ) {
3666
-			$this->save();
3667
-		}
3665
+        if ( ! $temp ) {
3666
+            $this->save();
3667
+        }
3668 3668
 
3669 3669
         return $this;
3670
-	}
3670
+    }
3671 3671
 
3672
-	/**
3673
-	 * @deprecated
3674
-	 */
3672
+    /**
3673
+     * @deprecated
3674
+     */
3675 3675
     public function validate_discount() {
3676 3676
 
3677 3677
         $discount_code = $this->get_discount_code();
@@ -3687,86 +3687,86 @@  discard block
 block discarded – undo
3687 3687
 
3688 3688
     }
3689 3689
 
3690
-	/**
3691
-	 * Refunds an invoice.
3692
-	 */
3690
+    /**
3691
+     * Refunds an invoice.
3692
+     */
3693 3693
     public function refund() {
3694
-		$this->set_status( 'wpi-refunded' );
3694
+        $this->set_status( 'wpi-refunded' );
3695 3695
         $this->save();
3696
-	}
3696
+    }
3697 3697
 
3698
-	/**
3699
-	 * Marks an invoice as paid.
3700
-	 * 
3701
-	 * @param string $transaction_id
3702
-	 */
3698
+    /**
3699
+     * Marks an invoice as paid.
3700
+     * 
3701
+     * @param string $transaction_id
3702
+     */
3703 3703
     public function mark_paid( $transaction_id = null, $note = '' ) {
3704 3704
 
3705
-		// Set the transaction id.
3706
-		if ( empty( $transaction_id ) ) {
3707
-			$transaction_id = $this->generate_key('trans_');
3708
-		}
3705
+        // Set the transaction id.
3706
+        if ( empty( $transaction_id ) ) {
3707
+            $transaction_id = $this->generate_key('trans_');
3708
+        }
3709 3709
 
3710
-		if ( ! $this->get_transaction_id() ) {
3711
-			$this->set_transaction_id( $transaction_id );
3712
-		}
3710
+        if ( ! $this->get_transaction_id() ) {
3711
+            $this->set_transaction_id( $transaction_id );
3712
+        }
3713 3713
 
3714
-		if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3715
-			return $this->save();
3716
-		}
3714
+        if ( $this->is_paid() && 'wpi-processing' != $this->get_status() ) {
3715
+            return $this->save();
3716
+        }
3717 3717
 
3718
-		// Set the completed date.
3719
-		$this->set_date_completed( current_time( 'mysql' ) );
3718
+        // Set the completed date.
3719
+        $this->set_date_completed( current_time( 'mysql' ) );
3720 3720
 
3721
-		// Set the new status.
3722
-		if ( $this->is_renewal() ) {
3721
+        // Set the new status.
3722
+        if ( $this->is_renewal() ) {
3723 3723
 
3724
-			$_note = sprintf(
3725
-				__( 'Renewed via %s', 'invoicing' ),
3726
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3727
-			);
3724
+            $_note = sprintf(
3725
+                __( 'Renewed via %s', 'invoicing' ),
3726
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3727
+            );
3728 3728
 
3729
-			if ( 'none' == $this->get_gateway() ) {
3730
-				$_note = $note;
3731
-			}
3729
+            if ( 'none' == $this->get_gateway() ) {
3730
+                $_note = $note;
3731
+            }
3732 3732
 
3733
-			$this->set_status( 'wpi-renewal', $_note );
3733
+            $this->set_status( 'wpi-renewal', $_note );
3734 3734
 
3735
-		} else {
3735
+        } else {
3736 3736
 
3737
-			$_note = sprintf(
3738
-				__( 'Paid via %s', 'invoicing' ),
3739
-				$this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3740
-			);
3737
+            $_note = sprintf(
3738
+                __( 'Paid via %s', 'invoicing' ),
3739
+                $this->get_gateway_title() . empty( $note ) ? '' : " ($note)"
3740
+            );
3741 3741
 
3742
-			if ( 'none' == $this->get_gateway() ) {
3743
-				$_note = $note;
3744
-			}
3742
+            if ( 'none' == $this->get_gateway() ) {
3743
+                $_note = $note;
3744
+            }
3745 3745
 
3746
-			$this->set_status( 'publish',$_note );
3746
+            $this->set_status( 'publish',$_note );
3747 3747
 
3748
-		}
3748
+        }
3749 3749
 
3750
-		// Set checkout mode.
3751
-		$mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3752
-		$this->set_mode( $mode );
3750
+        // Set checkout mode.
3751
+        $mode = wpinv_is_test_mode( $this->get_gateway() ) ? 'test' : 'live';
3752
+        $this->set_mode( $mode );
3753 3753
 
3754
-		// Save the invoice.
3754
+        // Save the invoice.
3755 3755
         $this->save();
3756
-	}
3757
-
3758
-
3759
-	/**
3760
-	 * Save data to the database.
3761
-	 *
3762
-	 * @since 1.0.19
3763
-	 * @return int invoice ID
3764
-	 */
3765
-	public function save() {
3766
-		$this->maybe_set_date_paid();
3767
-		parent::save();
3768
-		$this->status_transition();
3769
-		return $this->get_id();
3770
-	}
3756
+    }
3757
+
3758
+
3759
+    /**
3760
+     * Save data to the database.
3761
+     *
3762
+     * @since 1.0.19
3763
+     * @return int invoice ID
3764
+     */
3765
+    public function save() {
3766
+        $this->maybe_set_date_paid();
3767
+        parent::save();
3768
+        $this->status_transition();
3769
+        return $this->get_id();
3770
+    }
3771 3771
 
3772 3772
 }
Please login to merge, or discard this patch.