Passed
Pull Request — master (#785)
by
unknown
14:17
created
includes/class-wpinv-item.php 1 patch
Indentation   +751 added lines, -751 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'          => '',
@@ -62,13 +62,13 @@  discard block
 block discarded – undo
62 62
     );
63 63
 
64 64
     /**
65
-	 * Stores meta in cache for future reads.
66
-	 *
67
-	 * A group must be set to to enable caching.
68
-	 *
69
-	 * @var string
70
-	 */
71
-	protected $cache_group = 'getpaid_items';
65
+     * Stores meta in cache for future reads.
66
+     *
67
+     * A group must be set to to enable caching.
68
+     *
69
+     * @var string
70
+     */
71
+    protected $cache_group = 'getpaid_items';
72 72
 
73 73
     /**
74 74
      * Stores a reference to the original WP_Post object
@@ -78,36 +78,36 @@  discard block
 block discarded – undo
78 78
     protected $post = null;
79 79
 
80 80
     /**
81
-	 * Get the item if ID is passed, otherwise the item is new and empty.
82
-	 *
83
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
84
-	 */
85
-	public function __construct( $item = 0 ) {
86
-		parent::__construct( $item );
87
-
88
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
89
-			$this->set_id( $item );
90
-		} elseif ( $item instanceof self ) {
91
-			$this->set_id( $item->get_id() );
92
-		} elseif ( ! empty( $item->ID ) ) {
93
-			$this->set_id( $item->ID );
94
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
95
-			$this->set_id( $item_id );
96
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
97
-			$this->set_id( $item_id );
98
-		} else {
99
-			$this->set_object_read( true );
100
-		}
81
+     * Get the item if ID is passed, otherwise the item is new and empty.
82
+     *
83
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
84
+     */
85
+    public function __construct( $item = 0 ) {
86
+        parent::__construct( $item );
87
+
88
+        if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
89
+            $this->set_id( $item );
90
+        } elseif ( $item instanceof self ) {
91
+            $this->set_id( $item->get_id() );
92
+        } elseif ( ! empty( $item->ID ) ) {
93
+            $this->set_id( $item->ID );
94
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
95
+            $this->set_id( $item_id );
96
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
97
+            $this->set_id( $item_id );
98
+        } else {
99
+            $this->set_object_read( true );
100
+        }
101 101
 
102 102
         // Load the datastore.
103
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
103
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
104 104
 
105
-		if ( $this->get_id() > 0 ) {
105
+        if ( $this->get_id() > 0 ) {
106 106
             $this->post = get_post( $this->get_id() );
107 107
             $this->ID   = $this->get_id();
108
-			$this->data_store->read( $this );
108
+            $this->data_store->read( $this );
109 109
         }
110
-	}
110
+    }
111 111
 
112 112
     /*
113 113
 	|--------------------------------------------------------------------------
@@ -125,188 +125,188 @@  discard block
 block discarded – undo
125 125
     */
126 126
 
