Passed
Pull Request — master (#785)
by
unknown
04:48
created
includes/class-wpinv-item.php 2 patches
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.
Spacing   +241 added lines, -241 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -82,30 +82,30 @@  discard block
 block discarded – undo
82 82
 	 *
83 83
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
84 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 );
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 98
 		} else {
99
-			$this->set_object_read( true );
99
+			$this->set_object_read(true);
100 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 ) {
106
-            $this->post = get_post( $this->get_id() );
105
+		if ($this->get_id() > 0) {
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
 
@@ -131,8 +131,8 @@  discard block
 block discarded – undo
131 131
 	 * @param  string $context View or edit context.
132 132
 	 * @return int
133 133
 	 */
134
-	public function get_parent_id( $context = 'view' ) {
135
-		return (int) $this->get_prop( 'parent_id', $context );
134
+	public function get_parent_id($context = 'view') {
135
+		return (int) $this->get_prop('parent_id', $context);
136 136
     }
137 137
 
138 138
     /**
@@ -142,8 +142,8 @@  discard block
 block discarded – undo
142 142
 	 * @param  string $context View or edit context.
143 143
 	 * @return string
144 144
 	 */
145
-	public function get_status( $context = 'view' ) {
146
-		return $this->get_prop( 'status', $context );
145
+	public function get_status($context = 'view') {
146
+		return $this->get_prop('status', $context);
147 147
     }
148 148
 
149 149
     /**
@@ -153,8 +153,8 @@  discard block
 block discarded – undo
153 153
 	 * @param  string $context View or edit context.
154 154
 	 * @return string
155 155
 	 */
156
-	public function get_version( $context = 'view' ) {
157
-		return $this->get_prop( 'version', $context );
156
+	public function get_version($context = 'view') {
157
+		return $this->get_prop('version', $context);
158 158
     }
159 159
 
160 160
     /**
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 	 * @param  string $context View or edit context.
165 165
 	 * @return string
166 166
 	 */
167
-	public function get_date_created( $context = 'view' ) {
168
-		return $this->get_prop( 'date_created', $context );
167
+	public function get_date_created($context = 'view') {
168
+		return $this->get_prop('date_created', $context);
169 169
     }
170 170
 
171 171
     /**
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
 	 * @param  string $context View or edit context.
176 176
 	 * @return string
177 177
 	 */
178
-	public function get_date_created_gmt( $context = 'view' ) {
179
-        $date = $this->get_date_created( $context );
178
+	public function get_date_created_gmt($context = 'view') {
179
+        $date = $this->get_date_created($context);
180 180
 
181
-        if ( $date ) {
182
-            $date = get_gmt_from_date( $date );
181
+        if ($date) {
182
+            $date = get_gmt_from_date($date);
183 183
         }
184 184
 		return $date;
185 185
     }
@@ -191,8 +191,8 @@  discard block
 block discarded – undo
191 191
 	 * @param  string $context View or edit context.
192 192
 	 * @return string
193 193
 	 */
194
-	public function get_date_modified( $context = 'view' ) {
195
-		return $this->get_prop( 'date_modified', $context );
194
+	public function get_date_modified($context = 'view') {
195
+		return $this->get_prop('date_modified', $context);
196 196
     }
197 197
 
198 198
     /**
@@ -202,11 +202,11 @@  discard block
 block discarded – undo
202 202
 	 * @param  string $context View or edit context.
203 203
 	 * @return string
204 204
 	 */
205
-	public function get_date_modified_gmt( $context = 'view' ) {
206
-        $date = $this->get_date_modified( $context );
205
+	public function get_date_modified_gmt($context = 'view') {
206
+        $date = $this->get_date_modified($context);
207 207
 
208
-        if ( $date ) {
209
-            $date = get_gmt_from_date( $date );
208
+        if ($date) {
209
+            $date = get_gmt_from_date($date);
210 210
         }
211 211
 		return $date;
212 212
     }
@@ -218,8 +218,8 @@  discard block
 block discarded – undo
218 218
 	 * @param  string $context View or edit context.
219 219
 	 * @return string
220 220
 	 */
221
-	public function get_name( $context = 'view' ) {
222
-		return $this->get_prop( 'name', $context );
221
+	public function get_name($context = 'view') {
222
+		return $this->get_prop('name', $context);
223 223
     }
224 224
 
225 225
     /**
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
 	 * @param  string $context View or edit context.
230 230
 	 * @return string
231 231
 	 */
232
-	public function get_title( $context = 'view' ) {
233
-		return $this->get_name( $context );
232
+	public function get_title($context = 'view') {
233
+		return $this->get_name($context);
234 234
     }
235 235
 
236 236
     /**
@@ -240,8 +240,8 @@  discard block
 block discarded – undo
240 240
 	 * @param  string $context View or edit context.
241 241
 	 * @return string
242 242
 	 */
243
-	public function get_description( $context = 'view' ) {
244
-		return $this->get_prop( 'description', $context );
243
+	public function get_description($context = 'view') {
244
+		return $this->get_prop('description', $context);
245 245
     }
246 246
 
247 247
     /**
@@ -251,8 +251,8 @@  discard block
 block discarded – undo
251 251
 	 * @param  string $context View or edit context.
252 252
 	 * @return string
253 253
 	 */
254
-	public function get_excerpt( $context = 'view' ) {
255
-		return $this->get_description( $context );
254
+	public function get_excerpt($context = 'view') {
255
+		return $this->get_description($context);
256 256
     }
257 257
 
258 258
     /**
@@ -262,8 +262,8 @@  discard block
 block discarded – undo
262 262
 	 * @param  string $context View or edit context.
263 263
 	 * @return string
264 264
 	 */
265
-	public function get_summary( $context = 'view' ) {
266
-		return $this->get_description( $context );
265
+	public function get_summary($context = 'view') {
266
+		return $this->get_description($context);
267 267
     }
268 268
 
269 269
     /**
@@ -273,8 +273,8 @@  discard block
 block discarded – undo
273 273
 	 * @param  string $context View or edit context.
274 274
 	 * @return int
275 275
 	 */
276
-	public function get_author( $context = 'view' ) {
277
-		return (int) $this->get_prop( 'author', $context );
276
+	public function get_author($context = 'view') {
277
+		return (int) $this->get_prop('author', $context);
278 278
 	}
279 279
 
280 280
 	/**
@@ -284,8 +284,8 @@  discard block
 block discarded – undo
284 284
 	 * @param  string $context View or edit context.
285 285
 	 * @return int
286 286
 	 */
287
-	public function get_owner( $context = 'view' ) {
288
-		return $this->get_author( $context );
287
+	public function get_owner($context = 'view') {
288
+		return $this->get_author($context);
289 289
     }
290 290
 
291 291
     /**
@@ -295,8 +295,8 @@  discard block
 block discarded – undo
295 295
 	 * @param  string $context View or edit context.
296 296
 	 * @return float
297 297
 	 */
298
-	public function get_price( $context = 'view' ) {
299
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
298
+	public function get_price($context = 'view') {
299
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
300 300
 	}
301 301
 
302 302
 	/**
@@ -306,24 +306,24 @@  discard block
 block discarded – undo
306 306
 	 * @param  string $context View or edit context.
307 307
 	 * @return float
308 308
 	 */
309
-	public function get_initial_price( $context = 'view', $price_id = null ) {
309
+	public function get_initial_price($context = 'view', $price_id = null) {
310 310
         $price = 0;
311 311
 
312
-        if ( null === $price_id ) {
313
-            $price = (float) $this->get_price( $context );
312
+        if (null === $price_id) {
313
+            $price = (float) $this->get_price($context);
314 314
 
315
-            if ( $this->has_free_trial() ) {
315
+            if ($this->has_free_trial()) {
316 316
                 $price = 0;
317 317
             }
318 318
         } else {
319 319
             $prices = $this->get_variable_prices();
320 320
 
321
-            if ( isset( $prices[ $price_id ] ) ) {
322
-                $price = (float) $prices[ $price_id ]['amount'];
321
+            if (isset($prices[$price_id])) {
322
+                $price = (float) $prices[$price_id]['amount'];
323 323
             }
324 324
         }
325 325
 
326
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
326
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this));
327 327
     }
328 328
 
329 329
     /**
@@ -334,7 +334,7 @@  discard block
 block discarded – undo
334 334
 	 * @return string
335 335
 	 */
336 336
     public function get_the_price() {
337
-        return wpinv_price( $this->get_price() );
337
+        return wpinv_price($this->get_price());
338 338
 	}
339 339
 
340 340
 	/**
@@ -345,7 +345,7 @@  discard block
 block discarded – undo
345 345
 	 * @return string
346 346
 	 */
347 347
     public function get_the_initial_price() {
348
-        return wpinv_price( $this->get_initial_price() );
348
+        return wpinv_price($this->get_initial_price());
349 349
     }
350 350
 
351 351
     /**
@@ -355,8 +355,8 @@  discard block
 block discarded – undo
355 355
 	 * @param  string $context View or edit context.
356 356
 	 * @return string
357 357
 	 */
358
-	public function get_vat_rule( $context = 'view' ) {
359
-        return $this->get_prop( 'vat_rule', $context );
358
+	public function get_vat_rule($context = 'view') {
359
+        return $this->get_prop('vat_rule', $context);
360 360
     }
361 361
 
362 362
     /**
@@ -366,8 +366,8 @@  discard block
 block discarded – undo
366 366
 	 * @param  string $context View or edit context.
367 367
 	 * @return string
368 368
 	 */
369
-	public function get_vat_class( $context = 'view' ) {
370
-        return $this->get_prop( 'vat_class', $context );
369
+	public function get_vat_class($context = 'view') {
370
+        return $this->get_prop('vat_class', $context);
371 371
     }
372 372
 
373 373
     /**
@@ -377,8 +377,8 @@  discard block
 block discarded – undo
377 377
 	 * @param  string $context View or edit context.
378 378
 	 * @return string
379 379
 	 */
380
-	public function get_type( $context = 'view' ) {
381
-        return $this->get_prop( 'type', $context );
380
+	public function get_type($context = 'view') {
381
+        return $this->get_prop('type', $context);
382 382
     }
383 383
 
384 384
     /**
@@ -388,8 +388,8 @@  discard block
 block discarded – undo
388 388
 	 * @param  string $context View or edit context.
389 389
 	 * @return string
390 390
 	 */
391
-	public function get_custom_id( $context = 'view' ) {
392
-        return $this->get_prop( 'custom_id', $context );
391
+	public function get_custom_id($context = 'view') {
392
+        return $this->get_prop('custom_id', $context);
393 393
     }
394 394
 
395 395
     /**
@@ -399,8 +399,8 @@  discard block
 block discarded – undo
399 399
 	 * @param  string $context View or edit context.
400 400
 	 * @return string
401 401
 	 */
402
-	public function get_custom_name( $context = 'view' ) {
403
-        return $this->get_prop( 'custom_name', $context );
402
+	public function get_custom_name($context = 'view') {
403
+        return $this->get_prop('custom_name', $context);
404 404
     }
405 405
 
406 406
     /**
@@ -410,8 +410,8 @@  discard block
 block discarded – undo
410 410
 	 * @param  string $context View or edit context.
411 411
 	 * @return string
412 412
 	 */
413
-	public function get_custom_singular_name( $context = 'view' ) {
414
-        return $this->get_prop( 'custom_singular_name', $context );
413
+	public function get_custom_singular_name($context = 'view') {
414
+        return $this->get_prop('custom_singular_name', $context);
415 415
     }
416 416
 
417 417
     /**
@@ -421,8 +421,8 @@  discard block
 block discarded – undo
421 421
 	 * @param  string $context View or edit context.
422 422
 	 * @return int
423 423
 	 */
424
-	public function get_is_editable( $context = 'view' ) {
425
-        return (int) $this->get_prop( 'is_editable', $context );
424
+	public function get_is_editable($context = 'view') {
425
+        return (int) $this->get_prop('is_editable', $context);
426 426
     }
427 427
 
428 428
     /**
@@ -432,8 +432,8 @@  discard block
 block discarded – undo
432 432
 	 * @param  string $context View or edit context.
433 433
 	 * @return int
434 434
 	 */
435
-	public function get_editable( $context = 'view' ) {
436
-		return $this->get_is_editable( $context );
435
+	public function get_editable($context = 'view') {
436
+		return $this->get_is_editable($context);
437 437
     }
438 438
 
439 439
     /**
@@ -443,8 +443,8 @@  discard block
 block discarded – undo
443 443
 	 * @param  string $context View or edit context.
444 444
 	 * @return int
445 445
 	 */
446
-	public function get_is_dynamic_pricing( $context = 'view' ) {
447
-        return (int) $this->get_prop( 'is_dynamic_pricing', $context );
446
+	public function get_is_dynamic_pricing($context = 'view') {
447
+        return (int) $this->get_prop('is_dynamic_pricing', $context);
448 448
     }
449 449
 
450 450
     /**
@@ -454,8 +454,8 @@  discard block
 block discarded – undo
454 454
 	 * @param  string $context View or edit context.
455 455
 	 * @return float
456 456
 	 */
457
-	public function get_minimum_price( $context = 'view' ) {
458
-        return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
457
+	public function get_minimum_price($context = 'view') {
458
+        return wpinv_sanitize_amount($this->get_prop('minimum_price', $context));
459 459
     }
460 460
 
461 461
     /**
@@ -465,8 +465,8 @@  discard block
 block discarded – undo
465 465
      * @param  string $context View or edit context.
466 466
      * @return int
467 467
      */
468
-    public function get_is_multi_price_mode( $context = 'view' ) {
469
-        return (bool) $this->get_prop( 'is_multi_price_mode', $context );
468
+    public function get_is_multi_price_mode($context = 'view') {
469
+        return (bool) $this->get_prop('is_multi_price_mode', $context);
470 470
     }
471 471
 
472 472
     /**
@@ -487,8 +487,8 @@  discard block
 block discarded – undo
487 487
      * @param  string $context View or edit context.
488 488
      * @return int
489 489
      */
490
-    public function get_has_variable_pricing( $context = 'view' ) {
491
-        return (bool) $this->get_prop( 'has_variable_pricing', $context );
490
+    public function get_has_variable_pricing($context = 'view') {
491
+        return (bool) $this->get_prop('has_variable_pricing', $context);
492 492
     }
493 493
 
494 494
     /**
@@ -499,7 +499,7 @@  discard block
 block discarded – undo
499 499
      * @return int
500 500
      */
501 501
     public function has_variable_pricing() {
502
-        return $this->get_has_variable_pricing( 'view' );
502
+        return $this->get_has_variable_pricing('view');
503 503
     }
504 504
 
505 505
     /**
@@ -509,20 +509,20 @@  discard block
 block discarded – undo
509 509
      * @since 2.8.9
510 510
      * @return int              The Price ID to select by default
511 511
      */
512
-    public function get_default_price_id( $context = 'view' ) {
513
-        if ( ! $this->has_variable_pricing() ) {
512
+    public function get_default_price_id($context = 'view') {
513
+        if (!$this->has_variable_pricing()) {
514 514
             return false;
515 515
         }
516 516
 
517 517
         $prices = $this->get_variable_prices();
518 518
 
519
-        $default_price_id = (int) $this->get_prop( 'default_price_id', $context );
519
+        $default_price_id = (int) $this->get_prop('default_price_id', $context);
520 520
 
521
-        if ( '' === $default_price_id || ! isset( $prices[ $default_price_id ] ) ) {
522
-            $default_price_id = current( array_keys( $prices ) );
521
+        if ('' === $default_price_id || !isset($prices[$default_price_id])) {
522
+            $default_price_id = current(array_keys($prices));
523 523
         }
524 524
 
525
-        return  absint( $default_price_id );
525
+        return  absint($default_price_id);
526 526
     }
527 527
 
528 528
     /**
@@ -534,8 +534,8 @@  discard block
 block discarded – undo
534 534
     public function get_variable_prices() {
535 535
         $prices = array();
536 536
 
537
-        if ( true === $this->has_variable_pricing() ) {
538
-            $prices = $this->get_prop( 'variable_prices', 'view' );
537
+        if (true === $this->has_variable_pricing()) {
538
+            $prices = $this->get_prop('variable_prices', 'view');
539 539
         }
540 540
 
541 541
         return $prices;
@@ -548,8 +548,8 @@  discard block
 block discarded – undo
548 548
 	 * @param  string $context View or edit context.
549 549
 	 * @return int
550 550
 	 */
551
-	public function get_is_recurring( $context = 'view' ) {
552
-        return (int) $this->get_prop( 'is_recurring', $context );
551
+	public function get_is_recurring($context = 'view') {
552
+        return (int) $this->get_prop('is_recurring', $context);
553 553
 	}
554 554
 
555 555
 	/**
@@ -559,9 +559,9 @@  discard block
 block discarded – undo
559 559
 	 * @param  string $context View or edit context.
560 560
 	 * @return float
561 561
 	 */
562
-	public function get_recurring_price( $context = 'view' ) {
563
-		$price = $this->get_price( $context );
564
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
562
+	public function get_recurring_price($context = 'view') {
563
+		$price = $this->get_price($context);
564
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID));
565 565
 	}
566 566
 
567 567
 	/**
@@ -572,7 +572,7 @@  discard block
 block discarded – undo
572 572
 	 * @return string
573 573
 	 */
574 574
     public function get_the_recurring_price() {
575
-        return wpinv_price( $this->get_recurring_price() );
575
+        return wpinv_price($this->get_recurring_price());
576 576
 	}
577 577
 
578 578
 	/**
@@ -593,15 +593,15 @@  discard block
 block discarded – undo
593 593
 		$period   = $this->get_recurring_period();
594 594
 		$interval = $this->get_recurring_interval();
595 595
 
596
-		if ( $this->has_free_trial() ) {
596
+		if ($this->has_free_trial()) {
597 597
 			$period   = $this->get_trial_period();
598 598
 			$interval = $this->get_trial_interval();
599 599
 		}
600 600
 
601
-		$period       = $periods[ $period ];
602
-		$interval     = empty( $interval ) ? 1 : $interval;
603
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
604
-        return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
601
+		$period       = $periods[$period];
602
+		$interval     = empty($interval) ? 1 : $interval;
603
+		$next_renewal = strtotime("+$interval $period", current_time('timestamp'));
604
+        return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this);
605 605
     }
606 606
 
607 607
     /**
@@ -611,14 +611,14 @@  discard block
 block discarded – undo
611 611
 	 * @param  bool $full Return abbreviation or in full.
612 612
 	 * @return string
613 613
 	 */
614
-	public function get_recurring_period( $full = false ) {
615
-        $period = $this->get_prop( 'recurring_period', 'view' );
614
+	public function get_recurring_period($full = false) {
615
+        $period = $this->get_prop('recurring_period', 'view');
616 616
 
617
-        if ( $full && ! is_bool( $full ) ) {
617
+        if ($full && !is_bool($full)) {
618 618
             $full = false;
619 619
         }
620 620
 
621
-        return getpaid_sanitize_recurring_period( $period, $full );
621
+        return getpaid_sanitize_recurring_period($period, $full);
622 622
     }
623 623
 
624 624
     /**
@@ -628,9 +628,9 @@  discard block
 block discarded – undo
628 628
 	 * @param  string $context View or edit context.
629 629
 	 * @return int
630 630
 	 */
631
-	public function get_recurring_interval( $context = 'view' ) {
632
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
633
-		return max( 1, $interval );
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
     /**
@@ -640,8 +640,8 @@  discard block
 block discarded – undo
640 640
 	 * @param  string $context View or edit context.
641 641
 	 * @return int
642 642
 	 */
643
-	public function get_recurring_limit( $context = 'view' ) {
644
-        return (int) $this->get_prop( 'recurring_limit', $context );
643
+	public function get_recurring_limit($context = 'view') {
644
+        return (int) $this->get_prop('recurring_limit', $context);
645 645
     }
646 646
 
647 647
     /**
@@ -651,8 +651,8 @@  discard block
 block discarded – undo
651 651
 	 * @param  string $context View or edit context.
652 652
 	 * @return int
653 653
 	 */
654
-	public function get_is_free_trial( $context = 'view' ) {
655
-        return (int) $this->get_prop( 'is_free_trial', $context );
654
+	public function get_is_free_trial($context = 'view') {
655
+        return (int) $this->get_prop('is_free_trial', $context);
656 656
     }
657 657
 
658 658
     /**
@@ -662,8 +662,8 @@  discard block
 block discarded – undo
662 662
 	 * @param  string $context View or edit context.
663 663
 	 * @return int
664 664
 	 */
665
-	public function get_free_trial( $context = 'view' ) {
666
-        return $this->get_is_free_trial( $context );
665
+	public function get_free_trial($context = 'view') {
666
+        return $this->get_is_free_trial($context);
667 667
     }
668 668
 
669 669
     /**
@@ -673,14 +673,14 @@  discard block
 block discarded – undo
673 673
 	 * @param  bool $full Return abbreviation or in full.
674 674
 	 * @return string
675 675
 	 */
676
-	public function get_trial_period( $full = false ) {
677
-        $period = $this->get_prop( 'trial_period', 'view' );
676
+	public function get_trial_period($full = false) {
677
+        $period = $this->get_prop('trial_period', 'view');
678 678
 
679
-        if ( $full && ! is_bool( $full ) ) {
679
+        if ($full && !is_bool($full)) {
680 680
             $full = false;
681 681
         }
682 682
 
683
-        return getpaid_sanitize_recurring_period( $period, $full );
683
+        return getpaid_sanitize_recurring_period($period, $full);
684 684
     }
685 685
 
686 686
     /**
@@ -690,8 +690,8 @@  discard block
 block discarded – undo
690 690
 	 * @param  string $context View or edit context.
691 691
 	 * @return int
692 692
 	 */
693
-	public function get_trial_interval( $context = 'view' ) {
694
-        return (int) $this->get_prop( 'trial_interval', $context );
693
+	public function get_trial_interval($context = 'view') {
694
+        return (int) $this->get_prop('trial_interval', $context);
695 695
 	}
696 696
 
697 697
 	/**
@@ -701,7 +701,7 @@  discard block
 block discarded – undo
701 701
 	 * @return string
702 702
 	 */
703 703
 	public function get_edit_url() {
704
-        return get_edit_post_link( $this->get_id(), 'edit' );
704
+        return get_edit_post_link($this->get_id(), 'edit');
705 705
 	}
706 706
 
707 707
 	/**
@@ -715,35 +715,35 @@  discard block
 block discarded – undo
715 715
 	 * @since 1.0.15
716 716
 	 * @return int
717 717
 	 */
718
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
718
+	public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') {
719 719
 
720 720
 		// Trim the value.
721
-		$value = sanitize_text_field( $value );
722
-		if ( empty( $value ) ) {
721
+		$value = sanitize_text_field($value);
722
+		if (empty($value)) {
723 723
 			return 0;
724 724
 		}
725 725
 
726 726
         // Valid fields.
727
-        $fields = array( 'custom_id', 'name', 'slug' );
727
+        $fields = array('custom_id', 'name', 'slug');
728 728
 
729 729
 		// Ensure a field has been passed.
730
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
730
+		if (empty($field) || !in_array($field, $fields)) {
731 731
 			return 0;
732 732
 		}
733 733
 
734
-		if ( $field == 'name' ) {
734
+		if ($field == 'name') {
735 735
 			$field = 'slug';
736 736
 		}
737 737
 
738 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 ) ) {
739
+		$item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids");
740
+		if (!empty($item_id)) {
741 741
 			return $item_id;
742 742
 		}
743 743
 
744 744
 		// Fetch from the db.
745 745
 		$items = array();
746
-		if ( $field == 'slug' ) {
746
+		if ($field == 'slug') {
747 747
 			$items = get_posts(
748 748
 				array(
749 749
 					'post_type'      => 'wpi_item',
@@ -754,7 +754,7 @@  discard block
 block discarded – undo
754 754
 			);
755 755
 		}
756 756
 
757
-		if ( $field == 'custom_id' ) {
757
+		if ($field == 'custom_id') {
758 758
 			$items = get_posts(
759 759
 				array(
760 760
 					'post_type'      => 'wpi_item',
@@ -774,12 +774,12 @@  discard block
 block discarded – undo
774 774
 			);
775 775
 		}
776 776
 
777
-		if ( empty( $items ) ) {
777
+		if (empty($items)) {
778 778
 			return 0;
779 779
 		}
780 780
 
781 781
 		// Update the cache with our data
782
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
782
+		wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids");
783 783
 
784 784
 		return $items[0]->ID;
785 785
     }
@@ -787,19 +787,19 @@  discard block
 block discarded – undo
787 787
     /**
788 788
      * Margic method for retrieving a property.
789 789
      */
790
-    public function __get( $key ) {
790
+    public function __get($key) {
791 791
 
792 792
         // Check if we have a helper method for that.
793
-        if ( method_exists( $this, 'get_' . $key ) ) {
794
-            return call_user_func( array( $this, 'get_' . $key ) );
793
+        if (method_exists($this, 'get_' . $key)) {
794
+            return call_user_func(array($this, 'get_' . $key));
795 795
         }
796 796
 
797 797
         // Check if the key is in the associated $post object.
798
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
798
+        if (!empty($this->post) && isset($this->post->$key)) {
799 799
             return $this->post->$key;
800 800
         }
801 801
 
802
-        return $this->get_prop( $key );
802
+        return $this->get_prop($key);
803 803
     }
804 804
 
805 805
     /*
@@ -817,11 +817,11 @@  discard block
 block discarded – undo
817 817
 	 *
818 818
 	 * @since 1.0.19
819 819
 	 */
820
-	public function set_parent_id( $value ) {
821
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
820
+	public function set_parent_id($value) {
821
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
822 822
 			return;
823 823
 		}
824
-		$this->set_prop( 'parent_id', absint( $value ) );
824
+		$this->set_prop('parent_id', absint($value));
825 825
 	}
826 826
 
827 827
     /**
@@ -831,10 +831,10 @@  discard block
 block discarded – undo
831 831
 	 * @param  string $status New status.
832 832
 	 * @return array details of change.
833 833
 	 */
834
-	public function set_status( $status ) {
834
+	public function set_status($status) {
835 835
         $old_status = $this->get_status();
836 836
 
837
-        $this->set_prop( 'status', $status );
837
+        $this->set_prop('status', $status);
838 838
 
839 839
 		return array(
840 840
 			'from' => $old_status,
@@ -847,8 +847,8 @@  discard block
 block discarded – undo
847 847
 	 *
848 848
 	 * @since 1.0.19
849 849
 	 */
850
-	public function set_version( $value ) {
851
-		$this->set_prop( 'version', $value );
850
+	public function set_version($value) {
851
+		$this->set_prop('version', $value);
852 852
     }
853 853
 
854 854
     /**
@@ -858,11 +858,11 @@  discard block
 block discarded – undo
858 858
 	 * @param string $value Value to set.
859 859
      * @return bool Whether or not the date was set.
860 860
 	 */
861
-	public function set_date_created( $value ) {
862
-        $date = strtotime( $value );
861
+	public function set_date_created($value) {
862
+        $date = strtotime($value);
863 863
 
864
-        if ( $date ) {
865
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
864
+        if ($date) {
865
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
866 866
             return true;
867 867
         }
868 868
 
@@ -876,11 +876,11 @@  discard block
 block discarded – undo
876 876
 	 * @param string $value Value to set.
877 877
      * @return bool Whether or not the date was set.
878 878
 	 */
879
-	public function set_date_modified( $value ) {
880
-        $date = strtotime( $value );
879
+	public function set_date_modified($value) {
880
+        $date = strtotime($value);
881 881
 
882
-        if ( $date ) {
883
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
882
+        if ($date) {
883
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
884 884
             return true;
885 885
         }
886 886
 
@@ -893,9 +893,9 @@  discard block
 block discarded – undo
893 893
 	 * @since 1.0.19
894 894
 	 * @param  string $value New name.
895 895
 	 */
896
-	public function set_name( $value ) {
897
-        $name = sanitize_text_field( $value );
898
-		$this->set_prop( 'name', $name );
896
+	public function set_name($value) {
897
+        $name = sanitize_text_field($value);
898
+		$this->set_prop('name', $name);
899 899
     }
900 900
 
901 901
     /**
@@ -904,8 +904,8 @@  discard block
 block discarded – undo
904 904
 	 * @since 1.0.19
905 905
 	 * @param  string $value New name.
906 906
 	 */
907
-	public function set_title( $value ) {
908
-		$this->set_name( $value );
907
+	public function set_title($value) {
908
+		$this->set_name($value);
909 909
     }
910 910
 
911 911
     /**
@@ -914,9 +914,9 @@  discard block
 block discarded – undo
914 914
 	 * @since 1.0.19
915 915
 	 * @param  string $value New description.
916 916
 	 */
917
-	public function set_description( $value ) {
918
-		$description = wp_kses_post( wp_unslash( $value ) );
919
-		return $this->set_prop( 'description', $description );
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
     /**
@@ -925,8 +925,8 @@  discard block
 block discarded – undo
925 925
 	 * @since 1.0.19
926 926
 	 * @param  string $value New description.
927 927
 	 */
928
-	public function set_excerpt( $value ) {
929
-		$this->set_description( $value );
928
+	public function set_excerpt($value) {
929
+		$this->set_description($value);
930 930
     }
931 931
 
932 932
     /**
@@ -935,8 +935,8 @@  discard block
 block discarded – undo
935 935
 	 * @since 1.0.19
936 936
 	 * @param  string $value New description.
937 937
 	 */
938
-	public function set_summary( $value ) {
939
-		$this->set_description( $value );
938
+	public function set_summary($value) {
939
+		$this->set_description($value);
940 940
     }
941 941
 
942 942
     /**
@@ -945,8 +945,8 @@  discard block
 block discarded – undo
945 945
 	 * @since 1.0.19
946 946
 	 * @param  int $value New author.
947 947
 	 */
948
-	public function set_author( $value ) {
949
-		$this->set_prop( 'author', (int) $value );
948
+	public function set_author($value) {
949
+		$this->set_prop('author', (int) $value);
950 950
 	}
951 951
 
952 952
 	/**
@@ -955,8 +955,8 @@  discard block
 block discarded – undo
955 955
 	 * @since 1.0.19
956 956
 	 * @param  int $value New author.
957 957
 	 */
958
-	public function set_owner( $value ) {
959
-		$this->set_author( $value );
958
+	public function set_owner($value) {
959
+		$this->set_author($value);
960 960
     }
961 961
 
962 962
     /**
@@ -965,8 +965,8 @@  discard block
 block discarded – undo
965 965
 	 * @since 1.0.19
966 966
 	 * @param  float $value New price.
967 967
 	 */
968
-	public function set_price( $value ) {
969
-        $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
968
+	public function set_price($value) {
969
+        $this->set_prop('price', (float) wpinv_sanitize_amount($value));
970 970
     }
971 971
 
972 972
     /**
@@ -975,8 +975,8 @@  discard block
 block discarded – undo
975 975
 	 * @since 1.0.19
976 976
 	 * @param  string $value new rule.
977 977
 	 */
978
-	public function set_vat_rule( $value ) {
979
-        $this->set_prop( 'vat_rule', $value );
978
+	public function set_vat_rule($value) {
979
+        $this->set_prop('vat_rule', $value);
980 980
     }
981 981
 
982 982
     /**
@@ -985,8 +985,8 @@  discard block
 block discarded – undo
985 985
 	 * @since 1.0.19
986 986
 	 * @param  string $value new class.
987 987
 	 */
988
-	public function set_vat_class( $value ) {
989
-        $this->set_prop( 'vat_class', $value );
988
+	public function set_vat_class($value) {
989
+        $this->set_prop('vat_class', $value);
990 990
     }
991 991
 
992 992
     /**
@@ -996,13 +996,13 @@  discard block
 block discarded – undo
996 996
 	 * @param  string $value new item type.
997 997
 	 * @return string
998 998
 	 */
999
-	public function set_type( $value ) {
999
+	public function set_type($value) {
1000 1000
 
1001
-        if ( empty( $value ) ) {
1001
+        if (empty($value)) {
1002 1002
             $value = 'custom';
1003 1003
         }
1004 1004
 
1005
-        $this->set_prop( 'type', $value );
1005
+        $this->set_prop('type', $value);
1006 1006
     }
1007 1007
 
1008 1008
     /**
@@ -1011,8 +1011,8 @@  discard block
 block discarded – undo
1011 1011
 	 * @since 1.0.19
1012 1012
 	 * @param  string $value new custom id.
1013 1013
 	 */
1014
-	public function set_custom_id( $value ) {
1015
-        $this->set_prop( 'custom_id', $value );
1014
+	public function set_custom_id($value) {
1015
+        $this->set_prop('custom_id', $value);
1016 1016
     }
1017 1017
 
1018 1018
     /**
@@ -1021,8 +1021,8 @@  discard block
 block discarded – undo
1021 1021
 	 * @since 1.0.19
1022 1022
 	 * @param  string $value new custom name.
1023 1023
 	 */
1024
-	public function set_custom_name( $value ) {
1025
-        $this->set_prop( 'custom_name', $value );
1024
+	public function set_custom_name($value) {
1025
+        $this->set_prop('custom_name', $value);
1026 1026
     }
1027 1027
 
1028 1028
     /**
@@ -1031,8 +1031,8 @@  discard block
 block discarded – undo
1031 1031
 	 * @since 1.0.19
1032 1032
 	 * @param  string $value new custom singular name.
1033 1033
 	 */
1034
-	public function set_custom_singular_name( $value ) {
1035
-        $this->set_prop( 'custom_singular_name', $value );
1034
+	public function set_custom_singular_name($value) {
1035
+        $this->set_prop('custom_singular_name', $value);
1036 1036
     }
1037 1037
 
1038 1038
     /**
@@ -1041,8 +1041,8 @@  discard block
 block discarded – undo
1041 1041
 	 * @since 1.0.19
1042 1042
 	 * @param  int|bool $value whether or not the item is editable.
1043 1043
 	 */
1044
-	public function set_is_editable( $value ) {
1045
-		$this->set_prop( 'is_editable', (int) $value );
1044
+	public function set_is_editable($value) {
1045
+		$this->set_prop('is_editable', (int) $value);
1046 1046
     }
1047 1047
 
1048 1048
     /**
@@ -1051,8 +1051,8 @@  discard block
 block discarded – undo
1051 1051
 	 * @since 1.0.19
1052 1052
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1053 1053
 	 */
1054
-	public function set_is_dynamic_pricing( $value ) {
1055
-        $this->set_prop( 'is_dynamic_pricing', (int) $value );
1054
+	public function set_is_dynamic_pricing($value) {
1055
+        $this->set_prop('is_dynamic_pricing', (int) $value);
1056 1056
     }
1057 1057
 
1058 1058
     /**
@@ -1061,8 +1061,8 @@  discard block
 block discarded – undo
1061 1061
 	 * @since 1.0.19
1062 1062
 	 * @param  float $value minimum price.
1063 1063
 	 */
1064
-	public function set_minimum_price( $value ) {
1065
-        $this->set_prop( 'minimum_price', (float) wpinv_sanitize_amount( $value ) );
1064
+	public function set_minimum_price($value) {
1065
+        $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value));
1066 1066
     }
1067 1067
 
1068 1068
     /**
@@ -1071,8 +1071,8 @@  discard block
 block discarded – undo
1071 1071
 	 * @since 1.0.19
1072 1072
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1073 1073
 	 */
1074
-	public function set_is_multi_price_mode( $value ) {
1075
-        $this->set_prop( 'is_multi_price_mode', (int) $value );
1074
+	public function set_is_multi_price_mode($value) {
1075
+        $this->set_prop('is_multi_price_mode', (int) $value);
1076 1076
     }
1077 1077
 
1078 1078
     /**
@@ -1081,8 +1081,8 @@  discard block
 block discarded – undo
1081 1081
 	 * @since 1.0.19
1082 1082
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1083 1083
 	 */
1084
-	public function set_has_variable_pricing( $value ) {
1085
-        $this->set_prop( 'has_variable_pricing', (int) $value );
1084
+	public function set_has_variable_pricing($value) {
1085
+        $this->set_prop('has_variable_pricing', (int) $value);
1086 1086
     }
1087 1087
 
1088 1088
     /**
@@ -1091,8 +1091,8 @@  discard block
 block discarded – undo
1091 1091
 	 * @since 1.0.19
1092 1092
 	 * @param  int $value default price ID.
1093 1093
 	 */
1094
-	public function set_default_price_id( $value ) {
1095
-        return $this->set_prop( 'default_price_id', (int) $value );
1094
+	public function set_default_price_id($value) {
1095
+        return $this->set_prop('default_price_id', (int) $value);
1096 1096
     }
1097 1097
 
1098 1098
     /**
@@ -1101,23 +1101,23 @@  discard block
 block discarded – undo
1101 1101
 	 * @since 1.0.19
1102 1102
 	 * @param  int $prices variable prices.
1103 1103
 	 */
1104
-	public function set_variable_prices( $prices ) {
1105
-        if ( ! is_array( $prices ) ) {
1104
+	public function set_variable_prices($prices) {
1105
+        if (!is_array($prices)) {
1106 1106
             $prices = array();
1107 1107
         }
1108 1108
 
1109
-        foreach ( $prices as $id => $price ) {
1110
-            if ( empty( $price['amount'] ) && empty( $price['name'] ) ) {
1111
-                unset( $prices[ $id ] );
1109
+        foreach ($prices as $id => $price) {
1110
+            if (empty($price['amount']) && empty($price['name'])) {
1111
+                unset($prices[$id]);
1112 1112
                 continue;
1113
-            } elseif ( empty( $price['amount'] ) ) {
1113
+            } elseif (empty($price['amount'])) {
1114 1114
                 $price['amount'] = 0;
1115 1115
             }
1116 1116
 
1117
-            $prices[ $id ]['amount'] = getpaid_standardize_amount( $price['amount'] );
1117
+            $prices[$id]['amount'] = getpaid_standardize_amount($price['amount']);
1118 1118
         }
1119 1119
 
1120
-        return $this->set_prop( 'variable_prices', $prices );
1120
+        return $this->set_prop('variable_prices', $prices);
1121 1121
     }
1122 1122
 
1123 1123
     /**
@@ -1126,8 +1126,8 @@  discard block
 block discarded – undo
1126 1126
 	 * @since 1.0.19
1127 1127
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
1128 1128
 	 */
1129
-	public function set_is_recurring( $value ) {
1130
-        $this->set_prop( 'is_recurring', (int) $value );
1129
+	public function set_is_recurring($value) {
1130
+        $this->set_prop('is_recurring', (int) $value);
1131 1131
     }
1132 1132
 
1133 1133
     /**
@@ -1136,8 +1136,8 @@  discard block
 block discarded – undo
1136 1136
 	 * @since 1.0.19
1137 1137
 	 * @param  string $value new period.
1138 1138
 	 */
1139
-	public function set_recurring_period( $value ) {
1140
-        $this->set_prop( 'recurring_period', $value );
1139
+	public function set_recurring_period($value) {
1140
+        $this->set_prop('recurring_period', $value);
1141 1141
     }
1142 1142
 
1143 1143
     /**
@@ -1146,8 +1146,8 @@  discard block
 block discarded – undo
1146 1146
 	 * @since 1.0.19
1147 1147
 	 * @param  int $value recurring interval.
1148 1148
 	 */
1149
-	public function set_recurring_interval( $value ) {
1150
-        return $this->set_prop( 'recurring_interval', (int) $value );
1149
+	public function set_recurring_interval($value) {
1150
+        return $this->set_prop('recurring_interval', (int) $value);
1151 1151
     }
1152 1152
 
1153 1153
     /**
@@ -1156,8 +1156,8 @@  discard block
 block discarded – undo
1156 1156
 	 * @param  int $value The recurring limit.
1157 1157
 	 * @return int
1158 1158
 	 */
1159
-	public function set_recurring_limit( $value ) {
1160
-        $this->set_prop( 'recurring_limit', (int) $value );
1159
+	public function set_recurring_limit($value) {
1160
+        $this->set_prop('recurring_limit', (int) $value);
1161 1161
     }
1162 1162
 
1163 1163
     /**
@@ -1166,8 +1166,8 @@  discard block
 block discarded – undo
1166 1166
 	 * @since 1.0.19
1167 1167
 	 * @param  int|bool $value whether or not it has a free trial.
1168 1168
 	 */
1169
-	public function set_is_free_trial( $value ) {
1170
-        $this->set_prop( 'is_free_trial', (int) $value );
1169
+	public function set_is_free_trial($value) {
1170
+        $this->set_prop('is_free_trial', (int) $value);
1171 1171
     }
1172 1172
 
1173 1173
     /**
@@ -1176,8 +1176,8 @@  discard block
 block discarded – undo
1176 1176
 	 * @since 1.0.19
1177 1177
 	 * @param  string $value trial period.
1178 1178
 	 */
1179
-	public function set_trial_period( $value ) {
1180
-        $this->set_prop( 'trial_period', $value );
1179
+	public function set_trial_period($value) {
1180
+        $this->set_prop('trial_period', $value);
1181 1181
     }
1182 1182
 
1183 1183
     /**
@@ -1186,8 +1186,8 @@  discard block
 block discarded – undo
1186 1186
 	 * @since 1.0.19
1187 1187
 	 * @param  int $value trial interval.
1188 1188
 	 */
1189
-	public function set_trial_interval( $value ) {
1190
-        $this->set_prop( 'trial_interval', $value );
1189
+	public function set_trial_interval($value) {
1190
+        $this->set_prop('trial_interval', $value);
1191 1191
     }
1192 1192
 
1193 1193
     /**
@@ -1196,11 +1196,11 @@  discard block
 block discarded – undo
1196 1196
      * @deprecated
1197 1197
 	 * @return int item id
1198 1198
      */
1199
-    public function create( $data = array() ) {
1199
+    public function create($data = array()) {
1200 1200
 
1201 1201
 		// Set the properties.
1202
-		if ( is_array( $data ) ) {
1203
-			$this->set_props( $data );
1202
+		if (is_array($data)) {
1203
+			$this->set_props($data);
1204 1204
 		}
1205 1205
 
1206 1206
 		// Save the item.
@@ -1213,8 +1213,8 @@  discard block
 block discarded – undo
1213 1213
      * @deprecated
1214 1214
 	 * @return int item id
1215 1215
      */
1216
-    public function update( $data = array() ) {
1217
-        return $this->create( $data );
1216
+    public function update($data = array()) {
1217
+        return $this->create($data);
1218 1218
     }
1219 1219
 
1220 1220
     /*
@@ -1254,7 +1254,7 @@  discard block
 block discarded – undo
1254 1254
 	 */
1255 1255
     public function has_free_trial() {
1256 1256
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1257
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1257
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
1258 1258
     }
1259 1259
 
1260 1260
     /**
@@ -1264,8 +1264,8 @@  discard block
 block discarded – undo
1264 1264
 	 * @return bool
1265 1265
 	 */
1266 1266
     public function is_free() {
1267
-        $is_free   = $this->get_price() == 0;
1268
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1267
+        $is_free = $this->get_price() == 0;
1268
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this);
1269 1269
     }
1270 1270
 
1271 1271
     /**
@@ -1274,9 +1274,9 @@  discard block
 block discarded – undo
1274 1274
 	 * @param array|string $status Status to check.
1275 1275
 	 * @return bool
1276 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 );
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
     /**
@@ -1285,9 +1285,9 @@  discard block
 block discarded – undo
1285 1285
 	 * @param array|string $type Type to check.
1286 1286
 	 * @return bool
1287 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 );
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 1291
 	}
1292 1292
 
1293 1293
     /**
@@ -1298,7 +1298,7 @@  discard block
 block discarded – undo
1298 1298
 	 */
1299 1299
     public function is_editable() {
1300 1300
         $is_editable = $this->get_is_editable();
1301
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1301
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this);
1302 1302
 	}
1303 1303
 
1304 1304
 	/**
@@ -1317,11 +1317,11 @@  discard block
 block discarded – undo
1317 1317
     public function can_purchase() {
1318 1318
         $can_purchase = $this->exists();
1319 1319
 
1320
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
1320
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
1321 1321
             $can_purchase = false;
1322 1322
         }
1323 1323
 
1324
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
1324
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
1325 1325
     }
1326 1326
 
1327 1327
     /**
@@ -1331,6 +1331,6 @@  discard block
 block discarded – undo
1331 1331
 	 * @return bool
1332 1332
 	 */
1333 1333
     public function supports_dynamic_pricing() {
1334
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1334
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
1335 1335
     }
1336 1336
 }
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/payments/class-getpaid-form-item.php 2 patches
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.
Spacing   +65 added lines, -65 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -102,9 +102,9 @@  discard block
 block discarded – undo
102 102
 	 * @param  string $context View or edit context.
103 103
 	 * @return string
104 104
 	 */
105
-	public function get_name( $context = 'view' ) {
106
-		$name = parent::get_name( $context );
107
-		return $name . wpinv_get_item_suffix( $this );
105
+	public function get_name($context = 'view') {
106
+		$name = parent::get_name($context);
107
+		return $name . wpinv_get_item_suffix($this);
108 108
 	}
109 109
 
110 110
 	/**
@@ -114,8 +114,8 @@  discard block
 block discarded – undo
114 114
 	 * @param  string $context View or edit context.
115 115
 	 * @return string
116 116
 	 */
117
-	public function get_raw_name( $context = 'view' ) {
118
-		return parent::get_name( $context );
117
+	public function get_raw_name($context = 'view') {
118
+		return parent::get_name($context);
119 119
 	}
120 120
 
121 121
 	/**
@@ -125,13 +125,13 @@  discard block
 block discarded – undo
125 125
 	 * @param  string $context View or edit context.
126 126
 	 * @return string
127 127
 	 */
128
-	public function get_description( $context = 'view' ) {
128
+	public function get_description($context = 'view') {
129 129
 
130
-		if ( isset( $this->custom_description ) ) {
130
+		if (isset($this->custom_description)) {
131 131
 			return $this->custom_description;
132 132
 		}
133 133
 
134
-		return parent::get_description( $context );
134
+		return parent::get_description($context);
135 135
 	}
136 136
 
137 137
 	/**
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 	 * @param  string $context View or edit context.
142 142
 	 * @return float
143 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 );
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 146
 	}
147 147
 
148 148
 	/**
@@ -152,10 +152,10 @@  discard block
 block discarded – undo
152 152
 	 * @param  string $context View or edit context.
153 153
 	 * @return float
154 154
 	 */
155
-	public function get_recurring_sub_total( $context = 'view' ) {
155
+	public function get_recurring_sub_total($context = 'view') {
156 156
 
157
-		if ( $this->is_recurring() ) {
158
-			return $this->get_quantity( $context ) * $this->get_price( $context );
157
+		if ($this->is_recurring()) {
158
+			return $this->get_quantity($context) * $this->get_price($context);
159 159
 		}
160 160
 
161 161
 		return 0;
@@ -164,8 +164,8 @@  discard block
 block discarded – undo
164 164
 	/**
165 165
 	 * @deprecated
166 166
 	 */
167
-	public function get_qantity( $context = 'view' ) {
168
-		return $this->get_quantity( $context );
167
+	public function get_qantity($context = 'view') {
168
+		return $this->get_quantity($context);
169 169
 	}
170 170
 
171 171
 	/**
@@ -175,11 +175,11 @@  discard block
 block discarded – undo
175 175
 	 * @param  string $context View or edit context.
176 176
 	 * @return float
177 177
 	 */
178
-	public function get_quantity( $context = 'view' ) {
178
+	public function get_quantity($context = 'view') {
179 179
 		$quantity = (float) $this->quantity;
180 180
 
181
-		if ( 'view' === $context ) {
182
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
181
+		if ('view' === $context) {
182
+			return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this);
183 183
 		}
184 184
 
185 185
 		return $quantity;
@@ -192,11 +192,11 @@  discard block
 block discarded – undo
192 192
 	 * @param  string $context View or edit context.
193 193
 	 * @return meta
194 194
 	 */
195
-	public function get_item_meta( $context = 'view' ) {
195
+	public function get_item_meta($context = 'view') {
196 196
 		$meta = $this->meta;
197 197
 
198
-		if ( 'view' === $context ) {
199
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
198
+		if ('view' === $context) {
199
+			return apply_filters('getpaid_payment_form_item_meta', $meta, $this);
200 200
 		}
201 201
 
202 202
 		return $meta;
@@ -209,11 +209,11 @@  discard block
 block discarded – undo
209 209
 	 * @param  string $context View or edit context.
210 210
 	 * @return bool
211 211
 	 */
212
-	public function get_allow_quantities( $context = 'view' ) {
212
+	public function get_allow_quantities($context = 'view') {
213 213
 		$allow_quantities = (bool) $this->allow_quantities;
214 214
 
215
-		if ( 'view' === $context ) {
216
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
215
+		if ('view' === $context) {
216
+			return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this);
217 217
 		}
218 218
 
219 219
 		return $allow_quantities;
@@ -226,11 +226,11 @@  discard block
 block discarded – undo
226 226
 	 * @param  string $context View or edit context.
227 227
 	 * @return bool
228 228
 	 */
229
-	public function get_is_required( $context = 'view' ) {
229
+	public function get_is_required($context = 'view') {
230 230
 		$is_required = (bool) $this->is_required;
231 231
 
232
-		if ( 'view' === $context ) {
233
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
232
+		if ('view' === $context) {
233
+			return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this);
234 234
 		}
235 235
 
236 236
 		return $is_required;
@@ -243,11 +243,11 @@  discard block
 block discarded – undo
243 243
 	 * @param  string $context View or edit context.
244 244
 	 * @return int
245 245
 	 */
246
-	public function get_price_id( $context = 'view' ) {
246
+	public function get_price_id($context = 'view') {
247 247
 		$price_id = (int) $this->price_id;
248 248
 
249
-		if ( 'view' === $context ) {
250
-			return apply_filters( 'getpaid_payment_form_item_price_id', $price_id, $this );
249
+		if ('view' === $context) {
250
+			return apply_filters('getpaid_payment_form_item_price_id', $price_id, $this);
251 251
 		}
252 252
 
253 253
 		return $price_id;
@@ -259,11 +259,11 @@  discard block
 block discarded – undo
259 259
 	 * @since 1.0.19
260 260
 	 * @return array
261 261
 	 */
262
-	public function prepare_data_for_use( $required = null ) {
262
+	public function prepare_data_for_use($required = null) {
263 263
 
264
-		$required = is_null( $required ) ? $this->is_required() : $required;
264
+		$required = is_null($required) ? $this->is_required() : $required;
265 265
 		return array(
266
-			'title'            => wp_strip_all_tags( $this->get_name() ),
266
+			'title'            => wp_strip_all_tags($this->get_name()),
267 267
 			'id'               => $this->get_id(),
268 268
 			'price'            => $this->get_price(),
269 269
 			'recurring'        => $this->is_recurring(),
@@ -280,30 +280,30 @@  discard block
 block discarded – undo
280 280
 	 * @since 1.0.19
281 281
 	 * @return array
282 282
 	 */
283
-	public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
283
+	public function prepare_data_for_invoice_edit_ajax($currency = '', $is_renewal = false) {
284 284
 
285
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
285
+		$description = getpaid_item_recurring_price_help_text($this, $currency);
286 286
 
287
-		if ( $description ) {
287
+		if ($description) {
288 288
 			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
289 289
 		}
290 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();
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 293
 		return array(
294 294
 			'id'     => $this->get_id(),
295 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 ),
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 301
 			),
302 302
 			'inputs' => array(
303 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() ),
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 307
 				'item-price'       => $price,
308 308
 			),
309 309
 		);
@@ -320,16 +320,16 @@  discard block
 block discarded – undo
320 320
 		return array(
321 321
 			'post_id'          => $this->invoice_id,
322 322
 			'item_id'          => $this->get_id(),
323
-			'item_name'        => sanitize_text_field( $this->get_raw_name( 'edit' ) ),
324
-			'item_description' => $this->get_description( 'edit' ),
323
+			'item_name'        => sanitize_text_field($this->get_raw_name('edit')),
324
+			'item_description' => $this->get_description('edit'),
325 325
 			'tax'              => $this->item_tax,
326
-			'item_price'       => $this->get_price( 'edit' ),
327
-			'quantity'         => (float) $this->get_quantity( 'edit' ),
326
+			'item_price'       => $this->get_price('edit'),
327
+			'quantity'         => (float) $this->get_quantity('edit'),
328 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' ),
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 333
 		);
334 334
 	}
335 335
 
@@ -349,9 +349,9 @@  discard block
 block discarded – undo
349 349
 	 * @since 1.0.19
350 350
 	 * @param  float $quantity The item quantity.
351 351
 	 */
352
-	public function set_quantity( $quantity ) {
352
+	public function set_quantity($quantity) {
353 353
 
354
-		if ( ! is_numeric( $quantity ) ) {
354
+		if (!is_numeric($quantity)) {
355 355
 			$quantity = 1;
356 356
 		}
357 357
 
@@ -364,9 +364,9 @@  discard block
 block discarded – undo
364 364
 	 * @since 1.0.19
365 365
 	 * @param  float $price_id The item price ID.
366 366
 	 */
367
-	public function set_price_id( $price_id ) {
367
+	public function set_price_id($price_id) {
368 368
 
369
-		if ( ! is_numeric( $price_id ) ) {
369
+		if (!is_numeric($price_id)) {
370 370
 			$price_id = $this->get_default_price_id();
371 371
 		}
372 372
 
@@ -379,8 +379,8 @@  discard block
 block discarded – undo
379 379
 	 * @since 1.0.19
380 380
 	 * @param  array $meta The item meta data.
381 381
 	 */
382
-	public function set_item_meta( $meta ) {
383
-		$this->meta = maybe_unserialize( $meta );
382
+	public function set_item_meta($meta) {
383
+		$this->meta = maybe_unserialize($meta);
384 384
 	}
385 385
 
386 386
 	/**
@@ -389,7 +389,7 @@  discard block
 block discarded – undo
389 389
 	 * @since 1.0.19
390 390
 	 * @param  bool $allow_quantities
391 391
 	 */
392
-	public function set_allow_quantities( $allow_quantities ) {
392
+	public function set_allow_quantities($allow_quantities) {
393 393
 		$this->allow_quantities = (bool) $allow_quantities;
394 394
 	}
395 395
 
@@ -399,7 +399,7 @@  discard block
 block discarded – undo
399 399
 	 * @since 1.0.19
400 400
 	 * @param  bool $is_required
401 401
 	 */
402
-	public function set_is_required( $is_required ) {
402
+	public function set_is_required($is_required) {
403 403
 		$this->is_required = (bool) $is_required;
404 404
 	}
405 405
 
@@ -409,7 +409,7 @@  discard block
 block discarded – undo
409 409
 	 * @since 1.0.19
410 410
 	 * @param  string $description
411 411
 	 */
412
-	public function set_custom_description( $description ) {
412
+	public function set_custom_description($description) {
413 413
 		$this->custom_description = $description;
414 414
 	}
415 415
 
@@ -418,7 +418,7 @@  discard block
 block discarded – undo
418 418
      *
419 419
 	 * @return int item id
420 420
      */
421
-    public function save( $data = array() ) {
421
+    public function save($data = array()) {
422 422
         return $this->get_id();
423 423
 	}
424 424
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-checkout.php 2 patches
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.
Spacing   +139 added lines, -139 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Main Checkout Class.
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
 	 *
23 23
 	 * @param GetPaid_Payment_Form_Submission $submission
24 24
 	 */
25
-	public function __construct( $submission ) {
25
+	public function __construct($submission) {
26 26
 		$this->payment_form_submission = $submission;
27 27
 	}
28 28
 
@@ -38,22 +38,22 @@  discard block
 block discarded – undo
38 38
 		// Prepare the invoice.
39 39
 		$items    = $this->get_submission_items();
40 40
 		$invoice  = $this->get_submission_invoice();
41
-		$invoice  = $this->process_submission_invoice( $invoice, $items );
41
+		$invoice  = $this->process_submission_invoice($invoice, $items);
42 42
 		$prepared = $this->prepare_submission_data_for_saving();
43 43
 
44
-		$this->prepare_billing_info( $invoice );
44
+		$this->prepare_billing_info($invoice);
45 45
 
46
-		$shipping   = $this->prepare_shipping_info( $invoice );
46
+		$shipping = $this->prepare_shipping_info($invoice);
47 47
 
48 48
 		// Save the invoice.
49
-		$invoice->set_is_viewed( true );
49
+		$invoice->set_is_viewed(true);
50 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 55
 		// Send to the gateway.
56
-		$this->post_process_submission( $invoice, $prepared, $shipping );
56
+		$this->post_process_submission($invoice, $prepared, $shipping);
57 57
 	}
58 58
 
59 59
 	/**
@@ -66,34 +66,34 @@  discard block
 block discarded – undo
66 66
 		$data       = $submission->get_data();
67 67
 
68 68
 		// Do we have an error?
69
-        if ( ! empty( $submission->last_error ) ) {
70
-			wp_send_json_error( $submission->last_error );
69
+        if (!empty($submission->last_error)) {
70
+			wp_send_json_error($submission->last_error);
71 71
         }
72 72
 
73 73
 		// We need a billing email.
74
-        if ( ! $submission->has_billing_email() ) {
75
-            wp_send_json_error( __( 'Provide a valid billing email.', 'invoicing' ) );
74
+        if (!$submission->has_billing_email()) {
75
+            wp_send_json_error(__('Provide a valid billing email.', 'invoicing'));
76 76
 		}
77 77
 
78 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' ) );
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 81
 		}
82 82
 
83 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' ) );
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 86
 		}
87 87
 
88 88
 		// Clear any existing errors.
89 89
 		wpinv_clear_errors();
90 90
 
91 91
 		// Allow themes and plugins to hook to errors
92
-		do_action( 'getpaid_checkout_error_checks', $submission );
92
+		do_action('getpaid_checkout_error_checks', $submission);
93 93
 
94 94
 		// Do we have any errors?
95
-        if ( wpinv_get_errors() ) {
96
-            wp_send_json_error( getpaid_get_errors_html() );
95
+        if (wpinv_get_errors()) {
96
+            wp_send_json_error(getpaid_get_errors_html());
97 97
 		}
98 98
 
99 99
 	} 
@@ -108,8 +108,8 @@  discard block
 block discarded – undo
108 108
 		$items = $this->payment_form_submission->get_items();
109 109
 
110 110
         // Ensure that we have items.
111
-        if ( empty( $items ) && ! $this->payment_form_submission->has_fees() ) {
112
-            wp_send_json_error( __( 'Please provide at least one item or amount.', 'invoicing' ) );
111
+        if (empty($items) && !$this->payment_form_submission->has_fees()) {
112
+            wp_send_json_error(__('Please provide at least one item or amount.', 'invoicing'));
113 113
 		}
114 114
 
115 115
 		return $items;
@@ -123,17 +123,17 @@  discard block
 block discarded – undo
123 123
 	protected function get_submission_invoice() {
124 124
 		$submission = $this->payment_form_submission;
125 125
 
126
-		if ( ! $submission->has_invoice() ) {
126
+		if (!$submission->has_invoice()) {
127 127
 			$invoice = new WPInv_Invoice();
128
-			$invoice->set_created_via( 'payment_form' );
128
+			$invoice->set_created_via('payment_form');
129 129
 			return $invoice;
130 130
         }
131 131
 
132 132
 		$invoice = $submission->get_invoice();
133 133
 
134 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' ) );
135
+		if ($invoice->is_paid() || $invoice->is_refunded()) {
136
+			wp_send_json_error(__('This invoice has already been paid for.', 'invoicing'));
137 137
 		}
138 138
 
139 139
 		return $invoice;
@@ -146,34 +146,34 @@  discard block
 block discarded – undo
146 146
 	 * @param GetPaid_Form_Item[] $items
147 147
 	 * @return WPInv_Invoice
148 148
 	 */
149
-	protected function process_submission_invoice( $invoice, $items ) {
149
+	protected function process_submission_invoice($invoice, $items) {
150 150
 
151 151
 		$submission = $this->payment_form_submission;
152 152
 
153 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
-        $invoice->set_items( $items );
159
-        $invoice->set_fees( $submission->get_fees() );
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() );
164
-
165
-		if ( $submission->has_shipping() ) {
166
-			$invoice->set_shipping( $submission->get_shipping() );
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
+        $invoice->set_items($items);
159
+        $invoice->set_fees($submission->get_fees());
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());
164
+
165
+		if ($submission->has_shipping()) {
166
+			$invoice->set_shipping($submission->get_shipping());
167 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() ) {
173
-            $invoice->set_discount_code( $submission->get_discount_code() );
172
+		if ($submission->has_discount_code()) {
173
+            $invoice->set_discount_code($submission->get_discount_code());
174 174
 		}
175 175
 
176
-		getpaid_maybe_add_default_address( $invoice );
176
+		getpaid_maybe_add_default_address($invoice);
177 177
 		return $invoice;
178 178
 	}
179 179
 
@@ -186,34 +186,34 @@  discard block
 block discarded – undo
186 186
 		$submission = $this->payment_form_submission;
187 187
 
188 188
 		// If this is an existing invoice...
189
-		if ( $submission->has_invoice() ) {
189
+		if ($submission->has_invoice()) {
190 190
 			return $submission->get_invoice()->get_user_id();
191 191
 		}
192 192
 
193 193
 		// (Maybe) create the user.
194 194
         $user = get_current_user_id();
195 195
 
196
-        if ( empty( $user ) ) {
197
-            $user = get_user_by( 'email', $submission->get_billing_email() );
196
+        if (empty($user)) {
197
+            $user = get_user_by('email', $submission->get_billing_email());
198 198
         }
199 199
 
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 ) );
203
-            $user = wpinv_create_user( $submission->get_billing_email(), $name );
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));
203
+            $user = wpinv_create_user($submission->get_billing_email(), $name);
204 204
 
205 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' );
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 209
 			}
210 210
 		}
211 211
 
212
-        if ( is_wp_error( $user ) ) {
213
-            wp_send_json_error( $user->get_error_message() );
212
+        if (is_wp_error($user)) {
213
+            wp_send_json_error($user->get_error_message());
214 214
         }
215 215
 
216
-        if ( is_numeric( $user ) ) {
216
+        if (is_numeric($user)) {
217 217
             return $user;
218 218
 		}
219 219
 
@@ -237,72 +237,72 @@  discard block
 block discarded – undo
237 237
 		);
238 238
 
239 239
         // Raw submission details.
240
-		$data     = $submission->get_data();
240
+		$data = $submission->get_data();
241 241
 
242 242
 		// Loop through the submitted details.
243
-        foreach ( $submission->get_payment_form()->get_elements() as $field ) {
243
+        foreach ($submission->get_payment_form()->get_elements() as $field) {
244 244
 
245 245
 			// Skip premade fields.
246
-            if ( ! empty( $field['premade'] ) ) {
246
+            if (!empty($field['premade'])) {
247 247
                 continue;
248 248
             }
249 249
 
250 250
 			// Ensure address is provided.
251
-			if ( 'address' === $field['type'] ) {
252
-                $address_type = isset( $field['address_type'] ) && 'shipping' === $field['address_type'] ? 'shipping' : 'billing';
251
+			if ('address' === $field['type']) {
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' ) );
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 258
 					}
259 259
                 }
260 260
             }
261 261
 
262 262
             // If it is required and not set, abort.
263
-            if ( ! $submission->is_required_field_set( $field ) ) {
264
-                wp_send_json_error( __( 'Please fill all required fields.', 'invoicing' ) );
263
+            if (!$submission->is_required_field_set($field)) {
264
+                wp_send_json_error(__('Please fill all required fields.', 'invoicing'));
265 265
             }
266 266
 
267 267
             // Handle misc fields.
268
-            if ( isset( $data[ $field['id'] ] ) ) {
268
+            if (isset($data[$field['id']])) {
269 269
 
270 270
 				// Uploads.
271
-				if ( 'file_upload' === $field['type'] ) {
272
-					$max_file_num = empty( $field['max_file_num'] ) ? 1 : absint( $field['max_file_num'] );
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' ) );
274
+					if (count($data[$field['id']]) > $max_file_num) {
275
+						wp_send_json_error(__('Maximum number of allowed files exceeded.', 'invoicing'));
276 276
 					}
277 277
 
278 278
 					$value = array();
279 279
 
280
-					foreach ( $data[ $field['id'] ] as $url => $name ) {
280
+					foreach ($data[$field['id']] as $url => $name) {
281 281
 						$value[] = sprintf(
282 282
 							'<a href="%s" target="_blank">%s</a>',
283
-							esc_url_raw( $url ),
284
-							esc_html( $name )
283
+							esc_url_raw($url),
284
+							esc_html($name)
285 285
 						);
286 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' );
290
+				} elseif ('checkbox' === $field['type']) {
291
+					$value = !empty($data[$field['id']]) ? __('Yes', 'invoicing') : __('No', 'invoicing');
292 292
 				} else {
293
-					$value = wp_kses_post( $data[ $field['id'] ] );
293
+					$value = wp_kses_post($data[$field['id']]);
294 294
 				}
295 295
 
296 296
                 $label = $field['id'];
297 297
 
298
-                if ( isset( $field['label'] ) ) {
298
+                if (isset($field['label'])) {
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 );
302
+				if (!empty($field['add_meta'])) {
303
+					$prepared['meta'][wpinv_clean($label)] = wp_kses_post_deep($value);
304 304
 				}
305
-				$prepared['all'][ wpinv_clean( $label ) ] = wp_kses_post_deep( $value );
305
+				$prepared['all'][wpinv_clean($label)] = wp_kses_post_deep($value);
306 306
 
307 307
             }
308 308
 		}
@@ -318,30 +318,30 @@  discard block
 block discarded – undo
318 318
 	 * @param WPInv_Invoice $invoice
319 319
 	 * @param string $type
320 320
      */
321
-    public function prepare_address_details( $invoice, $type = 'billing' ) {
321
+    public function prepare_address_details($invoice, $type = 'billing') {
322 322
 
323 323
 		$data     = $this->payment_form_submission->get_data();
324
-		$type     = sanitize_key( $type );
324
+		$type     = sanitize_key($type);
325 325
 		$address  = array();
326 326
 		$prepared = array();
327 327
 
328
-		if ( ! empty( $data[ $type ] ) ) {
329
-			$address = $data[ $type ];
328
+		if (!empty($data[$type])) {
329
+			$address = $data[$type];
330 330
 		}
331 331
 
332 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 );
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 338
 		}
339 339
 
340 340
 		// Filter address details.
341
-		$prepared = apply_filters( "getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice );
341
+		$prepared = apply_filters("getpaid_checkout_{$type}_address", $prepared, $this->payment_form_submission, $invoice);
342 342
 
343 343
 		// Remove non-whitelisted values.
344
-		return array_filter( $prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY );
344
+		return array_filter($prepared, 'getpaid_is_address_field_whitelisted', ARRAY_FILTER_USE_KEY);
345 345
 
346 346
 	}
347 347
 
@@ -351,12 +351,12 @@  discard block
 block discarded – undo
351 351
 	 * @return array
352 352
 	 * @param WPInv_Invoice $invoice
353 353
      */
354
-    protected function prepare_billing_info( &$invoice ) {
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 358
 		// Update the invoice with the billing details.
359
-		$invoice->set_props( $billing_address );
359
+		$invoice->set_props($billing_address);
360 360
 
361 361
 	}
362 362
 
@@ -366,15 +366,15 @@  discard block
 block discarded – undo
366 366
 	 * @return array
367 367
 	 * @param WPInv_Invoice $invoice
368 368
      */
369
-    protected function prepare_shipping_info( $invoice ) {
369
+    protected function prepare_shipping_info($invoice) {
370 370
 
371 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' );
373
+		if (empty($data['same-shipping-address'])) {
374
+			return $this->prepare_address_details($invoice, 'shipping');
375 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
 
@@ -385,45 +385,45 @@  discard block
 block discarded – undo
385 385
 	 * @param array $prepared_payment_form_data
386 386
 	 * @param array $shipping
387 387
 	 */
388
-	protected function post_process_submission( $invoice, $prepared_payment_form_data, $shipping ) {
388
+	protected function post_process_submission($invoice, $prepared_payment_form_data, $shipping) {
389 389
 
390 390
 		// Ensure the invoice exists.
391
-        if ( ! $invoice->exists() ) {
392
-            wp_send_json_error( __( 'An error occured while saving your invoice. Please try again.', 'invoicing' ) );
391
+        if (!$invoice->exists()) {
392
+            wp_send_json_error(__('An error occured while saving your invoice. Please try again.', 'invoicing'));
393 393
         }
394 394
 
395 395
 		// Save payment form data.
396
-		$prepared_payment_form_data = apply_filters( 'getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice );
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 ) ) {
396
+		$prepared_payment_form_data = apply_filters('getpaid_prepared_payment_form_data', $prepared_payment_form_data, $invoice);
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)) {
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'] );
401
+			if (!empty($prepared_payment_form_data['all'])) {
402
+				update_post_meta($invoice->get_id(), 'payment_form_data', $prepared_payment_form_data['all']);
403 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'] );
405
+			if (!empty($prepared_payment_form_data['meta'])) {
406
+				update_post_meta($invoice->get_id(), 'additional_meta_data', $prepared_payment_form_data['meta']);
407 407
 			}
408 408
 		}
409 409
 
410 410
 		// Save payment form data.
411
-		$shipping = apply_filters( 'getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission );
412
-        if ( ! empty( $shipping ) ) {
413
-            update_post_meta( $invoice->get_id(), 'shipping_address', $shipping );
411
+		$shipping = apply_filters('getpaid_checkout_shipping_details', $shipping, $this->payment_form_submission);
412
+        if (!empty($shipping)) {
413
+            update_post_meta($invoice->get_id(), 'shipping_address', $shipping);
414 414
 		}
415 415
 
416 416
 		// Backwards compatibility.
417
-        add_filter( 'wp_redirect', array( $this, 'send_redirect_response' ) );
417
+        add_filter('wp_redirect', array($this, 'send_redirect_response'));
418 418
 
419 419
 		try {
420
-			$this->process_payment( $invoice );
421
-		} catch ( Exception $e ) {
422
-			wpinv_set_error( 'payment_error', $e->getMessage() );
420
+			$this->process_payment($invoice);
421
+		} catch (Exception $e) {
422
+			wpinv_set_error('payment_error', $e->getMessage());
423 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
 
@@ -432,41 +432,41 @@  discard block
 block discarded – undo
432 432
 	 *
433 433
 	 * @param WPInv_Invoice $invoice
434 434
 	 */
435
-	protected function process_payment( $invoice ) {
435
+	protected function process_payment($invoice) {
436 436
 
437 437
 		// Clear any checkout errors.
438 438
 		wpinv_clear_errors();
439 439
 
440 440
 		// No need to send free invoices to the gateway.
441
-		if ( $invoice->is_free() ) {
442
-			$this->process_free_payment( $invoice );
441
+		if ($invoice->is_free()) {
442
+			$this->process_free_payment($invoice);
443 443
 		}
444 444
 
445 445
 		$submission = $this->payment_form_submission;
446 446
 
447 447
 		// Fires before sending to the gateway.
448
-		do_action( 'getpaid_checkout_before_gateway', $invoice, $submission );
448
+		do_action('getpaid_checkout_before_gateway', $invoice, $submission);
449 449
 
450 450
 		// Allow the sumission data to be modified before it is sent to the gateway.
451 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 );
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 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' );
456
+		if (!apply_filters("getpaid_gateway_{$submission_gateway}_is_valid_for_currency", true, $invoice->get_currency())) {
457
+			wpinv_set_error('invalid_currency');
458 458
 		}
459 459
 
460 460
 		// Check to see if we have any errors.
461
-		if ( wpinv_get_errors() ) {
462
-			wpinv_send_back_to_checkout( $invoice );
461
+		if (wpinv_get_errors()) {
462
+			wpinv_send_back_to_checkout($invoice);
463 463
 		}
464 464
 
465 465
 		// Send info to the gateway for payment processing
466
-		do_action( "getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission );
466
+		do_action("getpaid_gateway_$submission_gateway", $invoice, $submission_data, $submission);
467 467
 
468 468
 		// Backwards compatibility.
469
-		wpinv_send_to_gateway( $submission_gateway, $invoice );
469
+		wpinv_send_to_gateway($submission_gateway, $invoice);
470 470
 
471 471
 	}
472 472
 
@@ -475,12 +475,12 @@  discard block
 block discarded – undo
475 475
 	 *
476 476
 	 * @param WPInv_Invoice $invoice
477 477
 	 */
478
-	protected function process_free_payment( $invoice ) {
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 );
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 482
 		$invoice->mark_paid();
483
-		wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
483
+		wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
484 484
 
485 485
 	}
486 486
 
@@ -488,9 +488,9 @@  discard block
 block discarded – undo
488 488
      * Sends a redrect response to payment details.
489 489
      *
490 490
      */
491
-    public function send_redirect_response( $url ) {
492
-        $url = rawurlencode( $url );
493
-        wp_send_json_success( $url );
491
+    public function send_redirect_response($url) {
492
+        $url = rawurlencode($url);
493
+        wp_send_json_success($url);
494 494
     }
495 495
 
496 496
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 2 patches
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.
Spacing   +67 added lines, -67 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission itemss class
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$data         = $submission->get_data();
29 29
 		$payment_form = $submission->get_payment_form();
@@ -32,59 +32,59 @@  discard block
 block discarded – undo
32 32
 
33 33
 		// Prepare the selected items.
34 34
 		$selected_items = array();
35
-		if ( ! empty( $data['getpaid-items'] ) ) {
36
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
+		if (!empty($data['getpaid-items'])) {
36
+			$selected_items = wpinv_clean($data['getpaid-items']);
37 37
 
38
-            if ( is_array( $submission->get_field( 'getpaid-variable-items' ) ) ) {
39
-                $selected_prices = $submission->get_field( 'getpaid-variable-items' );
38
+            if (is_array($submission->get_field('getpaid-variable-items'))) {
39
+                $selected_prices = $submission->get_field('getpaid-variable-items');
40 40
 
41 41
                 $selected_items = array_filter(
42 42
                     $selected_items,
43
-                    function ( $item ) use ( $selected_prices ) {
44
-                        return isset( $item['price_id'] ) && in_array( (int) $item['price_id'], $selected_prices );
43
+                    function($item) use ($selected_prices) {
44
+                        return isset($item['price_id']) && in_array((int) $item['price_id'], $selected_prices);
45 45
                     }
46 46
                 );
47 47
             }
48 48
 
49
-			if ( ! empty( $invoice ) && $submission->is_initial_fetch() ) {
50
-				foreach ( $invoice->get_items() as $invoice_item ) {
51
-                    if ( ! $invoice_item->has_variable_pricing() && isset( $selected_items[ $invoice_item->get_id() ] ) ) {
52
-                        $selected_items[ $invoice_item->get_id() ]['quantity'] = $invoice_item->get_quantity();
53
-                        $selected_items[ $invoice_item->get_id() ]['price']    = $invoice_item->get_price();
49
+			if (!empty($invoice) && $submission->is_initial_fetch()) {
50
+				foreach ($invoice->get_items() as $invoice_item) {
51
+                    if (!$invoice_item->has_variable_pricing() && isset($selected_items[$invoice_item->get_id()])) {
52
+                        $selected_items[$invoice_item->get_id()]['quantity'] = $invoice_item->get_quantity();
53
+                        $selected_items[$invoice_item->get_id()]['price']    = $invoice_item->get_price();
54 54
 
55
-                        $force_prices[ $invoice_item->get_id() ] = $invoice_item->get_price();
55
+                        $force_prices[$invoice_item->get_id()] = $invoice_item->get_price();
56 56
                     }
57 57
 				}
58 58
 			}
59 59
 		}
60 60
 
61 61
 		// (Maybe) set form items.
62
-		if ( isset( $data['getpaid-form-items'] ) ) {
62
+		if (isset($data['getpaid-form-items'])) {
63 63
 
64 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' ) );
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 68
 			}
69 69
 
70
-			$items    = array();
70
+			$items = array();
71 71
             $item_ids = array();
72 72
 
73
-            foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
74
-                if ( ! in_array( $item_id, $item_ids ) ) {
75
-                    $item = new GetPaid_Form_Item( $item_id );
73
+            foreach (getpaid_convert_items_to_array($form_items) as $item_id => $qty) {
74
+                if (!in_array($item_id, $item_ids)) {
75
+                    $item = new GetPaid_Form_Item($item_id);
76 76
 
77
-                    if ( ! $item->has_variable_pricing() ) {
78
-                        $item->set_quantity( $qty );
77
+                    if (!$item->has_variable_pricing()) {
78
+                        $item->set_quantity($qty);
79 79
 
80
-                        if ( empty( $qty ) ) {
81
-                            $item->set_allow_quantities( true );
82
-                            $item->set_is_required( false );
80
+                        if (empty($qty)) {
81
+                            $item->set_allow_quantities(true);
82
+                            $item->set_is_required(false);
83 83
                         }
84 84
 
85
-                        if ( ! $item->user_can_set_their_price() && isset( $force_prices[ $item_id ] ) ) {
86
-                            $item->set_is_dynamic_pricing( true );
87
-                            $item->set_minimum_price( 0 );
85
+                        if (!$item->user_can_set_their_price() && isset($force_prices[$item_id])) {
86
+                            $item->set_is_dynamic_pricing(true);
87
+                            $item->set_minimum_price(0);
88 88
                         }
89 89
                     }
90 90
 
@@ -93,22 +93,22 @@  discard block
 block discarded – undo
93 93
                 }
94 94
             }
95 95
 
96
-            if ( ! $payment_form->is_default() ) {
96
+            if (!$payment_form->is_default()) {
97 97
 
98
-                foreach ( $payment_form->get_items() as $item ) {
99
-                    if ( ! in_array( $item->get_id(), $item_ids ) ) {
98
+                foreach ($payment_form->get_items() as $item) {
99
+                    if (!in_array($item->get_id(), $item_ids)) {
100 100
                         $item_ids[] = $item->get_id();
101 101
                         $items[]    = $item;
102 102
                     }
103 103
                 }
104 104
 			}
105 105
 
106
-            $payment_form->set_items( $items );
106
+            $payment_form->set_items($items);
107 107
 		}
108 108
 
109 109
 		// Process each individual item.
110
-		foreach ( $payment_form->get_items() as $item ) {
111
-			$this->process_item( $item, $selected_items, $submission );
110
+		foreach ($payment_form->get_items() as $item) {
111
+			$this->process_item($item, $selected_items, $submission);
112 112
 		}
113 113
 	}
114 114
 
@@ -119,83 +119,83 @@  discard block
 block discarded – undo
119 119
 	 * @param array $selected_items
120 120
 	 * @param GetPaid_Payment_Form_Submission $submission
121 121
 	 */
122
-	public function process_item( $item, $selected_items, $submission ) {
122
+	public function process_item($item, $selected_items, $submission) {
123 123
 
124
-        if ( $item->has_variable_pricing() ) {
124
+        if ($item->has_variable_pricing()) {
125 125
 
126 126
             $selected_items = array_filter(
127 127
                 $selected_items,
128
-                function ( $selected_item ) use ( $item ) {
128
+                function($selected_item) use ($item) {
129 129
                     return (int) $selected_item['item_id'] === (int) $item->get_id();
130 130
                 }
131 131
             );
132 132
 
133
-            if ( ! $item->is_required() && ! count( $selected_items ) ) {
133
+            if (!$item->is_required() && !count($selected_items)) {
134 134
                 return;
135 135
             }
136 136
 
137 137
             $price_options = $item->get_variable_prices();
138
-            $price = current( $selected_items );
138
+            $price = current($selected_items);
139 139
 
140
-            $item->set_price_id( $price['price_id'] );
141
-            $item->set_quantity( $price['quantity'] );
140
+            $item->set_price_id($price['price_id']);
141
+            $item->set_quantity($price['quantity']);
142 142
 
143
-            $price = isset( $price_options[ $price['price_id'] ] ) ? $price_options[ $price['price_id'] ] : $price;
144
-            $item->set_price( (float) $price['amount'] );
143
+            $price = isset($price_options[$price['price_id']]) ? $price_options[$price['price_id']] : $price;
144
+            $item->set_price((float) $price['amount']);
145 145
 
146
-            if ( isset( $price['is-recurring'] ) && 'yes' === $price['is-recurring'] ) {
147
-                if ( isset( $price['trial-interval'], $price['trial-period'] ) && $price['trial-interval'] > 0 ) {
146
+            if (isset($price['is-recurring']) && 'yes' === $price['is-recurring']) {
147
+                if (isset($price['trial-interval'], $price['trial-period']) && $price['trial-interval'] > 0) {
148 148
                     $trial_interval = (int) $price['trial-interval'];
149 149
                     $trial_period = $price['trial-period'];
150 150
 
151
-                    $item->set_is_free_trial( 1 );
152
-                    $item->set_trial_interval( $trial_interval );
153
-                    $item->set_trial_period( $trial_period );
151
+                    $item->set_is_free_trial(1);
152
+                    $item->set_trial_interval($trial_interval);
153
+                    $item->set_trial_period($trial_period);
154 154
                 }
155 155
 
156
-                if ( isset( $price['recurring-interval'], $price['recurring-period'] ) && $price['recurring-interval'] > 0 ) {
156
+                if (isset($price['recurring-interval'], $price['recurring-period']) && $price['recurring-interval'] > 0) {
157 157
                     $recurring_interval = (int) $price['recurring-interval'];
158 158
                     $recurring_period = $price['recurring-period'];
159
-                    $recurring_limit = isset( $price['recurring-limit'] ) ? (int) $price['recurring-limit'] : 0;
159
+                    $recurring_limit = isset($price['recurring-limit']) ? (int) $price['recurring-limit'] : 0;
160 160
 
161
-                    $item->set_is_recurring( 1 );
162
-                    $item->set_recurring_interval( $recurring_interval );
163
-                    $item->set_recurring_period( $recurring_period );
164
-                    $item->set_recurring_limit( $recurring_limit );
161
+                    $item->set_is_recurring(1);
162
+                    $item->set_recurring_interval($recurring_interval);
163
+                    $item->set_recurring_period($recurring_period);
164
+                    $item->set_recurring_limit($recurring_limit);
165 165
                 }
166 166
             }
167 167
         } else {
168 168
 		    // Abort if this is an optional item and it has not been selected.
169
-            if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
169
+            if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
170 170
                 return;
171 171
             }
172 172
 
173 173
             // (maybe) let customers change the quantities and prices.
174
-            if ( isset( $selected_items[ $item->get_id() ] ) ) {
174
+            if (isset($selected_items[$item->get_id()])) {
175 175
 
176 176
                 // Maybe change the quantities.
177
-                if ( $item->allows_quantities() ) {
178
-                    $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
177
+                if ($item->allows_quantities()) {
178
+                    $item->set_quantity((float) $selected_items[$item->get_id()]['quantity']);
179 179
                 }
180 180
 
181 181
                 // Maybe change the price.
182
-                if ( $item->user_can_set_their_price() ) {
183
-                    $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
182
+                if ($item->user_can_set_their_price()) {
183
+                    $price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
184 184
 
185
-                    if ( $item->get_minimum_price() > $price ) {
186
-                        throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
185
+                    if ($item->get_minimum_price() > $price) {
186
+                        throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($item->get_minimum_price())));
187 187
                     }
188 188
 
189
-                    $item->set_price( $price );
189
+                    $item->set_price($price);
190 190
                 }
191 191
             }
192 192
         }
193 193
 
194
-		if ( 0 == $item->get_quantity() ) {
194
+		if (0 == $item->get_quantity()) {
195 195
 			return;
196 196
 		}
197 197
 
198 198
 		// Save the item.
199
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item', $item, $submission );
199
+		$this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission);
200 200
 	}
201 201
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
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.
Spacing   +133 added lines, -133 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -146,8 +146,8 @@  discard block
 block discarded – undo
146 146
 		$this->state   = wpinv_get_default_state();
147 147
 
148 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 ) ) );
149
+		if (isset($_POST['getpaid_payment_form_submission'])) {
150
+			$this->load_data(wp_kses_post_deep(wp_unslash($_POST)));
151 151
 		}
152 152
 	}
153 153
 
@@ -156,16 +156,16 @@  discard block
 block discarded – undo
156 156
 	 *
157 157
 	 * @param array $data
158 158
 	 */
159
-	public function load_data( $data ) {
159
+	public function load_data($data) {
160 160
 
161 161
 		// Allow plugins to filter the data.
162
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
162
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
163 163
 
164 164
 		// Cache it...
165 165
 		$this->data = $data;
166 166
 
167 167
 		// Then generate a unique id from the data.
168
-		$this->id   = md5( wp_json_encode( $data ) );
168
+		$this->id   = md5(wp_json_encode($data));
169 169
 
170 170
 		// Finally, process the submission.
171 171
 		try {
@@ -175,29 +175,29 @@  discard block
 block discarded – undo
175 175
 			$processors = apply_filters(
176 176
 				'getpaid_payment_form_submission_processors',
177 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' ),
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 184
 				),
185 185
 				$this
186 186
 			);
187 187
 
188
-			foreach ( $processors as $processor ) {
189
-				call_user_func_array( $processor, array( &$this ) );
188
+			foreach ($processors as $processor) {
189
+				call_user_func_array($processor, array(&$this));
190 190
 			}
191
-		} catch ( GetPaid_Payment_Exception $e ) {
191
+		} catch (GetPaid_Payment_Exception $e) {
192 192
 			$this->last_error      = $e->getMessage();
193 193
 			$this->last_error_code = $e->getErrorCode();
194
-		} catch ( Exception $e ) {
194
+		} catch (Exception $e) {
195 195
 			$this->last_error      = $e->getMessage();
196 196
 			$this->last_error_code = $e->getCode();
197 197
 		}
198 198
 
199 199
 		// Fired when we are done processing a submission.
200
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
200
+		do_action_ref_array('getpaid_process_submission', array(&$this));
201 201
 	}
202 202
 
203 203
 	/*
@@ -217,18 +217,18 @@  discard block
 block discarded – undo
217 217
 	public function process_payment_form() {
218 218
 
219 219
 		// Every submission needs an active payment form.
220
-		if ( empty( $this->data['form_id'] ) ) {
221
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
220
+		if (empty($this->data['form_id'])) {
221
+			throw new Exception(__('Missing payment form', 'invoicing'));
222 222
 		}
223 223
 
224 224
 		// Fetch the payment form.
225
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
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' ) );
227
+		if (!$this->payment_form->is_active()) {
228
+			throw new Exception(__('Payment form not active', 'invoicing'));
229 229
 		}
230 230
 
231
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
231
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
232 232
 	}
233 233
 
234 234
     /**
@@ -258,64 +258,64 @@  discard block
 block discarded – undo
258 258
 	public function process_invoice() {
259 259
 
260 260
 		// Abort if there is no invoice.
261
-		if ( empty( $this->data['invoice_id'] ) ) {
261
+		if (empty($this->data['invoice_id'])) {
262 262
 
263 263
 			// Check if we are resuming a payment.
264
-			if ( empty( $this->data['maybe_use_invoice'] ) ) {
264
+			if (empty($this->data['maybe_use_invoice'])) {
265 265
 				return;
266 266
 			}
267 267
 
268
-			$invoice = wpinv_get_invoice( $this->data['maybe_use_invoice'] );
269
-			if ( empty( $invoice ) || ! $invoice->has_status( 'draft, auto-draft, wpi-pending' ) ) {
268
+			$invoice = wpinv_get_invoice($this->data['maybe_use_invoice']);
269
+			if (empty($invoice) || !$invoice->has_status('draft, auto-draft, wpi-pending')) {
270 270
 				return;
271 271
 			}
272 272
 		}
273 273
 
274 274
 		// If the submission is for an existing invoice, ensure that it exists
275 275
 		// and that it is not paid for.
276
-		if ( empty( $invoice ) ) {
277
-			$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
276
+		if (empty($invoice)) {
277
+			$invoice = wpinv_get_invoice($this->data['invoice_id']);
278 278
 		}
279 279
 
280
-        if ( empty( $invoice ) ) {
281
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
280
+        if (empty($invoice)) {
281
+			throw new Exception(__('Invalid invoice', 'invoicing'));
282 282
 		}
283 283
 
284
-		if ( $invoice->is_paid() ) {
285
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
284
+		if ($invoice->is_paid()) {
285
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
286 286
 		}
287 287
 
288 288
 		$this->payment_form->invoice = $invoice;
289
-		if ( ! $this->payment_form->is_default() ) {
289
+		if (!$this->payment_form->is_default()) {
290 290
 
291 291
 			$items    = array();
292 292
 			$item_ids = array();
293 293
 
294
-			foreach ( $invoice->get_items() as $item ) {
295
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
294
+			foreach ($invoice->get_items() as $item) {
295
+				if (!in_array($item->get_id(), $item_ids)) {
296 296
 					$item_ids[] = $item->get_id();
297 297
 					$items[]    = $item;
298 298
 				}
299 299
 			}
300 300
 
301
-			foreach ( $this->payment_form->get_items() as $item ) {
302
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
301
+			foreach ($this->payment_form->get_items() as $item) {
302
+				if (!in_array($item->get_id(), $item_ids)) {
303 303
 					$item_ids[] = $item->get_id();
304 304
 					$items[]    = $item;
305 305
 				}
306 306
 			}
307 307
 
308
-			$this->payment_form->set_items( $items );
308
+			$this->payment_form->set_items($items);
309 309
 
310 310
 		} else {
311
-			$this->payment_form->set_items( $invoice->get_items() );
311
+			$this->payment_form->set_items($invoice->get_items());
312 312
 		}
313 313
 
314 314
 		$this->country = $invoice->get_country();
315 315
 		$this->state   = $invoice->get_state();
316 316
 		$this->invoice = $invoice;
317 317
 
318
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
318
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
319 319
 	}
320 320
 
321 321
 	/**
@@ -335,7 +335,7 @@  discard block
 block discarded – undo
335 335
 	 * @return bool
336 336
 	 */
337 337
 	public function has_invoice() {
338
-		return ! empty( $this->invoice );
338
+		return !empty($this->invoice);
339 339
 	}
340 340
 
341 341
 	/*
@@ -354,13 +354,13 @@  discard block
 block discarded – undo
354 354
 	 */
355 355
 	public function process_items() {
356 356
 
357
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
357
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
358 358
 
359
-		foreach ( $processor->items as $item ) {
360
-			$this->add_item( $item );
359
+		foreach ($processor->items as $item) {
360
+			$this->add_item($item);
361 361
 		}
362 362
 
363
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
363
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
364 364
 	}
365 365
 
366 366
 	/**
@@ -369,20 +369,20 @@  discard block
 block discarded – undo
369 369
 	 * @since 1.0.19
370 370
 	 * @param GetPaid_Form_Item $item
371 371
 	 */
372
-	public function add_item( $item ) {
372
+	public function add_item($item) {
373 373
 
374 374
 		// Make sure that it is available for purchase.
375
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
375
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
376 376
 			return;
377 377
 		}
378 378
 
379 379
 		// Each submission can only contain one recurring item.
380
-		if ( $item->is_recurring() ) {
380
+		if ($item->is_recurring()) {
381 381
 			$this->has_recurring = $item->get_id();
382 382
 		}
383 383
 
384 384
 		// Update the items and totals.
385
-		$this->items[ $item->get_id() ]         = $item;
385
+		$this->items[$item->get_id()]         = $item;
386 386
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
387 387
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
388 388
 	}
@@ -395,17 +395,17 @@  discard block
 block discarded – undo
395 395
 	 *
396 396
 	 * @since 1.0.19
397 397
 	 */
398
-	public function remove_item( $item_id ) {
398
+	public function remove_item($item_id) {
399 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();
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 403
 
404
-			if ( $this->items[ $item_id ]->is_recurring() ) {
404
+			if ($this->items[$item_id]->is_recurring()) {
405 405
 				$this->has_recurring = 0;
406 406
 			}
407 407
 
408
-			unset( $this->items[ $item_id ] );
408
+			unset($this->items[$item_id]);
409 409
 		}
410 410
 	}
411 411
 
@@ -416,7 +416,7 @@  discard block
 block discarded – undo
416 416
 	 */
417 417
 	public function get_subtotal() {
418 418
 
419
-		if ( wpinv_prices_include_tax() ) {
419
+		if (wpinv_prices_include_tax()) {
420 420
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
421 421
 		}
422 422
 
@@ -430,7 +430,7 @@  discard block
 block discarded – undo
430 430
 	 */
431 431
 	public function get_recurring_subtotal() {
432 432
 
433
-		if ( wpinv_prices_include_tax() ) {
433
+		if (wpinv_prices_include_tax()) {
434 434
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
435 435
 		}
436 436
 
@@ -454,7 +454,7 @@  discard block
 block discarded – undo
454 454
 	 * @return bool
455 455
 	 */
456 456
 	public function has_subscription_group() {
457
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
457
+		return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this));
458 458
 	}
459 459
 
460 460
 	/**
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
 	 * @return bool
465 465
 	 */
466 466
 	public function has_multiple_subscription_groups() {
467
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
467
+		return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this));
468 468
 	}
469 469
 
470 470
 	/*
@@ -484,39 +484,39 @@  discard block
 block discarded – undo
484 484
 	public function process_taxes() {
485 485
 
486 486
 		// Abort if we're not using taxes.
487
-		if ( ! $this->use_taxes() ) {
487
+		if (!$this->use_taxes()) {
488 488
 			return;
489 489
 		}
490 490
 
491 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 ) ) {
492
+		$country = $this->get_field('wpinv_country', 'billing');
493
+		if (!empty($country)) {
494 494
 			$this->country = $country;
495 495
 		}
496 496
 
497
-		$state = $this->get_field( 'wpinv_state', 'billing' );
498
-		if ( ! empty( $state ) ) {
497
+		$state = $this->get_field('wpinv_state', 'billing');
498
+		if (!empty($state)) {
499 499
 			$this->state = $state;
500 500
 		}
501 501
 
502 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' ) );
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 506
 		}
507 507
 
508 508
 		// Abort if the country is not taxable.
509
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
509
+		if (!wpinv_is_country_taxable($this->country)) {
510 510
 			return;
511 511
 		}
512 512
 
513
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
513
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
514 514
 
515
-		foreach ( $processor->taxes as $tax ) {
516
-			$this->add_tax( $tax );
515
+		foreach ($processor->taxes as $tax) {
516
+			$this->add_tax($tax);
517 517
 		}
518 518
 
519
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
519
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
520 520
 	}
521 521
 
522 522
 	/**
@@ -525,16 +525,16 @@  discard block
 block discarded – undo
525 525
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
526 526
 	 * @since 1.0.19
527 527
 	 */
528
-	public function add_tax( $tax ) {
528
+	public function add_tax($tax) {
529 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'] );
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 533
 		}
534 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'] );
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 538
 	}
539 539
 
540 540
 	/**
@@ -542,12 +542,12 @@  discard block
 block discarded – undo
542 542
 	 *
543 543
 	 * @since 1.0.19
544 544
 	 */
545
-	public function remove_tax( $tax_name ) {
545
+	public function remove_tax($tax_name) {
546 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 ] );
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 551
 		}
552 552
 	}
553 553
 
@@ -560,11 +560,11 @@  discard block
 block discarded – undo
560 560
 
561 561
 		$use_taxes = wpinv_use_taxes();
562 562
 
563
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
563
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
564 564
 			$use_taxes = false;
565 565
 		}
566 566
 
567
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
567
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
568 568
 	}
569 569
 
570 570
 	/**
@@ -612,13 +612,13 @@  discard block
 block discarded – undo
612 612
 
613 613
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
614 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 );
615
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
616 616
 
617
-		foreach ( $processor->discounts as $discount ) {
618
-			$this->add_discount( $discount );
617
+		foreach ($processor->discounts as $discount) {
618
+			$this->add_discount($discount);
619 619
 		}
620 620
 
621
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
621
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
622 622
 	}
623 623
 
624 624
 	/**
@@ -627,10 +627,10 @@  discard block
 block discarded – undo
627 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 628
 	 * @since 1.0.19
629 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'] );
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 634
 	}
635 635
 
636 636
 	/**
@@ -638,12 +638,12 @@  discard block
 block discarded – undo
638 638
 	 *
639 639
 	 * @since 1.0.19
640 640
 	 */
641
-	public function remove_discount( $name ) {
641
+	public function remove_discount($name) {
642 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 ] );
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 647
 		}
648 648
 	}
649 649
 
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 	 * @return bool
655 655
 	 */
656 656
 	public function has_discount_code() {
657
-		return ! empty( $this->discounts['discount_code'] );
657
+		return !empty($this->discounts['discount_code']);
658 658
 	}
659 659
 
660 660
 	/**
@@ -711,13 +711,13 @@  discard block
 block discarded – undo
711 711
 	 */
712 712
 	public function process_fees() {
713 713
 
714
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
714
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
715 715
 
716
-		foreach ( $fees_processor->fees as $fee ) {
717
-			$this->add_fee( $fee );
716
+		foreach ($fees_processor->fees as $fee) {
717
+			$this->add_fee($fee);
718 718
 		}
719 719
 
720
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
720
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
721 721
 	}
722 722
 
723 723
 	/**
@@ -726,17 +726,17 @@  discard block
 block discarded – undo
726 726
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
727 727
 	 * @since 1.0.19
728 728
 	 */
729
-	public function add_fee( $fee ) {
729
+	public function add_fee($fee) {
730 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'] );
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 734
 			return;
735 735
 		}
736 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'] );
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 740
 	}
741 741
 
742 742
 	/**
@@ -744,15 +744,15 @@  discard block
 block discarded – undo
744 744
 	 *
745 745
 	 * @since 1.0.19
746 746
 	 */
747
-	public function remove_fee( $name ) {
747
+	public function remove_fee($name) {
748 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 ] );
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 753
 		}
754 754
 
755
-		if ( 'shipping' == $name ) {
755
+		if ('shipping' == $name) {
756 756
 			$this->totals['shipping']['initial']   = 0;
757 757
 			$this->totals['shipping']['recurring'] = 0;
758 758
 		}
@@ -792,7 +792,7 @@  discard block
 block discarded – undo
792 792
 	 * @since 1.0.19
793 793
 	 */
794 794
 	public function has_fees() {
795
-		return count( $this->fees ) !== 0;
795
+		return count($this->fees) !== 0;
796 796
 	}
797 797
 
798 798
 	/*
@@ -828,7 +828,7 @@  discard block
 block discarded – undo
828 828
 	 * @since 1.0.19
829 829
 	 */
830 830
 	public function has_shipping() {
831
-		return apply_filters( 'getpaid_payment_form_has_shipping', false, $this );
831
+		return apply_filters('getpaid_payment_form_has_shipping', false, $this);
832 832
 	}
833 833
 
834 834
 	/**
@@ -838,7 +838,7 @@  discard block
 block discarded – undo
838 838
 	 * @since 1.0.19
839 839
 	 */
840 840
 	public function is_initial_fetch() {
841
-		return isset( $this->data['initial_state'] ) && empty( $this->data['initial_state'] );
841
+		return isset($this->data['initial_state']) && empty($this->data['initial_state']);
842 842
 	}
843 843
 
844 844
 	/**
@@ -848,7 +848,7 @@  discard block
 block discarded – undo
848 848
 	 */
849 849
 	public function get_total() {
850 850
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() + $this->get_shipping() - $this->get_discount();
851
-		return max( $total, 0 );
851
+		return max($total, 0);
852 852
 	}
853 853
 
854 854
 	/**
@@ -858,7 +858,7 @@  discard block
 block discarded – undo
858 858
 	 */
859 859
 	public function get_recurring_total() {
860 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 );
861
+		return max($total, 0);
862 862
 	}
863 863
 
864 864
 	/**
@@ -870,12 +870,12 @@  discard block
 block discarded – undo
870 870
 		$initial   = $this->get_total();
871 871
 		$recurring = $this->get_recurring_total();
872 872
 
873
-		if ( $this->has_recurring == 0 ) {
873
+		if ($this->has_recurring == 0) {
874 874
 			$recurring = 0;
875 875
 		}
876 876
 
877 877
 		$collect = $initial > 0 || $recurring > 0;
878
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this );
878
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
879 879
 	}
880 880
 
881 881
 	/**
@@ -884,7 +884,7 @@  discard block
 block discarded – undo
884 884
 	 * @since 1.0.19
885 885
 	 */
886 886
 	public function get_billing_email() {
887
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this );
887
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
888 888
 	}
889 889
 
890 890
 	/**
@@ -894,7 +894,7 @@  discard block
 block discarded – undo
894 894
 	 */
895 895
 	public function has_billing_email() {
896 896
 		$billing_email = $this->get_billing_email();
897
-		return ! empty( $billing_email ) && is_email( $billing_email );
897
+		return !empty($billing_email) && is_email($billing_email);
898 898
 	}
899 899
 
900 900
 	/**
@@ -924,8 +924,8 @@  discard block
 block discarded – undo
924 924
 	 * @since 1.0.19
925 925
 	 * @return mixed|null
926 926
 	 */
927
-	public function get_field( $field, $sub_array_key = null ) {
928
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
927
+	public function get_field($field, $sub_array_key = null) {
928
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
929 929
 	}
930 930
 
931 931
 	/**
@@ -933,8 +933,8 @@  discard block
 block discarded – undo
933 933
 	 *
934 934
 	 * @since 1.0.19
935 935
 	 */
936
-	public function is_required_field_set( $field ) {
937
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
936
+	public function is_required_field_set($field) {
937
+		return empty($field['required']) || !empty($this->data[$field['id']]);
938 938
 	}
939 939
 
940 940
 	/**
@@ -942,7 +942,7 @@  discard block
 block discarded – undo
942 942
 	 *
943 943
 	 * @since 1.0.19
944 944
 	 */
945
-	public function format_amount( $amount ) {
946
-		return wpinv_price( $amount, $this->get_currency() );
945
+	public function format_amount($amount) {
946
+		return wpinv_price($amount, $this->get_currency());
947 947
 	}
948 948
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-refresh-prices.php 2 patches
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.
Spacing   +84 added lines, -84 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission refresh prices class
@@ -23,29 +23,29 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$this->response = array(
29 29
 			'submission_id'                    => $submission->id,
30 30
             'has_recurring'                    => $submission->has_recurring,
31 31
 			'has_subscription_group'           => $submission->has_subscription_group(),
32 32
 			'has_multiple_subscription_groups' => $submission->has_multiple_subscription_groups(),
33
-            'is_free'                          => ! $submission->should_collect_payment_details(),
33
+            'is_free'                          => !$submission->should_collect_payment_details(),
34 34
 		);
35 35
 
36 36
 		$payment_form = $submission->get_payment_form();
37
-		if ( ! empty( $payment_form->invoice ) ) {
37
+		if (!empty($payment_form->invoice)) {
38 38
 			$this->response['invoice'] = $payment_form->invoice->get_id();
39 39
 		}
40 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 );
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 49
 	}
50 50
 
51 51
 	/**
@@ -53,30 +53,30 @@  discard block
 block discarded – undo
53 53
 	 *
54 54
 	 * @param GetPaid_Payment_Form_Submission $submission
55 55
 	 */
56
-	public function add_totals( $submission ) {
56
+	public function add_totals($submission) {
57 57
 
58 58
 		$this->response = array_merge(
59 59
 			$this->response,
60 60
 			array(
61 61
 
62 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 ),
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 69
 				),
70 70
 
71 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() ),
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 77
 				),
78 78
 
79
-				'initial_amt' => wpinv_round_amount( $submission->get_total(), null, true ),
79
+				'initial_amt' => wpinv_round_amount($submission->get_total(), null, true),
80 80
 				'currency'    => $submission->get_currency(),
81 81
 
82 82
 			)
@@ -88,53 +88,53 @@  discard block
 block discarded – undo
88 88
 	 *
89 89
 	 * @param GetPaid_Payment_Form_Submission $submission
90 90
 	 */
91
-	public function add_texts( $submission ) {
91
+	public function add_texts($submission) {
92 92
 
93
-		$payable = $submission->format_amount( $submission->get_total() );
94
-		$groups  = getpaid_get_subscription_groups( $submission );
93
+		$payable = $submission->format_amount($submission->get_total());
94
+		$groups  = getpaid_get_subscription_groups($submission);
95 95
 
96
-		if ( $submission->has_recurring && 2 > count( $groups ) ) {
96
+		if ($submission->has_recurring && 2 > count($groups)) {
97 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 );
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 101
 
102
-			if ( $submission->get_total() == $submission->get_recurring_total() ) {
102
+			if ($submission->get_total() == $submission->get_recurring_total()) {
103 103
 				$payable = "$payable / $period";
104
-			} elseif ( $main_item ) {
104
+			} elseif ($main_item) {
105 105
 
106
-				$main_item = reset( $main_item );
106
+				$main_item = reset($main_item);
107 107
 
108 108
 				// Calculate the next renewal date.
109
-				$_period      = $main_item->get_recurring_period( true );
109
+				$_period      = $main_item->get_recurring_period(true);
110 110
 				$_interval    = $main_item->get_recurring_interval();
111 111
 
112 112
 				// If the subscription item has a trial period...
113
-				if ( $main_item->has_free_trial() ) {
114
-					$_period   = $main_item->get_trial_period( true );
113
+				if ($main_item->has_free_trial()) {
114
+					$_period   = $main_item->get_trial_period(true);
115 115
 					$_interval = $main_item->get_trial_interval();
116 116
 				}
117 117
 
118 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() ),
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 122
 					$period
123 123
 				);
124 124
 
125 125
 				$payable .= sprintf(
126 126
 					'<small class="text-muted form-text">%s</small>',
127 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' ) ) ) )
128
+						__('First renewal on %s', 'invoicing'),
129
+						getpaid_format_date(date('Y-m-d H:i:s', strtotime("+$_interval $_period", current_time('timestamp'))))
130 130
 					)
131 131
 				);
132 132
 
133 133
 			} else {
134 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() ),
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 138
 					$period
139 139
 				);
140 140
 			}
@@ -144,20 +144,20 @@  discard block
 block discarded – undo
144 144
 			'.getpaid-checkout-total-payable' => $payable,
145 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" ] = '';
155
+			if ($item->get_quantity() == 1) {
156
+				$texts[".item-$item_id .getpaid-mobile-item-subtotal"] = '';
157 157
 			}
158 158
         }
159 159
 
160
-		$this->response = array_merge( $this->response, array( 'texts' => $texts ) );
160
+		$this->response = array_merge($this->response, array('texts' => $texts));
161 161
 	}
162 162
 
163 163
 	/**
@@ -165,21 +165,21 @@  discard block
 block discarded – undo
165 165
 	 *
166 166
 	 * @param GetPaid_Payment_Form_Submission $submission
167 167
 	 */
168
-	public function add_items( $submission ) {
168
+	public function add_items($submission) {
169 169
 
170 170
 		// Add items.
171 171
 		$items          = array();
172 172
 		$selected_items = array();
173 173
 
174
-        foreach ( $submission->get_items() as $item ) {
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(
178
+			$selected_items["$item_id"] = array(
179 179
 				'quantity'  => $item->get_quantity(),
180 180
 				'price'     => $item->get_price(),
181 181
                 'price_id'  => (int) $item_id,
182
-				'price_fmt' => $submission->format_amount( $item->get_price() ),
182
+				'price_fmt' => $submission->format_amount($item->get_price()),
183 183
 			);
184 184
 		}
185 185
 
@@ -197,17 +197,17 @@  discard block
 block discarded – undo
197 197
 	 *
198 198
 	 * @param GetPaid_Payment_Form_Submission $submission
199 199
 	 */
200
-	public function add_fees( $submission ) {
200
+	public function add_fees($submission) {
201 201
 
202 202
 		$fees = array();
203 203
 
204
-        foreach ( $submission->get_fees() as $name => $data ) {
205
-			$fees[ $name ] = $submission->format_amount( $data['initial_fee'] );
204
+        foreach ($submission->get_fees() as $name => $data) {
205
+			$fees[$name] = $submission->format_amount($data['initial_fee']);
206 206
 		}
207 207
 
208 208
 		$this->response = array_merge(
209 209
 			$this->response,
210
-			array( 'fees' => $fees )
210
+			array('fees' => $fees)
211 211
 		);
212 212
 	}
213 213
 
@@ -216,17 +216,17 @@  discard block
 block discarded – undo
216 216
 	 *
217 217
 	 * @param GetPaid_Payment_Form_Submission $submission
218 218
 	 */
219
-	public function add_discounts( $submission ) {
219
+	public function add_discounts($submission) {
220 220
 
221 221
 		$discounts = array();
222 222
 
223
-        foreach ( $submission->get_discounts() as $name => $data ) {
224
-			$discounts[ $name ] = $submission->format_amount( $data['initial_discount'] );
223
+        foreach ($submission->get_discounts() as $name => $data) {
224
+			$discounts[$name] = $submission->format_amount($data['initial_discount']);
225 225
 		}
226 226
 
227 227
 		$this->response = array_merge(
228 228
 			$this->response,
229
-			array( 'discounts' => $discounts )
229
+			array('discounts' => $discounts)
230 230
 		);
231 231
 	}
232 232
 
@@ -235,20 +235,20 @@  discard block
 block discarded – undo
235 235
 	 *
236 236
 	 * @param GetPaid_Payment_Form_Submission $submission
237 237
 	 */
238
-	public function add_taxes( $submission ) {
238
+	public function add_taxes($submission) {
239 239
 
240 240
 		$taxes  = array();
241 241
 		$markup = '';
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;
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 246
 			$markup        .= "<small class='form-text'>$name : $amount</small>";
247 247
 		}
248 248
 
249 249
 		$this->response = array_merge(
250 250
 			$this->response,
251
-			array( 'taxes' => $taxes )
251
+			array('taxes' => $taxes)
252 252
 		);
253 253
 	}
254 254
 
@@ -257,27 +257,27 @@  discard block
 block discarded – undo
257 257
 	 *
258 258
 	 * @param GetPaid_Payment_Form_Submission $submission
259 259
 	 */
260
-	public function add_gateways( $submission ) {
260
+	public function add_gateways($submission) {
261 261
 
262
-		$gateways = array_keys( wpinv_get_enabled_payment_gateways() );
262
+		$gateways = array_keys(wpinv_get_enabled_payment_gateways());
263 263
 
264
-		if ( $this->response['has_recurring'] ) {
264
+		if ($this->response['has_recurring']) {
265 265
 
266
-			foreach ( $gateways as $i => $gateway ) {
266
+			foreach ($gateways as $i => $gateway) {
267 267
 
268 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 ] );
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 273
 				}
274 274
             }
275 275
         }
276 276
 
277
-		$gateways = apply_filters( 'getpaid_submission_gateways', $gateways, $submission );
277
+		$gateways = apply_filters('getpaid_submission_gateways', $gateways, $submission);
278 278
 		$this->response = array_merge(
279 279
 			$this->response,
280
-			array( 'gateways' => $gateways )
280
+			array('gateways' => $gateways)
281 281
 		);
282 282
 	}
283 283
 
@@ -286,7 +286,7 @@  discard block
 block discarded – undo
286 286
 	 *
287 287
 	 * @param GetPaid_Payment_Form_Submission $submission
288 288
 	 */
289
-	public function add_data( $submission ) {
289
+	public function add_data($submission) {
290 290
 
291 291
 		$this->response = array_merge(
292 292
 			$this->response,
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form.php 2 patches
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.
Spacing   +158 added lines, -158 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -72,28 +72,28 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74 74
 	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
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() );
82
+			$this->set_id($form->get_id());
83 83
 			$this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
85
+		} elseif (!empty($form->ID)) {
86
+			$this->set_id($form->ID);
87 87
 		} else {
88
-			$this->set_object_read( true );
88
+			$this->set_object_read(true);
89 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 ) {
95
-            $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
94
+		if ($this->get_id() > 0) {
95
+            $this->post = get_post($this->get_id());
96
+			$this->data_store->read($this);
97 97
         }
98 98
 	}
99 99
 
@@ -119,8 +119,8 @@  discard block
 block discarded – undo
119 119
 	 * @param  string $context View or edit context.
120 120
 	 * @return string
121 121
 	 */
122
-	public function get_version( $context = 'view' ) {
123
-		return $this->get_prop( 'version', $context );
122
+	public function get_version($context = 'view') {
123
+		return $this->get_prop('version', $context);
124 124
     }
125 125
 
126 126
     /**
@@ -130,8 +130,8 @@  discard block
 block discarded – undo
130 130
 	 * @param  string $context View or edit context.
131 131
 	 * @return string
132 132
 	 */
133
-	public function get_date_created( $context = 'view' ) {
134
-		return $this->get_prop( 'date_created', $context );
133
+	public function get_date_created($context = 'view') {
134
+		return $this->get_prop('date_created', $context);
135 135
     }
136 136
 
137 137
     /**
@@ -141,11 +141,11 @@  discard block
 block discarded – undo
141 141
 	 * @param  string $context View or edit context.
142 142
 	 * @return string
143 143
 	 */
144
-	public function get_date_created_gmt( $context = 'view' ) {
145
-        $date = $this->get_date_created( $context );
144
+	public function get_date_created_gmt($context = 'view') {
145
+        $date = $this->get_date_created($context);
146 146
 
147
-        if ( $date ) {
148
-            $date = get_gmt_from_date( $date );
147
+        if ($date) {
148
+            $date = get_gmt_from_date($date);
149 149
         }
150 150
 		return $date;
151 151
     }
@@ -157,8 +157,8 @@  discard block
 block discarded – undo
157 157
 	 * @param  string $context View or edit context.
158 158
 	 * @return string
159 159
 	 */
160
-	public function get_date_modified( $context = 'view' ) {
161
-		return $this->get_prop( 'date_modified', $context );
160
+	public function get_date_modified($context = 'view') {
161
+		return $this->get_prop('date_modified', $context);
162 162
     }
163 163
 
164 164
     /**
@@ -168,11 +168,11 @@  discard block
 block discarded – undo
168 168
 	 * @param  string $context View or edit context.
169 169
 	 * @return string
170 170
 	 */
171
-	public function get_date_modified_gmt( $context = 'view' ) {
172
-        $date = $this->get_date_modified( $context );
171
+	public function get_date_modified_gmt($context = 'view') {
172
+        $date = $this->get_date_modified($context);
173 173
 
174
-        if ( $date ) {
175
-            $date = get_gmt_from_date( $date );
174
+        if ($date) {
175
+            $date = get_gmt_from_date($date);
176 176
         }
177 177
 		return $date;
178 178
     }
@@ -184,8 +184,8 @@  discard block
 block discarded – undo
184 184
 	 * @param  string $context View or edit context.
185 185
 	 * @return string
186 186
 	 */
187
-	public function get_name( $context = 'view' ) {
188
-		return $this->get_prop( 'name', $context );
187
+	public function get_name($context = 'view') {
188
+		return $this->get_prop('name', $context);
189 189
     }
190 190
 
191 191
     /**
@@ -195,8 +195,8 @@  discard block
 block discarded – undo
195 195
 	 * @param  string $context View or edit context.
196 196
 	 * @return string
197 197
 	 */
198
-	public function get_title( $context = 'view' ) {
199
-		return $this->get_name( $context );
198
+	public function get_title($context = 'view') {
199
+		return $this->get_name($context);
200 200
 	}
201 201
 
202 202
     /**
@@ -206,8 +206,8 @@  discard block
 block discarded – undo
206 206
 	 * @param  string $context View or edit context.
207 207
 	 * @return int
208 208
 	 */
209
-	public function get_author( $context = 'view' ) {
210
-		return (int) $this->get_prop( 'author', $context );
209
+	public function get_author($context = 'view') {
210
+		return (int) $this->get_prop('author', $context);
211 211
     }
212 212
 
213 213
     /**
@@ -217,21 +217,21 @@  discard block
 block discarded – undo
217 217
 	 * @param  string $context View or edit context.
218 218
 	 * @return array
219 219
 	 */
220
-	public function get_elements( $context = 'view' ) {
221
-		$elements = $this->get_prop( 'elements', $context );
220
+	public function get_elements($context = 'view') {
221
+		$elements = $this->get_prop('elements', $context);
222 222
 
223
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
-            return wpinv_get_data( 'sample-payment-form' );
223
+		if (empty($elements) || !is_array($elements)) {
224
+            return wpinv_get_data('sample-payment-form');
225 225
 		}
226 226
 
227 227
 		// Ensure that all required elements exist.
228 228
 		$_elements = array();
229
-		foreach ( $elements as $element ) {
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 233
 				$_elements[] = array(
234
-					'text'    => __( 'Select Payment Method', 'invoicing' ),
234
+					'text'    => __('Select Payment Method', 'invoicing'),
235 235
 					'id'      => 'gtscicd',
236 236
 					'name'    => 'gtscicd',
237 237
 					'type'    => 'gateway_select',
@@ -256,22 +256,22 @@  discard block
 block discarded – undo
256 256
 	 * @param  string $return objects or arrays.
257 257
 	 * @return GetPaid_Form_Item[]
258 258
 	 */
259
-	public function get_items( $context = 'view', $return = 'objects' ) {
260
-		$items = $this->get_prop( 'items', $context );
259
+	public function get_items($context = 'view', $return = 'objects') {
260
+		$items = $this->get_prop('items', $context);
261 261
 
262
-		if ( empty( $items ) || ! is_array( $items ) ) {
263
-            $items = wpinv_get_data( 'sample-payment-form-items' );
262
+		if (empty($items) || !is_array($items)) {
263
+            $items = wpinv_get_data('sample-payment-form-items');
264 264
 		}
265 265
 
266 266
 		// Convert the items.
267 267
 		$prepared = array();
268 268
 
269
-		foreach ( $items as $key => $value ) {
269
+		foreach ($items as $key => $value) {
270 270
 
271 271
 			// Form items.
272
-			if ( $value instanceof GetPaid_Form_Item ) {
272
+			if ($value instanceof GetPaid_Form_Item) {
273 273
 
274
-				if ( $value->can_purchase() ) {
274
+				if ($value->can_purchase()) {
275 275
 					$prepared[] = $value;
276 276
 				}
277 277
 
@@ -280,16 +280,16 @@  discard block
 block discarded – undo
280 280
 			}
281 281
 
282 282
 			// $item_id => $quantity (buy buttons)
283
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
284
-				$item = new GetPaid_Form_Item( $key );
283
+			if (is_numeric($key) && is_numeric($value)) {
284
+				$item = new GetPaid_Form_Item($key);
285 285
 
286
-				if ( $item->can_purchase() ) {
286
+				if ($item->can_purchase()) {
287 287
 
288 288
 					$value = (float) $value;
289
-					$item->set_quantity( $value );
290
-					if ( 0 == $value ) {
291
-						$item->set_quantity( 1 );
292
-						$item->set_allow_quantities( true );
289
+					$item->set_quantity($value);
290
+					if (0 == $value) {
291
+						$item->set_quantity(1);
292
+						$item->set_allow_quantities(true);
293 293
 					}
294 294
 
295 295
 					$prepared[] = $item;
@@ -299,33 +299,33 @@  discard block
 block discarded – undo
299 299
 			}
300 300
 
301 301
 			// Items saved via payment forms editor.
302
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
302
+			if (is_array($value) && isset($value['id'])) {
303 303
 
304
-				$item = new GetPaid_Form_Item( $value['id'] );
304
+				$item = new GetPaid_Form_Item($value['id']);
305 305
 
306
-				if ( ! $item->can_purchase() ) {
306
+				if (!$item->can_purchase()) {
307 307
 					continue;
308 308
 				}
309 309
 
310 310
 				// Sub-total (Cart items).
311
-				if ( isset( $value['subtotal'] ) ) {
312
-					$item->set_price( $value['subtotal'] );
311
+				if (isset($value['subtotal'])) {
312
+					$item->set_price($value['subtotal']);
313 313
 				}
314 314
 
315
-				if ( isset( $value['quantity'] ) ) {
316
-					$item->set_quantity( $value['quantity'] );
315
+				if (isset($value['quantity'])) {
316
+					$item->set_quantity($value['quantity']);
317 317
 				}
318 318
 
319
-				if ( isset( $value['allow_quantities'] ) ) {
320
-					$item->set_allow_quantities( $value['allow_quantities'] );
319
+				if (isset($value['allow_quantities'])) {
320
+					$item->set_allow_quantities($value['allow_quantities']);
321 321
 				}
322 322
 
323
-				if ( isset( $value['required'] ) ) {
324
-					$item->set_is_required( $value['required'] );
323
+				if (isset($value['required'])) {
324
+					$item->set_is_required($value['required']);
325 325
 				}
326 326
 
327
-				if ( isset( $value['description'] ) ) {
328
-					$item->set_custom_description( $value['description'] );
327
+				if (isset($value['description'])) {
328
+					$item->set_custom_description($value['description']);
329 329
 				}
330 330
 
331 331
 				$prepared[] = $item;
@@ -334,14 +334,14 @@  discard block
 block discarded – undo
334 334
 			}
335 335
 
336 336
 			// $item_id => array( 'price' => 10 ) (item variations)
337
-			if ( is_numeric( $key ) && is_array( $value ) ) {
338
-				$item = new GetPaid_Form_Item( $key );
337
+			if (is_numeric($key) && is_array($value)) {
338
+				$item = new GetPaid_Form_Item($key);
339 339
 
340
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
341
-					$item->set_price( $value['price'] );
340
+				if (isset($value['price']) && $item->user_can_set_their_price()) {
341
+					$item->set_price($value['price']);
342 342
 				}
343 343
 
344
-				if ( $item->can_purchase() ) {
344
+				if ($item->can_purchase()) {
345 345
 					$prepared[] = $item;
346 346
 				}
347 347
 
@@ -349,12 +349,12 @@  discard block
 block discarded – undo
349 349
 			}
350 350
 		}
351 351
 
352
-		if ( 'objects' == $return && 'view' == $context ) {
352
+		if ('objects' == $return && 'view' == $context) {
353 353
 			return $prepared;
354 354
 		}
355 355
 
356 356
 		$items = array();
357
-		foreach ( $prepared as $item ) {
357
+		foreach ($prepared as $item) {
358 358
 			$items[] = $item->prepare_data_for_use();
359 359
 		}
360 360
 
@@ -368,14 +368,14 @@  discard block
 block discarded – undo
368 368
 	 * @param  int $item_id The item id to return.
369 369
 	 * @return GetPaid_Form_Item|bool
370 370
 	 */
371
-	public function get_item( $item_id ) {
371
+	public function get_item($item_id) {
372 372
 
373
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
373
+		if (empty($item_id) || !is_numeric($item_id)) {
374 374
 			return false;
375 375
 		}
376 376
 
377
-		foreach ( $this->get_items() as $item ) {
378
-			if ( $item->get_id() == (int) $item_id ) {
377
+		foreach ($this->get_items() as $item) {
378
+			if ($item->get_id() == (int) $item_id) {
379 379
 				return $item;
380 380
 			}
381 381
 		}
@@ -390,15 +390,15 @@  discard block
 block discarded – undo
390 390
 	 * @param  string $element_type The element type to return.
391 391
 	 * @return array|bool
392 392
 	 */
393
-	public function get_element_type( $element_type ) {
393
+	public function get_element_type($element_type) {
394 394
 
395
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
395
+		if (empty($element_type) || !is_scalar($element_type)) {
396 396
 			return false;
397 397
 		}
398 398
 
399
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
399
+		foreach ($this->get_prop('elements') as $element) {
400 400
 
401
-			if ( $element['type'] === $element_type ) {
401
+			if ($element['type'] === $element_type) {
402 402
 				return $element;
403 403
 			}
404 404
 		}
@@ -413,8 +413,8 @@  discard block
 block discarded – undo
413 413
 	 * @param  string $context View or edit context.
414 414
 	 * @return float
415 415
 	 */
416
-	public function get_earned( $context = 'view' ) {
417
-		return $this->get_prop( 'earned', $context );
416
+	public function get_earned($context = 'view') {
417
+		return $this->get_prop('earned', $context);
418 418
 	}
419 419
 
420 420
 	/**
@@ -424,8 +424,8 @@  discard block
 block discarded – undo
424 424
 	 * @param  string $context View or edit context.
425 425
 	 * @return float
426 426
 	 */
427
-	public function get_refunded( $context = 'view' ) {
428
-		return $this->get_prop( 'refunded', $context );
427
+	public function get_refunded($context = 'view') {
428
+		return $this->get_prop('refunded', $context);
429 429
 	}
430 430
 
431 431
 	/**
@@ -435,8 +435,8 @@  discard block
 block discarded – undo
435 435
 	 * @param  string $context View or edit context.
436 436
 	 * @return float
437 437
 	 */
438
-	public function get_cancelled( $context = 'view' ) {
439
-		return $this->get_prop( 'cancelled', $context );
438
+	public function get_cancelled($context = 'view') {
439
+		return $this->get_prop('cancelled', $context);
440 440
 	}
441 441
 
442 442
 	/**
@@ -446,8 +446,8 @@  discard block
 block discarded – undo
446 446
 	 * @param  string $context View or edit context.
447 447
 	 * @return float
448 448
 	 */
449
-	public function get_failed( $context = 'view' ) {
450
-		return $this->get_prop( 'failed', $context );
449
+	public function get_failed($context = 'view') {
450
+		return $this->get_prop('failed', $context);
451 451
 	}
452 452
 
453 453
 	/**
@@ -458,8 +458,8 @@  discard block
 block discarded – undo
458 458
 	 * @return string
459 459
 	 */
460 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 );
461
+		$currency = empty($this->invoice) ? wpinv_get_currency() : $this->invoice->get_currency();
462
+		return apply_filters('getpaid-payment-form-currency', $currency, $this);
463 463
 	}
464 464
 
465 465
     /*
@@ -477,8 +477,8 @@  discard block
 block discarded – undo
477 477
 	 *
478 478
 	 * @since 1.0.19
479 479
 	 */
480
-	public function set_version( $value ) {
481
-		$this->set_prop( 'version', $value );
480
+	public function set_version($value) {
481
+		$this->set_prop('version', $value);
482 482
     }
483 483
 
484 484
     /**
@@ -488,11 +488,11 @@  discard block
 block discarded – undo
488 488
 	 * @param string $value Value to set.
489 489
      * @return bool Whether or not the date was set.
490 490
 	 */
491
-	public function set_date_created( $value ) {
492
-        $date = strtotime( $value );
491
+	public function set_date_created($value) {
492
+        $date = strtotime($value);
493 493
 
494
-        if ( $date ) {
495
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
494
+        if ($date) {
495
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
496 496
             return true;
497 497
         }
498 498
 
@@ -506,11 +506,11 @@  discard block
 block discarded – undo
506 506
 	 * @param string $value Value to set.
507 507
      * @return bool Whether or not the date was set.
508 508
 	 */
509
-	public function set_date_modified( $value ) {
510
-        $date = strtotime( $value );
509
+	public function set_date_modified($value) {
510
+        $date = strtotime($value);
511 511
 
512
-        if ( $date ) {
513
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
512
+        if ($date) {
513
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
514 514
             return true;
515 515
         }
516 516
 
@@ -523,8 +523,8 @@  discard block
 block discarded – undo
523 523
 	 * @since 1.0.19
524 524
 	 * @param  string $value New name.
525 525
 	 */
526
-	public function set_name( $value ) {
527
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
526
+	public function set_name($value) {
527
+		$this->set_prop('name', sanitize_text_field($value));
528 528
     }
529 529
 
530 530
     /**
@@ -533,8 +533,8 @@  discard block
 block discarded – undo
533 533
 	 * @since 1.0.19
534 534
 	 * @param  string $value New name.
535 535
 	 */
536
-	public function set_title( $value ) {
537
-		$this->set_name( $value );
536
+	public function set_title($value) {
537
+		$this->set_name($value);
538 538
     }
539 539
 
540 540
     /**
@@ -543,8 +543,8 @@  discard block
 block discarded – undo
543 543
 	 * @since 1.0.19
544 544
 	 * @param  int $value New author.
545 545
 	 */
546
-	public function set_author( $value ) {
547
-		$this->set_prop( 'author', (int) $value );
546
+	public function set_author($value) {
547
+		$this->set_prop('author', (int) $value);
548 548
 	}
549 549
 
550 550
 	/**
@@ -554,9 +554,9 @@  discard block
 block discarded – undo
554 554
 	 * @sinve 2.3.4 Array values sanitized.
555 555
 	 * @param  array $value Form elements.
556 556
 	 */
557
-	public function set_elements( $value ) {
558
-		if ( is_array( $value ) ) {
559
-			$this->set_prop( 'elements', wp_kses_post_deep( $value ) );
557
+	public function set_elements($value) {
558
+		if (is_array($value)) {
559
+			$this->set_prop('elements', wp_kses_post_deep($value));
560 560
 		}
561 561
 	}
562 562
 
@@ -567,36 +567,36 @@  discard block
 block discarded – undo
567 567
 	 *
568 568
 	 * @return mixed
569 569
 	 */
570
-	public function sanitize_array_values( $value ) {
570
+	public function sanitize_array_values($value) {
571 571
 
572 572
 		// sanitize
573
-		if ( ! empty( $value ) ) {
573
+		if (!empty($value)) {
574 574
 
575
-			foreach ( $value as $key => $val_arr ) {
575
+			foreach ($value as $key => $val_arr) {
576 576
 
577
-				if ( is_array( $val_arr ) ) {
577
+				if (is_array($val_arr)) {
578 578
 					// check if we have sub array items.
579 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 ] );
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 584
 						}
585 585
 					}
586 586
 
587 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'] ) : '';
588
+					$help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : '';
589 589
 
590 590
 					// sanitize array elements
591
-					$value[ $key ] = array_map( 'sanitize_text_field', $val_arr );
591
+					$value[$key] = array_map('sanitize_text_field', $val_arr);
592 592
 
593 593
 					// add back the description if set
594
-					if ( isset( $val_arr['description'] ) ) {
595
-                        $value[ $key ]['description'] = $help_text;}
594
+					if (isset($val_arr['description'])) {
595
+                        $value[$key]['description'] = $help_text; }
596 596
 
597 597
 					// add back sub array items after its been sanitized.
598
-					if ( ! empty( $sub_arr ) ) {
599
-						$value[ $key ] = array_merge( $value[ $key ], $sub_arr );
598
+					if (!empty($sub_arr)) {
599
+						$value[$key] = array_merge($value[$key], $sub_arr);
600 600
 					}
601 601
 				}
602 602
             }
@@ -611,9 +611,9 @@  discard block
 block discarded – undo
611 611
 	 * @since 1.0.19
612 612
 	 * @param  array $value Form elements.
613 613
 	 */
614
-	public function set_items( $value ) {
615
-		if ( is_array( $value ) ) {
616
-			$this->set_prop( 'items', $value );
614
+	public function set_items($value) {
615
+		if (is_array($value)) {
616
+			$this->set_prop('items', $value);
617 617
 		}
618 618
 	}
619 619
 
@@ -623,9 +623,9 @@  discard block
 block discarded – undo
623 623
 	 * @since 1.0.19
624 624
 	 * @param  float $value Amount earned.
625 625
 	 */
626
-	public function set_earned( $value ) {
627
-		$value = max( (float) $value, 0 );
628
-		$this->set_prop( 'earned', $value );
626
+	public function set_earned($value) {
627
+		$value = max((float) $value, 0);
628
+		$this->set_prop('earned', $value);
629 629
 	}
630 630
 
631 631
 	/**
@@ -634,9 +634,9 @@  discard block
 block discarded – undo
634 634
 	 * @since 1.0.19
635 635
 	 * @param  float $value Amount refunded.
636 636
 	 */
637
-	public function set_refunded( $value ) {
638
-		$value = max( (float) $value, 0 );
639
-		$this->set_prop( 'refunded', $value );
637
+	public function set_refunded($value) {
638
+		$value = max((float) $value, 0);
639
+		$this->set_prop('refunded', $value);
640 640
 	}
641 641
 
642 642
 	/**
@@ -645,9 +645,9 @@  discard block
 block discarded – undo
645 645
 	 * @since 1.0.19
646 646
 	 * @param  float $value Amount cancelled.
647 647
 	 */
648
-	public function set_cancelled( $value ) {
649
-		$value = max( (float) $value, 0 );
650
-		$this->set_prop( 'cancelled', $value );
648
+	public function set_cancelled($value) {
649
+		$value = max((float) $value, 0);
650
+		$this->set_prop('cancelled', $value);
651 651
 	}
652 652
 
653 653
 	/**
@@ -656,9 +656,9 @@  discard block
 block discarded – undo
656 656
 	 * @since 1.0.19
657 657
 	 * @param  float $value Amount cancelled.
658 658
 	 */
659
-	public function set_failed( $value ) {
660
-		$value = max( (float) $value, 0 );
661
-		$this->set_prop( 'failed', $value );
659
+	public function set_failed($value) {
660
+		$value = max((float) $value, 0);
661
+		$this->set_prop('failed', $value);
662 662
 	}
663 663
 
664 664
     /**
@@ -667,11 +667,11 @@  discard block
 block discarded – undo
667 667
      * @deprecated
668 668
 	 * @return int item id
669 669
      */
670
-    public function create( $data = array() ) {
670
+    public function create($data = array()) {
671 671
 
672 672
 		// Set the properties.
673
-		if ( is_array( $data ) ) {
674
-			$this->set_props( $data );
673
+		if (is_array($data)) {
674
+			$this->set_props($data);
675 675
 		}
676 676
 
677 677
 		// Save the item.
@@ -684,8 +684,8 @@  discard block
 block discarded – undo
684 684
      * @deprecated
685 685
 	 * @return int item id
686 686
      */
687
-    public function update( $data = array() ) {
688
-        return $this->create( $data );
687
+    public function update($data = array()) {
688
+        return $this->create($data);
689 689
     }
690 690
 
691 691
     /*
@@ -705,7 +705,7 @@  discard block
 block discarded – undo
705 705
 	 */
706 706
     public function is_default() {
707 707
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
708
-        return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
708
+        return (bool) apply_filters('wpinv_is_default_payment_form', $is_default, $this->get_id(), $this);
709 709
 	}
710 710
 
711 711
     /**
@@ -717,11 +717,11 @@  discard block
 block discarded – undo
717 717
     public function is_active() {
718 718
         $is_active = 0 !== (int) $this->get_id();
719 719
 
720
-        if ( $is_active && ! current_user_can( 'edit_post', $this->get_id() ) && $this->get_status() != 'publish' ) {
720
+        if ($is_active && !current_user_can('edit_post', $this->get_id()) && $this->get_status() != 'publish') {
721 721
             $is_active = false;
722 722
         }
723 723
 
724
-        return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
724
+        return (bool) apply_filters('wpinv_is_payment_form_active', $is_active, $this);
725 725
 	}
726 726
 
727 727
 	/**
@@ -730,8 +730,8 @@  discard block
 block discarded – undo
730 730
 	 * @since 1.0.19
731 731
 	 * @return bool
732 732
 	 */
733
-    public function has_item( $item_id ) {
734
-        return false !== $this->get_item( $item_id );
733
+    public function has_item($item_id) {
734
+        return false !== $this->get_item($item_id);
735 735
 	}
736 736
 
737 737
 	/**
@@ -740,8 +740,8 @@  discard block
 block discarded – undo
740 740
 	 * @since 1.0.19
741 741
 	 * @return bool
742 742
 	 */
743
-    public function has_element_type( $element_type ) {
744
-        return false !== $this->get_element_type( $element_type );
743
+    public function has_element_type($element_type) {
744
+        return false !== $this->get_element_type($element_type);
745 745
 	}
746 746
 
747 747
 	/**
@@ -752,13 +752,13 @@  discard block
 block discarded – undo
752 752
 	 */
753 753
     public function is_recurring() {
754 754
 
755
-		if ( ! empty( $this->invoice ) ) {
755
+		if (!empty($this->invoice)) {
756 756
 			return $this->invoice->is_recurring();
757 757
 		}
758 758
 
759
-		foreach ( $this->get_items() as $item ) {
759
+		foreach ($this->get_items() as $item) {
760 760
 
761
-			if ( $item->is_recurring() ) {
761
+			if ($item->is_recurring()) {
762 762
 				return true;
763 763
 			}
764 764
         }
@@ -771,7 +771,7 @@  discard block
 block discarded – undo
771 771
 	 *
772 772
 	 * @since 1.0.19
773 773
 	 */
774
-    public function get_html( $extra_markup = '' ) {
774
+    public function get_html($extra_markup = '') {
775 775
 
776 776
 		// Return the HTML.
777 777
 		return wpinv_get_template_html(
@@ -788,7 +788,7 @@  discard block
 block discarded – undo
788 788
 	 *
789 789
 	 * @since 1.0.19
790 790
 	 */
791
-    public function display( $extra_markup = '' ) {
791
+    public function display($extra_markup = '') {
792 792
 		wpinv_get_template(
793 793
 			'payment-forms/form.php',
794 794
 			array(
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Indentation   +64 added lines, -64 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
 
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
 
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
         global $getpaid_force_checkbox;
265 265
 
266 266
         // Is the request set up correctly?
267
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
268
-			aui()->alert(
269
-				array(
270
-					'type'    => 'warning',
271
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
267
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
268
+            aui()->alert(
269
+                array(
270
+                    'type'    => 'warning',
271
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
272 272
                 ),
273 273
                 true
274 274
             );
@@ -276,7 +276,7 @@  discard block
 block discarded – undo
276 276
         }
277 277
 
278 278
         // Payment form or button?
279
-		if ( ! empty( $_GET['form'] ) ) {
279
+        if ( ! empty( $_GET['form'] ) ) {
280 280
             $form = sanitize_text_field( urldecode( $_GET['form'] ) );
281 281
 
282 282
             if ( false !== strpos( $form, '|' ) ) {
@@ -330,10 +330,10 @@  discard block
 block discarded – undo
330 330
                 getpaid_display_payment_form( $form );
331 331
             }
332 332
         } elseif ( ! empty( $_GET['invoice'] ) ) {
333
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
333
+            getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
334 334
         } else {
335
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
336
-		    getpaid_display_item_payment_form( $items );
335
+            $items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
336
+            getpaid_display_item_payment_form( $items );
337 337
         }
338 338
 
339 339
         exit;
@@ -667,7 +667,7 @@  discard block
 block discarded – undo
667 667
         if ( is_wp_error( $error ) ) {
668 668
             $alert = $error->get_error_message();
669 669
             wp_send_json_success( compact( 'alert' ) );
670
-         }
670
+            }
671 671
 
672 672
         // Update totals.
673 673
         $invoice->recalculate_total();
@@ -1111,12 +1111,12 @@  discard block
 block discarded – undo
1111 1111
     }
1112 1112
 
1113 1113
     /**
1114
-	 * Handles file uploads.
1115
-	 *
1116
-	 * @since       1.0.0
1117
-	 * @return      void
1118
-	 */
1119
-	public static function file_upload() {
1114
+     * Handles file uploads.
1115
+     *
1116
+     * @since       1.0.0
1117
+     * @return      void
1118
+     */
1119
+    public static function file_upload() {
1120 1120
 
1121 1121
         // Check nonce.
1122 1122
         check_ajax_referer( 'getpaid_form_nonce' );
@@ -1177,7 +1177,7 @@  discard block
 block discarded – undo
1177 1177
 
1178 1178
         wp_send_json_success( $response );
1179 1179
 
1180
-	}
1180
+    }
1181 1181
 
1182 1182
 }
1183 1183
 
Please login to merge, or discard this patch.
Spacing   +339 added lines, -339 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
 
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
 
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -106,36 +106,36 @@  discard block
 block discarded – undo
106 106
             'file_upload'                   => true,
107 107
         );
108 108
 
109
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
110
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+        foreach ($ajax_events as $ajax_event => $nopriv) {
110
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112 112
 
113
-            if ( $nopriv ) {
114
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
115
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
116
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
113
+            if ($nopriv) {
114
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
115
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
116
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
117 117
             }
118 118
         }
119 119
     }
120 120
 
121 121
     public static function add_note() {
122
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
122
+        check_ajax_referer('add-invoice-note', '_nonce');
123 123
 
124
-        $post_id   = absint( $_POST['post_id'] );
125
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
126
-        $note_type = sanitize_text_field( $_POST['note_type'] );
124
+        $post_id   = absint($_POST['post_id']);
125
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
126
+        $note_type = sanitize_text_field($_POST['note_type']);
127 127
 
128
-        if ( ! wpinv_current_user_can( 'invoice_add_note', array( 'invoice_id' => $post_id, 'note_type' => $note_type ) ) ) {
128
+        if (!wpinv_current_user_can('invoice_add_note', array('invoice_id' => $post_id, 'note_type' => $note_type))) {
129 129
             die( -1 );
130 130
         }
131 131
 
132 132
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
133 133
 
134
-        if ( $post_id > 0 ) {
135
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
134
+        if ($post_id > 0) {
135
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
136 136
 
137
-            if ( $note_id > 0 && ! is_wp_error( $note_id ) ) {
138
-                wpinv_get_invoice_note_line_item( $note_id );
137
+            if ($note_id > 0 && !is_wp_error($note_id)) {
138
+                wpinv_get_invoice_note_line_item($note_id);
139 139
             }
140 140
         }
141 141
 
@@ -143,16 +143,16 @@  discard block
 block discarded – undo
143 143
     }
144 144
 
145 145
     public static function delete_note() {
146
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
146
+        check_ajax_referer('delete-invoice-note', '_nonce');
147 147
 
148
-        $note_id = (int)$_POST['note_id'];
148
+        $note_id = (int) $_POST['note_id'];
149 149
 
150
-        if ( ! wpinv_current_user_can( 'invoice_delete_note', array( 'note_id' => $note_id ) ) ) {
150
+        if (!wpinv_current_user_can('invoice_delete_note', array('note_id' => $note_id))) {
151 151
             die( -1 );
152 152
         }
153 153
 
154
-        if ( $note_id > 0 ) {
155
-            wp_delete_comment( $note_id, true );
154
+        if ($note_id > 0) {
155
+            wp_delete_comment($note_id, true);
156 156
         }
157 157
 
158 158
         die();
@@ -169,35 +169,35 @@  discard block
 block discarded – undo
169 169
      */
170 170
     public static function get_billing_details() {
171 171
         // Verify nonce.
172
-        check_ajax_referer( 'wpinv-nonce' );
172
+        check_ajax_referer('wpinv-nonce');
173 173
 
174 174
         // Do we have a user id?
175 175
         $user_id = (int) $_GET['user_id'];
176
-        $invoice_id = ! empty( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
176
+        $invoice_id = !empty($_REQUEST['post_id']) ? (int) $_REQUEST['post_id'] : 0;
177 177
 
178
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
178
+        if (empty($user_id) || !is_numeric($user_id)) {
179 179
             die( -1 );
180 180
         }
181 181
 
182 182
         // Can the user manage the plugin?
183
-        if ( ! wpinv_current_user_can( 'invoice_get_billing_details', array( 'user_id' => $user_id, 'invoice_id' => $invoice_id ) ) ) {
183
+        if (!wpinv_current_user_can('invoice_get_billing_details', array('user_id' => $user_id, 'invoice_id' => $invoice_id))) {
184 184
             die( -1 );
185 185
         }
186 186
 
187 187
         // Fetch the billing details.
188
-        $billing_details    = wpinv_get_user_address( $user_id );
189
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
188
+        $billing_details    = wpinv_get_user_address($user_id);
189
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
190 190
 
191 191
         // unset the user id and email.
192
-        $to_ignore = array( 'user_id', 'email' );
192
+        $to_ignore = array('user_id', 'email');
193 193
 
194
-        foreach ( $to_ignore as $key ) {
195
-            if ( isset( $billing_details[ $key ] ) ) {
196
-                unset( $billing_details[ $key ] );
194
+        foreach ($to_ignore as $key) {
195
+            if (isset($billing_details[$key])) {
196
+                unset($billing_details[$key]);
197 197
             }
198 198
         }
199 199
 
200
-        wp_send_json_success( $billing_details );
200
+        wp_send_json_success($billing_details);
201 201
 
202 202
     }
203 203
 
@@ -206,54 +206,54 @@  discard block
 block discarded – undo
206 206
      */
207 207
     public static function check_new_user_email() {
208 208
         // Verify nonce.
209
-        check_ajax_referer( 'wpinv-nonce' );
209
+        check_ajax_referer('wpinv-nonce');
210 210
 
211
-        $invoice_id = ! empty( $_REQUEST['post_id'] ) ? absint( $_REQUEST['post_id'] ) : 0;
211
+        $invoice_id = !empty($_REQUEST['post_id']) ? absint($_REQUEST['post_id']) : 0;
212 212
 
213
-        if ( empty( $invoice_id ) ) {
213
+        if (empty($invoice_id)) {
214 214
             die( -1 );
215 215
         }
216 216
 
217 217
         // Can the user manage the plugin?
218
-        if ( ! wpinv_current_user_can( 'invoice_check_new_user_email', array( 'invoice_id' => $invoice_id ) ) ) {
218
+        if (!wpinv_current_user_can('invoice_check_new_user_email', array('invoice_id' => $invoice_id))) {
219 219
             die( -1 );
220 220
         }
221 221
 
222 222
         // We need an email address.
223
-        if ( empty( $_GET['email'] ) ) {
224
-            esc_html_e( "Provide the new user's email address", 'invoicing' );
223
+        if (empty($_GET['email'])) {
224
+            esc_html_e("Provide the new user's email address", 'invoicing');
225 225
             exit;
226 226
         }
227 227
 
228 228
         // Ensure the email is valid.
229
-        $email = sanitize_email( $_GET['email'] );
230
-        if ( ! is_email( $email ) ) {
231
-            esc_html_e( 'Invalid email address', 'invoicing' );
229
+        $email = sanitize_email($_GET['email']);
230
+        if (!is_email($email)) {
231
+            esc_html_e('Invalid email address', 'invoicing');
232 232
             exit;
233 233
         }
234 234
 
235 235
         // And it does not exist.
236
-        $id = email_exists( $email );
237
-        if ( $id ) {
238
-            wp_send_json_success( compact( 'id' ) );
236
+        $id = email_exists($email);
237
+        if ($id) {
238
+            wp_send_json_success(compact('id'));
239 239
         }
240 240
 
241
-        wp_send_json_success( true );
241
+        wp_send_json_success(true);
242 242
     }
243 243
 
244 244
     public static function run_tool() {
245
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
245
+        check_ajax_referer('wpinv-nonce', '_nonce');
246 246
 
247
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
247
+        if (!wpinv_current_user_can_manage_invoicing()) {
248 248
             die( -1 );
249 249
         }
250 250
 
251
-        $tool = sanitize_text_field( $_POST['tool'] );
251
+        $tool = sanitize_text_field($_POST['tool']);
252 252
 
253
-        do_action( 'wpinv_run_tool' );
253
+        do_action('wpinv_run_tool');
254 254
 
255
-        if ( ! empty( $tool ) ) {
256
-            do_action( 'wpinv_tool_' . $tool );
255
+        if (!empty($tool)) {
256
+            do_action('wpinv_tool_' . $tool);
257 257
         }
258 258
     }
259 259
 
@@ -264,11 +264,11 @@  discard block
 block discarded – undo
264 264
         global $getpaid_force_checkbox;
265 265
 
266 266
         // Is the request set up correctly?
267
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
267
+		if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) {
268 268
 			aui()->alert(
269 269
 				array(
270 270
 					'type'    => 'warning',
271
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
271
+					'content' => __('No payment form or item provided', 'invoicing'),
272 272
                 ),
273 273
                 true
274 274
             );
@@ -276,29 +276,29 @@  discard block
 block discarded – undo
276 276
         }
277 277
 
278 278
         // Payment form or button?
279
-		if ( ! empty( $_GET['form'] ) ) {
280
-            $form = sanitize_text_field( urldecode( $_GET['form'] ) );
279
+		if (!empty($_GET['form'])) {
280
+            $form = sanitize_text_field(urldecode($_GET['form']));
281 281
 
282
-            if ( false !== strpos( $form, '|' ) ) {
283
-                $form_pos = strpos( $form, '|' );
284
-                $_items   = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) );
285
-                $form     = substr( $form, 0, $form_pos );
282
+            if (false !== strpos($form, '|')) {
283
+                $form_pos = strpos($form, '|');
284
+                $_items   = getpaid_convert_items_to_array(substr($form, $form_pos + 1));
285
+                $form     = substr($form, 0, $form_pos);
286 286
 
287 287
                 // Retrieve appropriate payment form.
288
-                $payment_form = new GetPaid_Payment_Form( $form );
289
-                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
288
+                $payment_form = new GetPaid_Payment_Form($form);
289
+                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
290 290
 
291 291
                 $items    = array();
292 292
                 $item_ids = array();
293 293
 
294
-                foreach ( $_items as $item_id => $qty ) {
295
-                    if ( ! in_array( $item_id, $item_ids ) ) {
296
-                        $item = new GetPaid_Form_Item( $item_id );
297
-                        $item->set_quantity( $qty );
294
+                foreach ($_items as $item_id => $qty) {
295
+                    if (!in_array($item_id, $item_ids)) {
296
+                        $item = new GetPaid_Form_Item($item_id);
297
+                        $item->set_quantity($qty);
298 298
 
299
-                        if ( 0 == $qty ) {
300
-                            $item->set_allow_quantities( true );
301
-                            $item->set_is_required( false );
299
+                        if (0 == $qty) {
300
+                            $item->set_allow_quantities(true);
301
+                            $item->set_is_required(false);
302 302
                             $getpaid_force_checkbox = true;
303 303
                         }
304 304
 
@@ -307,33 +307,33 @@  discard block
 block discarded – undo
307 307
                     }
308 308
                 }
309 309
 
310
-                if ( ! $payment_form->is_default() ) {
310
+                if (!$payment_form->is_default()) {
311 311
 
312
-                    foreach ( $payment_form->get_items() as $item ) {
313
-                        if ( ! in_array( $item->get_id(), $item_ids ) ) {
312
+                    foreach ($payment_form->get_items() as $item) {
313
+                        if (!in_array($item->get_id(), $item_ids)) {
314 314
                             $item_ids[] = $item->get_id();
315 315
                             $items[]    = $item;
316 316
                         }
317 317
                     }
318 318
                 }
319 319
 
320
-                $payment_form->set_items( $items );
320
+                $payment_form->set_items($items);
321 321
 
322
-                $extra_items     = esc_attr( getpaid_convert_items_to_string( $_items ) );
323
-                $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items );
322
+                $extra_items     = esc_attr(getpaid_convert_items_to_string($_items));
323
+                $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items);
324 324
                 $extra_items     = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />";
325 325
                 $extra_items    .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />";
326
-                $payment_form->display( $extra_items );
326
+                $payment_form->display($extra_items);
327 327
                 $getpaid_force_checkbox = false;
328 328
 
329 329
             } else {
330
-                getpaid_display_payment_form( $form );
330
+                getpaid_display_payment_form($form);
331 331
             }
332
-        } elseif ( ! empty( $_GET['invoice'] ) ) {
333
-		    getpaid_display_invoice_payment_form( (int) urldecode( $_GET['invoice'] ) );
332
+        } elseif (!empty($_GET['invoice'])) {
333
+		    getpaid_display_invoice_payment_form((int) urldecode($_GET['invoice']));
334 334
         } else {
335
-			$items = getpaid_convert_items_to_array( sanitize_text_field( urldecode( $_GET['item'] ) ) );
336
-		    getpaid_display_item_payment_form( $items );
335
+			$items = getpaid_convert_items_to_array(sanitize_text_field(urldecode($_GET['item'])));
336
+		    getpaid_display_item_payment_form($items);
337 337
         }
338 338
 
339 339
         exit;
@@ -348,14 +348,14 @@  discard block
 block discarded – undo
348 348
     public static function payment_form() { 
349 349
 
350 350
         // ... form fields...
351
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
352
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
351
+        if (empty($_POST['getpaid_payment_form_submission'])) {
352
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
353 353
             exit;
354 354
         }
355 355
 
356 356
         // Process the payment form.
357
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
358
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
357
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
358
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
359 359
         $checkout->process_checkout();
360 360
 
361 361
         exit;
@@ -368,55 +368,55 @@  discard block
 block discarded – undo
368 368
      */
369 369
     public static function get_payment_form_states_field() {
370 370
 
371
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
371
+        if (empty($_GET['country']) || empty($_GET['form'])) {
372 372
             exit;
373 373
         }
374 374
 
375
-        $elements = getpaid_get_payment_form_elements( (int) $_GET['form'] );
375
+        $elements = getpaid_get_payment_form_elements((int) $_GET['form']);
376 376
 
377
-        if ( empty( $elements ) ) {
377
+        if (empty($elements)) {
378 378
             exit;
379 379
         }
380 380
 
381 381
         $address_fields = array();
382
-        foreach ( $elements as $element ) {
383
-            if ( 'address' === $element['type'] ) {
382
+        foreach ($elements as $element) {
383
+            if ('address' === $element['type']) {
384 384
                 $address_fields = $element;
385 385
                 break;
386 386
             }
387 387
         }
388 388
 
389
-        if ( empty( $address_fields ) ) {
389
+        if (empty($address_fields)) {
390 390
             exit;
391 391
         }
392 392
 
393
-        foreach ( $address_fields['fields'] as $address_field ) {
393
+        foreach ($address_fields['fields'] as $address_field) {
394 394
 
395
-            if ( 'wpinv_state' == $address_field['name'] ) {
395
+            if ('wpinv_state' == $address_field['name']) {
396 396
 
397
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
398
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
399
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
400
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
401
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
402
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
397
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
398
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
399
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
400
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
401
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
402
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
403 403
 
404
-                if ( ! empty( $address_field['required'] ) ) {
404
+                if (!empty($address_field['required'])) {
405 405
                     $label .= "<span class='text-danger'> *</span>";
406 406
                 }
407 407
 
408 408
                 $html = getpaid_get_states_select_markup(
409
-                    sanitize_text_field( $_GET['country'] ),
409
+                    sanitize_text_field($_GET['country']),
410 410
                     $value,
411 411
                     $placeholder,
412 412
                     $label,
413 413
                     $description,
414
-                    ! empty( $address_field['required'] ),
414
+                    !empty($address_field['required']),
415 415
                     $wrap_class,
416
-                    sanitize_text_field( $_GET['name'] )
416
+                    sanitize_text_field($_GET['name'])
417 417
                 );
418 418
 
419
-                wp_send_json_success( $html );
419
+                wp_send_json_success($html);
420 420
                 exit;
421 421
 
422 422
             }
@@ -430,68 +430,68 @@  discard block
 block discarded – undo
430 430
      */
431 431
     public static function recalculate_invoice_totals() {
432 432
         // Verify nonce.
433
-        check_ajax_referer( 'wpinv-nonce' );
433
+        check_ajax_referer('wpinv-nonce');
434 434
 
435
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
435
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
436 436
 
437
-        if ( empty( $invoice_id ) ) {
437
+        if (empty($invoice_id)) {
438 438
             die( -1 );
439 439
         }
440 440
 
441 441
         // Can the user manage the plugin?
442
-        if ( ! wpinv_current_user_can( 'invoice_recalculate_totals', array( 'invoice_id' => $invoice_id ) ) ) {
442
+        if (!wpinv_current_user_can('invoice_recalculate_totals', array('invoice_id' => $invoice_id))) {
443 443
             die( -1 );
444 444
         }
445 445
 
446 446
         // Fetch the invoice.
447
-        $invoice = new WPInv_Invoice( $invoice_id );
447
+        $invoice = new WPInv_Invoice($invoice_id);
448 448
 
449 449
         // Ensure it exists.
450
-        if ( ! $invoice->get_id() ) {
450
+        if (!$invoice->get_id()) {
451 451
             exit;
452 452
         }
453 453
 
454 454
         // Maybe set the country, state, currency.
455
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
456
-            if ( isset( $_POST[ $key ] ) ) {
455
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
456
+            if (isset($_POST[$key])) {
457 457
                 $method = "set_$key";
458
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
458
+                $invoice->$method(sanitize_text_field($_POST[$key]));
459 459
             }
460 460
         }
461 461
 
462 462
         // Maybe disable taxes.
463
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
463
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
464 464
 
465 465
         // Discount code.
466
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
467
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
468
-            if ( $discount->exists() ) {
469
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
466
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
467
+            $discount = new WPInv_Discount($invoice->get_discount_code());
468
+            if ($discount->exists()) {
469
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
470 470
             } else {
471
-                $invoice->remove_discount( 'discount_code' );
471
+                $invoice->remove_discount('discount_code');
472 472
             }
473 473
         }
474 474
 
475 475
         // Recalculate totals.
476 476
         $invoice->recalculate_total();
477 477
 
478
-        $total        = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
479
-        $suscriptions = getpaid_get_invoice_subscriptions( $invoice );
480
-        if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
481
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
482
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
478
+        $total        = wpinv_price($invoice->get_total(), $invoice->get_currency());
479
+        $suscriptions = getpaid_get_invoice_subscriptions($invoice);
480
+        if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
481
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
482
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
483 483
         }
484 484
 
485 485
         $totals = array(
486
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
487
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
488
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
486
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
487
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
488
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
489 489
             'total'    => $total,
490 490
         );
491 491
 
492
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
492
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
493 493
 
494
-        wp_send_json_success( compact( 'totals' ) );
494
+        wp_send_json_success(compact('totals'));
495 495
     }
496 496
 
497 497
     /**
@@ -499,35 +499,35 @@  discard block
 block discarded – undo
499 499
      */
500 500
     public static function get_invoice_items() {
501 501
         // Verify nonce.
502
-        check_ajax_referer( 'wpinv-nonce' );
502
+        check_ajax_referer('wpinv-nonce');
503 503
 
504
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
504
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
505 505
 
506
-        if ( empty( $invoice_id ) ) {
506
+        if (empty($invoice_id)) {
507 507
             exit;
508 508
         }
509 509
 
510 510
         // Can the user manage the plugin?
511
-        if ( ! wpinv_current_user_can( 'invoice_get_items', array( 'invoice_id' => $invoice_id ) ) ) {
511
+        if (!wpinv_current_user_can('invoice_get_items', array('invoice_id' => $invoice_id))) {
512 512
             exit;
513 513
         }
514 514
 
515 515
         // Fetch the invoice.
516
-        $invoice = new WPInv_Invoice( $invoice_id );
516
+        $invoice = new WPInv_Invoice($invoice_id);
517 517
 
518 518
         // Ensure it exists.
519
-        if ( ! $invoice->get_id() ) {
519
+        if (!$invoice->get_id()) {
520 520
             exit;
521 521
         }
522 522
 
523 523
         // Return an array of invoice items.
524 524
         $items = array();
525 525
 
526
-        foreach ( $invoice->get_items() as $item ) {
527
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency(), $invoice->is_renewal() );
526
+        foreach ($invoice->get_items() as $item) {
527
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
528 528
         }
529 529
 
530
-        wp_send_json_success( compact( 'items' ) );
530
+        wp_send_json_success(compact('items'));
531 531
     }
532 532
 
533 533
     /**
@@ -535,57 +535,57 @@  discard block
 block discarded – undo
535 535
      */
536 536
     public static function edit_invoice_item() {
537 537
         // Verify nonce.
538
-        check_ajax_referer( 'wpinv-nonce' );
538
+        check_ajax_referer('wpinv-nonce');
539 539
 
540 540
         // We need an invoice and item details.
541
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
541
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
542 542
             exit;
543 543
         }
544 544
 
545
-        $invoice_id = absint( $_POST['post_id'] );
545
+        $invoice_id = absint($_POST['post_id']);
546 546
 
547
-        if ( empty( $invoice_id ) ) {
547
+        if (empty($invoice_id)) {
548 548
             exit;
549 549
         }
550 550
 
551 551
         // Can the user manage the plugin?
552
-        if ( ! wpinv_current_user_can( 'invoice_edit_item', array( 'invoice_id' => $invoice_id ) ) ) {
552
+        if (!wpinv_current_user_can('invoice_edit_item', array('invoice_id' => $invoice_id))) {
553 553
             exit;
554 554
         }
555 555
 
556 556
         // Fetch the invoice.
557
-        $invoice = new WPInv_Invoice( $invoice_id );
557
+        $invoice = new WPInv_Invoice($invoice_id);
558 558
 
559 559
         // Ensure it exists and its not been paid for.
560
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
560
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
561 561
             exit;
562 562
         }
563 563
 
564 564
         // Format the data.
565
-        $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) );
565
+        $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')));
566 566
 
567 567
         // Ensure that we have an item id.
568
-        if ( empty( $data['id'] ) ) {
568
+        if (empty($data['id'])) {
569 569
             exit;
570 570
         }
571 571
 
572 572
         // Abort if the invoice does not have the specified item.
573
-        $item = $invoice->get_item( (int) $data['id'] );
573
+        $item = $invoice->get_item((int) $data['id']);
574 574
 
575
-        if ( empty( $item ) ) {
575
+        if (empty($item)) {
576 576
             exit;
577 577
         }
578 578
 
579 579
         // Update the item.
580
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
581
-        $item->set_name( sanitize_text_field( $data['name'] ) );
582
-        $item->set_description( wp_kses_post( $data['description'] ) );
583
-        $item->set_quantity( floatval( $data['quantity'] ) );
580
+        $item->set_price(getpaid_standardize_amount($data['price']));
581
+        $item->set_name(sanitize_text_field($data['name']));
582
+        $item->set_description(wp_kses_post($data['description']));
583
+        $item->set_quantity(floatval($data['quantity']));
584 584
 
585 585
         // Add it to the invoice.
586
-        $error = $invoice->add_item( $item );
586
+        $error = $invoice->add_item($item);
587 587
         $alert = false;
588
-        if ( is_wp_error( $error ) ) {
588
+        if (is_wp_error($error)) {
589 589
             $alert = $error->get_error_message();
590 590
         }
591 591
 
@@ -598,11 +598,11 @@  discard block
 block discarded – undo
598 598
         // Return an array of invoice items.
599 599
         $items = array();
600 600
 
601
-        foreach ( $invoice->get_items() as $item ) {
602
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
601
+        foreach ($invoice->get_items() as $item) {
602
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
603 603
         }
604 604
 
605
-        wp_send_json_success( compact( 'items', 'alert' ) );
605
+        wp_send_json_success(compact('items', 'alert'));
606 606
     }
607 607
 
608 608
     /**
@@ -610,63 +610,63 @@  discard block
 block discarded – undo
610 610
      */
611 611
     public static function create_invoice_item() {
612 612
         // Verify nonce.
613
-        check_ajax_referer( 'wpinv-nonce' );
613
+        check_ajax_referer('wpinv-nonce');
614 614
 
615 615
         // We need an invoice and item details.
616
-        if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) {
616
+        if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) {
617 617
             exit;
618 618
         }
619 619
 
620
-        $invoice_id = absint( $_POST['invoice_id'] );
620
+        $invoice_id = absint($_POST['invoice_id']);
621 621
 
622
-        if ( empty( $invoice_id ) ) {
622
+        if (empty($invoice_id)) {
623 623
             exit;
624 624
         }
625 625
 
626
-        if ( ! wpinv_current_user_can( 'invoice_create_item', array( 'invoice_id' => $invoice_id ) ) ) {
626
+        if (!wpinv_current_user_can('invoice_create_item', array('invoice_id' => $invoice_id))) {
627 627
             exit;
628 628
         }
629 629
 
630 630
         // Fetch the invoice.
631
-        $invoice = new WPInv_Invoice( $invoice_id );
631
+        $invoice = new WPInv_Invoice($invoice_id);
632 632
 
633 633
         // Ensure it exists and its not been paid for.
634
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
634
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
635 635
             exit;
636 636
         }
637 637
 
638 638
         // Format the data.
639
-        $data = wp_kses_post_deep( wp_unslash( $_POST['_wpinv_quick'] ) );
639
+        $data = wp_kses_post_deep(wp_unslash($_POST['_wpinv_quick']));
640 640
 
641 641
         $item = new WPInv_Item();
642
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
643
-        $item->set_name( sanitize_text_field( $data['name'] ) );
644
-        $item->set_description( wp_kses_post( $data['description'] ) );
645
-        $item->set_type( sanitize_text_field( $data['type'] ) );
646
-        $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) );
647
-        $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) );
648
-        $item->set_status( 'publish' );
642
+        $item->set_price(getpaid_standardize_amount($data['price']));
643
+        $item->set_name(sanitize_text_field($data['name']));
644
+        $item->set_description(wp_kses_post($data['description']));
645
+        $item->set_type(sanitize_text_field($data['type']));
646
+        $item->set_vat_rule(sanitize_text_field($data['vat_rule']));
647
+        $item->set_vat_class(sanitize_text_field($data['vat_class']));
648
+        $item->set_status('publish');
649 649
         $item->save();
650 650
 
651
-        if ( ! $item->exists() ) {
652
-            $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' );
653
-            wp_send_json_success( compact( 'alert' ) );
651
+        if (!$item->exists()) {
652
+            $alert = __('Could not create invoice item. Please try again.', 'invoicing');
653
+            wp_send_json_success(compact('alert'));
654 654
         }
655 655
 
656
-        if ( ! empty( $data['one-time'] ) ) {
657
-            update_post_meta( $item->get_id(), '_wpinv_one_time', 'yes' );
656
+        if (!empty($data['one-time'])) {
657
+            update_post_meta($item->get_id(), '_wpinv_one_time', 'yes');
658 658
         }
659 659
 
660
-        $item = new GetPaid_Form_Item( $item->get_id() );
661
-        $item->set_quantity( floatval( $data['qty'] ) );
660
+        $item = new GetPaid_Form_Item($item->get_id());
661
+        $item->set_quantity(floatval($data['qty']));
662 662
 
663 663
         // Add it to the invoice.
664
-        $error = $invoice->add_item( $item );
664
+        $error = $invoice->add_item($item);
665 665
         $alert = false;
666 666
 
667
-        if ( is_wp_error( $error ) ) {
667
+        if (is_wp_error($error)) {
668 668
             $alert = $error->get_error_message();
669
-            wp_send_json_success( compact( 'alert' ) );
669
+            wp_send_json_success(compact('alert'));
670 670
          }
671 671
 
672 672
         // Update totals.
@@ -679,9 +679,9 @@  discard block
 block discarded – undo
679 679
         $invoice->recalculate_total();
680 680
         $invoice->save();
681 681
         ob_start();
682
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
682
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
683 683
         $row = ob_get_clean();
684
-        wp_send_json_success( compact( 'row' ) );
684
+        wp_send_json_success(compact('row'));
685 685
     }
686 686
 
687 687
     /**
@@ -689,37 +689,37 @@  discard block
 block discarded – undo
689 689
      */
690 690
     public static function remove_invoice_item() {
691 691
         // Verify nonce.
692
-        check_ajax_referer( 'wpinv-nonce' );
692
+        check_ajax_referer('wpinv-nonce');
693 693
 
694 694
         // We need an invoice and item.
695
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
696
-        $item_id = ! empty( $_POST['item_id'] ) ? absint( $_POST['item_id'] ) : 0;
695
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
696
+        $item_id = !empty($_POST['item_id']) ? absint($_POST['item_id']) : 0;
697 697
 
698
-        if ( empty( $invoice_id ) || empty( $item_id ) ) {
698
+        if (empty($invoice_id) || empty($item_id)) {
699 699
             exit;
700 700
         }
701 701
 
702 702
         // Can the user manage the plugin?
703
-        if ( ! wpinv_current_user_can( 'invoice_remove_item', array( 'invoice_id' => $invoice_id, 'item_id' => $item_id ) ) ) {
703
+        if (!wpinv_current_user_can('invoice_remove_item', array('invoice_id' => $invoice_id, 'item_id' => $item_id))) {
704 704
             exit;
705 705
         }
706 706
 
707 707
         // Fetch the invoice.
708
-        $invoice = new WPInv_Invoice( $invoice_id );
708
+        $invoice = new WPInv_Invoice($invoice_id);
709 709
 
710 710
         // Ensure it exists and its not been paid for.
711
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
711
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
712 712
             exit;
713 713
         }
714 714
 
715 715
         // Abort if the invoice does not have the specified item.
716
-        $item = $invoice->get_item( $item_id );
716
+        $item = $invoice->get_item($item_id);
717 717
 
718
-        if ( empty( $item ) ) {
718
+        if (empty($item)) {
719 719
             exit;
720 720
         }
721 721
 
722
-        $invoice->remove_item( $item_id );
722
+        $invoice->remove_item($item_id);
723 723
 
724 724
         // Update totals.
725 725
         $invoice->recalculate_total();
@@ -730,11 +730,11 @@  discard block
 block discarded – undo
730 730
         // Return an array of invoice items.
731 731
         $items = array();
732 732
 
733
-        foreach ( $invoice->get_items() as $item ) {
734
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
733
+        foreach ($invoice->get_items() as $item) {
734
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
735 735
         }
736 736
 
737
-        wp_send_json_success( compact( 'items' ) );
737
+        wp_send_json_success(compact('items'));
738 738
     }
739 739
 
740 740
     /**
@@ -742,69 +742,69 @@  discard block
 block discarded – undo
742 742
      */
743 743
     public static function recalculate_full_prices() {
744 744
         // Verify nonce.
745
-        check_ajax_referer( 'wpinv-nonce' );
745
+        check_ajax_referer('wpinv-nonce');
746 746
 
747
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
747
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
748 748
 
749
-        if ( empty( $invoice_id ) ) {
749
+        if (empty($invoice_id)) {
750 750
             exit;
751 751
         }
752 752
 
753
-        if ( ! wpinv_current_user_can( 'invoice_recalculate_full_prices', array( 'invoice_id' => $invoice_id ) ) ) {
753
+        if (!wpinv_current_user_can('invoice_recalculate_full_prices', array('invoice_id' => $invoice_id))) {
754 754
             exit;
755 755
         }
756 756
 
757 757
         // Fetch the invoice.
758
-        $invoice = new WPInv_Invoice( $invoice_id );
758
+        $invoice = new WPInv_Invoice($invoice_id);
759 759
         $alert   = false;
760 760
 
761 761
         // Ensure it exists and its not been paid for.
762
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
762
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
763 763
             exit;
764 764
         }
765 765
 
766
-        $invoice->set_items( array() );
766
+        $invoice->set_items(array());
767 767
 
768
-        if ( ! empty( $_POST['getpaid_items'] ) ) {
768
+        if (!empty($_POST['getpaid_items'])) {
769 769
 
770
-            foreach ( wp_kses_post_deep( wp_unslash( $_POST['getpaid_items'] ) ) as $item_id => $args ) {
771
-                $item = new GetPaid_Form_Item( $item_id );
770
+            foreach (wp_kses_post_deep(wp_unslash($_POST['getpaid_items'])) as $item_id => $args) {
771
+                $item = new GetPaid_Form_Item($item_id);
772 772
 
773
-                if ( $item->exists() ) {
774
-                    $item->set_price( getpaid_standardize_amount( $args['price'] ) );
775
-                    $item->set_quantity( floatval( $args['quantity'] ) );
776
-                    $item->set_name( sanitize_text_field( $args['name'] ) );
777
-                    $item->set_description( wp_kses_post( $args['description'] ) );
778
-                    $invoice->add_item( $item );
773
+                if ($item->exists()) {
774
+                    $item->set_price(getpaid_standardize_amount($args['price']));
775
+                    $item->set_quantity(floatval($args['quantity']));
776
+                    $item->set_name(sanitize_text_field($args['name']));
777
+                    $item->set_description(wp_kses_post($args['description']));
778
+                    $invoice->add_item($item);
779 779
                 }
780 780
             }
781 781
         }
782 782
 
783
-        $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) );
783
+        $invoice->set_disable_taxes(!empty($_POST['disable_taxes']));
784 784
 
785 785
         // Maybe set the country, state, currency.
786
-        foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) {
787
-            if ( isset( $_POST[ $key ] ) ) {
788
-                $_key   = str_replace( 'wpinv_', '', $key );
786
+        foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) {
787
+            if (isset($_POST[$key])) {
788
+                $_key   = str_replace('wpinv_', '', $key);
789 789
                 $method = "set_$_key";
790
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
790
+                $invoice->$method(sanitize_text_field($_POST[$key]));
791 791
             }
792 792
         }
793 793
 
794
-        $discount = new WPInv_Discount( $invoice->get_discount_code() );
795
-        if ( $discount->exists() ) {
796
-            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
794
+        $discount = new WPInv_Discount($invoice->get_discount_code());
795
+        if ($discount->exists()) {
796
+            $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
797 797
         } else {
798
-            $invoice->remove_discount( 'discount_code' );
798
+            $invoice->remove_discount('discount_code');
799 799
         }
800 800
 
801 801
         // Save the invoice.
802 802
         $invoice->recalculate_total();
803 803
         $invoice->save();
804 804
         ob_start();
805
-        GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice );
805
+        GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice);
806 806
         $table = ob_get_clean();
807
-        wp_send_json_success( compact( 'table' ) );
807
+        wp_send_json_success(compact('table'));
808 808
     }
809 809
 
810 810
     /**
@@ -812,47 +812,47 @@  discard block
 block discarded – undo
812 812
      */
813 813
     public static function admin_add_invoice_item() {
814 814
         // Verify nonce.
815
-        check_ajax_referer( 'wpinv-nonce' );
815
+        check_ajax_referer('wpinv-nonce');
816 816
 
817 817
         // We need an invoice and item.
818
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
819
-        $item_id = ! empty( $_POST['item_id'] ) ? absint( $_POST['item_id'] ) : 0;
818
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
819
+        $item_id = !empty($_POST['item_id']) ? absint($_POST['item_id']) : 0;
820 820
 
821
-        if ( empty( $invoice_id ) || empty( $item_id ) ) {
821
+        if (empty($invoice_id) || empty($item_id)) {
822 822
             exit;
823 823
         }
824 824
 
825 825
         // Can the user manage the plugin?
826
-        if ( ! wpinv_current_user_can( 'invoice_add_item', array( 'invoice_id' => $invoice_id, 'item_id' => $item_id ) ) ) {
826
+        if (!wpinv_current_user_can('invoice_add_item', array('invoice_id' => $invoice_id, 'item_id' => $item_id))) {
827 827
             exit;
828 828
         }
829 829
 
830 830
         // Fetch the invoice.
831
-        $invoice = new WPInv_Invoice( $invoice_id );
831
+        $invoice = new WPInv_Invoice($invoice_id);
832 832
         $alert   = false;
833 833
 
834 834
         // Ensure it exists and its not been paid for.
835
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
835
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
836 836
             exit;
837 837
         }
838 838
 
839 839
         // Add the item.
840
-        $item  = new GetPaid_Form_Item( $item_id );
840
+        $item  = new GetPaid_Form_Item($item_id);
841 841
 
842
-        $error = $invoice->add_item( $item );
842
+        $error = $invoice->add_item($item);
843 843
 
844
-        if ( is_wp_error( $error ) ) {
844
+        if (is_wp_error($error)) {
845 845
             $alert = $error->get_error_message();
846
-            wp_send_json_success( compact( 'alert' ) );
846
+            wp_send_json_success(compact('alert'));
847 847
         }
848 848
 
849 849
         // Save the invoice.
850 850
         $invoice->recalculate_total();
851 851
         $invoice->save();
852 852
         ob_start();
853
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
853
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
854 854
         $row = ob_get_clean();
855
-        wp_send_json_success( compact( 'row' ) );
855
+        wp_send_json_success(compact('row'));
856 856
     }
857 857
 
858 858
     /**
@@ -860,42 +860,42 @@  discard block
 block discarded – undo
860 860
      */
861 861
     public static function add_invoice_items() {
862 862
         // Verify nonce.
863
-        check_ajax_referer( 'wpinv-nonce' );
863
+        check_ajax_referer('wpinv-nonce');
864 864
 
865
-        $invoice_id = ! empty( $_POST['post_id'] ) ? absint( $_POST['post_id'] ) : 0;
865
+        $invoice_id = !empty($_POST['post_id']) ? absint($_POST['post_id']) : 0;
866 866
 
867 867
         // We need an invoice and items.
868
-        if ( empty( $invoice_id ) || empty( $_POST['items'] ) ) {
868
+        if (empty($invoice_id) || empty($_POST['items'])) {
869 869
             exit;
870 870
         }
871 871
 
872 872
         // Can the user manage the plugin?
873
-        if ( ! wpinv_current_user_can( 'invoice_add_items', array( 'invoice_id' => $invoice_id ) ) ) {
873
+        if (!wpinv_current_user_can('invoice_add_items', array('invoice_id' => $invoice_id))) {
874 874
             exit;
875 875
         }
876 876
 
877 877
         // Fetch the invoice.
878
-        $invoice = new WPInv_Invoice( $invoice_id );
878
+        $invoice = new WPInv_Invoice($invoice_id);
879 879
         $alert   = false;
880 880
 
881 881
         // Ensure it exists and its not been paid for.
882
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
882
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
883 883
             exit;
884 884
         }
885 885
 
886 886
         // Add the items.
887
-        foreach ( wp_kses_post_deep( wp_unslash( $_POST['items'] ) ) as $data ) {
887
+        foreach (wp_kses_post_deep(wp_unslash($_POST['items'])) as $data) {
888 888
 
889
-            $item = new GetPaid_Form_Item( (int) $data['id'] );
889
+            $item = new GetPaid_Form_Item((int) $data['id']);
890 890
 
891
-            if ( is_numeric( $data['qty'] ) && (float) $data['qty'] > 0 ) {
892
-                $item->set_quantity( floatval( $data['qty'] ) );
891
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
892
+                $item->set_quantity(floatval($data['qty']));
893 893
             }
894 894
 
895
-            if ( $item->get_id() > 0 ) {
896
-                $error = $invoice->add_item( $item );
895
+            if ($item->get_id() > 0) {
896
+                $error = $invoice->add_item($item);
897 897
 
898
-                if ( is_wp_error( $error ) ) {
898
+                if (is_wp_error($error)) {
899 899
                     $alert = $error->get_error_message();
900 900
                 }
901 901
 }
@@ -908,11 +908,11 @@  discard block
 block discarded – undo
908 908
         // Return an array of invoice items.
909 909
         $items = array();
910 910
 
911
-        foreach ( $invoice->get_items() as $item ) {
912
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
911
+        foreach ($invoice->get_items() as $item) {
912
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
913 913
         }
914 914
 
915
-        wp_send_json_success( compact( 'items', 'alert' ) );
915
+        wp_send_json_success(compact('items', 'alert'));
916 916
     }
917 917
 
918 918
     /**
@@ -920,16 +920,16 @@  discard block
 block discarded – undo
920 920
      */
921 921
     public static function get_invoicing_items() {
922 922
         // Verify nonce.
923
-        check_ajax_referer( 'wpinv-nonce' );
923
+        check_ajax_referer('wpinv-nonce');
924 924
 
925 925
         // Can the user manage the plugin?
926
-        if ( ! wpinv_current_user_can( 'get_invoicing_items' ) ) {
926
+        if (!wpinv_current_user_can('get_invoicing_items')) {
927 927
             exit;
928 928
         }
929 929
 
930 930
         // We need a search term.
931
-        if ( empty( $_GET['search'] ) ) {
932
-            wp_send_json_success( array() );
931
+        if (empty($_GET['search'])) {
932
+            wp_send_json_success(array());
933 933
         }
934 934
 
935 935
         // Retrieve items.
@@ -938,8 +938,8 @@  discard block
 block discarded – undo
938 938
             'orderby'        => 'title',
939 939
             'order'          => 'ASC',
940 940
             'posts_per_page' => -1,
941
-            'post_status'    => array( 'publish' ),
942
-            's'              => sanitize_text_field( urldecode( $_GET['search'] ) ),
941
+            'post_status'    => array('publish'),
942
+            's'              => sanitize_text_field(urldecode($_GET['search'])),
943 943
             'meta_query'     => array(
944 944
                 array(
945 945
                     'key'     => '_wpinv_type',
@@ -953,25 +953,25 @@  discard block
 block discarded – undo
953 953
             ),
954 954
         );
955 955
 
956
-        if ( ! empty( $_GET['ignore'] ) ) {
957
-            $item_args['exclude'] = wp_parse_id_list( sanitize_text_field( $_GET['ignore'] ) );
956
+        if (!empty($_GET['ignore'])) {
957
+            $item_args['exclude'] = wp_parse_id_list(sanitize_text_field($_GET['ignore']));
958 958
         }
959 959
 
960
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
960
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
961 961
         $data  = array();
962 962
 
963
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( (int) $_GET['post_id'] ) );
963
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type((int) $_GET['post_id']));
964 964
 
965
-        foreach ( $items as $item ) {
966
-            $item      = new GetPaid_Form_Item( $item );
965
+        foreach ($items as $item) {
966
+            $item = new GetPaid_Form_Item($item);
967 967
             $data[] = array(
968 968
                 'id'        => (int) $item->get_id(),
969
-                'text'      => strip_tags( $item->get_name() ),
970
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
969
+                'text'      => strip_tags($item->get_name()),
970
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
971 971
             );
972 972
         }
973 973
 
974
-        wp_send_json_success( $data );
974
+        wp_send_json_success($data);
975 975
 
976 976
     }
977 977
 
@@ -980,40 +980,40 @@  discard block
 block discarded – undo
980 980
      */
981 981
     public static function get_customers() {
982 982
         // Verify nonce.
983
-        check_ajax_referer( 'wpinv-nonce' );
983
+        check_ajax_referer('wpinv-nonce');
984 984
 
985
-        $invoice_id = ! empty( $_REQUEST['post_id'] ) ? (int) $_REQUEST['post_id'] : 0;
985
+        $invoice_id = !empty($_REQUEST['post_id']) ? (int) $_REQUEST['post_id'] : 0;
986 986
 
987 987
         // Can the user manage the plugin?
988
-        if ( ! wpinv_current_user_can( 'invoice_get_customers', array( 'invoice_id' => $invoice_id ) ) ) {
988
+        if (!wpinv_current_user_can('invoice_get_customers', array('invoice_id' => $invoice_id))) {
989 989
             die( -1 );
990 990
         }
991 991
 
992 992
         // We need a search term.
993
-        if ( empty( $_GET['search'] ) ) {
994
-            wp_send_json_success( array() );
993
+        if (empty($_GET['search'])) {
994
+            wp_send_json_success(array());
995 995
         }
996 996
 
997 997
         // Retrieve customers.
998 998
 
999 999
         $customer_args = array(
1000
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
1000
+            'fields'         => array('ID', 'user_email', 'display_name'),
1001 1001
             'orderby'        => 'display_name',
1002
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
1003
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
1002
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
1003
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
1004 1004
         );
1005 1005
 
1006
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
1006
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
1007 1007
         $data      = array();
1008 1008
 
1009
-        foreach ( $customers as $customer ) {
1009
+        foreach ($customers as $customer) {
1010 1010
             $data[] = array(
1011 1011
                 'id'   => (int) $customer->ID,
1012
-                'text' => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
1012
+                'text' => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
1013 1013
             );
1014 1014
         }
1015 1015
 
1016
-        wp_send_json_success( $data );
1016
+        wp_send_json_success($data);
1017 1017
 
1018 1018
     }
1019 1019
 
@@ -1023,25 +1023,25 @@  discard block
 block discarded – undo
1023 1023
     public static function get_aui_states_field() {
1024 1024
 
1025 1025
         // We need a country.
1026
-        if ( empty( $_GET['country'] ) ) {
1026
+        if (empty($_GET['country'])) {
1027 1027
             exit;
1028 1028
         }
1029 1029
 
1030
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
1031
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
1032
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
1033
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
1030
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
1031
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
1032
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
1033
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
1034 1034
 
1035
-        if ( empty( $states ) ) {
1035
+        if (empty($states)) {
1036 1036
 
1037 1037
             $html = aui()->input(
1038 1038
                 array(
1039 1039
                     'type'        => 'text',
1040 1040
                     'id'          => 'wpinv_state',
1041 1041
                     'name'        => $name,
1042
-                    'label'       => __( 'State', 'invoicing' ),
1042
+                    'label'       => __('State', 'invoicing'),
1043 1043
                     'label_type'  => 'vertical',
1044
-                    'placeholder' => __( 'State', 'invoicing' ),
1044
+                    'placeholder' => __('State', 'invoicing'),
1045 1045
                     'class'       => $class,
1046 1046
                     'value'       => $state,
1047 1047
                 )
@@ -1053,9 +1053,9 @@  discard block
 block discarded – undo
1053 1053
                 array(
1054 1054
                     'id'               => 'wpinv_state',
1055 1055
                     'name'             => $name,
1056
-                    'label'            => __( 'State', 'invoicing' ),
1056
+                    'label'            => __('State', 'invoicing'),
1057 1057
                     'label_type'       => 'vertical',
1058
-                    'placeholder'      => __( 'Select a state', 'invoicing' ),
1058
+                    'placeholder'      => __('Select a state', 'invoicing'),
1059 1059
                     'class'            => $class,
1060 1060
                     'value'            => $state,
1061 1061
                     'options'          => $states,
@@ -1069,7 +1069,7 @@  discard block
 block discarded – undo
1069 1069
         wp_send_json_success(
1070 1070
             array(
1071 1071
                 'html'   => $html,
1072
-                'select' => ! empty( $states ),
1072
+                'select' => !empty($states),
1073 1073
             )
1074 1074
         );
1075 1075
 
@@ -1083,8 +1083,8 @@  discard block
 block discarded – undo
1083 1083
     public static function payment_form_refresh_prices() {
1084 1084
 
1085 1085
         // ... form fields...
1086
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1087
-            esc_html_e( 'Error: Reload the page and try again.', 'invoicing' );
1086
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1087
+            esc_html_e('Error: Reload the page and try again.', 'invoicing');
1088 1088
             exit;
1089 1089
         }
1090 1090
 
@@ -1092,7 +1092,7 @@  discard block
 block discarded – undo
1092 1092
         $submission = new GetPaid_Payment_Form_Submission();
1093 1093
 
1094 1094
         // Do we have an error?
1095
-        if ( ! empty( $submission->last_error ) ) {
1095
+        if (!empty($submission->last_error)) {
1096 1096
             wp_send_json_error(
1097 1097
                 array(
1098 1098
                     'code'  => $submission->last_error_code,
@@ -1102,12 +1102,12 @@  discard block
 block discarded – undo
1102 1102
         }
1103 1103
 
1104 1104
         // Prepare the response.
1105
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
1105
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
1106 1106
 
1107 1107
         // Filter the response.
1108
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
1108
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
1109 1109
 
1110
-        wp_send_json_success( $response );
1110
+        wp_send_json_success($response);
1111 1111
     }
1112 1112
 
1113 1113
     /**
@@ -1119,63 +1119,63 @@  discard block
 block discarded – undo
1119 1119
 	public static function file_upload() {
1120 1120
 
1121 1121
         // Check nonce.
1122
-        check_ajax_referer( 'getpaid_form_nonce' );
1122
+        check_ajax_referer('getpaid_form_nonce');
1123 1123
 
1124
-        if ( empty( $_POST['form_id'] ) || empty( $_POST['field_name'] ) || empty( $_FILES['file'] ) ) {
1125
-            wp_die( esc_html_e( 'Bad Request', 'invoicing' ), 400 );
1124
+        if (empty($_POST['form_id']) || empty($_POST['field_name']) || empty($_FILES['file'])) {
1125
+            wp_die(esc_html_e('Bad Request', 'invoicing'), 400);
1126 1126
         }
1127 1127
 
1128 1128
         // Fetch form.
1129
-        $form = new GetPaid_Payment_Form( intval( $_POST['form_id'] ) );
1129
+        $form = new GetPaid_Payment_Form(intval($_POST['form_id']));
1130 1130
 
1131
-        if ( ! $form->is_active() ) {
1132
-            wp_send_json_error( __( 'Payment form not active', 'invoicing' ) );
1131
+        if (!$form->is_active()) {
1132
+            wp_send_json_error(__('Payment form not active', 'invoicing'));
1133 1133
         }
1134 1134
 
1135 1135
         // Fetch appropriate field.
1136
-        $upload_field = current( wp_list_filter( $form->get_elements(), array( 'id' => sanitize_text_field( $_POST['field_name'] ) ) ) );
1137
-        if ( empty( $upload_field ) ) {
1138
-            wp_send_json_error( __( 'Invalid upload field.', 'invoicing' ) );
1136
+        $upload_field = current(wp_list_filter($form->get_elements(), array('id' => sanitize_text_field($_POST['field_name']))));
1137
+        if (empty($upload_field)) {
1138
+            wp_send_json_error(__('Invalid upload field.', 'invoicing'));
1139 1139
         }
1140 1140
 
1141 1141
         // Prepare allowed file types.
1142
-        $file_types = isset( $upload_field['file_types'] ) ? $upload_field['file_types'] : array( 'jpg|jpeg|jpe', 'gif', 'png' );
1142
+        $file_types = isset($upload_field['file_types']) ? $upload_field['file_types'] : array('jpg|jpeg|jpe', 'gif', 'png');
1143 1143
         $all_types  = getpaid_get_allowed_mime_types();
1144 1144
         $mime_types = array();
1145 1145
 
1146
-        foreach ( $file_types as $file_type ) {
1147
-            if ( isset( $all_types[ $file_type ] ) ) {
1148
-                $mime_types[] = $all_types[ $file_type ];
1146
+        foreach ($file_types as $file_type) {
1147
+            if (isset($all_types[$file_type])) {
1148
+                $mime_types[] = $all_types[$file_type];
1149 1149
             }
1150 1150
         }
1151 1151
 
1152
-        if ( ! in_array( $_FILES['file']['type'], $mime_types ) ) {
1153
-            wp_send_json_error( __( 'Unsupported file type.', 'invoicing' ) );
1152
+        if (!in_array($_FILES['file']['type'], $mime_types)) {
1153
+            wp_send_json_error(__('Unsupported file type.', 'invoicing'));
1154 1154
         }
1155 1155
 
1156 1156
         // Upload file.
1157
-        $file_name = explode( '.', strtolower( $_FILES['file']['name'] ) );
1158
-        $file_name = uniqid( 'getpaid-' ) . '.' . array_pop( $file_name );
1157
+        $file_name = explode('.', strtolower($_FILES['file']['name']));
1158
+        $file_name = uniqid('getpaid-') . '.' . array_pop($file_name);
1159 1159
 
1160 1160
         $uploaded = wp_upload_bits(
1161 1161
             $file_name,
1162 1162
             null,
1163
-            file_get_contents( $_FILES['file']['tmp_name'] )
1163
+            file_get_contents($_FILES['file']['tmp_name'])
1164 1164
         );
1165 1165
 
1166
-        if ( ! empty( $uploaded['error'] ) ) {
1167
-            wp_send_json_error( $uploaded['error'] );
1166
+        if (!empty($uploaded['error'])) {
1167
+            wp_send_json_error($uploaded['error']);
1168 1168
         }
1169 1169
 
1170 1170
         // Retrieve response.
1171 1171
         $response = sprintf(
1172 1172
             '<input type="hidden" name="%s[%s]" value="%s" />',
1173
-            esc_attr( sanitize_text_field( $_POST['field_name'] ) ),
1174
-            esc_url( $uploaded['url'] ),
1175
-            esc_attr( sanitize_text_field( strtolower( $_FILES['file']['name'] ) ) )
1173
+            esc_attr(sanitize_text_field($_POST['field_name'])),
1174
+            esc_url($uploaded['url']),
1175
+            esc_attr(sanitize_text_field(strtolower($_FILES['file']['name'])))
1176 1176
         );
1177 1177
 
1178
-        wp_send_json_success( $response );
1178
+        wp_send_json_success($response);
1179 1179
 
1180 1180
 	}
1181 1181
 
Please login to merge, or discard this patch.