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