127 127
     /**
128
-	 * Get parent item ID.
129
-	 *
130
-	 * @since 1.0.19
131
-	 * @param  string $context View or edit context.
132
-	 * @return int
133
-	 */
134
-	public function get_parent_id( $context = 'view' ) {
135
-		return (int) $this->get_prop( 'parent_id', $context );
128
+     * Get parent item ID.
129
+     *
130
+     * @since 1.0.19
131
+     * @param  string $context View or edit context.
132
+     * @return int
133
+     */
134
+    public function get_parent_id( $context = 'view' ) {
135
+        return (int) $this->get_prop( 'parent_id', $context );
136 136
     }
137 137
 
138 138
     /**
139
-	 * Get item status.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param  string $context View or edit context.
143
-	 * @return string
144
-	 */
145
-	public function get_status( $context = 'view' ) {
146
-		return $this->get_prop( 'status', $context );
139
+     * Get item status.
140
+     *
141
+     * @since 1.0.19
142
+     * @param  string $context View or edit context.
143
+     * @return string
144
+     */
145
+    public function get_status( $context = 'view' ) {
146
+        return $this->get_prop( 'status', $context );
147 147
     }
148 148
 
149 149
     /**
150
-	 * Get plugin version when the item was created.
151
-	 *
152
-	 * @since 1.0.19
153
-	 * @param  string $context View or edit context.
154
-	 * @return string
155
-	 */
156
-	public function get_version( $context = 'view' ) {
157
-		return $this->get_prop( 'version', $context );
150
+     * Get plugin version when the item was created.
151
+     *
152
+     * @since 1.0.19
153
+     * @param  string $context View or edit context.
154
+     * @return string
155
+     */
156
+    public function get_version( $context = 'view' ) {
157
+        return $this->get_prop( 'version', $context );
158 158
     }
159 159
 
160 160
     /**
161
-	 * Get date when the item was created.
162
-	 *
163
-	 * @since 1.0.19
164
-	 * @param  string $context View or edit context.
165
-	 * @return string
166
-	 */
167
-	public function get_date_created( $context = 'view' ) {
168
-		return $this->get_prop( 'date_created', $context );
161
+     * Get date when the item was created.
162
+     *
163
+     * @since 1.0.19
164
+     * @param  string $context View or edit context.
165
+     * @return string
166
+     */
167
+    public function get_date_created( $context = 'view' ) {
168
+        return $this->get_prop( 'date_created', $context );
169 169
     }
170 170
 
171 171
     /**
172
-	 * Get GMT date when the item was created.
173
-	 *
174
-	 * @since 1.0.19
175
-	 * @param  string $context View or edit context.
176
-	 * @return string
177
-	 */
178
-	public function get_date_created_gmt( $context = 'view' ) {
172
+     * Get GMT date when the item was created.
173
+     *
174
+     * @since 1.0.19
175
+     * @param  string $context View or edit context.
176
+     * @return string
177
+     */
178
+    public function get_date_created_gmt( $context = 'view' ) {
179 179
         $date = $this->get_date_created( $context );
180 180
 
181 181
         if ( $date ) {
182 182
             $date = get_gmt_from_date( $date );
183 183
         }
184
-		return $date;
184
+        return $date;
185 185
     }
186 186
 
187 187
     /**
188
-	 * Get date when the item was last modified.
189
-	 *
190
-	 * @since 1.0.19
191
-	 * @param  string $context View or edit context.
192
-	 * @return string
193
-	 */
194
-	public function get_date_modified( $context = 'view' ) {
195
-		return $this->get_prop( 'date_modified', $context );
188
+     * Get date when the item was last modified.
189
+     *
190
+     * @since 1.0.19
191
+     * @param  string $context View or edit context.
192
+     * @return string
193
+     */
194
+    public function get_date_modified( $context = 'view' ) {
195
+        return $this->get_prop( 'date_modified', $context );
196 196
     }
197 197
 
198 198
     /**
199
-	 * Get GMT date when the item was last modified.
200
-	 *
201
-	 * @since 1.0.19
202
-	 * @param  string $context View or edit context.
203
-	 * @return string
204
-	 */
205
-	public function get_date_modified_gmt( $context = 'view' ) {
199
+     * Get GMT date when the item was last modified.
200
+     *
201
+     * @since 1.0.19
202
+     * @param  string $context View or edit context.
203
+     * @return string
204
+     */
205
+    public function get_date_modified_gmt( $context = 'view' ) {
206 206
         $date = $this->get_date_modified( $context );
207 207
 
208 208
         if ( $date ) {
209 209
             $date = get_gmt_from_date( $date );
210 210
         }
211
-		return $date;
211
+        return $date;
212 212
     }
213 213
 
214 214
     /**
215
-	 * Get the item name.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return string
220
-	 */
221
-	public function get_name( $context = 'view' ) {
222
-		return $this->get_prop( 'name', $context );
215
+     * Get the item name.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return string
220
+     */
221
+    public function get_name( $context = 'view' ) {
222
+        return $this->get_prop( 'name', $context );
223 223
     }
224 224
 
225 225
     /**
226
-	 * Alias of self::get_name().
227
-	 *
228
-	 * @since 1.0.19
229
-	 * @param  string $context View or edit context.
230
-	 * @return string
231
-	 */
232
-	public function get_title( $context = 'view' ) {
233
-		return $this->get_name( $context );
226
+     * Alias of self::get_name().
227
+     *
228
+     * @since 1.0.19
229
+     * @param  string $context View or edit context.
230
+     * @return string
231
+     */
232
+    public function get_title( $context = 'view' ) {
233
+        return $this->get_name( $context );
234 234
     }
235 235
 
236 236
     /**
237
-	 * Get the item description.
238
-	 *
239
-	 * @since 1.0.19
240
-	 * @param  string $context View or edit context.
241
-	 * @return string
242
-	 */
243
-	public function get_description( $context = 'view' ) {
244
-		return $this->get_prop( 'description', $context );
237
+     * Get the item description.
238
+     *
239
+     * @since 1.0.19
240
+     * @param  string $context View or edit context.
241
+     * @return string
242
+     */
243
+    public function get_description( $context = 'view' ) {
244
+        return $this->get_prop( 'description', $context );
245 245
     }
246 246
 
247 247
     /**
248
-	 * Alias of self::get_description().
249
-	 *
250
-	 * @since 1.0.19
251
-	 * @param  string $context View or edit context.
252
-	 * @return string
253
-	 */
254
-	public function get_excerpt( $context = 'view' ) {
255
-		return $this->get_description( $context );
248
+     * Alias of self::get_description().
249
+     *
250
+     * @since 1.0.19
251
+     * @param  string $context View or edit context.
252
+     * @return string
253
+     */
254
+    public function get_excerpt( $context = 'view' ) {
255
+        return $this->get_description( $context );
256 256
     }
257 257
 
258 258
     /**
259
-	 * Alias of self::get_description().
260
-	 *
261
-	 * @since 1.0.19
262
-	 * @param  string $context View or edit context.
263
-	 * @return string
264
-	 */
265
-	public function get_summary( $context = 'view' ) {
266
-		return $this->get_description( $context );
259
+     * Alias of self::get_description().
260
+     *
261
+     * @since 1.0.19
262
+     * @param  string $context View or edit context.
263
+     * @return string
264
+     */
265
+    public function get_summary( $context = 'view' ) {
266
+        return $this->get_description( $context );
267 267
     }
268 268
 
269 269
     /**
270
-	 * Get the owner of the item.
271
-	 *
272
-	 * @since 1.0.19
273
-	 * @param  string $context View or edit context.
274
-	 * @return int
275
-	 */
276
-	public function get_author( $context = 'view' ) {
277
-		return (int) $this->get_prop( 'author', $context );
278
-	}
270
+     * Get the owner of the item.
271
+     *
272
+     * @since 1.0.19
273
+     * @param  string $context View or edit context.
274
+     * @return int
275
+     */
276
+    public function get_author( $context = 'view' ) {
277
+        return (int) $this->get_prop( 'author', $context );
278
+    }
279 279
 
280
-	/**
281
-	 * Alias of self::get_author().
282
-	 *
283
-	 * @since 1.0.19
284
-	 * @param  string $context View or edit context.
285
-	 * @return int
286
-	 */
287
-	public function get_owner( $context = 'view' ) {
288
-		return $this->get_author( $context );
280
+    /**
281
+     * Alias of self::get_author().
282
+     *
283
+     * @since 1.0.19
284
+     * @param  string $context View or edit context.
285
+     * @return int
286
+     */
287
+    public function get_owner( $context = 'view' ) {
288
+        return $this->get_author( $context );
289 289
     }
290 290
 
291 291
     /**
292
-	 * Get the price of the item.
293
-	 *
294
-	 * @since 1.0.19
295
-	 * @param  string $context View or edit context.
296
-	 * @return float
297
-	 */
298
-	public function get_price( $context = 'view' ) {
292
+     * Get the price of the item.
293
+     *
294
+     * @since 1.0.19
295
+     * @param  string $context View or edit context.
296
+     * @return float
297
+     */
298
+    public function get_price( $context = 'view' ) {
299 299
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
300
-	}
301
-
302
-	/**
303
-	 * Get the inital price of the item.
304
-	 *
305
-	 * @since 1.0.19
306
-	 * @param  string $context View or edit context.
307
-	 * @return float
308
-	 */
309
-	public function get_initial_price( $context = 'view', $price_id = null ) {
300
+    }
301
+
302
+    /**
303
+     * Get the inital price of the item.
304
+     *
305
+     * @since 1.0.19
306
+     * @param  string $context View or edit context.
307
+     * @return float
308
+     */
309
+    public function get_initial_price( $context = 'view', $price_id = null ) {
310 310
         $price = 0;
311 311
 
312 312
         if ( null === $price_id ) {
@@ -327,134 +327,134 @@  discard block
 block discarded – undo
327 327
     }
328 328
 
329 329
     /**
330
-	 * Returns a formated price.
331
-	 *
332
-	 * @since 1.0.19
333
-	 * @param  string $context View or edit context.
334
-	 * @return string
335
-	 */
330
+     * Returns a formated price.
331
+     *
332
+     * @since 1.0.19
333
+     * @param  string $context View or edit context.
334
+     * @return string
335
+     */
336 336
     public function get_the_price() {
337 337
         return wpinv_price( $this->get_price() );
338
-	}
339
-
340
-	/**
341
-	 * Returns the formated initial price.
342
-	 *
343
-	 * @since 1.0.19
344
-	 * @param  string $context View or edit context.
345
-	 * @return string
346
-	 */
338
+    }
339
+
340
+    /**
341
+     * Returns the formated initial price.
342
+     *
343
+     * @since 1.0.19
344
+     * @param  string $context View or edit context.
345
+     * @return string
346
+     */
347 347
     public function get_the_initial_price() {
348 348
         return wpinv_price( $this->get_initial_price() );
349 349
     }
350 350
 
351 351
     /**
352
-	 * Get the VAT rule of the item.
353
-	 *
354
-	 * @since 1.0.19
355
-	 * @param  string $context View or edit context.
356
-	 * @return string
357
-	 */
358
-	public function get_vat_rule( $context = 'view' ) {
352
+     * Get the VAT rule of the item.
353
+     *
354
+     * @since 1.0.19
355
+     * @param  string $context View or edit context.
356
+     * @return string
357
+     */
358
+    public function get_vat_rule( $context = 'view' ) {
359 359
         return $this->get_prop( 'vat_rule', $context );
360 360
     }
361 361
 
362 362
     /**
363
-	 * Get the VAT class of the item.
364
-	 *
365
-	 * @since 1.0.19
366
-	 * @param  string $context View or edit context.
367
-	 * @return string
368
-	 */
369
-	public function get_vat_class( $context = 'view' ) {
363
+     * Get the VAT class of the item.
364
+     *
365
+     * @since 1.0.19
366
+     * @param  string $context View or edit context.
367
+     * @return string
368
+     */
369
+    public function get_vat_class( $context = 'view' ) {
370 370
         return $this->get_prop( 'vat_class', $context );
371 371
     }
372 372
 
373 373
     /**
374
-	 * Get the type of the item.
375
-	 *
376
-	 * @since 1.0.19
377
-	 * @param  string $context View or edit context.
378
-	 * @return string
379
-	 */
380
-	public function get_type( $context = 'view' ) {
374
+     * Get the type of the item.
375
+     *
376
+     * @since 1.0.19
377
+     * @param  string $context View or edit context.
378
+     * @return string
379
+     */
380
+    public function get_type( $context = 'view' ) {
381 381
         return $this->get_prop( 'type', $context );
382 382
     }
383 383
 
384 384
     /**
385
-	 * Get the custom id of the item.
386
-	 *
387
-	 * @since 1.0.19
388
-	 * @param  string $context View or edit context.
389
-	 * @return string
390
-	 */
391
-	public function get_custom_id( $context = 'view' ) {
385
+     * Get the custom id of the item.
386
+     *
387
+     * @since 1.0.19
388
+     * @param  string $context View or edit context.
389
+     * @return string
390
+     */
391
+    public function get_custom_id( $context = 'view' ) {
392 392
         return $this->get_prop( 'custom_id', $context );
393 393
     }
394 394
 
395 395
     /**
396
-	 * Get the custom name of the item.
397
-	 *
398
-	 * @since 1.0.19
399
-	 * @param  string $context View or edit context.
400
-	 * @return string
401
-	 */
402
-	public function get_custom_name( $context = 'view' ) {
396
+     * Get the custom name of the item.
397
+     *
398
+     * @since 1.0.19
399
+     * @param  string $context View or edit context.
400
+     * @return string
401
+     */
402
+    public function get_custom_name( $context = 'view' ) {
403 403
         return $this->get_prop( 'custom_name', $context );
404 404
     }
405 405
 
406 406
     /**
407
-	 * Get the custom singular name of the item.
408
-	 *
409
-	 * @since 1.0.19
410
-	 * @param  string $context View or edit context.
411
-	 * @return string
412
-	 */
413
-	public function get_custom_singular_name( $context = 'view' ) {
407
+     * Get the custom singular name of the item.
408
+     *
409
+     * @since 1.0.19
410
+     * @param  string $context View or edit context.
411
+     * @return string
412
+     */
413
+    public function get_custom_singular_name( $context = 'view' ) {
414 414
         return $this->get_prop( 'custom_singular_name', $context );
415 415
     }
416 416
 
417 417
     /**
418
-	 * Checks if an item is editable..
419
-	 *
420
-	 * @since 1.0.19
421
-	 * @param  string $context View or edit context.
422
-	 * @return int
423
-	 */
424
-	public function get_is_editable( $context = 'view' ) {
418
+     * Checks if an item is editable..
419
+     *
420
+     * @since 1.0.19
421
+     * @param  string $context View or edit context.
422
+     * @return int
423
+     */
424
+    public function get_is_editable( $context = 'view' ) {
425 425
         return (int) $this->get_prop( 'is_editable', $context );
426 426
     }
427 427
 
428 428
     /**
429
-	 * Alias of self::get_is_editable().
430
-	 *
431
-	 * @since 1.0.19
432
-	 * @param  string $context View or edit context.
433
-	 * @return int
434
-	 */
435
-	public function get_editable( $context = 'view' ) {
436
-		return $this->get_is_editable( $context );
429
+     * Alias of self::get_is_editable().
430
+     *
431
+     * @since 1.0.19
432
+     * @param  string $context View or edit context.
433
+     * @return int
434
+     */
435
+    public function get_editable( $context = 'view' ) {
436
+        return $this->get_is_editable( $context );
437 437
     }
438 438
 
439 439
     /**
440
-	 * Checks if dynamic pricing is enabled.
441
-	 *
442
-	 * @since 1.0.19
443
-	 * @param  string $context View or edit context.
444
-	 * @return int
445
-	 */
446
-	public function get_is_dynamic_pricing( $context = 'view' ) {
440
+     * Checks if dynamic pricing is enabled.
441
+     *
442
+     * @since 1.0.19
443
+     * @param  string $context View or edit context.
444
+     * @return int
445
+     */
446
+    public function get_is_dynamic_pricing( $context = 'view' ) {
447 447
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
448 448
     }
449 449
 
450 450
     /**
451
-	 * Returns the minimum price if dynamic pricing is enabled.
452
-	 *
453
-	 * @since 1.0.19
454
-	 * @param  string $context View or edit context.
455
-	 * @return float
456
-	 */
457
-	public function get_minimum_price( $context = 'view' ) {
451
+     * Returns the minimum price if dynamic pricing is enabled.
452
+     *
453
+     * @since 1.0.19
454
+     * @param  string $context View or edit context.
455
+     * @return float
456
+     */
457
+    public function get_minimum_price( $context = 'view' ) {
458 458
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
459 459
     }
460 460
 
@@ -528,7 +528,7 @@  discard block
 block discarded – undo
528 528
     /**
529 529
      * Retrieve the variable prices
530 530
      *
531
-    * @since 2.8.9
531
+     * @since 2.8.9
532 532
      * @return array List of the variable prices
533 533
      */
534 534
     public function get_variable_prices() {
@@ -542,76 +542,76 @@  discard block
 block discarded – undo
542 542
     }
543 543
 
544 544
     /**
545
-	 * Checks if this is a recurring item.
546
-	 *
547
-	 * @since 1.0.19
548
-	 * @param  string $context View or edit context.
549
-	 * @return int
550
-	 */
551
-	public function get_is_recurring( $context = 'view' ) {
545
+     * Checks if this is a recurring item.
546
+     *
547
+     * @since 1.0.19
548
+     * @param  string $context View or edit context.
549
+     * @return int
550
+     */
551
+    public function get_is_recurring( $context = 'view' ) {
552 552
         return (int) $this->get_prop( 'is_recurring', $context );
553
-	}
554
-
555
-	/**
556
-	 * Get the recurring price of the item.
557
-	 *
558
-	 * @since 1.0.19
559
-	 * @param  string $context View or edit context.
560
-	 * @return float
561
-	 */
562
-	public function get_recurring_price( $context = 'view' ) {
563
-		$price = $this->get_price( $context );
553
+    }
554
+
555
+    /**
556
+     * Get the recurring price of the item.
557
+     *
558
+     * @since 1.0.19
559
+     * @param  string $context View or edit context.
560
+     * @return float
561
+     */
562
+    public function get_recurring_price( $context = 'view' ) {
563
+        $price = $this->get_price( $context );
564 564
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
565
-	}
566
-
567
-	/**
568
-	 * Get the formatted recurring price of the item.
569
-	 *
570
-	 * @since 1.0.19
571
-	 * @param  string $context View or edit context.
572
-	 * @return string
573
-	 */
565
+    }
566
+
567
+    /**
568
+     * Get the formatted recurring price of the item.
569
+     *
570
+     * @since 1.0.19
571
+     * @param  string $context View or edit context.
572
+     * @return string
573
+     */
574 574
     public function get_the_recurring_price() {
575 575
         return wpinv_price( $this->get_recurring_price() );
576
-	}
577
-
578
-	/**
579
-	 * Get the first renewal date (in timestamps) of the item.
580
-	 *
581
-	 * @since 1.0.19
582
-	 * @return int
583
-	 */
584
-	public function get_first_renewal_date() {
585
-
586
-		$periods = array(
587
-			'D' => 'days',
588
-			'W' => 'weeks',
589
-			'M' => 'months',
590
-			'Y' => 'years',
591
-		);
592
-
593
-		$period   = $this->get_recurring_period();
594
-		$interval = $this->get_recurring_interval();
595
-
596
-		if ( $this->has_free_trial() ) {
597
-			$period   = $this->get_trial_period();
598
-			$interval = $this->get_trial_interval();
599
-		}
600
-
601
-		$period       = $periods[ $period ];
602
-		$interval     = empty( $interval ) ? 1 : $interval;
603
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
576
+    }
577
+
578
+    /**
579
+     * Get the first renewal date (in timestamps) of the item.
580
+     *
581
+     * @since 1.0.19
582
+     * @return int
583
+     */
584
+    public function get_first_renewal_date() {
585
+
586
+        $periods = array(
587
+            'D' => 'days',
588
+            'W' => 'weeks',
589
+            'M' => 'months',
590
+            'Y' => 'years',
591
+        );
592
+
593
+        $period   = $this->get_recurring_period();
594
+        $interval = $this->get_recurring_interval();
595
+
596
+        if ( $this->has_free_trial() ) {
597
+            $period   = $this->get_trial_period();
598
+            $interval = $this->get_trial_interval();
599
+        }
600
+
601
+        $period       = $periods[ $period ];
602
+        $interval     = empty( $interval ) ? 1 : $interval;
603
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
604 604
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
605 605
     }
606 606
 
607 607
     /**
608
-	 * Get the recurring period.
609
-	 *
610
-	 * @since 1.0.19
611
-	 * @param  bool $full Return abbreviation or in full.
612
-	 * @return string
613
-	 */
614
-	public function get_recurring_period( $full = false ) {
608
+     * Get the recurring period.
609
+     *
610
+     * @since 1.0.19
611
+     * @param  bool $full Return abbreviation or in full.
612
+     * @return string
613
+     */
614
+    public function get_recurring_period( $full = false ) {
615 615
         $period = $this->get_prop( 'recurring_period', 'view' );
616 616
 
617 617
         if ( $full && ! is_bool( $full ) ) {
@@ -622,58 +622,58 @@  discard block
 block discarded – undo
622 622
     }
623 623
 
624 624
     /**
625
-	 * Get the recurring interval.
626
-	 *
627
-	 * @since 1.0.19
628
-	 * @param  string $context View or edit context.
629
-	 * @return int
630
-	 */
631
-	public function get_recurring_interval( $context = 'view' ) {
632
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
633
-		return max( 1, $interval );
625
+     * Get the recurring interval.
626
+     *
627
+     * @since 1.0.19
628
+     * @param  string $context View or edit context.
629
+     * @return int
630
+     */
631
+    public function get_recurring_interval( $context = 'view' ) {
632
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
633
+        return max( 1, $interval );
634 634
     }
635 635
 
636 636
     /**
637
-	 * Get the recurring limit.
638
-	 *
639
-	 * @since 1.0.19
640
-	 * @param  string $context View or edit context.
641
-	 * @return int
642
-	 */
643
-	public function get_recurring_limit( $context = 'view' ) {
637
+     * Get the recurring limit.
638
+     *
639
+     * @since 1.0.19
640
+     * @param  string $context View or edit context.
641
+     * @return int
642
+     */
643
+    public function get_recurring_limit( $context = 'view' ) {
644 644
         return (int) $this->get_prop( 'recurring_limit', $context );
645 645
     }
646 646
 
647 647
     /**
648
-	 * Checks if we have a free trial.
649
-	 *
650
-	 * @since 1.0.19
651
-	 * @param  string $context View or edit context.
652
-	 * @return int
653
-	 */
654
-	public function get_is_free_trial( $context = 'view' ) {
648
+     * Checks if we have a free trial.
649
+     *
650
+     * @since 1.0.19
651
+     * @param  string $context View or edit context.
652
+     * @return int
653
+     */
654
+    public function get_is_free_trial( $context = 'view' ) {
655 655
         return (int) $this->get_prop( 'is_free_trial', $context );
656 656
     }
657 657
 
658 658
     /**
659
-	 * Alias for self::get_is_free_trial().
660
-	 *
661
-	 * @since 1.0.19
662
-	 * @param  string $context View or edit context.
663
-	 * @return int
664
-	 */
665
-	public function get_free_trial( $context = 'view' ) {
659
+     * Alias for self::get_is_free_trial().
660
+     *
661
+     * @since 1.0.19
662
+     * @param  string $context View or edit context.
663
+     * @return int
664
+     */
665
+    public function get_free_trial( $context = 'view' ) {
666 666
         return $this->get_is_free_trial( $context );
667 667
     }
668 668
 
669 669
     /**
670
-	 * Get the trial period.
671
-	 *
672
-	 * @since 1.0.19
673
-	 * @param  bool $full Return abbreviation or in full.
674
-	 * @return string
675
-	 */
676
-	public function get_trial_period( $full = false ) {
670
+     * Get the trial period.
671
+     *
672
+     * @since 1.0.19
673
+     * @param  bool $full Return abbreviation or in full.
674
+     * @return string
675
+     */
676
+    public function get_trial_period( $full = false ) {
677 677
         $period = $this->get_prop( 'trial_period', 'view' );
678 678
 
679 679
         if ( $full && ! is_bool( $full ) ) {
@@ -684,104 +684,104 @@  discard block
 block discarded – undo
684 684
     }
685 685
 
686 686
     /**
687
-	 * Get the trial interval.
688
-	 *
689
-	 * @since 1.0.19
690
-	 * @param  string $context View or edit context.
691
-	 * @return int
692
-	 */
693
-	public function get_trial_interval( $context = 'view' ) {
687
+     * Get the trial interval.
688
+     *
689
+     * @since 1.0.19
690
+     * @param  string $context View or edit context.
691
+     * @return int
692
+     */
693
+    public function get_trial_interval( $context = 'view' ) {
694 694
         return (int) $this->get_prop( 'trial_interval', $context );
695
-	}
696
-
697
-	/**
698
-	 * Get the item's edit url.
699
-	 *
700
-	 * @since 1.0.19
701
-	 * @return string
702
-	 */
703
-	public function get_edit_url() {
695
+    }
696
+
697
+    /**
698
+     * Get the item's edit url.
699
+     *
700
+     * @since 1.0.19
701
+     * @return string
702
+     */
703
+    public function get_edit_url() {
704 704
         return get_edit_post_link( $this->get_id(), 'edit' );
705
-	}
706
-
707
-	/**
708
-	 * Given an item's name/custom id, it returns its id.
709
-	 *
710
-	 *
711
-	 * @static
712
-	 * @param string $value The item name or custom id.
713
-	 * @param string $field Either name or custom_id.
714
-	 * @param string $type in case you need to search for a given type.
715
-	 * @since 1.0.15
716
-	 * @return int
717
-	 */
718
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
719
-
720
-		// Trim the value.
721
-		$value = sanitize_text_field( $value );
722
-		if ( empty( $value ) ) {
723
-			return 0;
724
-		}
705
+    }
706
+
707
+    /**
708
+     * Given an item's name/custom id, it returns its id.
709
+     *
710
+     *
711
+     * @static
712
+     * @param string $value The item name or custom id.
713
+     * @param string $field Either name or custom_id.
714
+     * @param string $type in case you need to search for a given type.
715
+     * @since 1.0.15
716
+     * @return int
717
+     */
718
+    public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
719
+
720
+        // Trim the value.
721
+        $value = sanitize_text_field( $value );
722
+        if ( empty( $value ) ) {
723
+            return 0;
724
+        }
725 725
 
726 726
         // Valid fields.
727 727
         $fields = array( 'custom_id', 'name', 'slug' );
728 728
 
729
-		// Ensure a field has been passed.
730
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
731
-			return 0;
732
-		}
733
-
734
-		if ( $field == 'name' ) {
735
-			$field = 'slug';
736
-		}
737
-
738
-		// Maybe retrieve from the cache.
739
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
740
-		if ( ! empty( $item_id ) ) {
741
-			return $item_id;
742
-		}
743
-
744
-		// Fetch from the db.
745
-		$items = array();
746
-		if ( $field == 'slug' ) {
747
-			$items = get_posts(
748
-				array(
749
-					'post_type'      => 'wpi_item',
750
-					'name'           => $value,
751
-					'posts_per_page' => 1,
752
-					'post_status'    => 'any',
753
-				)
754
-			);
755
-		}
756
-
757
-		if ( $field == 'custom_id' ) {
758
-			$items = get_posts(
759
-				array(
760
-					'post_type'      => 'wpi_item',
761
-					'posts_per_page' => 1,
762
-					'post_status'    => 'any',
763
-					'meta_query'     => array(
764
-						array(
765
-							'key'   => '_wpinv_type',
766
-                			'value' => $type,
767
-						),
768
-						array(
769
-							'key'   => '_wpinv_custom_id',
770
-                			'value' => $value,
771
-						),
772
-					),
773
-				)
774
-			);
775
-		}
776
-
777
-		if ( empty( $items ) ) {
778
-			return 0;
779
-		}
780
-
781
-		// Update the cache with our data
782
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
783
-
784
-		return $items[0]->ID;
729
+        // Ensure a field has been passed.
730
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
731
+            return 0;
732
+        }
733
+
734
+        if ( $field == 'name' ) {
735
+            $field = 'slug';
736
+        }
737
+
738
+        // Maybe retrieve from the cache.
739
+        $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
740
+        if ( ! empty( $item_id ) ) {
741
+            return $item_id;
742
+        }
743
+
744
+        // Fetch from the db.
745
+        $items = array();
746
+        if ( $field == 'slug' ) {
747
+            $items = get_posts(
748
+                array(
749
+                    'post_type'      => 'wpi_item',
750
+                    'name'           => $value,
751
+                    'posts_per_page' => 1,
752
+                    'post_status'    => 'any',
753
+                )
754
+            );
755
+        }
756
+
757
+        if ( $field == 'custom_id' ) {
758
+            $items = get_posts(
759
+                array(
760
+                    'post_type'      => 'wpi_item',
761
+                    'posts_per_page' => 1,
762
+                    'post_status'    => 'any',
763
+                    'meta_query'     => array(
764
+                        array(
765
+                            'key'   => '_wpinv_type',
766
+                            'value' => $type,
767
+                        ),
768
+                        array(
769
+                            'key'   => '_wpinv_custom_id',
770
+                            'value' => $value,
771
+                        ),
772
+                    ),
773
+                )
774
+            );
775
+        }
776
+
777
+        if ( empty( $items ) ) {
778
+            return 0;
779
+        }
780
+
781
+        // Update the cache with our data
782
+        wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
783
+
784
+        return $items[0]->ID;
785 785
     }
786 786
 
787 787
     /**
@@ -813,52 +813,52 @@  discard block
 block discarded – undo
813 813
     */
814 814
 
815 815
     /**
816
-	 * Set parent order ID.
817
-	 *
818
-	 * @since 1.0.19
819
-	 */
820
-	public function set_parent_id( $value ) {
821
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
822
-			return;
823
-		}
824
-		$this->set_prop( 'parent_id', absint( $value ) );
825
-	}
826
-
827
-    /**
828
-	 * Sets item status.
829
-	 *
830
-	 * @since 1.0.19
831
-	 * @param  string $status New status.
832
-	 * @return array details of change.
833
-	 */
834
-	public function set_status( $status ) {
816
+     * Set parent order ID.
817
+     *
818
+     * @since 1.0.19
819
+     */
820
+    public function set_parent_id( $value ) {
821
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
822
+            return;
823
+        }
824
+        $this->set_prop( 'parent_id', absint( $value ) );
825
+    }
826
+
827
+    /**
828
+     * Sets item status.
829
+     *
830
+     * @since 1.0.19
831
+     * @param  string $status New status.
832
+     * @return array details of change.
833
+     */
834
+    public function set_status( $status ) {
835 835
         $old_status = $this->get_status();
836 836
 
837 837
         $this->set_prop( 'status', $status );
838 838
 
839
-		return array(
840
-			'from' => $old_status,
841
-			'to'   => $status,
842
-		);
839
+        return array(
840
+            'from' => $old_status,
841
+            'to'   => $status,
842
+        );
843 843
     }
844 844
 
845 845
     /**
846
-	 * Set plugin version when the item was created.
847
-	 *
848
-	 * @since 1.0.19
849
-	 */
850
-	public function set_version( $value ) {
851
-		$this->set_prop( 'version', $value );
846
+     * Set plugin version when the item was created.
847
+     *
848
+     * @since 1.0.19
849
+     */
850
+    public function set_version( $value ) {
851
+        $this->set_prop( 'version', $value );
852 852
     }
853 853
 
854 854
     /**
855
-	 * Set date when the item was created.
856
-	 *
857
-	 * @since 1.0.19
858
-	 * @param string $value Value to set.
855
+     * Set date when the item was created.
856
+     *
857
+     * @since 1.0.19
858
+     * @param string $value Value to set.
859 859
      * @return bool Whether or not the date was set.
860
-	 */
861
-	public function set_date_created( $value ) {
860
+     */
861
+    public function set_date_created( $value ) {
862 862
         $date = strtotime( $value );
863 863
 
864 864
         if ( $date ) {
@@ -870,13 +870,13 @@  discard block
 block discarded – undo
870 870
     }
871 871
 
872 872
     /**
873
-	 * Set date when the item was last modified.
874
-	 *
875
-	 * @since 1.0.19
876
-	 * @param string $value Value to set.
873
+     * Set date when the item was last modified.
874
+     *
875
+     * @since 1.0.19
876
+     * @param string $value Value to set.
877 877
      * @return bool Whether or not the date was set.
878
-	 */
879
-	public function set_date_modified( $value ) {
878
+     */
879
+    public function set_date_modified( $value ) {
880 880
         $date = strtotime( $value );
881 881
 
882 882
         if ( $date ) {
@@ -888,115 +888,115 @@  discard block
 block discarded – undo
888 888
     }
889 889
 
890 890
     /**
891
-	 * Set the item name.
892
-	 *
893
-	 * @since 1.0.19
894
-	 * @param  string $value New name.
895
-	 */
896
-	public function set_name( $value ) {
891
+     * Set the item name.
892
+     *
893
+     * @since 1.0.19
894
+     * @param  string $value New name.
895
+     */
896
+    public function set_name( $value ) {
897 897
         $name = sanitize_text_field( $value );
898
-		$this->set_prop( 'name', $name );
898
+        $this->set_prop( 'name', $name );
899 899
     }
900 900
 
901 901
     /**
902
-	 * Alias of self::set_name().
903
-	 *
904
-	 * @since 1.0.19
905
-	 * @param  string $value New name.
906
-	 */
907
-	public function set_title( $value ) {
908
-		$this->set_name( $value );
902
+     * Alias of self::set_name().
903
+     *
904
+     * @since 1.0.19
905
+     * @param  string $value New name.
906
+     */
907
+    public function set_title( $value ) {
908
+        $this->set_name( $value );
909 909
     }
910 910
 
911 911
     /**
912
-	 * Set the item description.
913
-	 *
914
-	 * @since 1.0.19
915
-	 * @param  string $value New description.
916
-	 */
917
-	public function set_description( $value ) {
918
-		$description = wp_kses_post( wp_unslash( $value ) );
919
-		return $this->set_prop( 'description', $description );
912
+     * Set the item description.
913
+     *
914
+     * @since 1.0.19
915
+     * @param  string $value New description.
916
+     */
917
+    public function set_description( $value ) {
918
+        $description = wp_kses_post( wp_unslash( $value ) );
919
+        return $this->set_prop( 'description', $description );
920 920
     }
921 921
 
922 922
     /**
923
-	 * Alias of self::set_description().
924
-	 *
925
-	 * @since 1.0.19
926
-	 * @param  string $value New description.
927
-	 */
928
-	public function set_excerpt( $value ) {
929
-		$this->set_description( $value );
923
+     * Alias of self::set_description().
924
+     *
925
+     * @since 1.0.19
926
+     * @param  string $value New description.
927
+     */
928
+    public function set_excerpt( $value ) {
929
+        $this->set_description( $value );
930 930
     }
931 931
 
932 932
     /**
933
-	 * Alias of self::set_description().
934
-	 *
935
-	 * @since 1.0.19
936
-	 * @param  string $value New description.
937
-	 */
938
-	public function set_summary( $value ) {
939
-		$this->set_description( $value );
933
+     * Alias of self::set_description().
934
+     *
935
+     * @since 1.0.19
936
+     * @param  string $value New description.
937
+     */
938
+    public function set_summary( $value ) {
939
+        $this->set_description( $value );
940 940
     }
941 941
 
942 942
     /**
943
-	 * Set the owner of the item.
944
-	 *
945
-	 * @since 1.0.19
946
-	 * @param  int $value New author.
947
-	 */
948
-	public function set_author( $value ) {
949
-		$this->set_prop( 'author', (int) $value );
950
-	}
943
+     * Set the owner of the item.
944
+     *
945
+     * @since 1.0.19
946
+     * @param  int $value New author.
947
+     */
948
+    public function set_author( $value ) {
949
+        $this->set_prop( 'author', (int) $value );
950
+    }
951 951
 
952
-	/**
953
-	 * Alias of self::set_author().
954
-	 *
955
-	 * @since 1.0.19
956
-	 * @param  int $value New author.
957
-	 */
958
-	public function set_owner( $value ) {
959
-		$this->set_author( $value );
952
+    /**
953
+     * Alias of self::set_author().
954
+     *
955
+     * @since 1.0.19
956
+     * @param  int $value New author.
957
+     */
958
+    public function set_owner( $value ) {
959
+        $this->set_author( $value );
960 960
     }
961 961
 
962 962
     /**
963
-	 * Set the price of the item.
964
-	 *
965
-	 * @since 1.0.19
966
-	 * @param  float $value New price.
967
-	 */
968
-	public function set_price( $value ) {
963
+     * Set the price of the item.
964
+     *
965
+     * @since 1.0.19
966
+     * @param  float $value New price.
967
+     */
968
+    public function set_price( $value ) {
969 969
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
970 970
     }
971 971
 
972 972
     /**
973
-	 * Set the VAT rule of the item.
974
-	 *
975
-	 * @since 1.0.19
976
-	 * @param  string $value new rule.
977
-	 */
978
-	public function set_vat_rule( $value ) {
973
+     * Set the VAT rule of the item.
974
+     *
975
+     * @since 1.0.19
976
+     * @param  string $value new rule.
977
+     */
978
+    public function set_vat_rule( $value ) {
979 979
         $this->set_prop( 'vat_rule', $value );
980 980
     }
981 981
 
982 982
     /**
983
-	 * Set the VAT class of the item.
984
-	 *
985
-	 * @since 1.0.19
986
-	 * @param  string $value new class.
987
-	 */
988
-	public function set_vat_class( $value ) {
983
+     * Set the VAT class of the item.
984
+     *
985
+     * @since 1.0.19
986
+     * @param  string $value new class.
987
+     */
988
+    public function set_vat_class( $value ) {
989 989
         $this->set_prop( 'vat_class', $value );
990 990
     }
991 991
 
992 992
     /**
993
-	 * Set the type of the item.
994
-	 *
995
-	 * @since 1.0.19
996
-	 * @param  string $value new item type.
997
-	 * @return string
998
-	 */
999
-	public function set_type( $value ) {
993
+     * Set the type of the item.
994
+     *
995
+     * @since 1.0.19
996
+     * @param  string $value new item type.
997
+     * @return string
998
+     */
999
+    public function set_type( $value ) {
1000 1000
 
1001 1001
         if ( empty( $value ) ) {
1002 1002
             $value = 'custom';
@@ -1006,102 +1006,102 @@  discard block
 block discarded – undo
1006 1006
     }
1007 1007
 
1008 1008
     /**
1009
-	 * Set the custom id of the item.
1010
-	 *
1011
-	 * @since 1.0.19
1012
-	 * @param  string $value new custom id.
1013
-	 */
1014
-	public function set_custom_id( $value ) {
1009
+     * Set the custom id of the item.
1010
+     *
1011
+     * @since 1.0.19
1012
+     * @param  string $value new custom id.
1013
+     */
1014
+    public function set_custom_id( $value ) {
1015 1015
         $this->set_prop( 'custom_id', $value );
1016 1016
     }
1017 1017
 
1018 1018
     /**
1019
-	 * Set the custom name of the item.
1020
-	 *
1021
-	 * @since 1.0.19
1022
-	 * @param  string $value new custom name.
1023
-	 */
1024
-	public function set_custom_name( $value ) {
1019
+     * Set the custom name of the item.
1020
+     *
1021
+     * @since 1.0.19
1022
+     * @param  string $value new custom name.
1023
+     */
1024
+    public function set_custom_name( $value ) {
1025 1025
         $this->set_prop( 'custom_name', $value );
1026 1026
     }
1027 1027
 
1028 1028
     /**
1029
-	 * Set the custom singular name of the item.
1030
-	 *
1031
-	 * @since 1.0.19
1032
-	 * @param  string $value new custom singular name.
1033
-	 */
1034
-	public function set_custom_singular_name( $value ) {
1029
+     * Set the custom singular name of the item.
1030
+     *
1031
+     * @since 1.0.19
1032
+     * @param  string $value new custom singular name.
1033
+     */
1034
+    public function set_custom_singular_name( $value ) {
1035 1035
         $this->set_prop( 'custom_singular_name', $value );
1036 1036
     }
1037 1037
 
1038 1038
     /**
1039
-	 * Sets if an item is editable..
1040
-	 *
1041
-	 * @since 1.0.19
1042
-	 * @param  int|bool $value whether or not the item is editable.
1043
-	 */
1044
-	public function set_is_editable( $value ) {
1045
-		$this->set_prop( 'is_editable', (int) $value );
1039
+     * Sets if an item is editable..
1040
+     *
1041
+     * @since 1.0.19
1042
+     * @param  int|bool $value whether or not the item is editable.
1043
+     */
1044
+    public function set_is_editable( $value ) {
1045
+        $this->set_prop( 'is_editable', (int) $value );
1046 1046
     }
1047 1047
 
1048 1048
     /**
1049
-	 * Sets if dynamic pricing is enabled.
1050
-	 *
1051
-	 * @since 1.0.19
1052
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1053
-	 */
1054
-	public function set_is_dynamic_pricing( $value ) {
1049
+     * Sets if dynamic pricing is enabled.
1050
+     *
1051
+     * @since 1.0.19
1052
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
1053
+     */
1054
+    public function set_is_dynamic_pricing( $value ) {
1055 1055
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
1056 1056
     }
1057 1057
 
1058 1058
     /**
1059
-	 * Sets the minimum price if dynamic pricing is enabled.
1060
-	 *
1061
-	 * @since 1.0.19
1062
-	 * @param  float $value minimum price.
1063
-	 */
1064
-	public function set_minimum_price( $value ) {
1059
+     * Sets the minimum price if dynamic pricing is enabled.
1060
+     *
1061
+     * @since 1.0.19
1062
+     * @param  float $value minimum price.
1063
+     */
1064
+    public function set_minimum_price( $value ) {
1065 1065
         $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) );
1066 1066
     }
1067 1067
 
1068 1068
     /**
1069
-	 * Sets if this item has multi price mode.
1070
-	 *
1071
-	 * @since 1.0.19
1072
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1073
-	 */
1074
-	public function set_is_multi_price_mode( $value ) {
1069
+     * Sets if this item has multi price mode.
1070
+     *
1071
+     * @since 1.0.19
1072
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
1073
+     */
1074
+    public function set_is_multi_price_mode( $value ) {
1075 1075
         $this->set_prop( 'is_multi_price_mode', (int) $value );
1076 1076
     }
1077 1077
 
1078 1078
     /**
1079
-	 * Sets if this item has variable pricing.
1080
-	 *
1081
-	 * @since 1.0.19
1082
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1083
-	 */
1084
-	public function set_has_variable_pricing( $value ) {
1079
+     * Sets if this item has variable pricing.
1080
+     *
1081
+     * @since 1.0.19
1082
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
1083
+     */
1084
+    public function set_has_variable_pricing( $value ) {
1085 1085
         $this->set_prop( 'has_variable_pricing', (int) $value );
1086 1086
     }
1087 1087
 
1088 1088
     /**
1089
-	 * Set the default price ID.
1090
-	 *
1091
-	 * @since 1.0.19
1092
-	 * @param  int $value default price ID.
1093
-	 */
1094
-	public function set_default_price_id( $value ) {
1089
+     * Set the default price ID.
1090
+     *
1091
+     * @since 1.0.19
1092
+     * @param  int $value default price ID.
1093
+     */
1094
+    public function set_default_price_id( $value ) {
1095 1095
         return $this->set_prop( 'default_price_id', (int) $value );
1096 1096
     }
1097 1097
 
1098 1098
     /**
1099
-	 * Set the variable prices.
1100
-	 *
1101
-	 * @since 1.0.19
1102
-	 * @param  int $prices variable prices.
1103
-	 */
1104
-	public function set_variable_prices( $prices ) {
1099
+     * Set the variable prices.
1100
+     *
1101
+     * @since 1.0.19
1102
+     * @param  int $prices variable prices.
1103
+     */
1104
+    public function set_variable_prices( $prices ) {
1105 1105
         if ( ! is_array( $prices ) ) {
1106 1106
             $prices = array();
1107 1107
         }
@@ -1121,72 +1121,72 @@  discard block
 block discarded – undo
1121 1121
     }
1122 1122
 
1123 1123
     /**
1124
-	 * Sets if this is a recurring item.
1125
-	 *
1126
-	 * @since 1.0.19
1127
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1128
-	 */
1129
-	public function set_is_recurring( $value ) {
1124
+     * Sets if this is a recurring item.
1125
+     *
1126
+     * @since 1.0.19
1127
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
1128
+     */
1129
+    public function set_is_recurring( $value ) {
1130 1130
         $this->set_prop( 'is_recurring', (int) $value );
1131 1131
     }
1132 1132
 
1133 1133
     /**
1134
-	 * Set the recurring period.
1135
-	 *
1136
-	 * @since 1.0.19
1137
-	 * @param  string $value new period.
1138
-	 */
1139
-	public function set_recurring_period( $value ) {
1134
+     * Set the recurring period.
1135
+     *
1136
+     * @since 1.0.19
1137
+     * @param  string $value new period.
1138
+     */
1139
+    public function set_recurring_period( $value ) {
1140 1140
         $this->set_prop( 'recurring_period', $value );
1141 1141
     }
1142 1142
 
1143 1143
     /**
1144
-	 * Set the recurring interval.
1145
-	 *
1146
-	 * @since 1.0.19
1147
-	 * @param  int $value recurring interval.
1148
-	 */
1149
-	public function set_recurring_interval( $value ) {
1144
+     * Set the recurring interval.
1145
+     *
1146
+     * @since 1.0.19
1147
+     * @param  int $value recurring interval.
1148
+     */
1149
+    public function set_recurring_interval( $value ) {
1150 1150
         return $this->set_prop( 'recurring_interval', (int) $value );
1151 1151
     }
1152 1152
 
1153 1153
     /**
1154
-	 * Get the recurring limit.
1155
-	 * @since 1.0.19
1156
-	 * @param  int $value The recurring limit.
1157
-	 * @return int
1158
-	 */
1159
-	public function set_recurring_limit( $value ) {
1154
+     * Get the recurring limit.
1155
+     * @since 1.0.19
1156
+     * @param  int $value The recurring limit.
1157
+     * @return int
1158
+     */
1159
+    public function set_recurring_limit( $value ) {
1160 1160
         $this->set_prop( 'recurring_limit', (int) $value );
1161 1161
     }
1162 1162
 
1163 1163
     /**
1164
-	 * Checks if we have a free trial.
1165
-	 *
1166
-	 * @since 1.0.19
1167
-	 * @param  int|bool $value whether or not it has a free trial.
1168
-	 */
1169
-	public function set_is_free_trial( $value ) {
1164
+     * Checks if we have a free trial.
1165
+     *
1166
+     * @since 1.0.19
1167
+     * @param  int|bool $value whether or not it has a free trial.
1168
+     */
1169
+    public function set_is_free_trial( $value ) {
1170 1170
         $this->set_prop( 'is_free_trial', (int) $value );
1171 1171
     }
1172 1172
 
1173 1173
     /**
1174
-	 * Set the trial period.
1175
-	 *
1176
-	 * @since 1.0.19
1177
-	 * @param  string $value trial period.
1178
-	 */
1179
-	public function set_trial_period( $value ) {
1174
+     * Set the trial period.
1175
+     *
1176
+     * @since 1.0.19
1177
+     * @param  string $value trial period.
1178
+     */
1179
+    public function set_trial_period( $value ) {
1180 1180
         $this->set_prop( 'trial_period', $value );
1181 1181
     }
1182 1182
 
1183 1183
     /**
1184
-	 * Set the trial interval.
1185
-	 *
1186
-	 * @since 1.0.19
1187
-	 * @param  int $value trial interval.
1188
-	 */
1189
-	public function set_trial_interval( $value ) {
1184
+     * Set the trial interval.
1185
+     *
1186
+     * @since 1.0.19
1187
+     * @param  int $value trial interval.
1188
+     */
1189
+    public function set_trial_interval( $value ) {
1190 1190
         $this->set_prop( 'trial_interval', $value );
1191 1191
     }
1192 1192
 
@@ -1194,24 +1194,24 @@  discard block
 block discarded – undo
1194 1194
      * Create an item. For backwards compatibilty.
1195 1195
      *
1196 1196
      * @deprecated
1197
-	 * @return int item id
1197
+     * @return int item id
1198 1198
      */
1199 1199
     public function create( $data = array() ) {
1200 1200
 
1201
-		// Set the properties.
1202
-		if ( is_array( $data ) ) {
1203
-			$this->set_props( $data );
1204
-		}
1201
+        // Set the properties.
1202
+        if ( is_array( $data ) ) {
1203
+            $this->set_props( $data );
1204
+        }
1205 1205
 
1206
-		// Save the item.
1207
-		return $this->save();
1206
+        // Save the item.
1207
+        return $this->save();
1208 1208
     }
1209 1209
 
1210 1210
     /**
1211 1211
      * Updates an item. For backwards compatibilty.
1212 1212
      *
1213 1213
      * @deprecated
1214
-	 * @return int item id
1214
+     * @return int item id
1215 1215
      */
1216 1216
     public function update( $data = array() ) {
1217 1217
         return $this->create( $data );
@@ -1227,93 +1227,93 @@  discard block
 block discarded – undo
1227 1227
 	*/
1228 1228
 
1229 1229
     /**
1230
-	 * Checks whether the item has enabled dynamic pricing.
1231
-	 *
1232
-	 * @since 1.0.19
1233
-	 * @return bool
1234
-	 */
1235
-	public function user_can_set_their_price() {
1230
+     * Checks whether the item has enabled dynamic pricing.
1231
+     *
1232
+     * @since 1.0.19
1233
+     * @return bool
1234
+     */
1235
+    public function user_can_set_their_price() {
1236 1236
         return (bool) $this->get_is_dynamic_pricing();
1237
-	}
1238
-
1239
-	/**
1240
-	 * Checks whether the item is recurring.
1241
-	 *
1242
-	 * @since 1.0.19
1243
-	 * @return bool
1244
-	 */
1245
-	public function is_recurring() {
1237
+    }
1238
+
1239
+    /**
1240
+     * Checks whether the item is recurring.
1241
+     *
1242
+     * @since 1.0.19
1243
+     * @return bool
1244
+     */
1245
+    public function is_recurring() {
1246 1246
         return (bool) $this->get_is_recurring();
1247 1247
     }
1248 1248
 
1249 1249
     /**
1250
-	 * Checks whether the item has a free trial.
1251
-	 *
1252
-	 * @since 1.0.19
1253
-	 * @return bool
1254
-	 */
1250
+     * Checks whether the item has a free trial.
1251
+     *
1252
+     * @since 1.0.19
1253
+     * @return bool
1254
+     */
1255 1255
     public function has_free_trial() {
1256 1256
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1257 1257
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1258 1258
     }
1259 1259
 
1260 1260
     /**
1261
-	 * Checks whether the item is free.
1262
-	 *
1263
-	 * @since 1.0.19
1264
-	 * @return bool
1265
-	 */
1261
+     * Checks whether the item is free.
1262
+     *
1263
+     * @since 1.0.19
1264
+     * @return bool
1265
+     */
1266 1266
     public function is_free() {
1267 1267
         $is_free   = $this->get_price() == 0;
1268 1268
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1269 1269
     }
1270 1270
 
1271 1271
     /**
1272
-	 * Checks the item status against a passed in status.
1273
-	 *
1274
-	 * @param array|string $status Status to check.
1275
-	 * @return bool
1276
-	 */
1277
-	public function has_status( $status ) {
1278
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1279
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1272
+     * Checks the item status against a passed in status.
1273
+     *
1274
+     * @param array|string $status Status to check.
1275
+     * @return bool
1276
+     */
1277
+    public function has_status( $status ) {
1278
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1279
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1280 1280
     }
1281 1281
 
1282 1282
     /**
1283
-	 * Checks the item type against a passed in types.
1284
-	 *
1285
-	 * @param array|string $type Type to check.
1286
-	 * @return bool
1287
-	 */
1288
-	public function is_type( $type ) {
1289
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1290
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1291
-	}
1283
+     * Checks the item type against a passed in types.
1284
+     *
1285
+     * @param array|string $type Type to check.
1286
+     * @return bool
1287
+     */
1288
+    public function is_type( $type ) {
1289
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1290
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1291
+    }
1292 1292
 
1293 1293
     /**
1294
-	 * Checks whether the item is editable.
1295
-	 *
1296
-	 * @since 1.0.19
1297
-	 * @return bool
1298
-	 */
1294
+     * Checks whether the item is editable.
1295
+     *
1296
+     * @since 1.0.19
1297
+     * @return bool
1298
+     */
1299 1299
     public function is_editable() {
1300 1300
         $is_editable = $this->get_is_editable();
1301 1301
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1302
-	}
1302
+    }
1303 1303
 
1304
-	/**
1305
-	 * Returns an array of cart fees.
1306
-	 */
1307
-	public function get_fees() {
1304
+    /**
1305
+     * Returns an array of cart fees.
1306
+     */
1307
+    public function get_fees() {
1308 1308
         return array();
1309 1309
     }
1310 1310
 
1311 1311
     /**
1312
-	 * Checks whether the item is purchasable.
1313
-	 *
1314
-	 * @since 1.0.19
1315
-	 * @return bool
1316
-	 */
1312
+     * Checks whether the item is purchasable.
1313
+     *
1314
+     * @since 1.0.19
1315
+     * @return bool
1316
+     */
1317 1317
     public function can_purchase() {
1318 1318
         $can_purchase = $this->exists();
1319 1319
 
@@ -1325,11 +1325,11 @@  discard block
 block discarded – undo
1325 1325
     }
1326 1326
 
1327 1327
     /**
1328
-	 * Checks whether the item supports dynamic pricing.
1329
-	 *
1330
-	 * @since 1.0.19
1331
-	 * @return bool
1332
-	 */
1328
+     * Checks whether the item supports dynamic pricing.
1329
+     *
1330
+     * @since 1.0.19
1331
+     * @return bool
1332
+     */
1333 1333
     public function supports_dynamic_pricing() {
1334 1334
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1335 1335
     }
Please login to merge, or discard this patch.
includes/admin/class-getpaid-installer.php 1 patch
Indentation   +494 added lines, -494 removed lines patch added patch discarded remove patch
@@ -20,411 +20,411 @@  discard block
 block discarded – undo
20 20
  */
21 21
 class GetPaid_Installer {
22 22
 
23
-	private static $schema = null;
24
-	private static $schema_version = null;
25
-
26
-	/**
27
-	 * Upgrades the install.
28
-	 *
29
-	 * @param string $upgrade_from The current invoicing version.
30
-	 */
31
-	public function upgrade_db( $upgrade_from ) {
32
-
33
-		// Save the current invoicing version.
34
-		update_option( 'wpinv_version', WPINV_VERSION );
35
-
36
-		// Setup the invoice Custom Post Type.
37
-		GetPaid_Post_Types::register_post_types();
38
-
39
-		// Clear the permalinks
40
-		flush_rewrite_rules();
41
-
42
-		// Maybe create new/missing pages.
43
-		$this->create_pages();
44
-
45
-		// Maybe re(add) admin capabilities.
46
-		$this->add_capabilities();
47
-
48
-		// Maybe create the default payment form.
49
-		wpinv_get_default_payment_form();
50
-
51
-		// Create any missing database tables.
52
-		$method = "upgrade_from_$upgrade_from";
53
-
54
-		$installed = get_option( 'gepaid_installed_on' );
55
-
56
-		if ( empty( $installed ) ) {
57
-			update_option( 'gepaid_installed_on', time() );
58
-		}
59
-
60
-		if ( method_exists( $this, $method ) ) {
61
-			$this->$method();
62
-		}
63
-
64
-	}
65
-
66
-	/**
67
-	 * Do a fresh install.
68
-	 *
69
-	 */
70
-	public function upgrade_from_0() {
71
-
72
-		// Save default tax rates.
73
-		update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
-	}
75
-
76
-	/**
77
-	 * Upgrade to 0.0.5
78
-	 *
79
-	 */
80
-	public function upgrade_from_004() {
81
-		global $wpdb;
82
-
83
-		// Invoices.
84
-		$results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
-		if ( ! empty( $results ) ) {
86
-			$wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
-
88
-			// Clean post cache
89
-			foreach ( $results as $row ) {
90
-				clean_post_cache( $row->ID );
91
-			}
92
-		}
93
-
94
-		// Item meta key changes
95
-		$query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
-		$results = $wpdb->get_results( $query );
97
-
98
-		if ( ! empty( $results ) ) {
99
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
-			$wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
-
103
-			foreach ( $results as $row ) {
104
-				clean_post_cache( $row->post_id );
105
-			}
106
-		}
107
-
108
-		$this->upgrade_from_118();
109
-	}
110
-
111
-	/**
112
-	 * Upgrade to version 2.0.0.
113
-	 *
114
-	 */
115
-	public function upgrade_from_118() {
116
-		$this->migrate_old_invoices();
117
-		$this->upgrade_from_279();
118
-	}
119
-
120
-	/**
121
-	 * Upgrade to version 2.0.0.
122
-	 *
123
-	 */
124
-	public function upgrade_from_279() {
125
-		self::migrate_old_customers();
126
-	}
127
-
128
-	/**
129
-	 * Give administrators the capability to manage GetPaid.
130
-	 *
131
-	 */
132
-	public function add_capabilities() {
133
-		$GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
134
-	}
135
-
136
-	/**
137
-	 * Retreives GetPaid pages.
138
-	 *
139
-	 */
140
-	public static function get_pages() {
141
-
142
-		return apply_filters(
143
-			'wpinv_create_pages',
144
-			array(
145
-
146
-				// Checkout page.
147
-				'checkout_page'             => array(
148
-					'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
149
-					'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
150
-					'content' => '
23
+    private static $schema = null;
24
+    private static $schema_version = null;
25
+
26
+    /**
27
+     * Upgrades the install.
28
+     *
29
+     * @param string $upgrade_from The current invoicing version.
30
+     */
31
+    public function upgrade_db( $upgrade_from ) {
32
+
33
+        // Save the current invoicing version.
34
+        update_option( 'wpinv_version', WPINV_VERSION );
35
+
36
+        // Setup the invoice Custom Post Type.
37
+        GetPaid_Post_Types::register_post_types();
38
+
39
+        // Clear the permalinks
40
+        flush_rewrite_rules();
41
+
42
+        // Maybe create new/missing pages.
43
+        $this->create_pages();
44
+
45
+        // Maybe re(add) admin capabilities.
46
+        $this->add_capabilities();
47
+
48
+        // Maybe create the default payment form.
49
+        wpinv_get_default_payment_form();
50
+
51
+        // Create any missing database tables.
52
+        $method = "upgrade_from_$upgrade_from";
53
+
54
+        $installed = get_option( 'gepaid_installed_on' );
55
+
56
+        if ( empty( $installed ) ) {
57
+            update_option( 'gepaid_installed_on', time() );
58
+        }
59
+
60
+        if ( method_exists( $this, $method ) ) {
61
+            $this->$method();
62
+        }
63
+
64
+    }
65
+
66
+    /**
67
+     * Do a fresh install.
68
+     *
69
+     */
70
+    public function upgrade_from_0() {
71
+
72
+        // Save default tax rates.
73
+        update_option( 'wpinv_tax_rates', wpinv_get_data( 'tax-rates' ) );
74
+    }
75
+
76
+    /**
77
+     * Upgrade to 0.0.5
78
+     *
79
+     */
80
+    public function upgrade_from_004() {
81
+        global $wpdb;
82
+
83
+        // Invoices.
84
+        $results = $wpdb->get_results( "SELECT ID FROM {$wpdb->posts} WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
85
+        if ( ! empty( $results ) ) {
86
+            $wpdb->query( "UPDATE {$wpdb->posts} SET post_status = CONCAT( 'wpi-', post_status ) WHERE post_type = 'wpi_invoice' AND post_status IN( 'pending', 'processing', 'onhold', 'refunded', 'cancelled', 'failed', 'renewal' )" );
87
+
88
+            // Clean post cache
89
+            foreach ( $results as $row ) {
90
+                clean_post_cache( $row->ID );
91
+            }
92
+        }
93
+
94
+        // Item meta key changes
95
+        $query = 'SELECT DISTINCT post_id FROM ' . $wpdb->postmeta . " WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id', '_wpinv_cpt_name', '_wpinv_cpt_singular_name' )";
96
+        $results = $wpdb->get_results( $query );
97
+
98
+        if ( ! empty( $results ) ) {
99
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_id' WHERE meta_key IN( '_wpinv_item_id', '_wpinv_package_id', '_wpinv_post_id' )" );
100
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_name' WHERE meta_key = '_wpinv_cpt_name'" );
101
+            $wpdb->query( 'UPDATE ' . $wpdb->postmeta . " SET meta_key = '_wpinv_custom_singular_name' WHERE meta_key = '_wpinv_cpt_singular_name'" );
102
+
103
+            foreach ( $results as $row ) {
104
+                clean_post_cache( $row->post_id );
105
+            }
106
+        }
107
+
108
+        $this->upgrade_from_118();
109
+    }
110
+
111
+    /**
112
+     * Upgrade to version 2.0.0.
113
+     *
114
+     */
115
+    public function upgrade_from_118() {
116
+        $this->migrate_old_invoices();
117
+        $this->upgrade_from_279();
118
+    }
119
+
120
+    /**
121
+     * Upgrade to version 2.0.0.
122
+     *
123
+     */
124
+    public function upgrade_from_279() {
125
+        self::migrate_old_customers();
126
+    }
127
+
128
+    /**
129
+     * Give administrators the capability to manage GetPaid.
130
+     *
131
+     */
132
+    public function add_capabilities() {
133
+        $GLOBALS['wp_roles']->add_cap( 'administrator', 'manage_invoicing' );
134
+    }
135
+
136
+    /**
137
+     * Retreives GetPaid pages.
138
+     *
139
+     */
140
+    public static function get_pages() {
141
+
142
+        return apply_filters(
143
+            'wpinv_create_pages',
144
+            array(
145
+
146
+                // Checkout page.
147
+                'checkout_page'             => array(
148
+                    'name'    => _x( 'gp-checkout', 'Page slug', 'invoicing' ),
149
+                    'title'   => _x( 'Checkout', 'Page title', 'invoicing' ),
150
+                    'content' => '
151 151
 						<!-- wp:shortcode -->
152 152
 						[wpinv_checkout]
153 153
 						<!-- /wp:shortcode -->
154 154
 					',
155
-					'parent'  => '',
156
-				),
157
-
158
-				// Invoice history page.
159
-				'invoice_history_page'      => array(
160
-					'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
161
-					'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
162
-					'content' => '
155
+                    'parent'  => '',
156
+                ),
157
+
158
+                // Invoice history page.
159
+                'invoice_history_page'      => array(
160
+                    'name'    => _x( 'gp-invoices', 'Page slug', 'invoicing' ),
161
+                    'title'   => _x( 'My Invoices', 'Page title', 'invoicing' ),
162
+                    'content' => '
163 163
 					<!-- wp:shortcode -->
164 164
 					[wpinv_history]
165 165
 					<!-- /wp:shortcode -->
166 166
 				',
167
-					'parent'  => '',
168
-				),
169
-
170
-				// Success page content.
171
-				'success_page'              => array(
172
-					'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
173
-					'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
174
-					'content' => '
167
+                    'parent'  => '',
168
+                ),
169
+
170
+                // Success page content.
171
+                'success_page'              => array(
172
+                    'name'    => _x( 'gp-receipt', 'Page slug', 'invoicing' ),
173
+                    'title'   => _x( 'Payment Confirmation', 'Page title', 'invoicing' ),
174
+                    'content' => '
175 175
 					<!-- wp:shortcode -->
176 176
 					[wpinv_receipt]
177 177
 					<!-- /wp:shortcode -->
178 178
 				',
179
-					'parent'  => 'gp-checkout',
180
-				),
181
-
182
-				// Failure page content.
183
-				'failure_page'              => array(
184
-					'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
185
-					'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
186
-					'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
187
-					'parent'  => 'gp-checkout',
188
-				),
189
-
190
-				// Subscriptions history page.
191
-				'invoice_subscription_page' => array(
192
-					'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
193
-					'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
194
-					'content' => '
179
+                    'parent'  => 'gp-checkout',
180
+                ),
181
+
182
+                // Failure page content.
183
+                'failure_page'              => array(
184
+                    'name'    => _x( 'gp-transaction-failed', 'Page slug', 'invoicing' ),
185
+                    'title'   => _x( 'Transaction Failed', 'Page title', 'invoicing' ),
186
+                    'content' => __( 'Your transaction failed, please try again or contact site support.', 'invoicing' ),
187
+                    'parent'  => 'gp-checkout',
188
+                ),
189
+
190
+                // Subscriptions history page.
191
+                'invoice_subscription_page' => array(
192
+                    'name'    => _x( 'gp-subscriptions', 'Page slug', 'invoicing' ),
193
+                    'title'   => _x( 'My Subscriptions', 'Page title', 'invoicing' ),
194
+                    'content' => '
195 195
 					<!-- wp:shortcode -->
196 196
 					[wpinv_subscriptions]
197 197
 					<!-- /wp:shortcode -->
198 198
 				',
199
-					'parent'  => '',
200
-				),
201
-
202
-			)
203
-		);
204
-
205
-	}
206
-
207
-	/**
208
-	 * Re-create GetPaid pages.
209
-	 *
210
-	 */
211
-	public function create_pages() {
212
-
213
-		foreach ( self::get_pages() as $key => $page ) {
214
-			wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
215
-		}
216
-
217
-	}
218
-
219
-	/**
220
-	 * Migrates old invoices to new invoices.
221
-	 *
222
-	 */
223
-	public function migrate_old_invoices() {
224
-		global $wpdb;
225
-
226
-		$invoices_table      = $wpdb->prefix . 'getpaid_invoices';
227
-		$invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
228
-		$migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
229
-		$invoices            = array_unique(
230
-			get_posts(
231
-				array(
232
-					'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
233
-					'posts_per_page' => -1,
234
-					'fields'         => 'ids',
235
-					'post_status'    => array_keys( get_post_stati() ),
236
-					'exclude'        => (array) $migrated,
237
-				)
238
-			)
239
-		);
240
-
241
-		// Abort if we do not have any invoices.
242
-		if ( empty( $invoices ) ) {
243
-			return;
244
-		}
245
-
246
-		require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
247
-
248
-		$invoice_rows = array();
249
-		foreach ( $invoices as $invoice ) {
250
-
251
-			$invoice = new WPInv_Legacy_Invoice( $invoice );
252
-
253
-			if ( empty( $invoice->ID ) ) {
254
-				return;
255
-			}
256
-
257
-			$fields = array(
258
-				'post_id'            => $invoice->ID,
259
-				'number'             => $invoice->get_number(),
260
-				'key'                => $invoice->get_key(),
261
-				'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
262
-				'mode'               => $invoice->mode,
263
-				'user_ip'            => $invoice->get_ip(),
264
-				'first_name'         => $invoice->get_first_name(),
265
-				'last_name'          => $invoice->get_last_name(),
266
-				'address'            => $invoice->get_address(),
267
-				'city'               => $invoice->city,
268
-				'state'              => $invoice->state,
269
-				'country'            => $invoice->country,
270
-				'zip'                => $invoice->zip,
271
-				'adddress_confirmed' => (int) $invoice->adddress_confirmed,
272
-				'gateway'            => $invoice->get_gateway(),
273
-				'transaction_id'     => $invoice->get_transaction_id(),
274
-				'currency'           => $invoice->get_currency(),
275
-				'subtotal'           => $invoice->get_subtotal(),
276
-				'tax'                => $invoice->get_tax(),
277
-				'fees_total'         => $invoice->get_fees_total(),
278
-				'total'              => $invoice->get_total(),
279
-				'discount'           => $invoice->get_discount(),
280
-				'discount_code'      => $invoice->get_discount_code(),
281
-				'disable_taxes'      => $invoice->disable_taxes,
282
-				'due_date'           => $invoice->get_due_date(),
283
-				'completed_date'     => $invoice->get_completed_date(),
284
-				'company'            => $invoice->company,
285
-				'vat_number'         => $invoice->vat_number,
286
-				'vat_rate'           => $invoice->vat_rate,
287
-				'custom_meta'        => $invoice->payment_meta,
288
-			);
289
-
290
-			foreach ( $fields as $key => $val ) {
291
-				if ( is_null( $val ) ) {
292
-					$val = '';
293
-				}
294
-				$val = maybe_serialize( $val );
295
-				$fields[ $key ] = $wpdb->prepare( '%s', $val );
296
-			}
297
-
298
-			$fields = implode( ', ', $fields );
299
-			$invoice_rows[] = "($fields)";
300
-
301
-			$item_rows    = array();
302
-			$item_columns = array();
303
-			foreach ( $invoice->get_cart_details() as $details ) {
304
-				$fields = array(
305
-					'post_id'          => $invoice->ID,
306
-					'item_id'          => $details['id'],
307
-					'item_name'        => $details['name'],
308
-					'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
309
-					'vat_rate'         => $details['vat_rate'],
310
-					'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
311
-					'tax'              => $details['tax'],
312
-					'item_price'       => $details['item_price'],
313
-					'custom_price'     => $details['custom_price'],
314
-					'quantity'         => $details['quantity'],
315
-					'discount'         => $details['discount'],
316
-					'subtotal'         => $details['subtotal'],
317
-					'price'            => $details['price'],
318
-					'meta'             => $details['meta'],
319
-					'fees'             => $details['fees'],
320
-				);
321
-
322
-				$item_columns = array_keys( $fields );
323
-
324
-				foreach ( $fields as $key => $val ) {
325
-					if ( is_null( $val ) ) {
326
-						$val = '';
327
-					}
328
-					$val = maybe_serialize( $val );
329
-					$fields[ $key ] = $wpdb->prepare( '%s', $val );
330
-				}
331
-
332
-				$fields = implode( ', ', $fields );
333
-				$item_rows[] = "($fields)";
334
-			}
335
-
336
-			$item_rows    = implode( ', ', $item_rows );
337
-			$item_columns = implode( ', ', $item_columns );
338
-			$wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
339
-		}
340
-
341
-		if ( empty( $invoice_rows ) ) {
342
-			return;
343
-		}
344
-
345
-		$invoice_rows = implode( ', ', $invoice_rows );
346
-		$wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
347
-
348
-	}
349
-
350
-	/**
351
-	 * Migrates old customers to new table.
352
-	 *
353
-	 */
354
-	public static function migrate_old_customers() {
355
-		global $wpdb;
356
-
357
-		// Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null.
358
-		$invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" );
359
-
360
-		foreach ( $invoice_ids as $invoice_id ) {
361
-			$invoice = wpinv_get_invoice( $invoice_id );
362
-
363
-			if ( empty( $invoice ) ) {
364
-				continue;
365
-			}
366
-
367
-			// Fetch customer from the user ID.
368
-			$user_id = $invoice->get_user_id();
369
-
370
-			if ( empty( $user_id ) ) {
371
-				continue;
372
-			}
373
-
374
-			$customer = getpaid_get_customer_by_user_id( $user_id );
375
-
376
-			// Create if not exists.
377
-			if ( empty( $customer ) ) {
378
-				$customer = new GetPaid_Customer( 0 );
379
-				$customer->clone_user( $user_id );
380
-				$customer->save();
381
-			}
382
-
383
-			$invoice->set_customer_id( $customer->get_id() );
384
-			$invoice->save();
385
-		}
386
-
387
-	}
388
-
389
-	/**
390
-	 * Migrates old invoices to new invoices.
391
-	 *
392
-	 */
393
-	public static function rename_gateways_label() {
394
-		global $wpdb;
395
-
396
-		foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
397
-
398
-			$wpdb->update(
399
-				$wpdb->prefix . 'getpaid_invoices',
400
-				array( 'gateway' => $gateway ),
401
-				array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
402
-				'%s',
403
-				'%s'
404
-			);
405
-
406
-		}
407
-	}
408
-
409
-	/**
410
-	 * Returns the DB schema.
411
-	 *
412
-	 */
413
-	public static function get_db_schema() {
414
-		global $wpdb;
415
-
416
-		if ( ! empty( self::$schema ) ) {
417
-			return self::$schema;
418
-		}
199
+                    'parent'  => '',
200
+                ),
201
+
202
+            )
203
+        );
204
+
205
+    }
206
+
207
+    /**
208
+     * Re-create GetPaid pages.
209
+     *
210
+     */
211
+    public function create_pages() {
212
+
213
+        foreach ( self::get_pages() as $key => $page ) {
214
+            wpinv_create_page( esc_sql( $page['name'] ), $key, $page['title'], $page['content'], $page['parent'] );
215
+        }
216
+
217
+    }
218
+
219
+    /**
220
+     * Migrates old invoices to new invoices.
221
+     *
222
+     */
223
+    public function migrate_old_invoices() {
224
+        global $wpdb;
225
+
226
+        $invoices_table      = $wpdb->prefix . 'getpaid_invoices';
227
+        $invoice_items_table = $wpdb->prefix . 'getpaid_invoice_items';
228
+        $migrated            = $wpdb->get_col( "SELECT post_id FROM $invoices_table" );
229
+        $invoices            = array_unique(
230
+            get_posts(
231
+                array(
232
+                    'post_type'      => array( 'wpi_invoice', 'wpi_quote' ),
233
+                    'posts_per_page' => -1,
234
+                    'fields'         => 'ids',
235
+                    'post_status'    => array_keys( get_post_stati() ),
236
+                    'exclude'        => (array) $migrated,
237
+                )
238
+            )
239
+        );
240
+
241
+        // Abort if we do not have any invoices.
242
+        if ( empty( $invoices ) ) {
243
+            return;
244
+        }
245
+
246
+        require_once WPINV_PLUGIN_DIR . 'includes/class-wpinv-legacy-invoice.php';
247
+
248
+        $invoice_rows = array();
249
+        foreach ( $invoices as $invoice ) {
250
+
251
+            $invoice = new WPInv_Legacy_Invoice( $invoice );
252
+
253
+            if ( empty( $invoice->ID ) ) {
254
+                return;
255
+            }
256
+
257
+            $fields = array(
258
+                'post_id'            => $invoice->ID,
259
+                'number'             => $invoice->get_number(),
260
+                'key'                => $invoice->get_key(),
261
+                'type'               => str_replace( 'wpi_', '', $invoice->post_type ),
262
+                'mode'               => $invoice->mode,
263
+                'user_ip'            => $invoice->get_ip(),
264
+                'first_name'         => $invoice->get_first_name(),
265
+                'last_name'          => $invoice->get_last_name(),
266
+                'address'            => $invoice->get_address(),
267
+                'city'               => $invoice->city,
268
+                'state'              => $invoice->state,
269
+                'country'            => $invoice->country,
270
+                'zip'                => $invoice->zip,
271
+                'adddress_confirmed' => (int) $invoice->adddress_confirmed,
272
+                'gateway'            => $invoice->get_gateway(),
273
+                'transaction_id'     => $invoice->get_transaction_id(),
274
+                'currency'           => $invoice->get_currency(),
275
+                'subtotal'           => $invoice->get_subtotal(),
276
+                'tax'                => $invoice->get_tax(),
277
+                'fees_total'         => $invoice->get_fees_total(),
278
+                'total'              => $invoice->get_total(),
279
+                'discount'           => $invoice->get_discount(),
280
+                'discount_code'      => $invoice->get_discount_code(),
281
+                'disable_taxes'      => $invoice->disable_taxes,
282
+                'due_date'           => $invoice->get_due_date(),
283
+                'completed_date'     => $invoice->get_completed_date(),
284
+                'company'            => $invoice->company,
285
+                'vat_number'         => $invoice->vat_number,
286
+                'vat_rate'           => $invoice->vat_rate,
287
+                'custom_meta'        => $invoice->payment_meta,
288
+            );
289
+
290
+            foreach ( $fields as $key => $val ) {
291
+                if ( is_null( $val ) ) {
292
+                    $val = '';
293
+                }
294
+                $val = maybe_serialize( $val );
295
+                $fields[ $key ] = $wpdb->prepare( '%s', $val );
296
+            }
297
+
298
+            $fields = implode( ', ', $fields );
299
+            $invoice_rows[] = "($fields)";
300
+
301
+            $item_rows    = array();
302
+            $item_columns = array();
303
+            foreach ( $invoice->get_cart_details() as $details ) {
304
+                $fields = array(
305
+                    'post_id'          => $invoice->ID,
306
+                    'item_id'          => $details['id'],
307
+                    'item_name'        => $details['name'],
308
+                    'item_description' => empty( $details['meta']['description'] ) ? '' : $details['meta']['description'],
309
+                    'vat_rate'         => $details['vat_rate'],
310
+                    'vat_class'        => empty( $details['vat_class'] ) ? '_standard' : $details['vat_class'],
311
+                    'tax'              => $details['tax'],
312
+                    'item_price'       => $details['item_price'],
313
+                    'custom_price'     => $details['custom_price'],
314
+                    'quantity'         => $details['quantity'],
315
+                    'discount'         => $details['discount'],
316
+                    'subtotal'         => $details['subtotal'],
317
+                    'price'            => $details['price'],
318
+                    'meta'             => $details['meta'],
319
+                    'fees'             => $details['fees'],
320
+                );
321
+
322
+                $item_columns = array_keys( $fields );
323
+
324
+                foreach ( $fields as $key => $val ) {
325
+                    if ( is_null( $val ) ) {
326
+                        $val = '';
327
+                    }
328
+                    $val = maybe_serialize( $val );
329
+                    $fields[ $key ] = $wpdb->prepare( '%s', $val );
330
+                }
331
+
332
+                $fields = implode( ', ', $fields );
333
+                $item_rows[] = "($fields)";
334
+            }
335
+
336
+            $item_rows    = implode( ', ', $item_rows );
337
+            $item_columns = implode( ', ', $item_columns );
338
+            $wpdb->query( "INSERT INTO $invoice_items_table ($item_columns) VALUES $item_rows" );
339
+        }
340
+
341
+        if ( empty( $invoice_rows ) ) {
342
+            return;
343
+        }
344
+
345
+        $invoice_rows = implode( ', ', $invoice_rows );
346
+        $wpdb->query( "INSERT INTO $invoices_table VALUES $invoice_rows" );
347
+
348
+    }
349
+
350
+    /**
351
+     * Migrates old customers to new table.
352
+     *
353
+     */
354
+    public static function migrate_old_customers() {
355
+        global $wpdb;
356
+
357
+        // Fetch post_id from $wpdb->prefix . 'getpaid_invoices' where customer_id = 0 or null.
358
+        $invoice_ids = $wpdb->get_col( "SELECT post_id FROM {$wpdb->prefix}getpaid_invoices WHERE customer_id = 0 OR customer_id IS NULL" );
359
+
360
+        foreach ( $invoice_ids as $invoice_id ) {
361
+            $invoice = wpinv_get_invoice( $invoice_id );
362
+
363
+            if ( empty( $invoice ) ) {
364
+                continue;
365
+            }
366
+
367
+            // Fetch customer from the user ID.
368
+            $user_id = $invoice->get_user_id();
369
+
370
+            if ( empty( $user_id ) ) {
371
+                continue;
372
+            }
373
+
374
+            $customer = getpaid_get_customer_by_user_id( $user_id );
375
+
376
+            // Create if not exists.
377
+            if ( empty( $customer ) ) {
378
+                $customer = new GetPaid_Customer( 0 );
379
+                $customer->clone_user( $user_id );
380
+                $customer->save();
381
+            }
382
+
383
+            $invoice->set_customer_id( $customer->get_id() );
384
+            $invoice->save();
385
+        }
386
+
387
+    }
388
+
389
+    /**
390
+     * Migrates old invoices to new invoices.
391
+     *
392
+     */
393
+    public static function rename_gateways_label() {
394
+        global $wpdb;
395
+
396
+        foreach ( array_keys( wpinv_get_payment_gateways() ) as $gateway ) {
397
+
398
+            $wpdb->update(
399
+                $wpdb->prefix . 'getpaid_invoices',
400
+                array( 'gateway' => $gateway ),
401
+                array( 'gateway' => wpinv_get_gateway_admin_label( $gateway ) ),
402
+                '%s',
403
+                '%s'
404
+            );
405
+
406
+        }
407
+    }
408
+
409
+    /**
410
+     * Returns the DB schema.
411
+     *
412
+     */
413
+    public static function get_db_schema() {
414
+        global $wpdb;
415
+
416
+        if ( ! empty( self::$schema ) ) {
417
+            return self::$schema;
418
+        }
419 419
 
420
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
420
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
421 421
 
422
-		$charset_collate = $wpdb->get_charset_collate();
422
+        $charset_collate = $wpdb->get_charset_collate();
423 423
 
424
-		$schema = array();
424
+        $schema = array();
425 425
 
426
-		// Subscriptions.
427
-		$schema['subscriptions'] = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions (
426
+        // Subscriptions.
427
+        $schema['subscriptions'] = "CREATE TABLE {$wpdb->prefix}wpinv_subscriptions (
428 428
 			id bigint(20) unsigned NOT NULL auto_increment,
429 429
 			customer_id bigint(20) NOT NULL,
430 430
 			frequency int(11) NOT NULL DEFAULT '1',
@@ -447,8 +447,8 @@  discard block
 block discarded – undo
447 447
 			KEY customer_and_status (customer_id, status)
448 448
 		  ) $charset_collate;";
449 449
 
450
-		// Invoices.
451
-		$schema['invoices'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoices (
450
+        // Invoices.
451
+        $schema['invoices'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoices (
452 452
 			post_id BIGINT(20) NOT NULL,
453 453
 			customer_id BIGINT(20) NOT NULL DEFAULT 0,
454 454
             `number` VARCHAR(100),
@@ -485,8 +485,8 @@  discard block
 block discarded – undo
485 485
 			KEY invoice_key (invoice_key)
486 486
 		  ) $charset_collate;";
487 487
 
488
-		// Invoice items.
489
-		$schema['items'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items (
488
+        // Invoice items.
489
+        $schema['items'] = "CREATE TABLE {$wpdb->prefix}getpaid_invoice_items (
490 490
 			ID BIGINT(20) NOT NULL AUTO_INCREMENT,
491 491
             post_id BIGINT(20) NOT NULL,
492 492
             item_id BIGINT(20) NOT NULL,
@@ -510,8 +510,8 @@  discard block
 block discarded – undo
510 510
 			KEY price_id (price_id)
511 511
 		  ) $charset_collate;";
512 512
 
513
-		// Customers.
514
-		$schema['customers'] = "CREATE TABLE {$wpdb->prefix}getpaid_customers (
513
+        // Customers.
514
+        $schema['customers'] = "CREATE TABLE {$wpdb->prefix}getpaid_customers (
515 515
 			id BIGINT(20) NOT NULL AUTO_INCREMENT,
516 516
 			user_id BIGINT(20) NOT NULL,
517 517
 			email VARCHAR(100) NOT NULL,
@@ -521,38 +521,38 @@  discard block
 block discarded – undo
521 521
 			purchase_count BIGINT(20) NOT NULL DEFAULT 0,
522 522
 			";
523 523
 
524
-		// Add address fields.
525
-		foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) {
526
-			// Skip id, user_id and email.
527
-			if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
528
-				continue;
529
-			}
530
-
531
-			$field   = sanitize_key( $field );
532
-			$length  = 100;
533
-			$default = '';
534
-
535
-			// Country.
536
-			if ( 'country' === $field ) {
537
-				$length  = 2;
538
-				$default = wpinv_get_default_country();
539
-			}
540
-
541
-			// State.
542
-			if ( 'state' === $field ) {
543
-				$default = wpinv_get_default_state();
544
-			}
545
-
546
-			// Phone, zip.
547
-			if ( in_array( $field, array( 'phone', 'zip' ), true ) ) {
548
-				$length = 20;
549
-			}
550
-
551
-			$schema['customers'] .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',
524
+        // Add address fields.
525
+        foreach ( array_keys( getpaid_user_address_fields( true ) ) as $field ) {
526
+            // Skip id, user_id and email.
527
+            if ( in_array( $field, array( 'id', 'user_id', 'email', 'purchase_value', 'purchase_count', 'date_created', 'date_modified', 'uuid' ), true ) ) {
528
+                continue;
529
+            }
530
+
531
+            $field   = sanitize_key( $field );
532
+            $length  = 100;
533
+            $default = '';
534
+
535
+            // Country.
536
+            if ( 'country' === $field ) {
537
+                $length  = 2;
538
+                $default = wpinv_get_default_country();
539
+            }
540
+
541
+            // State.
542
+            if ( 'state' === $field ) {
543
+                $default = wpinv_get_default_state();
544
+            }
545
+
546
+            // Phone, zip.
547
+            if ( in_array( $field, array( 'phone', 'zip' ), true ) ) {
548
+                $length = 20;
549
+            }
550
+
551
+            $schema['customers'] .= "`$field` VARCHAR($length) NOT NULL DEFAULT '$default',
552 552
 			";
553
-		}
553
+        }
554 554
 
555
-		$schema['customers'] .= "date_created DATETIME NOT NULL,
555
+        $schema['customers'] .= "date_created DATETIME NOT NULL,
556 556
 			date_modified DATETIME NOT NULL,
557 557
 			uuid VARCHAR(100) NOT NULL,
558 558
 			PRIMARY KEY  (id),
@@ -560,8 +560,8 @@  discard block
 block discarded – undo
560 560
 			KEY email (email)
561 561
 		  ) $charset_collate;";
562 562
 
563
-		// Customer meta.
564
-		$schema['customer_meta'] = "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta (
563
+        // Customer meta.
564
+        $schema['customer_meta'] = "CREATE TABLE {$wpdb->prefix}getpaid_customer_meta (
565 565
 			meta_id BIGINT(20) NOT NULL AUTO_INCREMENT,
566 566
 			customer_id BIGINT(20) NOT NULL,
567 567
 			meta_key VARCHAR(255) NOT NULL,
@@ -571,75 +571,75 @@  discard block
 block discarded – undo
571 571
 			KEY meta_key (meta_key(191))
572 572
 		  ) $charset_collate;";
573 573
 
574
-		// Filter.
575
-		$schema = apply_filters( 'getpaid_db_schema', $schema );
576
-
577
-		self::$schema         = implode( "\n", array_values( $schema ) );
578
-		self::$schema_version = md5( sanitize_key( self::$schema ) );
579
-
580
-		return self::$schema;
581
-	}
582
-
583
-	/**
584
-	 * Returns the DB schema version.
585
-	 *
586
-	 */
587
-	public static function get_db_schema_version() {
588
-		if ( ! empty( self::$schema_version ) ) {
589
-			return self::$schema_version;
590
-		}
591
-
592
-		self::get_db_schema();
593
-
594
-		return self::$schema_version;
595
-	}
596
-
597
-	/**
598
-	 * Checks if the db schema is up to date.
599
-	 *
600
-	 * @return bool
601
-	 */
602
-	public static function is_db_schema_up_to_date() {
603
-		return self::get_db_schema_version() === get_option( 'getpaid_db_schema' );
604
-	}
605
-
606
-	/**
607
-	 * Set up the database tables which the plugin needs to function.
608
-	 */
609
-	public static function create_db_tables() {
610
-		global $wpdb;
611
-
612
-		$wpdb->hide_errors();
613
-
614
-		require_once ABSPATH . 'wp-admin/includes/upgrade.php';
615
-
616
-		$schema = self::get_db_schema();
617
-
618
-		// If invoices table exists, rename key to invoice_key.
619
-		$invoices_table = "{$wpdb->prefix}getpaid_invoices";
620
-
621
-		if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) {
622
-			$fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" );
623
-
624
-			foreach ( $fields as $field ) {
625
-				if ( 'key' === $field->Field ) {
626
-					$wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" );
627
-					break;
628
-				}
629
-			}
630
-		}
631
-
632
-		dbDelta( $schema );
633
-		wp_cache_flush();
634
-		update_option( 'getpaid_db_schema', self::get_db_schema_version() );
635
-	}
636
-
637
-	/**
638
-	 * Creates tables if schema is not up to date.
639
-	 */
640
-	public static function maybe_create_db_tables() {
641
-		if ( ! self::is_db_schema_up_to_date() ) {
642
-			self::create_db_tables();
643
-		}
644
-	}
574
+        // Filter.
575
+        $schema = apply_filters( 'getpaid_db_schema', $schema );
576
+
577
+        self::$schema         = implode( "\n", array_values( $schema ) );
578
+        self::$schema_version = md5( sanitize_key( self::$schema ) );
579
+
580
+        return self::$schema;
581
+    }
582
+
583
+    /**
584
+     * Returns the DB schema version.
585
+     *
586
+     */
587
+    public static function get_db_schema_version() {
588
+        if ( ! empty( self::$schema_version ) ) {
589
+            return self::$schema_version;
590
+        }
591
+
592
+        self::get_db_schema();
593
+
594
+        return self::$schema_version;
595
+    }
596
+
597
+    /**
598
+     * Checks if the db schema is up to date.
599
+     *
600
+     * @return bool
601
+     */
602
+    public static function is_db_schema_up_to_date() {
603
+        return self::get_db_schema_version() === get_option( 'getpaid_db_schema' );
604
+    }
605
+
606
+    /**
607
+     * Set up the database tables which the plugin needs to function.
608
+     */
609
+    public static function create_db_tables() {
610
+        global $wpdb;
611
+
612
+        $wpdb->hide_errors();
613
+
614
+        require_once ABSPATH . 'wp-admin/includes/upgrade.php';
615
+
616
+        $schema = self::get_db_schema();
617
+
618
+        // If invoices table exists, rename key to invoice_key.
619
+        $invoices_table = "{$wpdb->prefix}getpaid_invoices";
620
+
621
+        if ( $wpdb->get_var( "SHOW TABLES LIKE '{$wpdb->prefix}getpaid_invoices'" ) === $invoices_table ) {
622
+            $fields = $wpdb->get_results( "SHOW COLUMNS FROM {$wpdb->prefix}getpaid_invoices" );
623
+
624
+            foreach ( $fields as $field ) {
625
+                if ( 'key' === $field->Field ) {
626
+                    $wpdb->query( "ALTER TABLE {$wpdb->prefix}getpaid_invoices CHANGE `key` `invoice_key` VARCHAR(100)" );
627
+                    break;
628
+                }
629
+            }
630
+        }
631
+
632
+        dbDelta( $schema );
633
+        wp_cache_flush();
634
+        update_option( 'getpaid_db_schema', self::get_db_schema_version() );
635
+    }
636
+
637
+    /**
638
+     * Creates tables if schema is not up to date.
639
+     */
640
+    public static function maybe_create_db_tables() {
641
+        if ( ! self::is_db_schema_up_to_date() ) {
642
+            self::create_db_tables();
643
+        }
644
+    }
645 645
 }
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-item-details.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -696,7 +696,7 @@
 block discarded – undo
696 696
                                     $extra_attributes,
697 697
                                     array( 'size' => 4 )
698 698
                                 ),
699
-							),
699
+                            ),
700 700
                             true
701 701
                         );
702 702
                         ?>
Please login to merge, or discard this patch.
includes/payments/class-getpaid-form-item.php 1 patch
Indentation   +388 added lines, -388 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,75 +10,75 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Form_Item extends WPInv_Item {
11 11
 
12 12
     /**
13
-	 * Stores a custom description for the item.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $custom_description = null;
18
-
19
-	/**
20
-	 * Stores the item quantity.
21
-	 *
22
-	 * @var float
23
-	 */
24
-	protected $quantity = 1;
25
-
26
-	/**
27
-	 * Stores the item meta.
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $meta = array();
32
-
33
-	/**
34
-	 * Is this item required?
35
-	 *
36
-	 * @var int
37
-	 */
38
-	protected $is_required = true;
39
-
40
-	/**
41
-	 * Are quantities allowed?
42
-	 *
43
-	 * @var int
44
-	 */
45
-	protected $allow_quantities = false;
46
-
47
-	/**
48
-	 * Associated invoice.
49
-	 *
50
-	 * @var int
51
-	 */
52
-	public $invoice_id = 0;
53
-
54
-	/**
55
-	 * Item discount.
56
-	 *
57
-	 * @var float
58
-	 */
59
-	public $item_discount = 0;
60
-
61
-	/**
62
-	 * Recurring item discount.
63
-	 *
64
-	 * @var float
65
-	 */
66
-	public $recurring_item_discount = 0;
67
-
68
-	/**
69
-	 * Item tax.
70
-	 *
71
-	 * @var float
72
-	 */
73
-	public $item_tax = 0;
74
-
75
-
76
-    /**
77
-	 * Item price ID.
78
-	 *
79
-	 * @var int
80
-	 */
81
-	public $price_id = 0;
13
+     * Stores a custom description for the item.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $custom_description = null;
18
+
19
+    /**
20
+     * Stores the item quantity.
21
+     *
22
+     * @var float
23
+     */
24
+    protected $quantity = 1;
25
+
26
+    /**
27
+     * Stores the item meta.
28
+     *
29
+     * @var array
30
+     */
31
+    protected $meta = array();
32
+
33
+    /**
34
+     * Is this item required?
35
+     *
36
+     * @var int
37
+     */
38
+    protected $is_required = true;
39
+
40
+    /**
41
+     * Are quantities allowed?
42
+     *
43
+     * @var int
44
+     */
45
+    protected $allow_quantities = false;
46
+
47
+    /**
48
+     * Associated invoice.
49
+     *
50
+     * @var int
51
+     */
52
+    public $invoice_id = 0;
53
+
54
+    /**
55
+     * Item discount.
56
+     *
57
+     * @var float
58
+     */
59
+    public $item_discount = 0;
60
+
61
+    /**
62
+     * Recurring item discount.
63
+     *
64
+     * @var float
65
+     */
66
+    public $recurring_item_discount = 0;
67
+
68
+    /**
69
+     * Item tax.
70
+     *
71
+     * @var float
72
+     */
73
+    public $item_tax = 0;
74
+
75
+
76
+    /**
77
+     * Item price ID.
78
+     *
79
+     * @var int
80
+     */
81
+    public $price_id = 0;
82 82
 
83 83
     /*
84 84
 	|--------------------------------------------------------------------------
@@ -96,242 +96,242 @@  discard block
 block discarded – undo
96 96
     */
97 97
 
98 98
     /**
99
-	 * Get the item name.
100
-	 *
101
-	 * @since 1.0.19
102
-	 * @param  string $context View or edit context.
103
-	 * @return string
104
-	 */
105
-	public function get_name( $context = 'view' ) {
106
-		$name = parent::get_name( $context );
107
-		return $name . wpinv_get_item_suffix( $this );
108
-	}
109
-
110
-	/**
111
-	 * Get the item name without a suffix.
112
-	 *
113
-	 * @since 1.0.19
114
-	 * @param  string $context View or edit context.
115
-	 * @return string
116
-	 */
117
-	public function get_raw_name( $context = 'view' ) {
118
-		return parent::get_name( $context );
119
-	}
120
-
121
-	/**
122
-	 * Get the item description.
123
-	 *
124
-	 * @since 1.0.19
125
-	 * @param  string $context View or edit context.
126
-	 * @return string
127
-	 */
128
-	public function get_description( $context = 'view' ) {
129
-
130
-		if ( isset( $this->custom_description ) ) {
131
-			return $this->custom_description;
132
-		}
133
-
134
-		return parent::get_description( $context );
135
-	}
136
-
137
-	/**
138
-	 * Returns the sub total.
139
-	 *
140
-	 * @since 1.0.19
141
-	 * @param  string $context View or edit context.
142
-	 * @return float
143
-	 */
144
-	public function get_sub_total( $context = 'view', $price_id = null ) {
145
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context, $price_id );
146
-	}
147
-
148
-	/**
149
-	 * Returns the recurring sub total.
150
-	 *
151
-	 * @since 1.0.19
152
-	 * @param  string $context View or edit context.
153
-	 * @return float
154
-	 */
155
-	public function get_recurring_sub_total( $context = 'view' ) {
156
-
157
-		if ( $this->is_recurring() ) {
158
-			return $this->get_quantity( $context ) * $this->get_price( $context );
159
-		}
160
-
161
-		return 0;
162
-	}
163
-
164
-	/**
165
-	 * @deprecated
166
-	 */
167
-	public function get_qantity( $context = 'view' ) {
168
-		return $this->get_quantity( $context );
169
-	}
170
-
171
-	/**
172
-	 * Get the item quantity.
173
-	 *
174
-	 * @since 1.0.19
175
-	 * @param  string $context View or edit context.
176
-	 * @return float
177
-	 */
178
-	public function get_quantity( $context = 'view' ) {
179
-		$quantity = (float) $this->quantity;
180
-
181
-		if ( 'view' === $context ) {
182
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
183
-		}
184
-
185
-		return $quantity;
186
-	}
187
-
188
-	/**
189
-	 * Get the item meta data.
190
-	 *
191
-	 * @since 1.0.19
192
-	 * @param  string $context View or edit context.
193
-	 * @return meta
194
-	 */
195
-	public function get_item_meta( $context = 'view' ) {
196
-		$meta = $this->meta;
197
-
198
-		if ( 'view' === $context ) {
199
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
200
-		}
201
-
202
-		return $meta;
203
-	}
204
-
205
-	/**
206
-	 * Returns whether or not customers can update the item quantity.
207
-	 *
208
-	 * @since 1.0.19
209
-	 * @param  string $context View or edit context.
210
-	 * @return bool
211
-	 */
212
-	public function get_allow_quantities( $context = 'view' ) {
213
-		$allow_quantities = (bool) $this->allow_quantities;
214
-
215
-		if ( 'view' === $context ) {
216
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
217
-		}
218
-
219
-		return $allow_quantities;
220
-	}
221
-
222
-	/**
223
-	 * Returns whether or not the item is required.
224
-	 *
225
-	 * @since 1.0.19
226
-	 * @param  string $context View or edit context.
227
-	 * @return bool
228
-	 */
229
-	public function get_is_required( $context = 'view' ) {
230
-		$is_required = (bool) $this->is_required;
231
-
232
-		if ( 'view' === $context ) {
233
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
234
-		}
235
-
236
-		return $is_required;
237
-	}
238
-
239
-    /**
240
-	 * Returns whether or not customers can update the item quantity.
241
-	 *
242
-	 * @since 1.0.19
243
-	 * @param  string $context View or edit context.
244
-	 * @return int
245
-	 */
246
-	public function get_price_id( $context = 'view' ) {
247
-		$price_id = (int) $this->price_id;
248
-
249
-		if ( 'view' === $context ) {
250
-			return apply_filters( 'getpaid_payment_form_item_price_id', $price_id, $this );
251
-		}
252
-
253
-		return $price_id;
254
-	}
255
-
256
-	/**
257
-	 * Prepares form data for use.
258
-	 *
259
-	 * @since 1.0.19
260
-	 * @return array
261
-	 */
262
-	public function prepare_data_for_use( $required = null ) {
263
-
264
-		$required = is_null( $required ) ? $this->is_required() : $required;
265
-		return array(
266
-			'title'            => wp_strip_all_tags( $this->get_name() ),
267
-			'id'               => $this->get_id(),
268
-			'price'            => $this->get_price(),
269
-			'recurring'        => $this->is_recurring(),
270
-			'description'      => $this->get_description(),
271
-			'allow_quantities' => $this->allows_quantities(),
272
-			'price_id'         => $this->get_price_id(),
273
-			'required'         => $required,
274
-		);
275
-	}
276
-
277
-	/**
278
-	 * Prepares form data for ajax use.
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @return array
282
-	 */
283
-	public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
284
-
285
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
286
-
287
-		if ( $description ) {
288
-			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
289
-		}
290
-
291
-		$price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
292
-		$subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
293
-		return array(
294
-			'id'     => $this->get_id(),
295
-			'texts'  => array(
296
-				'item-name'        => sanitize_text_field( $this->get_name() ),
297
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
298
-				'item-quantity'    => floatval( $this->get_quantity() ),
299
-				'item-price'       => wpinv_price( $price, $currency ),
300
-				'item-total'       => wpinv_price( $subtotal, $currency ),
301
-			),
302
-			'inputs' => array(
303
-				'item-id'          => $this->get_id(),
304
-				'item-name'        => sanitize_text_field( $this->get_name() ),
305
-				'item-description' => wp_kses_post( $this->get_description() ),
306
-				'item-quantity'    => floatval( $this->get_quantity() ),
307
-				'item-price'       => $price,
308
-			),
309
-		);
310
-	}
311
-
312
-	/**
313
-	 * Prepares form data for saving (cart_details).
314
-	 *
315
-	 * @since 1.0.19
316
-	 * @return array
317
-	 */
318
-	public function prepare_data_for_saving() {
319
-
320
-		return array(
321
-			'post_id'          => $this->invoice_id,
322
-			'item_id'          => $this->get_id(),
323
-			'item_name'        => sanitize_text_field( $this->get_raw_name( 'edit' ) ),
324
-			'item_description' => $this->get_description( 'edit' ),
325
-			'tax'              => $this->item_tax,
326
-			'item_price'       => $this->get_price( 'edit' ),
327
-			'quantity'         => (float) $this->get_quantity( 'edit' ),
328
-			'discount'         => $this->item_discount,
329
-			'subtotal'         => $this->get_sub_total( 'edit' ),
330
-			'price'            => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount,
331
-			'price_id'         => (int) $this->get_price_id( 'edit' ),
332
-			'meta'             => $this->get_item_meta( 'edit' ),
333
-		);
334
-	}
99
+     * Get the item name.
100
+     *
101
+     * @since 1.0.19
102
+     * @param  string $context View or edit context.
103
+     * @return string
104
+     */
105
+    public function get_name( $context = 'view' ) {
106
+        $name = parent::get_name( $context );
107
+        return $name . wpinv_get_item_suffix( $this );
108
+    }
109
+
110
+    /**
111
+     * Get the item name without a suffix.
112
+     *
113
+     * @since 1.0.19
114
+     * @param  string $context View or edit context.
115
+     * @return string
116
+     */
117
+    public function get_raw_name( $context = 'view' ) {
118
+        return parent::get_name( $context );
119
+    }
120
+
121
+    /**
122
+     * Get the item description.
123
+     *
124
+     * @since 1.0.19
125
+     * @param  string $context View or edit context.
126
+     * @return string
127
+     */
128
+    public function get_description( $context = 'view' ) {
129
+
130
+        if ( isset( $this->custom_description ) ) {
131
+            return $this->custom_description;
132
+        }
133
+
134
+        return parent::get_description( $context );
135
+    }
136
+
137
+    /**
138
+     * Returns the sub total.
139
+     *
140
+     * @since 1.0.19
141
+     * @param  string $context View or edit context.
142
+     * @return float
143
+     */
144
+    public function get_sub_total( $context = 'view', $price_id = null ) {
145
+        return $this->get_quantity( $context ) * $this->get_initial_price( $context, $price_id );
146
+    }
147
+
148
+    /**
149
+     * Returns the recurring sub total.
150
+     *
151
+     * @since 1.0.19
152
+     * @param  string $context View or edit context.
153
+     * @return float
154
+     */
155
+    public function get_recurring_sub_total( $context = 'view' ) {
156
+
157
+        if ( $this->is_recurring() ) {
158
+            return $this->get_quantity( $context ) * $this->get_price( $context );
159
+        }
160
+
161
+        return 0;
162
+    }
163
+
164
+    /**
165
+     * @deprecated
166
+     */
167
+    public function get_qantity( $context = 'view' ) {
168
+        return $this->get_quantity( $context );
169
+    }
170
+
171
+    /**
172
+     * Get the item quantity.
173
+     *
174
+     * @since 1.0.19
175
+     * @param  string $context View or edit context.
176
+     * @return float
177
+     */
178
+    public function get_quantity( $context = 'view' ) {
179
+        $quantity = (float) $this->quantity;
180
+
181
+        if ( 'view' === $context ) {
182
+            return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
183
+        }
184
+
185
+        return $quantity;
186
+    }
187
+
188
+    /**
189
+     * Get the item meta data.
190
+     *
191
+     * @since 1.0.19
192
+     * @param  string $context View or edit context.
193
+     * @return meta
194
+     */
195
+    public function get_item_meta( $context = 'view' ) {
196
+        $meta = $this->meta;
197
+
198
+        if ( 'view' === $context ) {
199
+            return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
200
+        }
201
+
202
+        return $meta;
203
+    }
204
+
205
+    /**
206
+     * Returns whether or not customers can update the item quantity.
207
+     *
208
+     * @since 1.0.19
209
+     * @param  string $context View or edit context.
210
+     * @return bool
211
+     */
212
+    public function get_allow_quantities( $context = 'view' ) {
213
+        $allow_quantities = (bool) $this->allow_quantities;
214
+
215
+        if ( 'view' === $context ) {
216
+            return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
217
+        }
218
+
219
+        return $allow_quantities;
220
+    }
221
+
222
+    /**
223
+     * Returns whether or not the item is required.
224
+     *
225
+     * @since 1.0.19
226
+     * @param  string $context View or edit context.
227
+     * @return bool
228
+     */
229
+    public function get_is_required( $context = 'view' ) {
230
+        $is_required = (bool) $this->is_required;
231
+
232
+        if ( 'view' === $context ) {
233
+            return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
234
+        }
235
+
236
+        return $is_required;
237
+    }
238
+
239
+    /**
240
+     * Returns whether or not customers can update the item quantity.
241
+     *
242
+     * @since 1.0.19
243
+     * @param  string $context View or edit context.
244
+     * @return int
245
+     */
246
+    public function get_price_id( $context = 'view' ) {
247
+        $price_id = (int) $this->price_id;
248
+
249
+        if ( 'view' === $context ) {
250
+            return apply_filters( 'getpaid_payment_form_item_price_id', $price_id, $this );
251
+        }
252
+
253
+        return $price_id;
254
+    }
255
+
256
+    /**
257
+     * Prepares form data for use.
258
+     *
259
+     * @since 1.0.19
260
+     * @return array
261
+     */
262
+    public function prepare_data_for_use( $required = null ) {
263
+
264
+        $required = is_null( $required ) ? $this->is_required() : $required;
265
+        return array(
266
+            'title'            => wp_strip_all_tags( $this->get_name() ),
267
+            'id'               => $this->get_id(),
268
+            'price'            => $this->get_price(),
269
+            'recurring'        => $this->is_recurring(),
270
+            'description'      => $this->get_description(),
271
+            'allow_quantities' => $this->allows_quantities(),
272
+            'price_id'         => $this->get_price_id(),
273
+            'required'         => $required,
274
+        );
275
+    }
276
+
277
+    /**
278
+     * Prepares form data for ajax use.
279
+     *
280
+     * @since 1.0.19
281
+     * @return array
282
+     */
283
+    public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
284
+
285
+        $description = getpaid_item_recurring_price_help_text( $this, $currency );
286
+
287
+        if ( $description ) {
288
+            $description = "<div class='getpaid-subscription-help-text'>$description</div>";
289
+        }
290
+
291
+        $price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
292
+        $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
293
+        return array(
294
+            'id'     => $this->get_id(),
295
+            'texts'  => array(
296
+                'item-name'        => sanitize_text_field( $this->get_name() ),
297
+                'item-description' => wp_kses_post( $this->get_description() ) . $description,
298
+                'item-quantity'    => floatval( $this->get_quantity() ),
299
+                'item-price'       => wpinv_price( $price, $currency ),
300
+                'item-total'       => wpinv_price( $subtotal, $currency ),
301
+            ),
302
+            'inputs' => array(
303
+                'item-id'          => $this->get_id(),
304
+                'item-name'        => sanitize_text_field( $this->get_name() ),
305
+                'item-description' => wp_kses_post( $this->get_description() ),
306
+                'item-quantity'    => floatval( $this->get_quantity() ),
307
+                'item-price'       => $price,
308
+            ),
309
+        );
310
+    }
311
+
312
+    /**
313
+     * Prepares form data for saving (cart_details).
314
+     *
315
+     * @since 1.0.19
316
+     * @return array
317
+     */
318
+    public function prepare_data_for_saving() {
319
+
320
+        return array(
321
+            'post_id'          => $this->invoice_id,
322
+            'item_id'          => $this->get_id(),
323
+            'item_name'        => sanitize_text_field( $this->get_raw_name( 'edit' ) ),
324
+            'item_description' => $this->get_description( 'edit' ),
325
+            'tax'              => $this->item_tax,
326
+            'item_price'       => $this->get_price( 'edit' ),
327
+            'quantity'         => (float) $this->get_quantity( 'edit' ),
328
+            'discount'         => $this->item_discount,
329
+            'subtotal'         => $this->get_sub_total( 'edit' ),
330
+            'price'            => $this->get_sub_total( 'edit' ) + $this->item_tax - $this->item_discount,
331
+            'price_id'         => (int) $this->get_price_id( 'edit' ),
332
+            'meta'             => $this->get_item_meta( 'edit' ),
333
+        );
334
+    }
335 335
 
336 336
     /*
337 337
 	|--------------------------------------------------------------------------
@@ -343,84 +343,84 @@  discard block
 block discarded – undo
343 343
 	| object.
344 344
     */
345 345
 
346
-	/**
347
-	 * Set the item qantity.
348
-	 *
349
-	 * @since 1.0.19
350
-	 * @param  float $quantity The item quantity.
351
-	 */
352
-	public function set_quantity( $quantity ) {
346
+    /**
347
+     * Set the item qantity.
348
+     *
349
+     * @since 1.0.19
350
+     * @param  float $quantity The item quantity.
351
+     */
352
+    public function set_quantity( $quantity ) {
353
+
354
+        if ( ! is_numeric( $quantity ) ) {
355
+            $quantity = 1;
356
+        }
357
+
358
+        $this->quantity = (float) $quantity;
359
+    }
360
+
361
+    /**
362
+     * Set the item price ID.
363
+     *
364
+     * @since 1.0.19
365
+     * @param  float $price_id The item price ID.
366
+     */
367
+    public function set_price_id( $price_id ) {
368
+
369
+        if ( ! is_numeric( $price_id ) ) {
370
+            $price_id = $this->get_default_price_id();
371
+        }
353 372
 
354
-		if ( ! is_numeric( $quantity ) ) {
355
-			$quantity = 1;
356
-		}
373
+        $this->price_id = (int) $price_id;
374
+    }
357 375
 
358
-		$this->quantity = (float) $quantity;
376
+    /**
377
+     * Set the item meta data.
378
+     *
379
+     * @since 1.0.19
380
+     * @param  array $meta The item meta data.
381
+     */
382
+    public function set_item_meta( $meta ) {
383
+        $this->meta = maybe_unserialize( $meta );
359 384
     }
360 385
 
361 386
     /**
362
-	 * Set the item price ID.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param  float $price_id The item price ID.
366
-	 */
367
-	public function set_price_id( $price_id ) {
368
-
369
-		if ( ! is_numeric( $price_id ) ) {
370
-			$price_id = $this->get_default_price_id();
371
-		}
372
-
373
-		$this->price_id = (int) $price_id;
374
-	}
375
-
376
-	/**
377
-	 * Set the item meta data.
378
-	 *
379
-	 * @since 1.0.19
380
-	 * @param  array $meta The item meta data.
381
-	 */
382
-	public function set_item_meta( $meta ) {
383
-		$this->meta = maybe_unserialize( $meta );
384
-	}
385
-
386
-	/**
387
-	 * Set whether or not the quantities are allowed.
388
-	 *
389
-	 * @since 1.0.19
390
-	 * @param  bool $allow_quantities
391
-	 */
392
-	public function set_allow_quantities( $allow_quantities ) {
393
-		$this->allow_quantities = (bool) $allow_quantities;
394
-	}
395
-
396
-	/**
397
-	 * Set whether or not the item is required.
398
-	 *
399
-	 * @since 1.0.19
400
-	 * @param  bool $is_required
401
-	 */
402
-	public function set_is_required( $is_required ) {
403
-		$this->is_required = (bool) $is_required;
404
-	}
405
-
406
-	/**
407
-	 * Sets the custom item description.
408
-	 *
409
-	 * @since 1.0.19
410
-	 * @param  string $description
411
-	 */
412
-	public function set_custom_description( $description ) {
413
-		$this->custom_description = $description;
414
-	}
387
+     * Set whether or not the quantities are allowed.
388
+     *
389
+     * @since 1.0.19
390
+     * @param  bool $allow_quantities
391
+     */
392
+    public function set_allow_quantities( $allow_quantities ) {
393
+        $this->allow_quantities = (bool) $allow_quantities;
394
+    }
395
+
396
+    /**
397
+     * Set whether or not the item is required.
398
+     *
399
+     * @since 1.0.19
400
+     * @param  bool $is_required
401
+     */
402
+    public function set_is_required( $is_required ) {
403
+        $this->is_required = (bool) $is_required;
404
+    }
405
+
406
+    /**
407
+     * Sets the custom item description.
408
+     *
409
+     * @since 1.0.19
410
+     * @param  string $description
411
+     */
412
+    public function set_custom_description( $description ) {
413
+        $this->custom_description = $description;
414
+    }
415 415
 
416 416
     /**
417 417
      * We do not want to save items to the database.
418 418
      *
419
-	 * @return int item id
419
+     * @return int item id
420 420
      */
421 421
     public function save( $data = array() ) {
422 422
         return $this->get_id();
423
-	}
423
+    }
424 424
 
425 425
     /*
426 426
 	|--------------------------------------------------------------------------
@@ -432,22 +432,22 @@  discard block
 block discarded – undo
432 432
 	*/
433 433
 
434 434
     /**
435
-	 * Checks whether the item has enabled dynamic pricing.
436
-	 *
437
-	 * @since 1.0.19
438
-	 * @return bool
439
-	 */
440
-	public function is_required() {
435
+     * Checks whether the item has enabled dynamic pricing.
436
+     *
437
+     * @since 1.0.19
438
+     * @return bool
439
+     */
440
+    public function is_required() {
441 441
         return (bool) $this->get_is_required();
442
-	}
443
-
444
-	/**
445
-	 * Checks whether users can edit the quantities.
446
-	 *
447
-	 * @since 1.0.19
448
-	 * @return bool
449
-	 */
450
-	public function allows_quantities() {
442
+    }
443
+
444
+    /**
445
+     * Checks whether users can edit the quantities.
446
+     *
447
+     * @since 1.0.19
448
+     * @return bool
449
+     */
450
+    public function allows_quantities() {
451 451
         return (bool) $this->get_allow_quantities();
452
-	}
452
+    }
453 453
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 1 patch
Indentation   +308 added lines, -308 removed lines patch added patch discarded remove patch
@@ -12,185 +12,185 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Checkout {
14 14
 
15
-	/**
16
-	 * @var GetPaid_Payment_Form_Submission
17
-	 */
18
-	protected $payment_form_submission;
19
-
20
-	/**
21
-	 * Class constructor.
22
-	 *
23
-	 * @param GetPaid_Payment_Form_Submission $submission
24
-	 */
25
-	public function __construct( $submission ) {
26
-		$this->payment_form_submission = $submission;
27
-	}
28
-
29
-	/**
30
-	 * Processes the checkout.
31
-	 *
32
-	 */
33
-	public function process_checkout() {
34
-
35
-		// Validate the submission.
36
-		$this->validate_submission();
37
-
38
-		// Prepare the invoice.
39
-		$items    = $this->get_submission_items();
40
-		$invoice  = $this->get_submission_invoice();
41
-		$invoice  = $this->process_submission_invoice( $invoice, $items );
42
-		$prepared = $this->prepare_submission_data_for_saving();
43
-
44
-		$this->prepare_billing_info( $invoice );
45
-
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
47
-
48
-		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
50
-		$invoice->recalculate_total();
15
+    /**
16
+     * @var GetPaid_Payment_Form_Submission
17
+     */
18
+    protected $payment_form_submission;
19
+
20
+    /**
21
+     * Class constructor.
22
+     *
23
+     * @param GetPaid_Payment_Form_Submission $submission
24
+     */
25
+    public function __construct( $submission ) {
26
+        $this->payment_form_submission = $submission;
27
+    }
28
+
29
+    /**
30
+     * Processes the checkout.
31
+     *
32
+     */
33
+    public function process_checkout() {
34
+
35
+        // Validate the submission.
36
+        $this->validate_submission();
37
+
38
+        // Prepare the invoice.
39
+        $items    = $this->get_submission_items();
40
+        $invoice  = $this->get_submission_invoice();
41
+        $invoice  = $this->process_submission_invoice( $invoice, $items );
42
+        $prepared = $this->prepare_submission_data_for_saving();
43
+
44
+        $this->prepare_billing_info( $invoice );
45
+
46
+        $shipping   = $this->prepare_shipping_info( $invoice );
47
+
48
+        // Save the invoice.
49
+        $invoice->set_is_viewed( true );
50
+        $invoice->recalculate_total();
51 51
         $invoice->save();
52 52
 
53
-		do_action( 'getpaid_checkout_invoice_updated', $invoice );
53
+        do_action( 'getpaid_checkout_invoice_updated', $invoice );
54 54
 
55
-		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
57
-	}
55
+        // Send to the gateway.
56
+        $this->post_process_submission( $invoice, $prepared, $shipping );
57
+    }
58 58
 
59
-	/**
60
-	 * Validates the submission.
61
-	 *
62
-	 */
63
-	protected function validate_submission() {
59
+    /**
60
+     * Validates the submission.
61
+     *
62
+     */
63
+    protected function validate_submission() {
64 64
 
65
-		$submission = $this->payment_form_submission;
66
-		$data       = $submission->get_data();
65
+        $submission = $this->payment_form_submission;
66
+        $data       = $submission->get_data();
67 67
 
68
-		// Do we have an error?
68
+        // Do we have an error?
69 69
         if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
70
+            wp_send_json_error( $submission->last_error );
71 71
         }
72 72
 
73
-		// We need a billing email.
73
+        // We need a billing email.
74 74
         if ( ! $submission->has_billing_email() ) {
75 75
             wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
76
-		}
76
+        }
77 77
 
78
-		// Non-recurring gateways should not be allowed to process recurring invoices.
79
-		if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
-			wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
-		}
78
+        // Non-recurring gateways should not be allowed to process recurring invoices.
79
+        if ( $submission->should_collect_payment_details() && $submission->has_recurring && ! wpinv_gateway_support_subscription( $data['wpi-gateway'] ) ) {
80
+            wp_send_json_error( __( 'The selected payment gateway does not support subscription payments.', 'invoicing' ) );
81
+        }
82 82
 
83
-		// Ensure the gateway is active.
84
-		if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
-			wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
-		}
83
+        // Ensure the gateway is active.
84
+        if ( $submission->should_collect_payment_details() && ! wpinv_is_gateway_active( $data['wpi-gateway'] ) ) {
85
+            wp_send_json_error( __( 'The selected payment gateway is not active', 'invoicing' ) );
86
+        }
87 87
 
88
-		// Clear any existing errors.
89
-		wpinv_clear_errors();
88
+        // Clear any existing errors.
89
+        wpinv_clear_errors();
90 90
 
91
-		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
91
+        // Allow themes and plugins to hook to errors
92
+        do_action( 'getpaid_checkout_error_checks', $submission );
93 93
 
94
-		// Do we have any errors?
94
+        // Do we have any errors?
95 95
         if ( wpinv_get_errors() ) {
96 96
             wp_send_json_error( getpaid_get_errors_html() );
97
-		}
97
+        }
98 98
 
99
-	} 
99
+    } 
100 100
 
101
-	/**
102
-	 * Retrieves submission items.
103
-	 *
104
-	 * @return GetPaid_Form_Item[]
105
-	 */
106
-	protected function get_submission_items() {
101
+    /**
102
+     * Retrieves submission items.
103
+     *
104
+     * @return GetPaid_Form_Item[]
105
+     */
106
+    protected function get_submission_items() {
107 107
 
108
-		$items = $this->payment_form_submission->get_items();
108
+        $items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111 111
         if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112 112
             wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
113
-		}
114
-
115
-		return $items;
116
-	}
117
-
118
-	/**
119
-	 * Retrieves submission invoice.
120
-	 *
121
-	 * @return WPInv_Invoice
122
-	 */
123
-	protected function get_submission_invoice() {
124
-		$submission = $this->payment_form_submission;
125
-
126
-		if ( ! $submission->has_invoice() ) {
127
-			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
129
-			return $invoice;
130 113
         }
131 114
 
132
-		$invoice = $submission->get_invoice();
115
+        return $items;
116
+    }
117
+
118
+    /**
119
+     * Retrieves submission invoice.
120
+     *
121
+     * @return WPInv_Invoice
122
+     */
123
+    protected function get_submission_invoice() {
124
+        $submission = $this->payment_form_submission;
133 125
 
134
-		// Make sure that it is neither paid or refunded.
135
-		if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
-			wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
-		}
126
+        if ( ! $submission->has_invoice() ) {
127
+            $invoice = new WPInv_Invoice();
128
+            $invoice->set_created_via( 'payment_form' );
129
+            return $invoice;
130
+        }
138 131
 
139
-		return $invoice;
140
-	}
132
+        $invoice = $submission->get_invoice();
141 133
 
142
-	/**
143
-	 * Processes the submission invoice.
144
-	 *
145
-	 * @param WPInv_Invoice $invoice
146
-	 * @param GetPaid_Form_Item[] $items
147
-	 * @return WPInv_Invoice
148
-	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
134
+        // Make sure that it is neither paid or refunded.
135
+        if ( $invoice->is_paid() || $invoice->is_refunded() ) {
136
+            wp_send_json_error( __( 'This invoice has already been paid for.', 'invoicing' ) );
137
+        }
150 138
 
151
-		$submission = $this->payment_form_submission;
139
+        return $invoice;
140
+    }
152 141
 
153
-		// Set-up the invoice details.
154
-		$invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
-		$invoice->set_user_id( $this->get_submission_customer() );
156
-		$invoice->set_submission_id( $submission->id );
157
-		$invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
142
+    /**
143
+     * Processes the submission invoice.
144
+     *
145
+     * @param WPInv_Invoice $invoice
146
+     * @param GetPaid_Form_Item[] $items
147
+     * @return WPInv_Invoice
148
+     */
149
+    protected function process_submission_invoice( $invoice, $items ) {
150
+
151
+        $submission = $this->payment_form_submission;
152
+
153
+        // Set-up the invoice details.
154
+        $invoice->set_email( sanitize_email( $submission->get_billing_email() ) );
155
+        $invoice->set_user_id( $this->get_submission_customer() );
156
+        $invoice->set_submission_id( $submission->id );
157
+        $invoice->set_payment_form( absint( $submission->get_payment_form()->get_id() ) );
158 158
         $invoice->set_items( $items );
159 159
         $invoice->set_fees( $submission->get_fees() );
160 160
         $invoice->set_taxes( $submission->get_taxes() );
161
-		$invoice->set_discounts( $submission->get_discounts() );
162
-		$invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
163
-		$invoice->set_currency( $submission->get_currency() );
161
+        $invoice->set_discounts( $submission->get_discounts() );
162
+        $invoice->set_gateway( $submission->get_field( 'wpi-gateway' ) );
163
+        $invoice->set_currency( $submission->get_currency() );
164 164
 
165
-		if ( $submission->has_shipping() ) {
166
-			$invoice->set_shipping( $submission->get_shipping() );
167
-		}
165
+        if ( $submission->has_shipping() ) {
166
+            $invoice->set_shipping( $submission->get_shipping() );
167
+        }
168 168
 
169
-		$address_confirmed = $submission->get_field( 'confirm-address' );
170
-		$invoice->set_address_confirmed( ! empty( $address_confirmed ) );
169
+        $address_confirmed = $submission->get_field( 'confirm-address' );
170
+        $invoice->set_address_confirmed( ! empty( $address_confirmed ) );
171 171
 
172
-		if ( $submission->has_discount_code() ) {
172
+        if ( $submission->has_discount_code() ) {
173 173
             $invoice->set_discount_code( $submission->get_discount_code() );
174
-		}
175
-
176
-		getpaid_maybe_add_default_address( $invoice );
177
-		return $invoice;
178
-	}
179
-
180
-	/**
181
-	 * Retrieves the submission's customer.
182
-	 *
183
-	 * @return int The customer id.
184
-	 */
185
-	protected function get_submission_customer() {
186
-		$submission = $this->payment_form_submission;
187
-
188
-		// If this is an existing invoice...
189
-		if ( $submission->has_invoice() ) {
190
-			return $submission->get_invoice()->get_user_id();
191
-		}
192
-
193
-		// (Maybe) create the user.
174
+        }
175
+
176
+        getpaid_maybe_add_default_address( $invoice );
177
+        return $invoice;
178
+    }
179
+
180
+    /**
181
+     * Retrieves the submission's customer.
182
+     *
183
+     * @return int The customer id.
184
+     */
185
+    protected function get_submission_customer() {
186
+        $submission = $this->payment_form_submission;
187
+
188
+        // If this is an existing invoice...
189
+        if ( $submission->has_invoice() ) {
190
+            return $submission->get_invoice()->get_user_id();
191
+        }
192
+
193
+        // (Maybe) create the user.
194 194
         $user = get_current_user_id();
195 195
 
196 196
         if ( empty( $user ) ) {
@@ -198,16 +198,16 @@  discard block
 block discarded – undo
198 198
         }
199 199
 
200 200
         if ( empty( $user ) ) {
201
-			$name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
202
-			$name = implode( '', array_filter( $name ) );
201
+            $name = array( $submission->get_field( 'wpinv_first_name', 'billing' ), $submission->get_field( 'wpinv_last_name', 'billing' ) );
202
+            $name = implode( '', array_filter( $name ) );
203 203
             $user = wpinv_create_user( $submission->get_billing_email(), $name );
204 204
 
205
-			// (Maybe) send new user notification.
206
-			$should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
207
-			if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
208
-				wp_send_new_user_notifications( $user, 'user' );
209
-			}
210
-		}
205
+            // (Maybe) send new user notification.
206
+            $should_send_notification = wpinv_get_option( 'disable_new_user_emails' );
207
+            if ( ! empty( $user ) && is_numeric( $user ) && apply_filters( 'getpaid_send_new_user_notification', empty( $should_send_notification ), $user ) ) {
208
+                wp_send_new_user_notifications( $user, 'user' );
209
+            }
210
+        }
211 211
 
212 212
         if ( is_wp_error( $user ) ) {
213 213
             wp_send_json_error( $user->get_error_message() );
@@ -215,47 +215,47 @@  discard block
 block discarded – undo
215 215
 
216 216
         if ( is_numeric( $user ) ) {
217 217
             return $user;
218
-		}
218
+        }
219 219
 
220
-		return $user->ID;
220
+        return $user->ID;
221 221
 
222
-	}
222
+    }
223 223
 
224
-	/**
224
+    /**
225 225
      * Prepares submission data for saving to the database.
226 226
      *
227
-	 * @return array
227
+     * @return array
228 228
      */
229 229
     public function prepare_submission_data_for_saving() {
230 230
 
231
-		$submission = $this->payment_form_submission;
231
+        $submission = $this->payment_form_submission;
232 232
 
233
-		// Prepared submission details.
233
+        // Prepared submission details.
234 234
         $prepared = array(
235
-			'all'  => array(),
236
-			'meta' => array(),
237
-		);
235
+            'all'  => array(),
236
+            'meta' => array(),
237
+        );
238 238
 
239 239
         // Raw submission details.
240
-		$data     = $submission->get_data();
240
+        $data     = $submission->get_data();
241 241
 
242
-		// Loop through the submitted details.
242
+        // Loop through the submitted details.
243 243
         foreach ( $submission->get_payment_form()->get_elements() as $field ) {
244 244
 
245
-			// Skip premade fields.
245
+            // Skip premade fields.
246 246
             if ( ! empty( $field['premade'] ) ) {
247 247
                 continue;
248 248
             }
249 249
 
250
-			// Ensure address is provided.
251
-			if ( 'address' === $field['type'] ) {
250
+            // Ensure address is provided.
251
+            if ( 'address' === $field['type'] ) {
252 252
                 $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
253 253
 
254
-				foreach ( $field['fields'] as $address_field ) {
254
+                foreach ( $field['fields'] as $address_field ) {
255 255
 
256
-					if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
257
-						wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
258
-					}
256
+                    if ( ! empty( $address_field['visible'] ) && ! empty( $address_field['required'] ) && '' === trim( $_POST[ $address_type ][ $address_field['name'] ] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing
257
+                        wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
258
+                    }
259 259
                 }
260 260
             }
261 261
 
@@ -267,31 +267,31 @@  discard block
 block discarded – undo
267 267
             // Handle misc fields.
268 268
             if ( isset( $data[ $field['id'] ] ) ) {
269 269
 
270
-				// Uploads.
271
-				if ( 'file_upload' === $field['type'] ) {
272
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
270
+                // Uploads.
271
+                if ( 'file_upload' === $field['type'] ) {
272
+                    $max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
273 273
 
274
-					if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
275
-						wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
276
-					}
274
+                    if ( count( $data[ $field['id'] ] ) > $max_file_num ) {
275
+                        wp_send_json_error( __( 'Maximum number of allowed files exceeded.', 'invoicing' ) );
276
+                    }
277 277
 
278
-					$value = array();
278
+                    $value = array();
279 279
 
280
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
281
-						$value[] = sprintf(
282
-							'<a href="%s" target="_blank">%s</a>',
283
-							esc_url_raw( $url ),
284
-							esc_html( $name )
285
-						);
286
-					}
280
+                    foreach ( $data[ $field['id'] ] as $url => $name ) {
281
+                        $value[] = sprintf(
282
+                            '<a href="%s" target="_blank">%s</a>',
283
+                            esc_url_raw( $url ),
284
+                            esc_html( $name )
285
+                        );
286
+                    }
287 287
 
288
-					$value = implode( ' | ', $value );
288
+                    $value = implode( ' | ', $value );
289 289
 
290
-				} elseif ( 'checkbox' === $field['type'] ) {
291
-					$value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
292
-				} else {
293
-					$value = wp_kses_post( $data[ $field['id'] ] );
294
-				}
290
+                } elseif ( 'checkbox' === $field['type'] ) {
291
+                    $value = ! empty( $data[ $field['id'] ] ) ? __( 'Yes', 'invoicing' ) : __( 'No', 'invoicing' );
292
+                } else {
293
+                    $value = wp_kses_post( $data[ $field['id'] ] );
294
+                }
295 295
 
296 296
                 $label = $field['id'];
297 297
 
@@ -299,192 +299,192 @@  discard block
 block discarded – undo
299 299
                     $label = $field['label'];
300 300
                 }
301 301
 
302
-				if ( ! empty( $field['add_meta'] ) ) {
303
-					$prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
-				}
305
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
302
+                if ( ! empty( $field['add_meta'] ) ) {
303
+                    $prepared['meta'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
304
+                }
305
+                $prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
306 306
 
307 307
             }
308
-		}
308
+        }
309 309
 
310
-		return $prepared;
310
+        return $prepared;
311 311
 
312
-	}
312
+    }
313 313
 
314
-	/**
314
+    /**
315 315
      * Retrieves address details.
316 316
      *
317
-	 * @return array
318
-	 * @param WPInv_Invoice $invoice
319
-	 * @param string $type
317
+     * @return array
318
+     * @param WPInv_Invoice $invoice
319
+     * @param string $type
320 320
      */
321 321
     public function prepare_address_details( $invoice, $type = 'billing' ) {
322 322
 
323
-		$data     = $this->payment_form_submission->get_data();
324
-		$type     = sanitize_key( $type );
325
-		$address  = array();
326
-		$prepared = array();
323
+        $data     = $this->payment_form_submission->get_data();
324
+        $type     = sanitize_key( $type );
325
+        $address  = array();
326
+        $prepared = array();
327 327
 
328
-		if ( ! empty( $data[ $type ] ) ) {
329
-			$address = $data[ $type ];
330
-		}
328
+        if ( ! empty( $data[ $type ] ) ) {
329
+            $address = $data[ $type ];
330
+        }
331 331
 
332
-		// Clean address details.
333
-		foreach ( $address as $key => $value ) {
334
-			$key             = sanitize_key( $key );
335
-			$key             = str_replace( 'wpinv_', '', $key );
336
-			$value           = wpinv_clean( $value );
337
-			$prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
338
-		}
332
+        // Clean address details.
333
+        foreach ( $address as $key => $value ) {
334
+            $key             = sanitize_key( $key );
335
+            $key             = str_replace( 'wpinv_', '', $key );
336
+            $value           = wpinv_clean( $value );
337
+            $prepared[ $key ] = apply_filters( "getpaid_checkout_{$type}_address_$key", $value, $this->payment_form_submission, $invoice );
338
+        }
339 339
 
340
-		// Filter address details.
341
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
340
+        // Filter address details.
341
+        $prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
342 342
 
343
-		// Remove non-whitelisted values.
344
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
343
+        // Remove non-whitelisted values.
344
+        return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
345 345
 
346
-	}
346
+    }
347 347
 
348
-	/**
348
+    /**
349 349
      * Prepares the billing details.
350 350
      *
351
-	 * @return array
352
-	 * @param WPInv_Invoice $invoice
351
+     * @return array
352
+     * @param WPInv_Invoice $invoice
353 353
      */
354 354
     protected function prepare_billing_info( &$invoice ) {
355 355
 
356
-		$billing_address = $this->prepare_address_details( $invoice, 'billing' );
356
+        $billing_address = $this->prepare_address_details( $invoice, 'billing' );
357 357
 
358
-		// Update the invoice with the billing details.
359
-		$invoice->set_props( $billing_address );
358
+        // Update the invoice with the billing details.
359
+        $invoice->set_props( $billing_address );
360 360
 
361
-	}
361
+    }
362 362
 
363
-	/**
363
+    /**
364 364
      * Prepares the shipping details.
365 365
      *
366
-	 * @return array
367
-	 * @param WPInv_Invoice $invoice
366
+     * @return array
367
+     * @param WPInv_Invoice $invoice
368 368
      */
369 369
     protected function prepare_shipping_info( $invoice ) {
370 370
 
371
-		$data = $this->payment_form_submission->get_data();
371
+        $data = $this->payment_form_submission->get_data();
372 372
 
373
-		if ( empty( $data['same-shipping-address'] ) ) {
374
-			return $this->prepare_address_details( $invoice, 'shipping' );
375
-		}
373
+        if ( empty( $data['same-shipping-address'] ) ) {
374
+            return $this->prepare_address_details( $invoice, 'shipping' );
375
+        }
376 376
 
377
-		return $this->prepare_address_details( $invoice, 'billing' );
377
+        return $this->prepare_address_details( $invoice, 'billing' );
378 378
 
379
-	}
379
+    }
380 380
 
381
-	/**
382
-	 * Confirms the submission is valid and send users to the gateway.
383
-	 *
384
-	 * @param WPInv_Invoice $invoice
385
-	 * @param array $prepared_payment_form_data
386
-	 * @param array $shipping
387
-	 */
388
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
381
+    /**
382
+     * Confirms the submission is valid and send users to the gateway.
383
+     *
384
+     * @param WPInv_Invoice $invoice
385
+     * @param array $prepared_payment_form_data
386
+     * @param array $shipping
387
+     */
388
+    protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
389 389
 
390
-		// Ensure the invoice exists.
390
+        // Ensure the invoice exists.
391 391
         if ( ! $invoice->exists() ) {
392 392
             wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
393 393
         }
394 394
 
395
-		// Save payment form data.
396
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
395
+        // Save payment form data.
396
+        $prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
397 397
         delete_post_meta( $invoice->get_id(), 'payment_form_data' );
398
-		delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
399
-		if ( ! empty( $prepared_payment_form_data ) ) {
398
+        delete_post_meta( $invoice->get_id(), 'additional_meta_data' );
399
+        if ( ! empty( $prepared_payment_form_data ) ) {
400 400
 
401
-			if ( ! empty( $prepared_payment_form_data['all'] ) ) {
402
-				update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
403
-			}
401
+            if ( ! empty( $prepared_payment_form_data['all'] ) ) {
402
+                update_post_meta( $invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all'] );
403
+            }
404 404
 
405
-			if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
406
-				update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
407
-			}
408
-		}
405
+            if ( ! empty( $prepared_payment_form_data['meta'] ) ) {
406
+                update_post_meta( $invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta'] );
407
+            }
408
+        }
409 409
 
410
-		// Save payment form data.
411
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
410
+        // Save payment form data.
411
+        $shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
412 412
         if ( ! empty( $shipping ) ) {
413 413
             update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
414
-		}
414
+        }
415 415
 
416
-		// Backwards compatibility.
416
+        // Backwards compatibility.
417 417
         add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
418 418
 
419
-		try {
420
-			$this->process_payment( $invoice );
421
-		} catch ( Exception $e ) {
422
-			wpinv_set_error( 'payment_error', $e->getMessage() );
423
-		}
419
+        try {
420
+            $this->process_payment( $invoice );
421
+        } catch ( Exception $e ) {
422
+            wpinv_set_error( 'payment_error', $e->getMessage() );
423
+        }
424 424
 
425 425
         // If we are here, there was an error.
426
-		wpinv_send_back_to_checkout( $invoice );
426
+        wpinv_send_back_to_checkout( $invoice );
427 427
 
428
-	}
428
+    }
429 429
 
430
-	/**
431
-	 * Processes the actual payment.
432
-	 *
433
-	 * @param WPInv_Invoice $invoice
434
-	 */
435
-	protected function process_payment( $invoice ) {
430
+    /**
431
+     * Processes the actual payment.
432
+     *
433
+     * @param WPInv_Invoice $invoice
434
+     */
435
+    protected function process_payment( $invoice ) {
436 436
 
437
-		// Clear any checkout errors.
438
-		wpinv_clear_errors();
437
+        // Clear any checkout errors.
438
+        wpinv_clear_errors();
439 439
 
440
-		// No need to send free invoices to the gateway.
441
-		if ( $invoice->is_free() ) {
442
-			$this->process_free_payment( $invoice );
443
-		}
440
+        // No need to send free invoices to the gateway.
441
+        if ( $invoice->is_free() ) {
442
+            $this->process_free_payment( $invoice );
443
+        }
444 444
 
445
-		$submission = $this->payment_form_submission;
445
+        $submission = $this->payment_form_submission;
446 446
 
447
-		// Fires before sending to the gateway.
448
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
447
+        // Fires before sending to the gateway.
448
+        do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
449 449
 
450
-		// Allow the sumission data to be modified before it is sent to the gateway.
451
-		$submission_data    = $submission->get_data();
452
-		$submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
453
-		$submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
450
+        // Allow the sumission data to be modified before it is sent to the gateway.
451
+        $submission_data    = $submission->get_data();
452
+        $submission_gateway = apply_filters( 'getpaid_gateway_submission_gateway', $invoice->get_gateway(), $submission, $invoice );
453
+        $submission_data    = apply_filters( 'getpaid_gateway_submission_data', $submission_data, $submission, $invoice );
454 454
 
455
-		// Validate the currency.
456
-		if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
457
-			wpinv_set_error( 'invalid_currency' );
458
-		}
455
+        // Validate the currency.
456
+        if ( ! apply_filters( "getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency() ) ) {
457
+            wpinv_set_error( 'invalid_currency' );
458
+        }
459 459
 
460
-		// Check to see if we have any errors.
461
-		if ( wpinv_get_errors() ) {
462
-			wpinv_send_back_to_checkout( $invoice );
463
-		}
460
+        // Check to see if we have any errors.
461
+        if ( wpinv_get_errors() ) {
462
+            wpinv_send_back_to_checkout( $invoice );
463
+        }
464 464
 
465
-		// Send info to the gateway for payment processing
466
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
465
+        // Send info to the gateway for payment processing
466
+        do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
467 467
 
468
-		// Backwards compatibility.
469
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
468
+        // Backwards compatibility.
469
+        wpinv_send_to_gateway( $submission_gateway, $invoice );
470 470
 
471
-	}
471
+    }
472 472
 
473
-	/**
474
-	 * Marks the invoice as paid in case the checkout is free.
475
-	 *
476
-	 * @param WPInv_Invoice $invoice
477
-	 */
478
-	protected function process_free_payment( $invoice ) {
473
+    /**
474
+     * Marks the invoice as paid in case the checkout is free.
475
+     *
476
+     * @param WPInv_Invoice $invoice
477
+     */
478
+    protected function process_free_payment( $invoice ) {
479 479
 
480
-		$invoice->set_gateway( 'none' );
481
-		$invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
482
-		$invoice->mark_paid();
483
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
480
+        $invoice->set_gateway( 'none' );
481
+        $invoice->add_note( __( "This is a free invoice and won't be sent to the payment gateway", 'invoicing' ), false, false, true );
482
+        $invoice->mark_paid();
483
+        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
484 484
 
485
-	}
485
+    }
486 486
 
487
-	/**
487
+    /**
488 488
      * Sends a redrect response to payment details.
489 489
      *
490 490
      */
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 1 patch
Indentation   +57 added lines, -57 removed lines patch added patch discarded remove patch
@@ -12,28 +12,28 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
30
-		$invoice      = $submission->get_invoice();
31
-		$force_prices = array();
32
-
33
-		// Prepare the selected items.
34
-		$selected_items = array();
35
-		if ( ! empty( $data['getpaid-items'] ) ) {
36
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30
+        $invoice      = $submission->get_invoice();
31
+        $force_prices = array();
32
+
33
+        // Prepare the selected items.
34
+        $selected_items = array();
35
+        if ( ! empty( $data['getpaid-items'] ) ) {
36
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
37 37
 
38 38
             if ( is_array( $submission->get_field( 'getpaid-variable-items' ) ) ) {
39 39
                 $selected_prices = $submission->get_field( 'getpaid-variable-items' );
@@ -46,28 +46,28 @@  discard block
 block discarded – undo
46 46
                 );
47 47
             }
48 48
 
49
-			if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) {
50
-				foreach ( $invoice->get_items() as $invoice_item ) {
49
+            if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) {
50
+                foreach ( $invoice->get_items() as $invoice_item ) {
51 51
                     if ( ! $invoice_item->has_variable_pricing() && isset( $selected_items[ $invoice_item->get_id() ] ) ) {
52 52
                         $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity();
53 53
                         $selected_items[ $invoice_item->get_id() ]['price']    = $invoice_item->get_price();
54 54
 
55 55
                         $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price();
56 56
                     }
57
-				}
58
-			}
59
-		}
57
+                }
58
+            }
59
+        }
60 60
 
61
-		// (Maybe) set form items.
62
-		if ( isset( $data['getpaid-form-items'] ) ) {
61
+        // (Maybe) set form items.
62
+        if ( isset( $data['getpaid-form-items'] ) ) {
63 63
 
64
-			// Confirm items key.
65
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
66
-			if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) {
67
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
68
-			}
64
+            // Confirm items key.
65
+            $form_items = wpinv_clean( $data['getpaid-form-items'] );
66
+            if ( ! isset( $data['getpaid-form-items-key'] ) || md5( NONCE_KEY . AUTH_KEY . $form_items ) !== $data['getpaid-form-items-key'] ) {
67
+                throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
68
+            }
69 69
 
70
-			$items    = array();
70
+            $items    = array();
71 71
             $item_ids = array();
72 72
 
73 73
             foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
@@ -101,25 +101,25 @@  discard block
 block discarded – undo
101 101
                         $items[]    = $item;
102 102
                     }
103 103
                 }
104
-			}
104
+            }
105 105
 
106 106
             $payment_form->set_items( $items );
107
-		}
108
-
109
-		// Process each individual item.
110
-		foreach ( $payment_form->get_items() as $item ) {
111
-			$this->process_item( $item, $selected_items, $submission );
112
-		}
113
-	}
114
-
115
-	/**
116
-	 * Process a single item.
117
-	 *
118
-	 * @param GetPaid_Form_Item $item
119
-	 * @param array $selected_items
120
-	 * @param GetPaid_Payment_Form_Submission $submission
121
-	 */
122
-	public function process_item( $item, $selected_items, $submission ) {
107
+        }
108
+
109
+        // Process each individual item.
110
+        foreach ( $payment_form->get_items() as $item ) {
111
+            $this->process_item( $item, $selected_items, $submission );
112
+        }
113
+    }
114
+
115
+    /**
116
+     * Process a single item.
117
+     *
118
+     * @param GetPaid_Form_Item $item
119
+     * @param array $selected_items
120
+     * @param GetPaid_Payment_Form_Submission $submission
121
+     */
122
+    public function process_item( $item, $selected_items, $submission ) {
123 123
 
124 124
         if ( $item->has_variable_pricing() ) {
125 125
 
@@ -165,7 +165,7 @@  discard block
 block discarded – undo
165 165
                 }
166 166
             }
167 167
         } else {
168
-		    // Abort if this is an optional item and it has not been selected.
168
+            // Abort if this is an optional item and it has not been selected.
169 169
             if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
170 170
                 return;
171 171
             }
@@ -191,11 +191,11 @@  discard block
 block discarded – undo
191 191
             }
192 192
         }
193 193
 
194
-		if ( 0 == $item->get_quantity() ) {
195
-			return;
196
-		}
194
+        if ( 0 == $item->get_quantity() ) {
195
+            return;
196
+        }
197 197
 
198
-		// Save the item.
199
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
200
-	}
198
+        // Save the item.
199
+        $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
200
+    }
201 201
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 1 patch
Indentation   +868 added lines, -868 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,197 +10,197 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal' => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount' => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'     => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'    => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-		'shipping' => array(
54
-			'initial'   => 0,
55
-			'recurring' => 0,
56
-		),
57
-
58
-	);
59
-
60
-	/**
61
-	 * Sets the associated payment form.
62
-	 *
63
-	 * @var GetPaid_Payment_Form
64
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal' => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount' => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'     => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'    => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+        'shipping' => array(
54
+            'initial'   => 0,
55
+            'recurring' => 0,
56
+        ),
57
+
58
+    );
59
+
60
+    /**
61
+     * Sets the associated payment form.
62
+     *
63
+     * @var GetPaid_Payment_Form
64
+     */
65 65
     protected $payment_form = null;
66 66
 
67 67
     /**
68
-	 * The country for the submission.
69
-	 *
70
-	 * @var string
71
-	 */
72
-	public $country = null;
73
-
74
-    /**
75
-	 * The state for the submission.
76
-	 *
77
-	 * @since 1.0.19
78
-	 * @var string
79
-	 */
80
-	public $state = null;
81
-
82
-	/**
83
-	 * The invoice associated with the submission.
84
-	 *
85
-	 * @var WPInv_Invoice
86
-	 */
87
-	protected $invoice = null;
88
-
89
-	/**
90
-	 * The recurring item for the submission.
91
-	 *
92
-	 * @var int
93
-	 */
94
-	public $has_recurring = 0;
95
-
96
-	/**
97
-	 * An array of fees for the submission.
98
-	 *
99
-	 * @var array
100
-	 */
101
-	protected $fees = array();
102
-
103
-	/**
104
-	 * An array of discounts for the submission.
105
-	 *
106
-	 * @var array
107
-	 */
108
-	protected $discounts = array();
109
-
110
-	/**
111
-	 * An array of taxes for the submission.
112
-	 *
113
-	 * @var array
114
-	 */
115
-	protected $taxes = array();
116
-
117
-	/**
118
-	 * An array of items for the submission.
119
-	 *
120
-	 * @var GetPaid_Form_Item[]
121
-	 */
122
-	protected $items = array();
123
-
124
-	/**
125
-	 * The last error.
126
-	 *
127
-	 * @var string
128
-	 */
129
-	public $last_error = null;
130
-
131
-	/**
132
-	 * The last error code.
133
-	 *
134
-	 * @var string
135
-	 */
136
-	public $last_error_code = null;
137
-
138
-    /**
139
-	 * Class constructor.
140
-	 *
141
-	 */
142
-	public function __construct() {
143
-
144
-		// Set the state and country to the default state and country.
145
-		$this->country = wpinv_default_billing_country();
146
-		$this->state   = wpinv_get_default_state();
147
-
148
-		// Do we have an actual submission?
149
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
-			$this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) );
151
-		}
152
-	}
153
-
154
-	/**
155
-	 * Loads submission data.
156
-	 *
157
-	 * @param array $data
158
-	 */
159
-	public function load_data( $data ) {
160
-
161
-		// Allow plugins to filter the data.
162
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
163
-
164
-		// Cache it...
165
-		$this->data = $data;
166
-
167
-		// Then generate a unique id from the data.
168
-		$this->id   = md5( wp_json_encode( $data ) );
169
-
170
-		// Finally, process the submission.
171
-		try {
172
-
173
-			// Each process is passed an instance of the class (with reference)
174
-			// and should throw an Exception whenever it encounters one.
175
-			$processors = apply_filters(
176
-				'getpaid_payment_form_submission_processors',
177
-				array(
178
-					array( $this, 'process_payment_form' ),
179
-					array( $this, 'process_invoice' ),
180
-					array( $this, 'process_fees' ),
181
-					array( $this, 'process_items' ),
182
-					array( $this, 'process_discount' ),
183
-					array( $this, 'process_taxes' ),
184
-				),
185
-				$this
186
-			);
187
-
188
-			foreach ( $processors as $processor ) {
189
-				call_user_func_array( $processor, array( &$this ) );
190
-			}
191
-		} catch ( GetPaid_Payment_Exception $e ) {
192
-			$this->last_error      = $e->getMessage();
193
-			$this->last_error_code = $e->getErrorCode();
194
-		} catch ( Exception $e ) {
195
-			$this->last_error      = $e->getMessage();
196
-			$this->last_error_code = $e->getCode();
197
-		}
198
-
199
-		// Fired when we are done processing a submission.
200
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
201
-	}
202
-
203
-	/*
68
+     * The country for the submission.
69
+     *
70
+     * @var string
71
+     */
72
+    public $country = null;
73
+
74
+    /**
75
+     * The state for the submission.
76
+     *
77
+     * @since 1.0.19
78
+     * @var string
79
+     */
80
+    public $state = null;
81
+
82
+    /**
83
+     * The invoice associated with the submission.
84
+     *
85
+     * @var WPInv_Invoice
86
+     */
87
+    protected $invoice = null;
88
+
89
+    /**
90
+     * The recurring item for the submission.
91
+     *
92
+     * @var int
93
+     */
94
+    public $has_recurring = 0;
95
+
96
+    /**
97
+     * An array of fees for the submission.
98
+     *
99
+     * @var array
100
+     */
101
+    protected $fees = array();
102
+
103
+    /**
104
+     * An array of discounts for the submission.
105
+     *
106
+     * @var array
107
+     */
108
+    protected $discounts = array();
109
+
110
+    /**
111
+     * An array of taxes for the submission.
112
+     *
113
+     * @var array
114
+     */
115
+    protected $taxes = array();
116
+
117
+    /**
118
+     * An array of items for the submission.
119
+     *
120
+     * @var GetPaid_Form_Item[]
121
+     */
122
+    protected $items = array();
123
+
124
+    /**
125
+     * The last error.
126
+     *
127
+     * @var string
128
+     */
129
+    public $last_error = null;
130
+
131
+    /**
132
+     * The last error code.
133
+     *
134
+     * @var string
135
+     */
136
+    public $last_error_code = null;
137
+
138
+    /**
139
+     * Class constructor.
140
+     *
141
+     */
142
+    public function __construct() {
143
+
144
+        // Set the state and country to the default state and country.
145
+        $this->country = wpinv_default_billing_country();
146
+        $this->state   = wpinv_get_default_state();
147
+
148
+        // Do we have an actual submission?
149
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
150
+            $this->load_data( wp_kses_post_deep( wp_unslash( $_POST ) ) );
151
+        }
152
+    }
153
+
154
+    /**
155
+     * Loads submission data.
156
+     *
157
+     * @param array $data
158
+     */
159
+    public function load_data( $data ) {
160
+
161
+        // Allow plugins to filter the data.
162
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
163
+
164
+        // Cache it...
165
+        $this->data = $data;
166
+
167
+        // Then generate a unique id from the data.
168
+        $this->id   = md5( wp_json_encode( $data ) );
169
+
170
+        // Finally, process the submission.
171
+        try {
172
+
173
+            // Each process is passed an instance of the class (with reference)
174
+            // and should throw an Exception whenever it encounters one.
175
+            $processors = apply_filters(
176
+                'getpaid_payment_form_submission_processors',
177
+                array(
178
+                    array( $this, 'process_payment_form' ),
179
+                    array( $this, 'process_invoice' ),
180
+                    array( $this, 'process_fees' ),
181
+                    array( $this, 'process_items' ),
182
+                    array( $this, 'process_discount' ),
183
+                    array( $this, 'process_taxes' ),
184
+                ),
185
+                $this
186
+            );
187
+
188
+            foreach ( $processors as $processor ) {
189
+                call_user_func_array( $processor, array( &$this ) );
190
+            }
191
+        } catch ( GetPaid_Payment_Exception $e ) {
192
+            $this->last_error      = $e->getMessage();
193
+            $this->last_error_code = $e->getErrorCode();
194
+        } catch ( Exception $e ) {
195
+            $this->last_error      = $e->getMessage();
196
+            $this->last_error_code = $e->getCode();
197
+        }
198
+
199
+        // Fired when we are done processing a submission.
200
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
201
+    }
202
+
203
+    /*
204 204
 	|--------------------------------------------------------------------------
205 205
 	| Payment Forms.
206 206
 	|--------------------------------------------------------------------------
@@ -209,39 +209,39 @@  discard block
 block discarded – undo
209 209
 	| submission has an active payment form etc.
210 210
     */
211 211
 
212
-	/**
213
-	 * Prepares the submission's payment form.
214
-	 *
215
-	 * @since 1.0.19
216
-	 */
217
-	public function process_payment_form() {
212
+    /**
213
+     * Prepares the submission's payment form.
214
+     *
215
+     * @since 1.0.19
216
+     */
217
+    public function process_payment_form() {
218 218
 
219
-		// Every submission needs an active payment form.
220
-		if ( empty( $this->data['form_id'] ) ) {
221
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
222
-		}
219
+        // Every submission needs an active payment form.
220
+        if ( empty( $this->data['form_id'] ) ) {
221
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
222
+        }
223 223
 
224
-		// Fetch the payment form.
225
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
224
+        // Fetch the payment form.
225
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
226 226
 
227
-		if ( ! $this->payment_form->is_active() ) {
228
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
229
-		}
227
+        if ( ! $this->payment_form->is_active() ) {
228
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
229
+        }
230 230
 
231
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
232
-	}
231
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
232
+    }
233 233
 
234 234
     /**
235
-	 * Returns the payment form.
236
-	 *
237
-	 * @since 1.0.19
238
-	 * @return GetPaid_Payment_Form
239
-	 */
240
-	public function get_payment_form() {
241
-		return $this->payment_form;
242
-	}
235
+     * Returns the payment form.
236
+     *
237
+     * @since 1.0.19
238
+     * @return GetPaid_Payment_Form
239
+     */
240
+    public function get_payment_form() {
241
+        return $this->payment_form;
242
+    }
243 243
 
244
-	/*
244
+    /*
245 245
 	|--------------------------------------------------------------------------
246 246
 	| Invoices.
247 247
 	|--------------------------------------------------------------------------
@@ -250,95 +250,95 @@  discard block
 block discarded – undo
250 250
 	| might be for an existing invoice.
251 251
 	*/
252 252
 
253
-	/**
254
-	 * Prepares the submission's invoice.
255
-	 *
256
-	 * @since 1.0.19
257
-	 */
258
-	public function process_invoice() {
259
-
260
-		// Abort if there is no invoice.
261
-		if ( empty( $this->data['invoice_id'] ) ) {
262
-
263
-			// Check if we are resuming a payment.
264
-			if ( empty( $this->data['maybe_use_invoice'] ) ) {
265
-				return;
266
-			}
267
-
268
-			$invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] );
269
-			if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) {
270
-				return;
271
-			}
272
-		}
273
-
274
-		// If the submission is for an existing invoice, ensure that it exists
275
-		// and that it is not paid for.
276
-		if ( empty( $invoice ) ) {
277
-			$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
278
-		}
253
+    /**
254
+     * Prepares the submission's invoice.
255
+     *
256
+     * @since 1.0.19
257
+     */
258
+    public function process_invoice() {
259
+
260
+        // Abort if there is no invoice.
261
+        if ( empty( $this->data['invoice_id'] ) ) {
262
+
263
+            // Check if we are resuming a payment.
264
+            if ( empty( $this->data['maybe_use_invoice'] ) ) {
265
+                return;
266
+            }
267
+
268
+            $invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] );
269
+            if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) {
270
+                return;
271
+            }
272
+        }
273
+
274
+        // If the submission is for an existing invoice, ensure that it exists
275
+        // and that it is not paid for.
276
+        if ( empty( $invoice ) ) {
277
+            $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
278
+        }
279 279
 
280 280
         if ( empty( $invoice ) ) {
281
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
282
-		}
283
-
284
-		if ( $invoice->is_paid() ) {
285
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
286
-		}
287
-
288
-		$this->payment_form->invoice = $invoice;
289
-		if ( ! $this->payment_form->is_default() ) {
290
-
291
-			$items    = array();
292
-			$item_ids = array();
293
-
294
-			foreach ( $invoice->get_items() as $item ) {
295
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
296
-					$item_ids[] = $item->get_id();
297
-					$items[]    = $item;
298
-				}
299
-			}
300
-
301
-			foreach ( $this->payment_form->get_items() as $item ) {
302
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
303
-					$item_ids[] = $item->get_id();
304
-					$items[]    = $item;
305
-				}
306
-			}
307
-
308
-			$this->payment_form->set_items( $items );
309
-
310
-		} else {
311
-			$this->payment_form->set_items( $invoice->get_items() );
312
-		}
313
-
314
-		$this->country = $invoice->get_country();
315
-		$this->state   = $invoice->get_state();
316
-		$this->invoice = $invoice;
317
-
318
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
319
-	}
320
-
321
-	/**
322
-	 * Returns the associated invoice.
323
-	 *
324
-	 * @since 1.0.19
325
-	 * @return WPInv_Invoice
326
-	 */
327
-	public function get_invoice() {
328
-		return $this->invoice;
329
-	}
330
-
331
-	/**
332
-	 * Checks whether there is an invoice associated with this submission.
333
-	 *
334
-	 * @since 1.0.19
335
-	 * @return bool
336
-	 */
337
-	public function has_invoice() {
338
-		return ! empty( $this->invoice );
339
-	}
340
-
341
-	/*
281
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
282
+        }
283
+
284
+        if ( $invoice->is_paid() ) {
285
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
286
+        }
287
+
288
+        $this->payment_form->invoice = $invoice;
289
+        if ( ! $this->payment_form->is_default() ) {
290
+
291
+            $items    = array();
292
+            $item_ids = array();
293
+
294
+            foreach ( $invoice->get_items() as $item ) {
295
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
296
+                    $item_ids[] = $item->get_id();
297
+                    $items[]    = $item;
298
+                }
299
+            }
300
+
301
+            foreach ( $this->payment_form->get_items() as $item ) {
302
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
303
+                    $item_ids[] = $item->get_id();
304
+                    $items[]    = $item;
305
+                }
306
+            }
307
+
308
+            $this->payment_form->set_items( $items );
309
+
310
+        } else {
311
+            $this->payment_form->set_items( $invoice->get_items() );
312
+        }
313
+
314
+        $this->country = $invoice->get_country();
315
+        $this->state   = $invoice->get_state();
316
+        $this->invoice = $invoice;
317
+
318
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
319
+    }
320
+
321
+    /**
322
+     * Returns the associated invoice.
323
+     *
324
+     * @since 1.0.19
325
+     * @return WPInv_Invoice
326
+     */
327
+    public function get_invoice() {
328
+        return $this->invoice;
329
+    }
330
+
331
+    /**
332
+     * Checks whether there is an invoice associated with this submission.
333
+     *
334
+     * @since 1.0.19
335
+     * @return bool
336
+     */
337
+    public function has_invoice() {
338
+        return ! empty( $this->invoice );
339
+    }
340
+
341
+    /*
342 342
 	|--------------------------------------------------------------------------
343 343
 	| Items.
344 344
 	|--------------------------------------------------------------------------
@@ -347,127 +347,127 @@  discard block
 block discarded – undo
347 347
 	| recurring item. But can have an unlimited number of non-recurring items.
348 348
 	*/
349 349
 
350
-	/**
351
-	 * Prepares the submission's items.
352
-	 *
353
-	 * @since 1.0.19
354
-	 */
355
-	public function process_items() {
356
-
357
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
358
-
359
-		foreach ( $processor->items as $item ) {
360
-			$this->add_item( $item );
361
-		}
362
-
363
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
364
-	}
365
-
366
-	/**
367
-	 * Adds an item to the submission.
368
-	 *
369
-	 * @since 1.0.19
370
-	 * @param GetPaid_Form_Item $item
371
-	 */
372
-	public function add_item( $item ) {
373
-
374
-		// Make sure that it is available for purchase.
375
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
376
-			return;
377
-		}
378
-
379
-		// Each submission can only contain one recurring item.
380
-		if ( $item->is_recurring() ) {
381
-			$this->has_recurring = $item->get_id();
382
-		}
383
-
384
-		// Update the items and totals.
385
-		$this->items[ $item->get_id() ]         = $item;
386
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
387
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
388
-	}
389
-
390
-	/**
391
-	 * Removes a specific item.
392
-	 *
393
-	 * You should not call this method after the discounts and taxes
394
-	 * have been calculated.
395
-	 *
396
-	 * @since 1.0.19
397
-	 */
398
-	public function remove_item( $item_id ) {
399
-
400
-		if ( isset( $this->items[ $item_id ] ) ) {
401
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
402
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
403
-
404
-			if ( $this->items[ $item_id ]->is_recurring() ) {
405
-				$this->has_recurring = 0;
406
-			}
407
-
408
-			unset( $this->items[ $item_id ] );
409
-		}
410
-	}
411
-
412
-	/**
413
-	 * Returns the subtotal.
414
-	 *
415
-	 * @since 1.0.19
416
-	 */
417
-	public function get_subtotal() {
418
-
419
-		if ( wpinv_prices_include_tax() ) {
420
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
421
-		}
422
-
423
-		return $this->totals['subtotal']['initial'];
424
-	}
425
-
426
-	/**
427
-	 * Returns the recurring subtotal.
428
-	 *
429
-	 * @since 1.0.19
430
-	 */
431
-	public function get_recurring_subtotal() {
432
-
433
-		if ( wpinv_prices_include_tax() ) {
434
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
435
-		}
436
-
437
-		return $this->totals['subtotal']['recurring'];
438
-	}
439
-
440
-	/**
441
-	 * Returns all items.
442
-	 *
443
-	 * @since 1.0.19
444
-	 * @return GetPaid_Form_Item[]
445
-	 */
446
-	public function get_items() {
447
-		return $this->items;
448
-	}
449
-
450
-	/**
451
-	 * Checks if there's a single subscription group in the submission.
452
-	 *
453
-	 * @since 2.3.0
454
-	 * @return bool
455
-	 */
456
-	public function has_subscription_group() {
457
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
458
-	}
459
-
460
-	/**
461
-	 * Checks if there are multipe subscription groups in the submission.
462
-	 *
463
-	 * @since 2.3.0
464
-	 * @return bool
465
-	 */
466
-	public function has_multiple_subscription_groups() {
467
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
468
-	}
469
-
470
-	/*
350
+    /**
351
+     * Prepares the submission's items.
352
+     *
353
+     * @since 1.0.19
354
+     */
355
+    public function process_items() {
356
+
357
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
358
+
359
+        foreach ( $processor->items as $item ) {
360
+            $this->add_item( $item );
361
+        }
362
+
363
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
364
+    }
365
+
366
+    /**
367
+     * Adds an item to the submission.
368
+     *
369
+     * @since 1.0.19
370
+     * @param GetPaid_Form_Item $item
371
+     */
372
+    public function add_item( $item ) {
373
+
374
+        // Make sure that it is available for purchase.
375
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
376
+            return;
377
+        }
378
+
379
+        // Each submission can only contain one recurring item.
380
+        if ( $item->is_recurring() ) {
381
+            $this->has_recurring = $item->get_id();
382
+        }
383
+
384
+        // Update the items and totals.
385
+        $this->items[ $item->get_id() ]         = $item;
386
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
387
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
388
+    }
389
+
390
+    /**
391
+     * Removes a specific item.
392
+     *
393
+     * You should not call this method after the discounts and taxes
394
+     * have been calculated.
395
+     *
396
+     * @since 1.0.19
397
+     */
398
+    public function remove_item( $item_id ) {
399
+
400
+        if ( isset( $this->items[ $item_id ] ) ) {
401
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
402
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
403
+
404
+            if ( $this->items[ $item_id ]->is_recurring() ) {
405
+                $this->has_recurring = 0;
406
+            }
407
+
408
+            unset( $this->items[ $item_id ] );
409
+        }
410
+    }
411
+
412
+    /**
413
+     * Returns the subtotal.
414
+     *
415
+     * @since 1.0.19
416
+     */
417
+    public function get_subtotal() {
418
+
419
+        if ( wpinv_prices_include_tax() ) {
420
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
421
+        }
422
+
423
+        return $this->totals['subtotal']['initial'];
424
+    }
425
+
426
+    /**
427
+     * Returns the recurring subtotal.
428
+     *
429
+     * @since 1.0.19
430
+     */
431
+    public function get_recurring_subtotal() {
432
+
433
+        if ( wpinv_prices_include_tax() ) {
434
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
435
+        }
436
+
437
+        return $this->totals['subtotal']['recurring'];
438
+    }
439
+
440
+    /**
441
+     * Returns all items.
442
+     *
443
+     * @since 1.0.19
444
+     * @return GetPaid_Form_Item[]
445
+     */
446
+    public function get_items() {
447
+        return $this->items;
448
+    }
449
+
450
+    /**
451
+     * Checks if there's a single subscription group in the submission.
452
+     *
453
+     * @since 2.3.0
454
+     * @return bool
455
+     */
456
+    public function has_subscription_group() {
457
+        return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
458
+    }
459
+
460
+    /**
461
+     * Checks if there are multipe subscription groups in the submission.
462
+     *
463
+     * @since 2.3.0
464
+     * @return bool
465
+     */
466
+    public function has_multiple_subscription_groups() {
467
+        return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
468
+    }
469
+
470
+    /*
471 471
 	|--------------------------------------------------------------------------
472 472
 	| Taxes
473 473
 	|--------------------------------------------------------------------------
@@ -476,125 +476,125 @@  discard block
 block discarded – undo
476 476
 	| or only one-time.
477 477
     */
478 478
 
479
-	/**
480
-	 * Prepares the submission's taxes.
481
-	 *
482
-	 * @since 1.0.19
483
-	 */
484
-	public function process_taxes() {
485
-
486
-		// Abort if we're not using taxes.
487
-		if ( ! $this->use_taxes() ) {
488
-			return;
489
-		}
490
-
491
-		// If a custom country && state has been passed in, use it to calculate taxes.
492
-		$country = $this->get_field( 'wpinv_country', 'billing' );
493
-		if ( ! empty( $country ) ) {
494
-			$this->country = $country;
495
-		}
496
-
497
-		$state = $this->get_field( 'wpinv_state', 'billing' );
498
-		if ( ! empty( $state ) ) {
499
-			$this->state = $state;
500
-		}
501
-
502
-		// Confirm if the provided country and the ip country are similar.
503
-		$address_confirmed = $this->get_field( 'confirm-address' );
504
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
505
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
506
-		}
507
-
508
-		// Abort if the country is not taxable.
509
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
510
-			return;
511
-		}
512
-
513
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
514
-
515
-		foreach ( $processor->taxes as $tax ) {
516
-			$this->add_tax( $tax );
517
-		}
518
-
519
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
520
-	}
521
-
522
-	/**
523
-	 * Adds a tax to the submission.
524
-	 *
525
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
526
-	 * @since 1.0.19
527
-	 */
528
-	public function add_tax( $tax ) {
529
-
530
-		if ( wpinv_round_tax_per_tax_rate() ) {
531
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
532
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
533
-		}
534
-
535
-		$this->taxes[ $tax['name'] ]         = $tax;
536
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
537
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
538
-	}
539
-
540
-	/**
541
-	 * Removes a specific tax.
542
-	 *
543
-	 * @since 1.0.19
544
-	 */
545
-	public function remove_tax( $tax_name ) {
546
-
547
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
548
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
549
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
550
-			unset( $this->taxes[ $tax_name ] );
551
-		}
552
-	}
553
-
554
-	/**
555
-	 * Whether or not we'll use taxes for the submission.
556
-	 *
557
-	 * @since 1.0.19
558
-	 */
559
-	public function use_taxes() {
560
-
561
-		$use_taxes = wpinv_use_taxes();
562
-
563
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
564
-			$use_taxes = false;
565
-		}
566
-
567
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
568
-	}
569
-
570
-	/**
571
-	 * Returns the tax.
572
-	 *
573
-	 * @since 1.0.19
574
-	 */
575
-	public function get_tax() {
576
-		return $this->totals['taxes']['initial'];
577
-	}
578
-
579
-	/**
580
-	 * Returns the recurring tax.
581
-	 *
582
-	 * @since 1.0.19
583
-	 */
584
-	public function get_recurring_tax() {
585
-		return $this->totals['taxes']['recurring'];
586
-	}
587
-
588
-	/**
589
-	 * Returns all taxes.
590
-	 *
591
-	 * @since 1.0.19
592
-	 */
593
-	public function get_taxes() {
594
-		return $this->taxes;
595
-	}
596
-
597
-	/*
479
+    /**
480
+     * Prepares the submission's taxes.
481
+     *
482
+     * @since 1.0.19
483
+     */
484
+    public function process_taxes() {
485
+
486
+        // Abort if we're not using taxes.
487
+        if ( ! $this->use_taxes() ) {
488
+            return;
489
+        }
490
+
491
+        // If a custom country && state has been passed in, use it to calculate taxes.
492
+        $country = $this->get_field( 'wpinv_country', 'billing' );
493
+        if ( ! empty( $country ) ) {
494
+            $this->country = $country;
495
+        }
496
+
497
+        $state = $this->get_field( 'wpinv_state', 'billing' );
498
+        if ( ! empty( $state ) ) {
499
+            $this->state = $state;
500
+        }
501
+
502
+        // Confirm if the provided country and the ip country are similar.
503
+        $address_confirmed = $this->get_field( 'confirm-address' );
504
+        if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
505
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
506
+        }
507
+
508
+        // Abort if the country is not taxable.
509
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
510
+            return;
511
+        }
512
+
513
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
514
+
515
+        foreach ( $processor->taxes as $tax ) {
516
+            $this->add_tax( $tax );
517
+        }
518
+
519
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
520
+    }
521
+
522
+    /**
523
+     * Adds a tax to the submission.
524
+     *
525
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
526
+     * @since 1.0.19
527
+     */
528
+    public function add_tax( $tax ) {
529
+
530
+        if ( wpinv_round_tax_per_tax_rate() ) {
531
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
532
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
533
+        }
534
+
535
+        $this->taxes[ $tax['name'] ]         = $tax;
536
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
537
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
538
+    }
539
+
540
+    /**
541
+     * Removes a specific tax.
542
+     *
543
+     * @since 1.0.19
544
+     */
545
+    public function remove_tax( $tax_name ) {
546
+
547
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
548
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
549
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
550
+            unset( $this->taxes[ $tax_name ] );
551
+        }
552
+    }
553
+
554
+    /**
555
+     * Whether or not we'll use taxes for the submission.
556
+     *
557
+     * @since 1.0.19
558
+     */
559
+    public function use_taxes() {
560
+
561
+        $use_taxes = wpinv_use_taxes();
562
+
563
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
564
+            $use_taxes = false;
565
+        }
566
+
567
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
568
+    }
569
+
570
+    /**
571
+     * Returns the tax.
572
+     *
573
+     * @since 1.0.19
574
+     */
575
+    public function get_tax() {
576
+        return $this->totals['taxes']['initial'];
577
+    }
578
+
579
+    /**
580
+     * Returns the recurring tax.
581
+     *
582
+     * @since 1.0.19
583
+     */
584
+    public function get_recurring_tax() {
585
+        return $this->totals['taxes']['recurring'];
586
+    }
587
+
588
+    /**
589
+     * Returns all taxes.
590
+     *
591
+     * @since 1.0.19
592
+     */
593
+    public function get_taxes() {
594
+        return $this->taxes;
595
+    }
596
+
597
+    /*
598 598
 	|--------------------------------------------------------------------------
599 599
 	| Discounts
600 600
 	|--------------------------------------------------------------------------
@@ -603,98 +603,98 @@  discard block
 block discarded – undo
603 603
 	| or only one-time. They also do not have to come from a discount code.
604 604
     */
605 605
 
606
-	/**
607
-	 * Prepares the submission's discount.
608
-	 *
609
-	 * @since 1.0.19
610
-	 */
611
-	public function process_discount() {
612
-
613
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
615
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
616
-
617
-		foreach ( $processor->discounts as $discount ) {
618
-			$this->add_discount( $discount );
619
-		}
620
-
621
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
622
-	}
623
-
624
-	/**
625
-	 * Adds a discount to the submission.
626
-	 *
627
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
628
-	 * @since 1.0.19
629
-	 */
630
-	public function add_discount( $discount ) {
631
-		$this->discounts[ $discount['name'] ]   = $discount;
632
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
633
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
634
-	}
635
-
636
-	/**
637
-	 * Removes a discount from the submission.
638
-	 *
639
-	 * @since 1.0.19
640
-	 */
641
-	public function remove_discount( $name ) {
642
-
643
-		if ( isset( $this->discounts[ $name ] ) ) {
644
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
645
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
646
-			unset( $this->discounts[ $name ] );
647
-		}
648
-	}
649
-
650
-	/**
651
-	 * Checks whether there is a discount code associated with this submission.
652
-	 *
653
-	 * @since 1.0.19
654
-	 * @return bool
655
-	 */
656
-	public function has_discount_code() {
657
-		return ! empty( $this->discounts['discount_code'] );
658
-	}
659
-
660
-	/**
661
-	 * Returns the discount code.
662
-	 *
663
-	 * @since 1.0.19
664
-	 * @return string
665
-	 */
666
-	public function get_discount_code() {
667
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
668
-	}
669
-
670
-	/**
671
-	 * Returns the discount.
672
-	 *
673
-	 * @since 1.0.19
674
-	 */
675
-	public function get_discount() {
676
-		return $this->totals['discount']['initial'];
677
-	}
678
-
679
-	/**
680
-	 * Returns the recurring discount.
681
-	 *
682
-	 * @since 1.0.19
683
-	 */
684
-	public function get_recurring_discount() {
685
-		return $this->totals['discount']['recurring'];
686
-	}
687
-
688
-	/**
689
-	 * Returns all discounts.
690
-	 *
691
-	 * @since 1.0.19
692
-	 */
693
-	public function get_discounts() {
694
-		return $this->discounts;
695
-	}
696
-
697
-	/*
606
+    /**
607
+     * Prepares the submission's discount.
608
+     *
609
+     * @since 1.0.19
610
+     */
611
+    public function process_discount() {
612
+
613
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
615
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
616
+
617
+        foreach ( $processor->discounts as $discount ) {
618
+            $this->add_discount( $discount );
619
+        }
620
+
621
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
622
+    }
623
+
624
+    /**
625
+     * Adds a discount to the submission.
626
+     *
627
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
628
+     * @since 1.0.19
629
+     */
630
+    public function add_discount( $discount ) {
631
+        $this->discounts[ $discount['name'] ]   = $discount;
632
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
633
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
634
+    }
635
+
636
+    /**
637
+     * Removes a discount from the submission.
638
+     *
639
+     * @since 1.0.19
640
+     */
641
+    public function remove_discount( $name ) {
642
+
643
+        if ( isset( $this->discounts[ $name ] ) ) {
644
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
645
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
646
+            unset( $this->discounts[ $name ] );
647
+        }
648
+    }
649
+
650
+    /**
651
+     * Checks whether there is a discount code associated with this submission.
652
+     *
653
+     * @since 1.0.19
654
+     * @return bool
655
+     */
656
+    public function has_discount_code() {
657
+        return ! empty( $this->discounts['discount_code'] );
658
+    }
659
+
660
+    /**
661
+     * Returns the discount code.
662
+     *
663
+     * @since 1.0.19
664
+     * @return string
665
+     */
666
+    public function get_discount_code() {
667
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
668
+    }
669
+
670
+    /**
671
+     * Returns the discount.
672
+     *
673
+     * @since 1.0.19
674
+     */
675
+    public function get_discount() {
676
+        return $this->totals['discount']['initial'];
677
+    }
678
+
679
+    /**
680
+     * Returns the recurring discount.
681
+     *
682
+     * @since 1.0.19
683
+     */
684
+    public function get_recurring_discount() {
685
+        return $this->totals['discount']['recurring'];
686
+    }
687
+
688
+    /**
689
+     * Returns all discounts.
690
+     *
691
+     * @since 1.0.19
692
+     */
693
+    public function get_discounts() {
694
+        return $this->discounts;
695
+    }
696
+
697
+    /*
698 698
 	|--------------------------------------------------------------------------
699 699
 	| Fees
700 700
 	|--------------------------------------------------------------------------
@@ -704,98 +704,98 @@  discard block
 block discarded – undo
704 704
 	| fees.
705 705
     */
706 706
 
707
-	/**
708
-	 * Prepares the submission's fees.
709
-	 *
710
-	 * @since 1.0.19
711
-	 */
712
-	public function process_fees() {
713
-
714
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
715
-
716
-		foreach ( $fees_processor->fees as $fee ) {
717
-			$this->add_fee( $fee );
718
-		}
719
-
720
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
721
-	}
722
-
723
-	/**
724
-	 * Adds a fee to the submission.
725
-	 *
726
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
727
-	 * @since 1.0.19
728
-	 */
729
-	public function add_fee( $fee ) {
730
-
731
-		if ( $fee['name'] == 'shipping' ) {
732
-			$this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
733
-			$this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
734
-			return;
735
-		}
736
-
737
-		$this->fees[ $fee['name'] ]         = $fee;
738
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
739
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
740
-	}
741
-
742
-	/**
743
-	 * Removes a fee from the submission.
744
-	 *
745
-	 * @since 1.0.19
746
-	 */
747
-	public function remove_fee( $name ) {
748
-
749
-		if ( isset( $this->fees[ $name ] ) ) {
750
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
751
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
752
-			unset( $this->fees[ $name ] );
753
-		}
754
-
755
-		if ( 'shipping' == $name ) {
756
-			$this->totals['shipping']['initial']   = 0;
757
-			$this->totals['shipping']['recurring'] = 0;
758
-		}
759
-	}
760
-
761
-	/**
762
-	 * Returns the fees.
763
-	 *
764
-	 * @since 1.0.19
765
-	 */
766
-	public function get_fee() {
767
-		return $this->totals['fees']['initial'];
768
-	}
769
-
770
-	/**
771
-	 * Returns the recurring fees.
772
-	 *
773
-	 * @since 1.0.19
774
-	 */
775
-	public function get_recurring_fee() {
776
-		return $this->totals['fees']['recurring'];
777
-	}
778
-
779
-	/**
780
-	 * Returns all fees.
781
-	 *
782
-	 * @since 1.0.19
783
-	 */
784
-	public function get_fees() {
785
-		return $this->fees;
786
-	}
787
-
788
-	/**
789
-	 * Checks if there are any fees for the form.
790
-	 *
791
-	 * @return bool
792
-	 * @since 1.0.19
793
-	 */
794
-	public function has_fees() {
795
-		return count( $this->fees ) !== 0;
796
-	}
797
-
798
-	/*
707
+    /**
708
+     * Prepares the submission's fees.
709
+     *
710
+     * @since 1.0.19
711
+     */
712
+    public function process_fees() {
713
+
714
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
715
+
716
+        foreach ( $fees_processor->fees as $fee ) {
717
+            $this->add_fee( $fee );
718
+        }
719
+
720
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
721
+    }
722
+
723
+    /**
724
+     * Adds a fee to the submission.
725
+     *
726
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
727
+     * @since 1.0.19
728
+     */
729
+    public function add_fee( $fee ) {
730
+
731
+        if ( $fee['name'] == 'shipping' ) {
732
+            $this->totals['shipping']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
733
+            $this->totals['shipping']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
734
+            return;
735
+        }
736
+
737
+        $this->fees[ $fee['name'] ]         = $fee;
738
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
739
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
740
+    }
741
+
742
+    /**
743
+     * Removes a fee from the submission.
744
+     *
745
+     * @since 1.0.19
746
+     */
747
+    public function remove_fee( $name ) {
748
+
749
+        if ( isset( $this->fees[ $name ] ) ) {
750
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
751
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
752
+            unset( $this->fees[ $name ] );
753
+        }
754
+
755
+        if ( 'shipping' == $name ) {
756
+            $this->totals['shipping']['initial']   = 0;
757
+            $this->totals['shipping']['recurring'] = 0;
758
+        }
759
+    }
760
+
761
+    /**
762
+     * Returns the fees.
763
+     *
764
+     * @since 1.0.19
765
+     */
766
+    public function get_fee() {
767
+        return $this->totals['fees']['initial'];
768
+    }
769
+
770
+    /**
771
+     * Returns the recurring fees.
772
+     *
773
+     * @since 1.0.19
774
+     */
775
+    public function get_recurring_fee() {
776
+        return $this->totals['fees']['recurring'];
777
+    }
778
+
779
+    /**
780
+     * Returns all fees.
781
+     *
782
+     * @since 1.0.19
783
+     */
784
+    public function get_fees() {
785
+        return $this->fees;
786
+    }
787
+
788
+    /**
789
+     * Checks if there are any fees for the form.
790
+     *
791
+     * @return bool
792
+     * @since 1.0.19
793
+     */
794
+    public function has_fees() {
795
+        return count( $this->fees ) !== 0;
796
+    }
797
+
798
+    /*
799 799
 	|--------------------------------------------------------------------------
800 800
 	| MISC
801 801
 	|--------------------------------------------------------------------------
@@ -803,146 +803,146 @@  discard block
 block discarded – undo
803 803
 	| Extra submission functions.
804 804
     */
805 805
 
806
-	/**
807
-	 * Returns the shipping amount.
808
-	 *
809
-	 * @since 1.0.19
810
-	 */
811
-	public function get_shipping() {
812
-		return $this->totals['shipping']['initial'];
813
-	}
814
-
815
-	/**
816
-	 * Returns the recurring shipping.
817
-	 *
818
-	 * @since 1.0.19
819
-	 */
820
-	public function get_recurring_shipping() {
821
-		return $this->totals['shipping']['recurring'];
822
-	}
823
-
824
-	/**
825
-	 * Checks if there are any shipping fees for the form.
826
-	 *
827
-	 * @return bool
828
-	 * @since 1.0.19
829
-	 */
830
-	public function has_shipping() {
831
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
832
-	}
833
-
834
-	/**
835
-	 * Checks if this is the initial fetch.
836
-	 *
837
-	 * @return bool
838
-	 * @since 1.0.19
839
-	 */
840
-	public function is_initial_fetch() {
841
-		return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] );
842
-	}
843
-
844
-	/**
845
-	 * Returns the total amount to collect for this submission.
846
-	 *
847
-	 * @since 1.0.19
848
-	 */
849
-	public function get_total() {
850
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
851
-		return max( $total, 0 );
852
-	}
853
-
854
-	/**
855
-	 * Returns the recurring total amount to collect for this submission.
856
-	 *
857
-	 * @since 1.0.19
858
-	 */
859
-	public function get_recurring_total() {
860
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
861
-		return max( $total, 0 );
862
-	}
863
-
864
-	/**
865
-	 * Whether payment details should be collected for this submission.
866
-	 *
867
-	 * @since 1.0.19
868
-	 */
869
-	public function should_collect_payment_details() {
870
-		$initial   = $this->get_total();
871
-		$recurring = $this->get_recurring_total();
872
-
873
-		if ( $this->has_recurring == 0 ) {
874
-			$recurring = 0;
875
-		}
876
-
877
-		$collect = $initial > 0 || $recurring > 0;
878
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this );
879
-	}
880
-
881
-	/**
882
-	 * Returns the billing email of the user.
883
-	 *
884
-	 * @since 1.0.19
885
-	 */
886
-	public function get_billing_email() {
887
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this );
888
-	}
889
-
890
-	/**
891
-	 * Checks if the submitter has a billing email.
892
-	 *
893
-	 * @since 1.0.19
894
-	 */
895
-	public function has_billing_email() {
896
-		$billing_email = $this->get_billing_email();
897
-		return ! empty( $billing_email ) && is_email( $billing_email );
898
-	}
899
-
900
-	/**
901
-	 * Returns the appropriate currency for the submission.
902
-	 *
903
-	 * @since 1.0.19
904
-	 * @return string
905
-	 */
906
-	public function get_currency() {
907
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
908
-    }
909
-
910
-    /**
911
-	 * Returns the raw submission data.
912
-	 *
913
-	 * @since 1.0.19
914
-	 * @return array
915
-	 */
916
-	public function get_data() {
917
-		return $this->data;
918
-	}
919
-
920
-	/**
921
-	 * Returns a field from the submission data
922
-	 *
923
-	 * @param string $field
924
-	 * @since 1.0.19
925
-	 * @return mixed|null
926
-	 */
927
-	public function get_field( $field, $sub_array_key = null ) {
928
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
929
-	}
930
-
931
-	/**
932
-	 * Checks if a required field is set.
933
-	 *
934
-	 * @since 1.0.19
935
-	 */
936
-	public function is_required_field_set( $field ) {
937
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
938
-	}
939
-
940
-	/**
941
-	 * Formats an amount
942
-	 *
943
-	 * @since 1.0.19
944
-	 */
945
-	public function format_amount( $amount ) {
946
-		return wpinv_price( $amount, $this->get_currency() );
947
-	}
806
+    /**
807
+     * Returns the shipping amount.
808
+     *
809
+     * @since 1.0.19
810
+     */
811
+    public function get_shipping() {
812
+        return $this->totals['shipping']['initial'];
813
+    }
814
+
815
+    /**
816
+     * Returns the recurring shipping.
817
+     *
818
+     * @since 1.0.19
819
+     */
820
+    public function get_recurring_shipping() {
821
+        return $this->totals['shipping']['recurring'];
822
+    }
823
+
824
+    /**
825
+     * Checks if there are any shipping fees for the form.
826
+     *
827
+     * @return bool
828
+     * @since 1.0.19
829
+     */
830
+    public function has_shipping() {
831
+        return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
832
+    }
833
+
834
+    /**
835
+     * Checks if this is the initial fetch.
836
+     *
837
+     * @return bool
838
+     * @since 1.0.19
839
+     */
840
+    public function is_initial_fetch() {
841
+        return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] );
842
+    }
843
+
844
+    /**
845
+     * Returns the total amount to collect for this submission.
846
+     *
847
+     * @since 1.0.19
848
+     */
849
+    public function get_total() {
850
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
851
+        return max( $total, 0 );
852
+    }
853
+
854
+    /**
855
+     * Returns the recurring total amount to collect for this submission.
856
+     *
857
+     * @since 1.0.19
858
+     */
859
+    public function get_recurring_total() {
860
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() + $this->get_recurring_shipping() - $this->get_recurring_discount();
861
+        return max( $total, 0 );
862
+    }
863
+
864
+    /**
865
+     * Whether payment details should be collected for this submission.
866
+     *
867
+     * @since 1.0.19
868
+     */
869
+    public function should_collect_payment_details() {
870
+        $initial   = $this->get_total();
871
+        $recurring = $this->get_recurring_total();
872
+
873
+        if ( $this->has_recurring == 0 ) {
874
+            $recurring = 0;
875
+        }
876
+
877
+        $collect = $initial > 0 || $recurring > 0;
878
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this );
879
+    }
880
+
881
+    /**
882
+     * Returns the billing email of the user.
883
+     *
884
+     * @since 1.0.19
885
+     */
886
+    public function get_billing_email() {
887
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this );
888
+    }
889
+
890
+    /**
891
+     * Checks if the submitter has a billing email.
892
+     *
893
+     * @since 1.0.19
894
+     */
895
+    public function has_billing_email() {
896
+        $billing_email = $this->get_billing_email();
897
+        return ! empty( $billing_email ) && is_email( $billing_email );
898
+    }
899
+
900
+    /**
901
+     * Returns the appropriate currency for the submission.
902
+     *
903
+     * @since 1.0.19
904
+     * @return string
905
+     */
906
+    public function get_currency() {
907
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
908
+    }
909
+
910
+    /**
911
+     * Returns the raw submission data.
912
+     *
913
+     * @since 1.0.19
914
+     * @return array
915
+     */
916
+    public function get_data() {
917
+        return $this->data;
918
+    }
919
+
920
+    /**
921
+     * Returns a field from the submission data
922
+     *
923
+     * @param string $field
924
+     * @since 1.0.19
925
+     * @return mixed|null
926
+     */
927
+    public function get_field( $field, $sub_array_key = null ) {
928
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
929
+    }
930
+
931
+    /**
932
+     * Checks if a required field is set.
933
+     *
934
+     * @since 1.0.19
935
+     */
936
+    public function is_required_field_set( $field ) {
937
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
938
+    }
939
+
940
+    /**
941
+     * Formats an amount
942
+     *
943
+     * @since 1.0.19
944
+     */
945
+    public function format_amount( $amount ) {
946
+        return wpinv_price( $amount, $this->get_currency() );
947
+    }
948 948
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 1 patch
Indentation   +259 added lines, -259 removed lines patch added patch discarded remove patch
@@ -12,293 +12,293 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Refresh_Prices {
14 14
 
15
-	/**
16
-	 * Contains the response for refreshing prices.
17
-	 * @var array
18
-	 */
19
-	public $response = array();
15
+    /**
16
+     * Contains the response for refreshing prices.
17
+     * @var array
18
+     */
19
+    public $response = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$this->response = array(
29
-			'submission_id'                    => $submission->id,
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $this->response = array(
29
+            'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31
-			'has_subscription_group'           => $submission->has_subscription_group(),
32
-			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
31
+            'has_subscription_group'           => $submission->has_subscription_group(),
32
+            'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33 33
             'is_free'                          => ! $submission->should_collect_payment_details(),
34
-		);
35
-
36
-		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
38
-			$this->response['invoice'] = $payment_form->invoice->get_id();
39
-		}
40
-
41
-		$this->add_totals( $submission );
42
-		$this->add_texts( $submission );
43
-		$this->add_items( $submission );
44
-		$this->add_fees( $submission );
45
-		$this->add_discounts( $submission );
46
-		$this->add_taxes( $submission );
47
-		$this->add_gateways( $submission );
48
-		$this->add_data( $submission );
49
-	}
50
-
51
-	/**
52
-	 * Adds totals to a response for submission refresh prices.
53
-	 *
54
-	 * @param GetPaid_Payment_Form_Submission $submission
55
-	 */
56
-	public function add_totals( $submission ) {
57
-
58
-		$this->response = array_merge(
59
-			$this->response,
60
-			array(
61
-
62
-				'totals'      => array(
63
-					'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
64
-					'discount'  => $submission->format_amount( $submission->get_discount() ),
65
-					'fees'      => $submission->format_amount( $submission->get_fee() ),
66
-					'tax'       => $submission->format_amount( $submission->get_tax() ),
67
-					'total'     => $submission->format_amount( $submission->get_total() ),
68
-					'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
69
-				),
70
-
71
-				'recurring'   => array(
72
-					'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
73
-					'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
74
-					'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
75
-					'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
76
-					'total'    => $submission->format_amount( $submission->get_recurring_total() ),
77
-				),
78
-
79
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
80
-				'currency'    => $submission->get_currency(),
81
-
82
-			)
83
-		);
84
-	}
85
-
86
-	/**
87
-	 * Adds texts to a response for submission refresh prices.
88
-	 *
89
-	 * @param GetPaid_Payment_Form_Submission $submission
90
-	 */
91
-	public function add_texts( $submission ) {
92
-
93
-		$payable = $submission->format_amount( $submission->get_total() );
94
-		$groups  = getpaid_get_subscription_groups( $submission );
95
-
96
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
97
-
98
-			$recurring = new WPInv_Item( $submission->has_recurring );
99
-			$period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
100
-			$main_item = reset( $groups );
101
-
102
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
103
-				$payable = "$payable / $period";
104
-			} elseif ( $main_item ) {
105
-
106
-				$main_item = reset( $main_item );
107
-
108
-				// Calculate the next renewal date.
109
-				$_period      = $main_item->get_recurring_period( true );
110
-				$_interval    = $main_item->get_recurring_interval();
111
-
112
-				// If the subscription item has a trial period...
113
-				if ( $main_item->has_free_trial() ) {
114
-					$_period   = $main_item->get_trial_period( true );
115
-					$_interval = $main_item->get_trial_interval();
116
-				}
117
-
118
-				$payable = sprintf(
119
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
120
-					$submission->format_amount( $submission->get_total() ),
121
-					$submission->format_amount( $submission->get_recurring_total() ),
122
-					$period
123
-				);
124
-
125
-				$payable .= sprintf(
126
-					'<small class="text-muted form-text">%s</small>',
127
-					sprintf(
128
-						__( 'First renewal on %s', 'invoicing' ),
129
-						getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
130
-					)
131
-				);
132
-
133
-			} else {
134
-				$payable = sprintf(
135
-					__( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
136
-					$submission->format_amount( $submission->get_total() ),
137
-					$submission->format_amount( $submission->get_recurring_total() ),
138
-					$period
139
-				);
140
-			}
34
+        );
35
+
36
+        $payment_form = $submission->get_payment_form();
37
+        if ( ! empty( $payment_form->invoice ) ) {
38
+            $this->response['invoice'] = $payment_form->invoice->get_id();
39
+        }
40
+
41
+        $this->add_totals( $submission );
42
+        $this->add_texts( $submission );
43
+        $this->add_items( $submission );
44
+        $this->add_fees( $submission );
45
+        $this->add_discounts( $submission );
46
+        $this->add_taxes( $submission );
47
+        $this->add_gateways( $submission );
48
+        $this->add_data( $submission );
49
+    }
50
+
51
+    /**
52
+     * Adds totals to a response for submission refresh prices.
53
+     *
54
+     * @param GetPaid_Payment_Form_Submission $submission
55
+     */
56
+    public function add_totals( $submission ) {
57
+
58
+        $this->response = array_merge(
59
+            $this->response,
60
+            array(
61
+
62
+                'totals'      => array(
63
+                    'subtotal'  => $submission->format_amount( $submission->get_subtotal() ),
64
+                    'discount'  => $submission->format_amount( $submission->get_discount() ),
65
+                    'fees'      => $submission->format_amount( $submission->get_fee() ),
66
+                    'tax'       => $submission->format_amount( $submission->get_tax() ),
67
+                    'total'     => $submission->format_amount( $submission->get_total() ),
68
+                    'raw_total' => html_entity_decode( sanitize_text_field( $submission->format_amount( $submission->get_total() ) ), ENT_QUOTES ),
69
+                ),
70
+
71
+                'recurring'   => array(
72
+                    'subtotal' => $submission->format_amount( $submission->get_recurring_subtotal() ),
73
+                    'discount' => $submission->format_amount( $submission->get_recurring_discount() ),
74
+                    'fees'     => $submission->format_amount( $submission->get_recurring_fee() ),
75
+                    'tax'      => $submission->format_amount( $submission->get_recurring_tax() ),
76
+                    'total'    => $submission->format_amount( $submission->get_recurring_total() ),
77
+                ),
78
+
79
+                'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
80
+                'currency'    => $submission->get_currency(),
81
+
82
+            )
83
+        );
84
+    }
85
+
86
+    /**
87
+     * Adds texts to a response for submission refresh prices.
88
+     *
89
+     * @param GetPaid_Payment_Form_Submission $submission
90
+     */
91
+    public function add_texts( $submission ) {
92
+
93
+        $payable = $submission->format_amount( $submission->get_total() );
94
+        $groups  = getpaid_get_subscription_groups( $submission );
95
+
96
+        if ( $submission->has_recurring && 2 > count( $groups ) ) {
97
+
98
+            $recurring = new WPInv_Item( $submission->has_recurring );
99
+            $period    = getpaid_get_subscription_period_label( $recurring->get_recurring_period( true ), $recurring->get_recurring_interval(), '' );
100
+            $main_item = reset( $groups );
101
+
102
+            if ( $submission->get_total() == $submission->get_recurring_total() ) {
103
+                $payable = "$payable / $period";
104
+            } elseif ( $main_item ) {
105
+
106
+                $main_item = reset( $main_item );
107
+
108
+                // Calculate the next renewal date.
109
+                $_period      = $main_item->get_recurring_period( true );
110
+                $_interval    = $main_item->get_recurring_interval();
111
+
112
+                // If the subscription item has a trial period...
113
+                if ( $main_item->has_free_trial() ) {
114
+                    $_period   = $main_item->get_trial_period( true );
115
+                    $_interval = $main_item->get_trial_interval();
116
+                }
117
+
118
+                $payable = sprintf(
119
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
120
+                    $submission->format_amount( $submission->get_total() ),
121
+                    $submission->format_amount( $submission->get_recurring_total() ),
122
+                    $period
123
+                );
124
+
125
+                $payable .= sprintf(
126
+                    '<small class="text-muted form-text">%s</small>',
127
+                    sprintf(
128
+                        __( 'First renewal on %s', 'invoicing' ),
129
+                        getpaid_format_date( date( 'Y-m-d H:i:s', strtotime( "+$_interval $_period", current_time( 'timestamp' ) ) ) )
130
+                    )
131
+                );
132
+
133
+            } else {
134
+                $payable = sprintf(
135
+                    __( '%1$s (renews at %2$s / %3$s)', 'invoicing' ),
136
+                    $submission->format_amount( $submission->get_total() ),
137
+                    $submission->format_amount( $submission->get_recurring_total() ),
138
+                    $period
139
+                );
140
+            }
141 141
         }
142 142
 
143
-		$texts = array(
144
-			'.getpaid-checkout-total-payable' => $payable,
145
-		);
143
+        $texts = array(
144
+            '.getpaid-checkout-total-payable' => $payable,
145
+        );
146 146
 
147
-		foreach ( $submission->get_items() as $item ) {
147
+        foreach ( $submission->get_items() as $item ) {
148 148
             $item_id = $item->has_variable_pricing() ? $item->get_price_id() : $item->get_id();
149 149
 
150
-			$initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
151
-			$recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
152
-			$texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
153
-			$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
150
+            $initial_price                                         = $submission->format_amount( $item->get_sub_total() - $item->item_discount );
151
+            $recurring_price                                       = $submission->format_amount( $item->get_recurring_sub_total() - $item->recurring_item_discount );
152
+            $texts[ ".item-$item_id .getpaid-form-item-price-desc" ] = getpaid_item_recurring_price_help_text( $item, $submission->get_currency(), $initial_price, $recurring_price );
153
+            $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = sprintf( __( 'Subtotal: %s', 'invoicing' ), $submission->format_amount( $item->get_sub_total() ) );
154 154
 
155
-			if ( $item->get_quantity() == 1 ) {
156
-				$texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
157
-			}
155
+            if ( $item->get_quantity() == 1 ) {
156
+                $texts[ ".item-$item_id .getpaid-mobile-item-subtotal" ] = '';
157
+            }
158 158
         }
159 159
 
160
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
161
-	}
160
+        $this->response = array_merge( $this->response, array( 'texts' => $texts ) );
161
+    }
162 162
 
163
-	/**
164
-	 * Adds items to a response for submission refresh prices.
165
-	 *
166
-	 * @param GetPaid_Payment_Form_Submission $submission
167
-	 */
168
-	public function add_items( $submission ) {
163
+    /**
164
+     * Adds items to a response for submission refresh prices.
165
+     *
166
+     * @param GetPaid_Payment_Form_Submission $submission
167
+     */
168
+    public function add_items( $submission ) {
169 169
 
170
-		// Add items.
171
-		$items          = array();
172
-		$selected_items = array();
170
+        // Add items.
171
+        $items          = array();
172
+        $selected_items = array();
173 173
 
174 174
         foreach ( $submission->get_items() as $item ) {
175 175
             $item_id = $item->has_variable_pricing() ? $item->get_price_id() : $item->get_id();
176
-			$items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
176
+            $items[ "$item_id" ] = $submission->format_amount( $item->get_sub_total() );
177 177
 
178
-			$selected_items[ "$item_id" ] = array(
179
-				'quantity'  => $item->get_quantity(),
180
-				'price'     => $item->get_price(),
178
+            $selected_items[ "$item_id" ] = array(
179
+                'quantity'  => $item->get_quantity(),
180
+                'price'     => $item->get_price(),
181 181
                 'price_id'  => (int) $item_id,
182
-				'price_fmt' => $submission->format_amount( $item->get_price() ),
183
-			);
184
-		}
185
-
186
-		$this->response = array_merge(
187
-			$this->response,
188
-			array(
189
-				'items'          => $items,
190
-				'selected_items' => $selected_items,
191
-			)
192
-		);
193
-	}
194
-
195
-	/**
196
-	 * Adds fees to a response for submission refresh prices.
197
-	 *
198
-	 * @param GetPaid_Payment_Form_Submission $submission
199
-	 */
200
-	public function add_fees( $submission ) {
201
-
202
-		$fees = array();
182
+                'price_fmt' => $submission->format_amount( $item->get_price() ),
183
+            );
184
+        }
185
+
186
+        $this->response = array_merge(
187
+            $this->response,
188
+            array(
189
+                'items'          => $items,
190
+                'selected_items' => $selected_items,
191
+            )
192
+        );
193
+    }
194
+
195
+    /**
196
+     * Adds fees to a response for submission refresh prices.
197
+     *
198
+     * @param GetPaid_Payment_Form_Submission $submission
199
+     */
200
+    public function add_fees( $submission ) {
201
+
202
+        $fees = array();
203 203
 
204 204
         foreach ( $submission->get_fees() as $name => $data ) {
205
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
206
-		}
205
+            $fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
206
+        }
207 207
 
208
-		$this->response = array_merge(
209
-			$this->response,
210
-			array( 'fees' => $fees )
211
-		);
212
-	}
208
+        $this->response = array_merge(
209
+            $this->response,
210
+            array( 'fees' => $fees )
211
+        );
212
+    }
213 213
 
214
-	/**
215
-	 * Adds discounts to a response for submission refresh prices.
216
-	 *
217
-	 * @param GetPaid_Payment_Form_Submission $submission
218
-	 */
219
-	public function add_discounts( $submission ) {
214
+    /**
215
+     * Adds discounts to a response for submission refresh prices.
216
+     *
217
+     * @param GetPaid_Payment_Form_Submission $submission
218
+     */
219
+    public function add_discounts( $submission ) {
220 220
 
221
-		$discounts = array();
221
+        $discounts = array();
222 222
 
223 223
         foreach ( $submission->get_discounts() as $name => $data ) {
224
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
225
-		}
226
-
227
-		$this->response = array_merge(
228
-			$this->response,
229
-			array( 'discounts' => $discounts )
230
-		);
231
-	}
232
-
233
-	/**
234
-	 * Adds taxes to a response for submission refresh prices.
235
-	 *
236
-	 * @param GetPaid_Payment_Form_Submission $submission
237
-	 */
238
-	public function add_taxes( $submission ) {
239
-
240
-		$taxes  = array();
241
-		$markup = '';
224
+            $discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
225
+        }
226
+
227
+        $this->response = array_merge(
228
+            $this->response,
229
+            array( 'discounts' => $discounts )
230
+        );
231
+    }
232
+
233
+    /**
234
+     * Adds taxes to a response for submission refresh prices.
235
+     *
236
+     * @param GetPaid_Payment_Form_Submission $submission
237
+     */
238
+    public function add_taxes( $submission ) {
239
+
240
+        $taxes  = array();
241
+        $markup = '';
242 242
         foreach ( $submission->get_taxes() as $name => $data ) {
243
-			$name           = sanitize_text_field( $name );
244
-			$amount         = $submission->format_amount( $data['initial_tax'] );
245
-			$taxes[ $name ] = $amount;
246
-			$markup        .= "<small class='form-text'>$name : $amount</small>";
247
-		}
248
-
249
-		$this->response = array_merge(
250
-			$this->response,
251
-			array( 'taxes' => $taxes )
252
-		);
253
-	}
254
-
255
-	/**
256
-	 * Adds gateways to a response for submission refresh prices.
257
-	 *
258
-	 * @param GetPaid_Payment_Form_Submission $submission
259
-	 */
260
-	public function add_gateways( $submission ) {
261
-
262
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
263
-
264
-		if ( $this->response['has_recurring'] ) {
265
-
266
-			foreach ( $gateways as $i => $gateway ) {
267
-
268
-				if (
269
-					! getpaid_payment_gateway_supports( $gateway, 'subscription' )
270
-					|| ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
271
-					|| ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
272
-					unset( $gateways[ $i ] );
273
-				}
243
+            $name           = sanitize_text_field( $name );
244
+            $amount         = $submission->format_amount( $data['initial_tax'] );
245
+            $taxes[ $name ] = $amount;
246
+            $markup        .= "<small class='form-text'>$name : $amount</small>";
247
+        }
248
+
249
+        $this->response = array_merge(
250
+            $this->response,
251
+            array( 'taxes' => $taxes )
252
+        );
253
+    }
254
+
255
+    /**
256
+     * Adds gateways to a response for submission refresh prices.
257
+     *
258
+     * @param GetPaid_Payment_Form_Submission $submission
259
+     */
260
+    public function add_gateways( $submission ) {
261
+
262
+        $gateways = array_keys( wpinv_get_enabled_payment_gateways() );
263
+
264
+        if ( $this->response['has_recurring'] ) {
265
+
266
+            foreach ( $gateways as $i => $gateway ) {
267
+
268
+                if (
269
+                    ! getpaid_payment_gateway_supports( $gateway, 'subscription' )
270
+                    || ( $this->response['has_subscription_group'] && ! getpaid_payment_gateway_supports( $gateway, 'single_subscription_group' ) )
271
+                    || ( $this->response['has_multiple_subscription_groups'] && ! getpaid_payment_gateway_supports( $gateway, 'multiple_subscription_groups' ) ) ) {
272
+                    unset( $gateways[ $i ] );
273
+                }
274 274
             }
275 275
         }
276 276
 
277
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
278
-		$this->response = array_merge(
279
-			$this->response,
280
-			array( 'gateways' => $gateways )
281
-		);
282
-	}
283
-
284
-	/**
285
-	 * Adds data to a response for submission refresh prices.
286
-	 *
287
-	 * @param GetPaid_Payment_Form_Submission $submission
288
-	 */
289
-	public function add_data( $submission ) {
290
-
291
-		$this->response = array_merge(
292
-			$this->response,
293
-			array(
294
-				'js_data' => apply_filters(
295
-					'getpaid_submission_js_data',
296
-					array(
297
-						'is_recurring' => $this->response['has_recurring'],
298
-					),
299
-					$submission
300
-				),
301
-			)
302
-		);
303
-	}
277
+        $gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
278
+        $this->response = array_merge(
279
+            $this->response,
280
+            array( 'gateways' => $gateways )
281
+        );
282
+    }
283
+
284
+    /**
285
+     * Adds data to a response for submission refresh prices.
286
+     *
287
+     * @param GetPaid_Payment_Form_Submission $submission
288
+     */
289
+    public function add_data( $submission ) {
290
+
291
+        $this->response = array_merge(
292
+            $this->response,
293
+            array(
294
+                'js_data' => apply_filters(
295
+                    'getpaid_submission_js_data',
296
+                    array(
297
+                        'is_recurring' => $this->response['has_recurring'],
298
+                    ),
299
+                    $submission
300
+                ),
301
+            )
302
+        );
303
+    }
304 304
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 1 patch
Indentation   +579 added lines, -579 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,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form 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 = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'        => 'draft',
34
-		'version'       => '',
35
-		'date_created'  => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'        => 'draft',
34
+        'version'       => '',
35
+        'date_created'  => null,
36 36
         'date_modified' => null,
37 37
         'name'          => '',
38 38
         'author'        => 1,
39 39
         'elements'      => null,
40
-		'items'         => null,
41
-		'earned'        => 0,
42
-		'refunded'      => 0,
43
-		'cancelled'     => 0,
44
-		'failed'        => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'         => null,
41
+        'earned'        => 0,
42
+        'refunded'      => 0,
43
+        'cancelled'     => 0,
44
+        'failed'        => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,34 +68,34 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98
-	}
98
+    }
99 99
 
100 100
     /*
101 101
 	|--------------------------------------------------------------------------
@@ -113,354 +113,354 @@  discard block
 block discarded – undo
113 113
     */
114 114
 
115 115
     /**
116
-	 * Get plugin version when the form was created.
117
-	 *
118
-	 * @since 1.0.19
119
-	 * @param  string $context View or edit context.
120
-	 * @return string
121
-	 */
122
-	public function get_version( $context = 'view' ) {
123
-		return $this->get_prop( 'version', $context );
116
+     * Get plugin version when the form was created.
117
+     *
118
+     * @since 1.0.19
119
+     * @param  string $context View or edit context.
120
+     * @return string
121
+     */
122
+    public function get_version( $context = 'view' ) {
123
+        return $this->get_prop( 'version', $context );
124 124
     }
125 125
 
126 126
     /**
127
-	 * Get date when the form was created.
128
-	 *
129
-	 * @since 1.0.19
130
-	 * @param  string $context View or edit context.
131
-	 * @return string
132
-	 */
133
-	public function get_date_created( $context = 'view' ) {
134
-		return $this->get_prop( 'date_created', $context );
127
+     * Get date when the form was created.
128
+     *
129
+     * @since 1.0.19
130
+     * @param  string $context View or edit context.
131
+     * @return string
132
+     */
133
+    public function get_date_created( $context = 'view' ) {
134
+        return $this->get_prop( 'date_created', $context );
135 135
     }
136 136
 
137 137
     /**
138
-	 * Get GMT date when the form was created.
139
-	 *
140
-	 * @since 1.0.19
141
-	 * @param  string $context View or edit context.
142
-	 * @return string
143
-	 */
144
-	public function get_date_created_gmt( $context = 'view' ) {
138
+     * Get GMT date when the form was created.
139
+     *
140
+     * @since 1.0.19
141
+     * @param  string $context View or edit context.
142
+     * @return string
143
+     */
144
+    public function get_date_created_gmt( $context = 'view' ) {
145 145
         $date = $this->get_date_created( $context );
146 146
 
147 147
         if ( $date ) {
148 148
             $date = get_gmt_from_date( $date );
149 149
         }
150
-		return $date;
150
+        return $date;
151 151
     }
152 152
 
153 153
     /**
154
-	 * Get date when the form was last modified.
155
-	 *
156
-	 * @since 1.0.19
157
-	 * @param  string $context View or edit context.
158
-	 * @return string
159
-	 */
160
-	public function get_date_modified( $context = 'view' ) {
161
-		return $this->get_prop( 'date_modified', $context );
154
+     * Get date when the form was last modified.
155
+     *
156
+     * @since 1.0.19
157
+     * @param  string $context View or edit context.
158
+     * @return string
159
+     */
160
+    public function get_date_modified( $context = 'view' ) {
161
+        return $this->get_prop( 'date_modified', $context );
162 162
     }
163 163
 
164 164
     /**
165
-	 * Get GMT date when the form was last modified.
166
-	 *
167
-	 * @since 1.0.19
168
-	 * @param  string $context View or edit context.
169
-	 * @return string
170
-	 */
171
-	public function get_date_modified_gmt( $context = 'view' ) {
165
+     * Get GMT date when the form was last modified.
166
+     *
167
+     * @since 1.0.19
168
+     * @param  string $context View or edit context.
169
+     * @return string
170
+     */
171
+    public function get_date_modified_gmt( $context = 'view' ) {
172 172
         $date = $this->get_date_modified( $context );
173 173
 
174 174
         if ( $date ) {
175 175
             $date = get_gmt_from_date( $date );
176 176
         }
177
-		return $date;
177
+        return $date;
178 178
     }
179 179
 
180 180
     /**
181
-	 * Get the form name.
182
-	 *
183
-	 * @since 1.0.19
184
-	 * @param  string $context View or edit context.
185
-	 * @return string
186
-	 */
187
-	public function get_name( $context = 'view' ) {
188
-		return $this->get_prop( 'name', $context );
181
+     * Get the form name.
182
+     *
183
+     * @since 1.0.19
184
+     * @param  string $context View or edit context.
185
+     * @return string
186
+     */
187
+    public function get_name( $context = 'view' ) {
188
+        return $this->get_prop( 'name', $context );
189 189
     }
190 190
 
191 191
     /**
192
-	 * Alias of self::get_name().
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @param  string $context View or edit context.
196
-	 * @return string
197
-	 */
198
-	public function get_title( $context = 'view' ) {
199
-		return $this->get_name( $context );
200
-	}
192
+     * Alias of self::get_name().
193
+     *
194
+     * @since 1.0.19
195
+     * @param  string $context View or edit context.
196
+     * @return string
197
+     */
198
+    public function get_title( $context = 'view' ) {
199
+        return $this->get_name( $context );
200
+    }
201 201
 
202 202
     /**
203
-	 * Get the owner of the form.
204
-	 *
205
-	 * @since 1.0.19
206
-	 * @param  string $context View or edit context.
207
-	 * @return int
208
-	 */
209
-	public function get_author( $context = 'view' ) {
210
-		return (int) $this->get_prop( 'author', $context );
203
+     * Get the owner of the form.
204
+     *
205
+     * @since 1.0.19
206
+     * @param  string $context View or edit context.
207
+     * @return int
208
+     */
209
+    public function get_author( $context = 'view' ) {
210
+        return (int) $this->get_prop( 'author', $context );
211 211
     }
212 212
 
213 213
     /**
214
-	 * Get the elements that make up the form.
215
-	 *
216
-	 * @since 1.0.19
217
-	 * @param  string $context View or edit context.
218
-	 * @return array
219
-	 */
220
-	public function get_elements( $context = 'view' ) {
221
-		$elements = $this->get_prop( 'elements', $context );
214
+     * Get the elements that make up the form.
215
+     *
216
+     * @since 1.0.19
217
+     * @param  string $context View or edit context.
218
+     * @return array
219
+     */
220
+    public function get_elements( $context = 'view' ) {
221
+        $elements = $this->get_prop( 'elements', $context );
222 222
 
223
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
223
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
224 224
             return wpinv_get_data( 'sample-payment-form' );
225
-		}
225
+        }
226 226
 
227
-		// Ensure that all required elements exist.
228
-		$_elements = array();
229
-		foreach ( $elements as $element ) {
227
+        // Ensure that all required elements exist.
228
+        $_elements = array();
229
+        foreach ( $elements as $element ) {
230 230
 
231
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
231
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232 232
 
233
-				$_elements[] = array(
234
-					'text'    => __( 'Select Payment Method', 'invoicing' ),
235
-					'id'      => 'gtscicd',
236
-					'name'    => 'gtscicd',
237
-					'type'    => 'gateway_select',
238
-					'premade' => true,
233
+                $_elements[] = array(
234
+                    'text'    => __( 'Select Payment Method', 'invoicing' ),
235
+                    'id'      => 'gtscicd',
236
+                    'name'    => 'gtscicd',
237
+                    'type'    => 'gateway_select',
238
+                    'premade' => true,
239 239
 
240
-				);
240
+                );
241 241
 
242
-			}
242
+            }
243 243
 
244
-			$_elements[] = $element;
244
+            $_elements[] = $element;
245 245
 
246
-		}
246
+        }
247 247
 
248 248
         return $_elements;
249
-	}
250
-
251
-	/**
252
-	 * Get the items sold via the form.
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @param  string $return objects or arrays.
257
-	 * @return GetPaid_Form_Item[]
258
-	 */
259
-	public function get_items( $context = 'view', $return = 'objects' ) {
260
-		$items = $this->get_prop( 'items', $context );
261
-
262
-		if ( empty( $items ) || ! is_array( $items ) ) {
249
+    }
250
+
251
+    /**
252
+     * Get the items sold via the form.
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @param  string $return objects or arrays.
257
+     * @return GetPaid_Form_Item[]
258
+     */
259
+    public function get_items( $context = 'view', $return = 'objects' ) {
260
+        $items = $this->get_prop( 'items', $context );
261
+
262
+        if ( empty( $items ) || ! is_array( $items ) ) {
263 263
             $items = wpinv_get_data( 'sample-payment-form-items' );
264
-		}
264
+        }
265
+
266
+        // Convert the items.
267
+        $prepared = array();
268
+
269
+        foreach ( $items as $key => $value ) {
270
+
271
+            // Form items.
272
+            if ( $value instanceof GetPaid_Form_Item ) {
273
+
274
+                if ( $value->can_purchase() ) {
275
+                    $prepared[] = $value;
276
+                }
277
+
278
+                continue;
265 279
 
266
-		// Convert the items.
267
-		$prepared = array();
280
+            }
281
+
282
+            // $item_id => $quantity (buy buttons)
283
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
284
+                $item = new GetPaid_Form_Item( $key );
285
+
286
+                if ( $item->can_purchase() ) {
287
+
288
+                    $value = (float) $value;
289
+                    $item->set_quantity( $value );
290
+                    if ( 0 == $value ) {
291
+                        $item->set_quantity( 1 );
292
+                        $item->set_allow_quantities( true );
293
+                    }
294
+
295
+                    $prepared[] = $item;
296
+                }
297
+
298
+                continue;
299
+            }
268 300
 
269
-		foreach ( $items as $key => $value ) {
301
+            // Items saved via payment forms editor.
302
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
270 303
 
271
-			// Form items.
272
-			if ( $value instanceof GetPaid_Form_Item ) {
304
+                $item = new GetPaid_Form_Item( $value['id'] );
273 305
 
274
-				if ( $value->can_purchase() ) {
275
-					$prepared[] = $value;
276
-				}
306
+                if ( ! $item->can_purchase() ) {
307
+                    continue;
308
+                }
277 309
 
278
-				continue;
310
+                // Sub-total (Cart items).
311
+                if ( isset( $value['subtotal'] ) ) {
312
+                    $item->set_price( $value['subtotal'] );
313
+                }
279 314
 
280
-			}
315
+                if ( isset( $value['quantity'] ) ) {
316
+                    $item->set_quantity( $value['quantity'] );
317
+                }
281 318
 
282
-			// $item_id => $quantity (buy buttons)
283
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
284
-				$item = new GetPaid_Form_Item( $key );
319
+                if ( isset( $value['allow_quantities'] ) ) {
320
+                    $item->set_allow_quantities( $value['allow_quantities'] );
321
+                }
285 322
 
286
-				if ( $item->can_purchase() ) {
323
+                if ( isset( $value['required'] ) ) {
324
+                    $item->set_is_required( $value['required'] );
325
+                }
287 326
 
288
-					$value = (float) $value;
289
-					$item->set_quantity( $value );
290
-					if ( 0 == $value ) {
291
-						$item->set_quantity( 1 );
292
-						$item->set_allow_quantities( true );
293
-					}
327
+                if ( isset( $value['description'] ) ) {
328
+                    $item->set_custom_description( $value['description'] );
329
+                }
294 330
 
295
-					$prepared[] = $item;
296
-				}
331
+                $prepared[] = $item;
332
+                continue;
297 333
 
298
-				continue;
299
-			}
334
+            }
300 335
 
301
-			// Items saved via payment forms editor.
302
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
336
+            // $item_id => array( 'price' => 10 ) (item variations)
337
+            if ( is_numeric( $key ) && is_array( $value ) ) {
338
+                $item = new GetPaid_Form_Item( $key );
303 339
 
304
-				$item = new GetPaid_Form_Item( $value['id'] );
340
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
341
+                    $item->set_price( $value['price'] );
342
+                }
305 343
 
306
-				if ( ! $item->can_purchase() ) {
307
-					continue;
308
-				}
344
+                if ( $item->can_purchase() ) {
345
+                    $prepared[] = $item;
346
+                }
309 347
 
310
-				// Sub-total (Cart items).
311
-				if ( isset( $value['subtotal'] ) ) {
312
-					$item->set_price( $value['subtotal'] );
313
-				}
348
+                continue;
349
+            }
350
+        }
314 351
 
315
-				if ( isset( $value['quantity'] ) ) {
316
-					$item->set_quantity( $value['quantity'] );
317
-				}
352
+        if ( 'objects' == $return && 'view' == $context ) {
353
+            return $prepared;
354
+        }
318 355
 
319
-				if ( isset( $value['allow_quantities'] ) ) {
320
-					$item->set_allow_quantities( $value['allow_quantities'] );
321
-				}
356
+        $items = array();
357
+        foreach ( $prepared as $item ) {
358
+            $items[] = $item->prepare_data_for_use();
359
+        }
360
+
361
+        return $items;
362
+    }
322 363
 
323
-				if ( isset( $value['required'] ) ) {
324
-					$item->set_is_required( $value['required'] );
325
-				}
326
-
327
-				if ( isset( $value['description'] ) ) {
328
-					$item->set_custom_description( $value['description'] );
329
-				}
330
-
331
-				$prepared[] = $item;
332
-				continue;
333
-
334
-			}
335
-
336
-			// $item_id => array( 'price' => 10 ) (item variations)
337
-			if ( is_numeric( $key ) && is_array( $value ) ) {
338
-				$item = new GetPaid_Form_Item( $key );
339
-
340
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
341
-					$item->set_price( $value['price'] );
342
-				}
343
-
344
-				if ( $item->can_purchase() ) {
345
-					$prepared[] = $item;
346
-				}
347
-
348
-				continue;
349
-			}
350
-		}
351
-
352
-		if ( 'objects' == $return && 'view' == $context ) {
353
-			return $prepared;
354
-		}
355
-
356
-		$items = array();
357
-		foreach ( $prepared as $item ) {
358
-			$items[] = $item->prepare_data_for_use();
359
-		}
360
-
361
-		return $items;
362
-	}
363
-
364
-	/**
365
-	 * Get a single item belonging to the form.
366
-	 *
367
-	 * @since 1.0.19
368
-	 * @param  int $item_id The item id to return.
369
-	 * @return GetPaid_Form_Item|bool
370
-	 */
371
-	public function get_item( $item_id ) {
372
-
373
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
374
-			return false;
375
-		}
376
-
377
-		foreach ( $this->get_items() as $item ) {
378
-			if ( $item->get_id() == (int) $item_id ) {
379
-				return $item;
380
-			}
381
-		}
382
-
383
-		return false;
384
-	}
385
-
386
-	/**
387
-	 * Gets a single element.
388
-	 *
389
-	 * @since 1.0.19
390
-	 * @param  string $element_type The element type to return.
391
-	 * @return array|bool
392
-	 */
393
-	public function get_element_type( $element_type ) {
394
-
395
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
396
-			return false;
397
-		}
398
-
399
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
400
-
401
-			if ( $element['type'] === $element_type ) {
402
-				return $element;
403
-			}
404
-		}
405
-
406
-		return false;
407
-	}
408
-
409
-	/**
410
-	 * Get the total amount earned via this form.
411
-	 *
412
-	 * @since 1.0.19
413
-	 * @param  string $context View or edit context.
414
-	 * @return float
415
-	 */
416
-	public function get_earned( $context = 'view' ) {
417
-		return $this->get_prop( 'earned', $context );
418
-	}
419
-
420
-	/**
421
-	 * Get the total amount refunded via this form.
422
-	 *
423
-	 * @since 1.0.19
424
-	 * @param  string $context View or edit context.
425
-	 * @return float
426
-	 */
427
-	public function get_refunded( $context = 'view' ) {
428
-		return $this->get_prop( 'refunded', $context );
429
-	}
430
-
431
-	/**
432
-	 * Get the total amount cancelled via this form.
433
-	 *
434
-	 * @since 1.0.19
435
-	 * @param  string $context View or edit context.
436
-	 * @return float
437
-	 */
438
-	public function get_cancelled( $context = 'view' ) {
439
-		return $this->get_prop( 'cancelled', $context );
440
-	}
441
-
442
-	/**
443
-	 * Get the total amount failed via this form.
444
-	 *
445
-	 * @since 1.0.19
446
-	 * @param  string $context View or edit context.
447
-	 * @return float
448
-	 */
449
-	public function get_failed( $context = 'view' ) {
450
-		return $this->get_prop( 'failed', $context );
451
-	}
452
-
453
-	/**
454
-	 * Get the currency.
455
-	 *
456
-	 * @since 1.0.19
457
-	 * @param  string $context View or edit context.
458
-	 * @return string
459
-	 */
460
-	public function get_currency() {
461
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
462
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
463
-	}
364
+    /**
365
+     * Get a single item belonging to the form.
366
+     *
367
+     * @since 1.0.19
368
+     * @param  int $item_id The item id to return.
369
+     * @return GetPaid_Form_Item|bool
370
+     */
371
+    public function get_item( $item_id ) {
372
+
373
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
374
+            return false;
375
+        }
376
+
377
+        foreach ( $this->get_items() as $item ) {
378
+            if ( $item->get_id() == (int) $item_id ) {
379
+                return $item;
380
+            }
381
+        }
382
+
383
+        return false;
384
+    }
385
+
386
+    /**
387
+     * Gets a single element.
388
+     *
389
+     * @since 1.0.19
390
+     * @param  string $element_type The element type to return.
391
+     * @return array|bool
392
+     */
393
+    public function get_element_type( $element_type ) {
394
+
395
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
396
+            return false;
397
+        }
398
+
399
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
400
+
401
+            if ( $element['type'] === $element_type ) {
402
+                return $element;
403
+            }
404
+        }
405
+
406
+        return false;
407
+    }
408
+
409
+    /**
410
+     * Get the total amount earned via this form.
411
+     *
412
+     * @since 1.0.19
413
+     * @param  string $context View or edit context.
414
+     * @return float
415
+     */
416
+    public function get_earned( $context = 'view' ) {
417
+        return $this->get_prop( 'earned', $context );
418
+    }
419
+
420
+    /**
421
+     * Get the total amount refunded via this form.
422
+     *
423
+     * @since 1.0.19
424
+     * @param  string $context View or edit context.
425
+     * @return float
426
+     */
427
+    public function get_refunded( $context = 'view' ) {
428
+        return $this->get_prop( 'refunded', $context );
429
+    }
430
+
431
+    /**
432
+     * Get the total amount cancelled via this form.
433
+     *
434
+     * @since 1.0.19
435
+     * @param  string $context View or edit context.
436
+     * @return float
437
+     */
438
+    public function get_cancelled( $context = 'view' ) {
439
+        return $this->get_prop( 'cancelled', $context );
440
+    }
441
+
442
+    /**
443
+     * Get the total amount failed via this form.
444
+     *
445
+     * @since 1.0.19
446
+     * @param  string $context View or edit context.
447
+     * @return float
448
+     */
449
+    public function get_failed( $context = 'view' ) {
450
+        return $this->get_prop( 'failed', $context );
451
+    }
452
+
453
+    /**
454
+     * Get the currency.
455
+     *
456
+     * @since 1.0.19
457
+     * @param  string $context View or edit context.
458
+     * @return string
459
+     */
460
+    public function get_currency() {
461
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
462
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
463
+    }
464 464
 
465 465
     /*
466 466
 	|--------------------------------------------------------------------------
@@ -473,22 +473,22 @@  discard block
 block discarded – undo
473 473
     */
474 474
 
475 475
     /**
476
-	 * Set plugin version when the item was created.
477
-	 *
478
-	 * @since 1.0.19
479
-	 */
480
-	public function set_version( $value ) {
481
-		$this->set_prop( 'version', $value );
476
+     * Set plugin version when the item was created.
477
+     *
478
+     * @since 1.0.19
479
+     */
480
+    public function set_version( $value ) {
481
+        $this->set_prop( 'version', $value );
482 482
     }
483 483
 
484 484
     /**
485
-	 * Set date when the item was created.
486
-	 *
487
-	 * @since 1.0.19
488
-	 * @param string $value Value to set.
485
+     * Set date when the item was created.
486
+     *
487
+     * @since 1.0.19
488
+     * @param string $value Value to set.
489 489
      * @return bool Whether or not the date was set.
490
-	 */
491
-	public function set_date_created( $value ) {
490
+     */
491
+    public function set_date_created( $value ) {
492 492
         $date = strtotime( $value );
493 493
 
494 494
         if ( $date ) {
@@ -500,13 +500,13 @@  discard block
 block discarded – undo
500 500
     }
501 501
 
502 502
     /**
503
-	 * Set date when the item was last modified.
504
-	 *
505
-	 * @since 1.0.19
506
-	 * @param string $value Value to set.
503
+     * Set date when the item was last modified.
504
+     *
505
+     * @since 1.0.19
506
+     * @param string $value Value to set.
507 507
      * @return bool Whether or not the date was set.
508
-	 */
509
-	public function set_date_modified( $value ) {
508
+     */
509
+    public function set_date_modified( $value ) {
510 510
         $date = strtotime( $value );
511 511
 
512 512
         if ( $date ) {
@@ -518,171 +518,171 @@  discard block
 block discarded – undo
518 518
     }
519 519
 
520 520
     /**
521
-	 * Set the item name.
522
-	 *
523
-	 * @since 1.0.19
524
-	 * @param  string $value New name.
525
-	 */
526
-	public function set_name( $value ) {
527
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
528
-    }
529
-
530
-    /**
531
-	 * Alias of self::set_name().
532
-	 *
533
-	 * @since 1.0.19
534
-	 * @param  string $value New name.
535
-	 */
536
-	public function set_title( $value ) {
537
-		$this->set_name( $value );
538
-    }
539
-
540
-    /**
541
-	 * Set the owner of the item.
542
-	 *
543
-	 * @since 1.0.19
544
-	 * @param  int $value New author.
545
-	 */
546
-	public function set_author( $value ) {
547
-		$this->set_prop( 'author', (int) $value );
548
-	}
549
-
550
-	/**
551
-	 * Set the form elements.
552
-	 *
553
-	 * @since 1.0.19
554
-	 * @sinve 2.3.4 Array values sanitized.
555
-	 * @param  array $value Form elements.
556
-	 */
557
-	public function set_elements( $value ) {
558
-		if ( is_array( $value ) ) {
559
-			$this->set_prop( 'elements', wp_kses_post_deep( $value ) );
560
-		}
561
-	}
562
-
563
-	/**
564
-	 * Sanitize array values.
565
-	 *
566
-	 * @param $value
567
-	 *
568
-	 * @return mixed
569
-	 */
570
-	public function sanitize_array_values( $value ) {
571
-
572
-		// sanitize
573
-		if ( ! empty( $value ) ) {
574
-
575
-			foreach ( $value as $key => $val_arr ) {
576
-
577
-				if ( is_array( $val_arr ) ) {
578
-					// check if we have sub array items.
579
-					$sub_arr = array();
580
-					foreach ( $val_arr as $key2 => $val2 ) {
581
-						if ( is_array( $val2 ) ) {
582
-							$sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
583
-							unset( $val_arr[ $key ][ $key2 ] );
584
-						}
585
-					}
586
-
587
-					// we allow some html in description so we sanitize it separately.
588
-					$help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
589
-
590
-					// sanitize array elements
591
-					$value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
592
-
593
-					// add back the description if set
594
-					if ( isset( $val_arr['description'] ) ) {
521
+     * Set the item name.
522
+     *
523
+     * @since 1.0.19
524
+     * @param  string $value New name.
525
+     */
526
+    public function set_name( $value ) {
527
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
528
+    }
529
+
530
+    /**
531
+     * Alias of self::set_name().
532
+     *
533
+     * @since 1.0.19
534
+     * @param  string $value New name.
535
+     */
536
+    public function set_title( $value ) {
537
+        $this->set_name( $value );
538
+    }
539
+
540
+    /**
541
+     * Set the owner of the item.
542
+     *
543
+     * @since 1.0.19
544
+     * @param  int $value New author.
545
+     */
546
+    public function set_author( $value ) {
547
+        $this->set_prop( 'author', (int) $value );
548
+    }
549
+
550
+    /**
551
+     * Set the form elements.
552
+     *
553
+     * @since 1.0.19
554
+     * @sinve 2.3.4 Array values sanitized.
555
+     * @param  array $value Form elements.
556
+     */
557
+    public function set_elements( $value ) {
558
+        if ( is_array( $value ) ) {
559
+            $this->set_prop( 'elements', wp_kses_post_deep( $value ) );
560
+        }
561
+    }
562
+
563
+    /**
564
+     * Sanitize array values.
565
+     *
566
+     * @param $value
567
+     *
568
+     * @return mixed
569
+     */
570
+    public function sanitize_array_values( $value ) {
571
+
572
+        // sanitize
573
+        if ( ! empty( $value ) ) {
574
+
575
+            foreach ( $value as $key => $val_arr ) {
576
+
577
+                if ( is_array( $val_arr ) ) {
578
+                    // check if we have sub array items.
579
+                    $sub_arr = array();
580
+                    foreach ( $val_arr as $key2 => $val2 ) {
581
+                        if ( is_array( $val2 ) ) {
582
+                            $sub_arr[ $key2 ] = $this->sanitize_array_values( $val2 );
583
+                            unset( $val_arr[ $key ][ $key2 ] );
584
+                        }
585
+                    }
586
+
587
+                    // we allow some html in description so we sanitize it separately.
588
+                    $help_text = ! empty( $val_arr['description'] ) ? wp_kses_post( $val_arr['description'] ) : '';
589
+
590
+                    // sanitize array elements
591
+                    $value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
592
+
593
+                    // add back the description if set
594
+                    if ( isset( $val_arr['description'] ) ) {
595 595
                         $value[ $key ]['description'] = $help_text;}
596 596
 
597
-					// add back sub array items after its been sanitized.
598
-					if ( ! empty( $sub_arr ) ) {
599
-						$value[ $key ] = array_merge( $value[ $key ], $sub_arr );
600
-					}
601
-				}
597
+                    // add back sub array items after its been sanitized.
598
+                    if ( ! empty( $sub_arr ) ) {
599
+                        $value[ $key ] = array_merge( $value[ $key ], $sub_arr );
600
+                    }
601
+                }
602 602
             }
603 603
         }
604 604
 
605
-		return $value;
606
-	}
607
-
608
-	/**
609
-	 * Set the form items.
610
-	 *
611
-	 * @since 1.0.19
612
-	 * @param  array $value Form elements.
613
-	 */
614
-	public function set_items( $value ) {
615
-		if ( is_array( $value ) ) {
616
-			$this->set_prop( 'items', $value );
617
-		}
618
-	}
619
-
620
-	/**
621
-	 * Set the total amount earned via this form.
622
-	 *
623
-	 * @since 1.0.19
624
-	 * @param  float $value Amount earned.
625
-	 */
626
-	public function set_earned( $value ) {
627
-		$value = max( (float) $value, 0 );
628
-		$this->set_prop( 'earned', $value );
629
-	}
630
-
631
-	/**
632
-	 * Set the total amount refunded via this form.
633
-	 *
634
-	 * @since 1.0.19
635
-	 * @param  float $value Amount refunded.
636
-	 */
637
-	public function set_refunded( $value ) {
638
-		$value = max( (float) $value, 0 );
639
-		$this->set_prop( 'refunded', $value );
640
-	}
641
-
642
-	/**
643
-	 * Set the total amount cancelled via this form.
644
-	 *
645
-	 * @since 1.0.19
646
-	 * @param  float $value Amount cancelled.
647
-	 */
648
-	public function set_cancelled( $value ) {
649
-		$value = max( (float) $value, 0 );
650
-		$this->set_prop( 'cancelled', $value );
651
-	}
652
-
653
-	/**
654
-	 * Set the total amount failed via this form.
655
-	 *
656
-	 * @since 1.0.19
657
-	 * @param  float $value Amount cancelled.
658
-	 */
659
-	public function set_failed( $value ) {
660
-		$value = max( (float) $value, 0 );
661
-		$this->set_prop( 'failed', $value );
662
-	}
605
+        return $value;
606
+    }
607
+
608
+    /**
609
+     * Set the form items.
610
+     *
611
+     * @since 1.0.19
612
+     * @param  array $value Form elements.
613
+     */
614
+    public function set_items( $value ) {
615
+        if ( is_array( $value ) ) {
616
+            $this->set_prop( 'items', $value );
617
+        }
618
+    }
619
+
620
+    /**
621
+     * Set the total amount earned via this form.
622
+     *
623
+     * @since 1.0.19
624
+     * @param  float $value Amount earned.
625
+     */
626
+    public function set_earned( $value ) {
627
+        $value = max( (float) $value, 0 );
628
+        $this->set_prop( 'earned', $value );
629
+    }
630
+
631
+    /**
632
+     * Set the total amount refunded via this form.
633
+     *
634
+     * @since 1.0.19
635
+     * @param  float $value Amount refunded.
636
+     */
637
+    public function set_refunded( $value ) {
638
+        $value = max( (float) $value, 0 );
639
+        $this->set_prop( 'refunded', $value );
640
+    }
641
+
642
+    /**
643
+     * Set the total amount cancelled via this form.
644
+     *
645
+     * @since 1.0.19
646
+     * @param  float $value Amount cancelled.
647
+     */
648
+    public function set_cancelled( $value ) {
649
+        $value = max( (float) $value, 0 );
650
+        $this->set_prop( 'cancelled', $value );
651
+    }
652
+
653
+    /**
654
+     * Set the total amount failed via this form.
655
+     *
656
+     * @since 1.0.19
657
+     * @param  float $value Amount cancelled.
658
+     */
659
+    public function set_failed( $value ) {
660
+        $value = max( (float) $value, 0 );
661
+        $this->set_prop( 'failed', $value );
662
+    }
663 663
 
664 664
     /**
665 665
      * Create an item. For backwards compatibilty.
666 666
      *
667 667
      * @deprecated
668
-	 * @return int item id
668
+     * @return int item id
669 669
      */
670 670
     public function create( $data = array() ) {
671 671
 
672
-		// Set the properties.
673
-		if ( is_array( $data ) ) {
674
-			$this->set_props( $data );
675
-		}
672
+        // Set the properties.
673
+        if ( is_array( $data ) ) {
674
+            $this->set_props( $data );
675
+        }
676 676
 
677
-		// Save the item.
678
-		return $this->save();
677
+        // Save the item.
678
+        return $this->save();
679 679
     }
680 680
 
681 681
     /**
682 682
      * Updates an item. For backwards compatibilty.
683 683
      *
684 684
      * @deprecated
685
-	 * @return int item id
685
+     * @return int item id
686 686
      */
687 687
     public function update( $data = array() ) {
688 688
         return $this->create( $data );
@@ -698,22 +698,22 @@  discard block
 block discarded – undo
698 698
 	*/
699 699
 
700 700
     /**
701
-	 * Checks whether this is the default payment form.
702
-	 *
703
-	 * @since 1.0.19
704
-	 * @return bool
705
-	 */
701
+     * Checks whether this is the default payment form.
702
+     *
703
+     * @since 1.0.19
704
+     * @return bool
705
+     */
706 706
     public function is_default() {
707 707
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
708 708
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
709
-	}
709
+    }
710 710
 
711 711
     /**
712
-	 * Checks whether the form is active.
713
-	 *
714
-	 * @since 1.0.19
715
-	 * @return bool
716
-	 */
712
+     * Checks whether the form is active.
713
+     *
714
+     * @since 1.0.19
715
+     * @return bool
716
+     */
717 717
     public function is_active() {
718 718
         $is_active = 0 !== (int) $this->get_id();
719 719
 
@@ -722,79 +722,79 @@  discard block
 block discarded – undo
722 722
         }
723 723
 
724 724
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
725
-	}
726
-
727
-	/**
728
-	 * Checks whether the form has a given item.
729
-	 *
730
-	 * @since 1.0.19
731
-	 * @return bool
732
-	 */
725
+    }
726
+
727
+    /**
728
+     * Checks whether the form has a given item.
729
+     *
730
+     * @since 1.0.19
731
+     * @return bool
732
+     */
733 733
     public function has_item( $item_id ) {
734 734
         return false !== $this->get_item( $item_id );
735
-	}
736
-
737
-	/**
738
-	 * Checks whether the form has a given element.
739
-	 *
740
-	 * @since 1.0.19
741
-	 * @return bool
742
-	 */
735
+    }
736
+
737
+    /**
738
+     * Checks whether the form has a given element.
739
+     *
740
+     * @since 1.0.19
741
+     * @return bool
742
+     */
743 743
     public function has_element_type( $element_type ) {
744 744
         return false !== $this->get_element_type( $element_type );
745
-	}
746
-
747
-	/**
748
-	 * Checks whether this form is recurring or not.
749
-	 *
750
-	 * @since 1.0.19
751
-	 * @return bool
752
-	 */
745
+    }
746
+
747
+    /**
748
+     * Checks whether this form is recurring or not.
749
+     *
750
+     * @since 1.0.19
751
+     * @return bool
752
+     */
753 753
     public function is_recurring() {
754 754
 
755
-		if ( ! empty( $this->invoice ) ) {
756
-			return $this->invoice->is_recurring();
757
-		}
755
+        if ( ! empty( $this->invoice ) ) {
756
+            return $this->invoice->is_recurring();
757
+        }
758 758
 
759
-		foreach ( $this->get_items() as $item ) {
759
+        foreach ( $this->get_items() as $item ) {
760 760
 
761
-			if ( $item->is_recurring() ) {
762
-				return true;
763
-			}
761
+            if ( $item->is_recurring() ) {
762
+                return true;
763
+            }
764 764
         }
765 765
 
766 766
         return false;
767
-	}
767
+    }
768 768
 
769
-	/**
770
-	 * Retrieves the form's html.
771
-	 *
772
-	 * @since 1.0.19
773
-	 */
769
+    /**
770
+     * Retrieves the form's html.
771
+     *
772
+     * @since 1.0.19
773
+     */
774 774
     public function get_html( $extra_markup = '' ) {
775 775
 
776
-		// Return the HTML.
777
-		return wpinv_get_template_html(
778
-			'payment-forms/form.php',
779
-			array(
780
-				'form'         => $this,
781
-				'extra_markup' => $extra_markup,
782
-			)
783
-		);
784
-	}
785
-
786
-	/**
787
-	 * Displays the payment form.
788
-	 *
789
-	 * @since 1.0.19
790
-	 */
776
+        // Return the HTML.
777
+        return wpinv_get_template_html(
778
+            'payment-forms/form.php',
779
+            array(
780
+                'form'         => $this,
781
+                'extra_markup' => $extra_markup,
782
+            )
783
+        );
784
+    }
785
+
786
+    /**
787
+     * Displays the payment form.
788
+     *
789
+     * @since 1.0.19
790
+     */
791 791
     public function display( $extra_markup = '' ) {
792
-		wpinv_get_template(
793
-			'payment-forms/form.php',
794
-			array(
795
-				'form'         => $this,
796
-				'extra_markup' => $extra_markup,
797
-			)
798
-		);
792
+        wpinv_get_template(
793
+            'payment-forms/form.php',
794
+            array(
795
+                'form'         => $this,
796
+                'extra_markup' => $extra_markup,
797
+            )
798
+        );
799 799
     }
800 800
 }
Please login to merge, or discard this patch.