Passed
Branch master (3a0618)
by Stiofan
05:00
created
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +818 added lines, -818 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,198 +10,198 @@  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
-	);
54
-
55
-	/**
56
-	 * Sets the associated payment form.
57
-	 *
58
-	 * @var GetPaid_Payment_Form
59
-	 */
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
+    );
54
+
55
+    /**
56
+     * Sets the associated payment form.
57
+     *
58
+     * @var GetPaid_Payment_Form
59
+     */
60 60
     protected $payment_form = null;
61 61
 
62 62
     /**
63
-	 * The country for the submission.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	public $country = null;
68
-
69
-    /**
70
-	 * The state for the submission.
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $state = null;
76
-
77
-	/**
78
-	 * The invoice associated with the submission.
79
-	 *
80
-	 * @var WPInv_Invoice
81
-	 */
82
-	protected $invoice = null;
83
-
84
-	/**
85
-	 * The recurring item for the submission.
86
-	 *
87
-	 * @var int
88
-	 */
89
-	public $has_recurring = 0;
90
-
91
-	/**
92
-	 * An array of fees for the submission.
93
-	 *
94
-	 * @var array
95
-	 */
96
-	protected $fees = array();
97
-
98
-	/**
99
-	 * An array of discounts for the submission.
100
-	 *
101
-	 * @var array
102
-	 */
103
-	protected $discounts = array();
104
-
105
-	/**
106
-	 * An array of taxes for the submission.
107
-	 *
108
-	 * @var array
109
-	 */
110
-	protected $taxes = array();
111
-
112
-	/**
113
-	 * An array of items for the submission.
114
-	 *
115
-	 * @var GetPaid_Form_Item[]
116
-	 */
117
-	protected $items = array();
118
-
119
-	/**
120
-	 * The last error.
121
-	 *
122
-	 * @var string
123
-	 */
124
-	public $last_error = null;
125
-
126
-	/**
127
-	 * The last error code.
128
-	 *
129
-	 * @var string
130
-	 */
131
-	public $last_error_code = null;
132
-
133
-    /**
134
-	 * Class constructor.
135
-	 *
136
-	 */
137
-	public function __construct() {
138
-
139
-		// Set the state and country to the default state and country.
140
-		$this->country = wpinv_default_billing_country();
141
-		$this->state   = wpinv_get_default_state();
142
-
143
-		// Do we have an actual submission?
144
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
145
-			$this->load_data( $_POST );
146
-		}
147
-
148
-	}
149
-
150
-	/**
151
-	 * Loads submission data.
152
-	 *
153
-	 * @param array $data
154
-	 */
155
-	public function load_data( $data ) {
156
-
157
-		// Remove slashes from the submitted data...
158
-		$data       = wp_unslash( $data );
159
-
160
-		// Allow plugins to filter the data.
161
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
162
-
163
-		// Cache it...
164
-		$this->data = $data;
165
-
166
-		// Then generate a unique id from the data.
167
-		$this->id   = md5( wp_json_encode( $data ) );
168
-
169
-		// Finally, process the submission.
170
-		try {
171
-
172
-			// Each process is passed an instance of the class (with reference)
173
-			// and should throw an Exception whenever it encounters one.
174
-			$processors = apply_filters(
175
-				'getpaid_payment_form_submission_processors',
176
-				array(
177
-					array( $this, 'process_payment_form' ),
178
-					array( $this, 'process_invoice' ),
179
-					array( $this, 'process_fees' ),
180
-					array( $this, 'process_items' ),
181
-					array( $this, 'process_discount' ),
182
-					array( $this, 'process_taxes' ),
183
-				),
184
-				$this		
185
-			);
186
-
187
-			foreach ( $processors as $processor ) {
188
-				call_user_func_array( $processor, array( &$this ) );
189
-			}
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
-	/*
63
+     * The country for the submission.
64
+     *
65
+     * @var string
66
+     */
67
+    public $country = null;
68
+
69
+    /**
70
+     * The state for the submission.
71
+     *
72
+     * @since 1.0.19
73
+     * @var string
74
+     */
75
+    public $state = null;
76
+
77
+    /**
78
+     * The invoice associated with the submission.
79
+     *
80
+     * @var WPInv_Invoice
81
+     */
82
+    protected $invoice = null;
83
+
84
+    /**
85
+     * The recurring item for the submission.
86
+     *
87
+     * @var int
88
+     */
89
+    public $has_recurring = 0;
90
+
91
+    /**
92
+     * An array of fees for the submission.
93
+     *
94
+     * @var array
95
+     */
96
+    protected $fees = array();
97
+
98
+    /**
99
+     * An array of discounts for the submission.
100
+     *
101
+     * @var array
102
+     */
103
+    protected $discounts = array();
104
+
105
+    /**
106
+     * An array of taxes for the submission.
107
+     *
108
+     * @var array
109
+     */
110
+    protected $taxes = array();
111
+
112
+    /**
113
+     * An array of items for the submission.
114
+     *
115
+     * @var GetPaid_Form_Item[]
116
+     */
117
+    protected $items = array();
118
+
119
+    /**
120
+     * The last error.
121
+     *
122
+     * @var string
123
+     */
124
+    public $last_error = null;
125
+
126
+    /**
127
+     * The last error code.
128
+     *
129
+     * @var string
130
+     */
131
+    public $last_error_code = null;
132
+
133
+    /**
134
+     * Class constructor.
135
+     *
136
+     */
137
+    public function __construct() {
138
+
139
+        // Set the state and country to the default state and country.
140
+        $this->country = wpinv_default_billing_country();
141
+        $this->state   = wpinv_get_default_state();
142
+
143
+        // Do we have an actual submission?
144
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
145
+            $this->load_data( $_POST );
146
+        }
147
+
148
+    }
149
+
150
+    /**
151
+     * Loads submission data.
152
+     *
153
+     * @param array $data
154
+     */
155
+    public function load_data( $data ) {
156
+
157
+        // Remove slashes from the submitted data...
158
+        $data       = wp_unslash( $data );
159
+
160
+        // Allow plugins to filter the data.
161
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
162
+
163
+        // Cache it...
164
+        $this->data = $data;
165
+
166
+        // Then generate a unique id from the data.
167
+        $this->id   = md5( wp_json_encode( $data ) );
168
+
169
+        // Finally, process the submission.
170
+        try {
171
+
172
+            // Each process is passed an instance of the class (with reference)
173
+            // and should throw an Exception whenever it encounters one.
174
+            $processors = apply_filters(
175
+                'getpaid_payment_form_submission_processors',
176
+                array(
177
+                    array( $this, 'process_payment_form' ),
178
+                    array( $this, 'process_invoice' ),
179
+                    array( $this, 'process_fees' ),
180
+                    array( $this, 'process_items' ),
181
+                    array( $this, 'process_discount' ),
182
+                    array( $this, 'process_taxes' ),
183
+                ),
184
+                $this		
185
+            );
186
+
187
+            foreach ( $processors as $processor ) {
188
+                call_user_func_array( $processor, array( &$this ) );
189
+            }
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
+    /*
205 205
 	|--------------------------------------------------------------------------
206 206
 	| Payment Forms.
207 207
 	|--------------------------------------------------------------------------
@@ -210,39 +210,39 @@  discard block
 block discarded – undo
210 210
 	| submission has an active payment form etc.
211 211
     */
212 212
 
213
-	/**
214
-	 * Prepares the submission's payment form.
215
-	 *
216
-	 * @since 1.0.19
217
-	 */
218
-	public function process_payment_form() {
213
+    /**
214
+     * Prepares the submission's payment form.
215
+     *
216
+     * @since 1.0.19
217
+     */
218
+    public function process_payment_form() {
219 219
 
220
-		// Every submission needs an active payment form.
221
-		if ( empty( $this->data['form_id'] ) ) {
222
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
223
-		}
220
+        // Every submission needs an active payment form.
221
+        if ( empty( $this->data['form_id'] ) ) {
222
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
223
+        }
224 224
 
225
-		// Fetch the payment form.
226
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
225
+        // Fetch the payment form.
226
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
227 227
 
228
-		if ( ! $this->payment_form->is_active() ) {
229
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
230
-		}
228
+        if ( ! $this->payment_form->is_active() ) {
229
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
230
+        }
231 231
 
232
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
233
-	}
232
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
233
+    }
234 234
 
235 235
     /**
236
-	 * Returns the payment form.
237
-	 *
238
-	 * @since 1.0.19
239
-	 * @return GetPaid_Payment_Form
240
-	 */
241
-	public function get_payment_form() {
242
-		return $this->payment_form;
243
-	}
236
+     * Returns the payment form.
237
+     *
238
+     * @since 1.0.19
239
+     * @return GetPaid_Payment_Form
240
+     */
241
+    public function get_payment_form() {
242
+        return $this->payment_form;
243
+    }
244 244
 
245
-	/*
245
+    /*
246 246
 	|--------------------------------------------------------------------------
247 247
 	| Invoices.
248 248
 	|--------------------------------------------------------------------------
@@ -251,84 +251,84 @@  discard block
 block discarded – undo
251 251
 	| might be for an existing invoice.
252 252
 	*/
253 253
 
254
-	/**
255
-	 * Prepares the submission's invoice.
256
-	 *
257
-	 * @since 1.0.19
258
-	 */
259
-	public function process_invoice() {
254
+    /**
255
+     * Prepares the submission's invoice.
256
+     *
257
+     * @since 1.0.19
258
+     */
259
+    public function process_invoice() {
260 260
 
261
-		// Abort if there is no invoice.
262
-		if ( empty( $this->data['invoice_id'] ) ) {
263
-			return;
264
-		}
261
+        // Abort if there is no invoice.
262
+        if ( empty( $this->data['invoice_id'] ) ) {
263
+            return;
264
+        }
265 265
 
266
-		// If the submission is for an existing invoice, ensure that it exists
267
-		// and that it is not paid for.
268
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
266
+        // If the submission is for an existing invoice, ensure that it exists
267
+        // and that it is not paid for.
268
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
269 269
 
270 270
         if ( empty( $invoice ) ) {
271
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
272
-		}
271
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
272
+        }
273 273
 
274
-		if ( $invoice->is_paid() ) {
275
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
276
-		}
274
+        if ( $invoice->is_paid() ) {
275
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
276
+        }
277 277
 
278
-		$this->payment_form->invoice = $invoice;
279
-		if ( ! $this->payment_form->is_default() ) {
278
+        $this->payment_form->invoice = $invoice;
279
+        if ( ! $this->payment_form->is_default() ) {
280 280
 
281
-			$items    = array();
282
-			$item_ids = array();
281
+            $items    = array();
282
+            $item_ids = array();
283 283
 	
284
-			foreach ( $invoice->get_items() as $item ) {
285
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
286
-					$item_ids[] = $item->get_id();
287
-					$items[]    = $item;
288
-				}
289
-			}
284
+            foreach ( $invoice->get_items() as $item ) {
285
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
286
+                    $item_ids[] = $item->get_id();
287
+                    $items[]    = $item;
288
+                }
289
+            }
290 290
 	
291
-			foreach ( $this->payment_form->get_items() as $item ) {
292
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
293
-					$item_ids[] = $item->get_id();
294
-					$items[]    = $item;
295
-				}
296
-			}
291
+            foreach ( $this->payment_form->get_items() as $item ) {
292
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
293
+                    $item_ids[] = $item->get_id();
294
+                    $items[]    = $item;
295
+                }
296
+            }
297 297
 	
298
-			$this->payment_form->set_items( $items );
298
+            $this->payment_form->set_items( $items );
299 299
 	
300
-		} else {
301
-			$this->payment_form->set_items( $invoice->get_items() );
302
-		}
303
-
304
-		$this->country = $invoice->get_country();
305
-		$this->state   = $invoice->get_state();
306
-		$this->invoice = $invoice;
307
-
308
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
309
-	}
310
-
311
-	/**
312
-	 * Returns the associated invoice.
313
-	 *
314
-	 * @since 1.0.19
315
-	 * @return WPInv_Invoice
316
-	 */
317
-	public function get_invoice() {
318
-		return $this->invoice;
319
-	}
320
-
321
-	/**
322
-	 * Checks whether there is an invoice associated with this submission.
323
-	 *
324
-	 * @since 1.0.19
325
-	 * @return bool
326
-	 */
327
-	public function has_invoice() {
328
-		return ! empty( $this->invoice );
329
-	}
330
-
331
-	/*
300
+        } else {
301
+            $this->payment_form->set_items( $invoice->get_items() );
302
+        }
303
+
304
+        $this->country = $invoice->get_country();
305
+        $this->state   = $invoice->get_state();
306
+        $this->invoice = $invoice;
307
+
308
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
309
+    }
310
+
311
+    /**
312
+     * Returns the associated invoice.
313
+     *
314
+     * @since 1.0.19
315
+     * @return WPInv_Invoice
316
+     */
317
+    public function get_invoice() {
318
+        return $this->invoice;
319
+    }
320
+
321
+    /**
322
+     * Checks whether there is an invoice associated with this submission.
323
+     *
324
+     * @since 1.0.19
325
+     * @return bool
326
+     */
327
+    public function has_invoice() {
328
+        return ! empty( $this->invoice );
329
+    }
330
+
331
+    /*
332 332
 	|--------------------------------------------------------------------------
333 333
 	| Items.
334 334
 	|--------------------------------------------------------------------------
@@ -337,129 +337,129 @@  discard block
 block discarded – undo
337 337
 	| recurring item. But can have an unlimited number of non-recurring items.
338 338
 	*/
339 339
 
340
-	/**
341
-	 * Prepares the submission's items.
342
-	 *
343
-	 * @since 1.0.19
344
-	 */
345
-	public function process_items() {
346
-
347
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
348
-
349
-		foreach ( $processor->items as $item ) {
350
-			$this->add_item( $item );
351
-		}
352
-
353
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
354
-	}
355
-
356
-	/**
357
-	 * Adds an item to the submission.
358
-	 *
359
-	 * @since 1.0.19
360
-	 * @param GetPaid_Form_Item $item
361
-	 */
362
-	public function add_item( $item ) {
363
-
364
-		// Make sure that it is available for purchase.
365
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
366
-			return;
367
-		}
368
-
369
-		// Each submission can only contain one recurring item.
370
-		if ( $item->is_recurring() ) {
371
-			$this->has_recurring = $item->get_id();
372
-		}
373
-
374
-		// Update the items and totals.
375
-		$this->items[ $item->get_id() ]         = $item;
376
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
377
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
378
-
379
-	}
380
-
381
-	/**
382
-	 * Removes a specific item.
383
-	 * 
384
-	 * You should not call this method after the discounts and taxes
385
-	 * have been calculated.
386
-	 *
387
-	 * @since 1.0.19
388
-	 */
389
-	public function remove_item( $item_id ) {
390
-
391
-		if ( isset( $this->items[ $item_id ] ) ) {
392
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
393
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
394
-
395
-			if ( $this->items[ $item_id ]->is_recurring() ) {
396
-				$this->has_recurring = 0;
397
-			}
398
-
399
-			unset( $this->items[ $item_id ] );
400
-		}
401
-
402
-	}
403
-
404
-	/**
405
-	 * Returns the subtotal.
406
-	 *
407
-	 * @since 1.0.19
408
-	 */
409
-	public function get_subtotal() {
410
-
411
-		if ( wpinv_prices_include_tax() ) {
412
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
413
-		}
414
-
415
-		return $this->totals['subtotal']['initial'];
416
-	}
417
-
418
-	/**
419
-	 * Returns the recurring subtotal.
420
-	 *
421
-	 * @since 1.0.19
422
-	 */
423
-	public function get_recurring_subtotal() {
424
-
425
-		if ( wpinv_prices_include_tax() ) {
426
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
427
-		}
428
-
429
-		return $this->totals['subtotal']['recurring'];
430
-	}
431
-
432
-	/**
433
-	 * Returns all items.
434
-	 *
435
-	 * @since 1.0.19
436
-	 * @return GetPaid_Form_Item[]
437
-	 */
438
-	public function get_items() {
439
-		return $this->items;
440
-	}
441
-
442
-	/**
443
-	 * Checks if there's a single subscription group in the submission.
444
-	 *
445
-	 * @since 2.3.0
446
-	 * @return bool
447
-	 */
448
-	public function has_subscription_group() {
449
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
450
-	}
451
-
452
-	/**
453
-	 * Checks if there are multipe subscription groups in the submission.
454
-	 *
455
-	 * @since 2.3.0
456
-	 * @return bool
457
-	 */
458
-	public function has_multiple_subscription_groups() {
459
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
460
-	}
461
-
462
-	/*
340
+    /**
341
+     * Prepares the submission's items.
342
+     *
343
+     * @since 1.0.19
344
+     */
345
+    public function process_items() {
346
+
347
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
348
+
349
+        foreach ( $processor->items as $item ) {
350
+            $this->add_item( $item );
351
+        }
352
+
353
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
354
+    }
355
+
356
+    /**
357
+     * Adds an item to the submission.
358
+     *
359
+     * @since 1.0.19
360
+     * @param GetPaid_Form_Item $item
361
+     */
362
+    public function add_item( $item ) {
363
+
364
+        // Make sure that it is available for purchase.
365
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
366
+            return;
367
+        }
368
+
369
+        // Each submission can only contain one recurring item.
370
+        if ( $item->is_recurring() ) {
371
+            $this->has_recurring = $item->get_id();
372
+        }
373
+
374
+        // Update the items and totals.
375
+        $this->items[ $item->get_id() ]         = $item;
376
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
377
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
378
+
379
+    }
380
+
381
+    /**
382
+     * Removes a specific item.
383
+     * 
384
+     * You should not call this method after the discounts and taxes
385
+     * have been calculated.
386
+     *
387
+     * @since 1.0.19
388
+     */
389
+    public function remove_item( $item_id ) {
390
+
391
+        if ( isset( $this->items[ $item_id ] ) ) {
392
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
393
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
394
+
395
+            if ( $this->items[ $item_id ]->is_recurring() ) {
396
+                $this->has_recurring = 0;
397
+            }
398
+
399
+            unset( $this->items[ $item_id ] );
400
+        }
401
+
402
+    }
403
+
404
+    /**
405
+     * Returns the subtotal.
406
+     *
407
+     * @since 1.0.19
408
+     */
409
+    public function get_subtotal() {
410
+
411
+        if ( wpinv_prices_include_tax() ) {
412
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
413
+        }
414
+
415
+        return $this->totals['subtotal']['initial'];
416
+    }
417
+
418
+    /**
419
+     * Returns the recurring subtotal.
420
+     *
421
+     * @since 1.0.19
422
+     */
423
+    public function get_recurring_subtotal() {
424
+
425
+        if ( wpinv_prices_include_tax() ) {
426
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
427
+        }
428
+
429
+        return $this->totals['subtotal']['recurring'];
430
+    }
431
+
432
+    /**
433
+     * Returns all items.
434
+     *
435
+     * @since 1.0.19
436
+     * @return GetPaid_Form_Item[]
437
+     */
438
+    public function get_items() {
439
+        return $this->items;
440
+    }
441
+
442
+    /**
443
+     * Checks if there's a single subscription group in the submission.
444
+     *
445
+     * @since 2.3.0
446
+     * @return bool
447
+     */
448
+    public function has_subscription_group() {
449
+        return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
450
+    }
451
+
452
+    /**
453
+     * Checks if there are multipe subscription groups in the submission.
454
+     *
455
+     * @since 2.3.0
456
+     * @return bool
457
+     */
458
+    public function has_multiple_subscription_groups() {
459
+        return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
460
+    }
461
+
462
+    /*
463 463
 	|--------------------------------------------------------------------------
464 464
 	| Taxes
465 465
 	|--------------------------------------------------------------------------
@@ -468,128 +468,128 @@  discard block
 block discarded – undo
468 468
 	| or only one-time.
469 469
     */
470 470
 
471
-	/**
472
-	 * Prepares the submission's taxes.
473
-	 *
474
-	 * @since 1.0.19
475
-	 */
476
-	public function process_taxes() {
477
-
478
-		// Abort if we're not using taxes.
479
-		if ( ! $this->use_taxes() ) {
480
-			return;
481
-		}
482
-
483
-		// If a custom country && state has been passed in, use it to calculate taxes.
484
-		$country = $this->get_field( 'wpinv_country', 'billing' );
485
-		if ( ! empty( $country ) ) {
486
-			$this->country = $country;
487
-		}
488
-
489
-		$state = $this->get_field( 'wpinv_state', 'billing' );
490
-		if ( ! empty( $state ) ) {
491
-			$this->state = $state;
492
-		}
493
-
494
-		// Confirm if the provided country and the ip country are similar.
495
-		$address_confirmed = $this->get_field( 'confirm-address' );
496
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
497
-			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' ) );
498
-		}
499
-
500
-		// Abort if the country is not taxable.
501
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
502
-			return;
503
-		}
504
-
505
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
506
-
507
-		foreach ( $processor->taxes as $tax ) {
508
-			$this->add_tax( $tax );
509
-		}
510
-
511
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
512
-	}
513
-
514
-	/**
515
-	 * Adds a tax to the submission.
516
-	 *
517
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
518
-	 * @since 1.0.19
519
-	 */
520
-	public function add_tax( $tax ) {
521
-
522
-		if ( wpinv_round_tax_per_tax_rate() ) {
523
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
524
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
525
-		}
526
-
527
-		$this->taxes[ $tax['name'] ]         = $tax;
528
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
529
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
530
-
531
-	}
532
-
533
-	/**
534
-	 * Removes a specific tax.
535
-	 *
536
-	 * @since 1.0.19
537
-	 */
538
-	public function remove_tax( $tax_name ) {
539
-
540
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
541
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
542
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
543
-			unset( $this->taxes[ $tax_name ] );
544
-		}
545
-
546
-	}
547
-
548
-	/**
549
-	 * Whether or not we'll use taxes for the submission.
550
-	 *
551
-	 * @since 1.0.19
552
-	 */
553
-	public function use_taxes() {
554
-
555
-		$use_taxes = wpinv_use_taxes();
556
-
557
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
558
-			$use_taxes = false;
559
-		}
560
-
561
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
562
-
563
-	}
564
-
565
-	/**
566
-	 * Returns the tax.
567
-	 *
568
-	 * @since 1.0.19
569
-	 */
570
-	public function get_tax() {
571
-		return $this->totals['taxes']['initial'];
572
-	}
573
-
574
-	/**
575
-	 * Returns the recurring tax.
576
-	 *
577
-	 * @since 1.0.19
578
-	 */
579
-	public function get_recurring_tax() {
580
-		return $this->totals['taxes']['recurring'];
581
-	}
582
-
583
-	/**
584
-	 * Returns all taxes.
585
-	 *
586
-	 * @since 1.0.19
587
-	 */
588
-	public function get_taxes() {
589
-		return $this->taxes;
590
-	}
591
-
592
-	/*
471
+    /**
472
+     * Prepares the submission's taxes.
473
+     *
474
+     * @since 1.0.19
475
+     */
476
+    public function process_taxes() {
477
+
478
+        // Abort if we're not using taxes.
479
+        if ( ! $this->use_taxes() ) {
480
+            return;
481
+        }
482
+
483
+        // If a custom country && state has been passed in, use it to calculate taxes.
484
+        $country = $this->get_field( 'wpinv_country', 'billing' );
485
+        if ( ! empty( $country ) ) {
486
+            $this->country = $country;
487
+        }
488
+
489
+        $state = $this->get_field( 'wpinv_state', 'billing' );
490
+        if ( ! empty( $state ) ) {
491
+            $this->state = $state;
492
+        }
493
+
494
+        // Confirm if the provided country and the ip country are similar.
495
+        $address_confirmed = $this->get_field( 'confirm-address' );
496
+        if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
497
+            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' ) );
498
+        }
499
+
500
+        // Abort if the country is not taxable.
501
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
502
+            return;
503
+        }
504
+
505
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
506
+
507
+        foreach ( $processor->taxes as $tax ) {
508
+            $this->add_tax( $tax );
509
+        }
510
+
511
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
512
+    }
513
+
514
+    /**
515
+     * Adds a tax to the submission.
516
+     *
517
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
518
+     * @since 1.0.19
519
+     */
520
+    public function add_tax( $tax ) {
521
+
522
+        if ( wpinv_round_tax_per_tax_rate() ) {
523
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
524
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
525
+        }
526
+
527
+        $this->taxes[ $tax['name'] ]         = $tax;
528
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
529
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
530
+
531
+    }
532
+
533
+    /**
534
+     * Removes a specific tax.
535
+     *
536
+     * @since 1.0.19
537
+     */
538
+    public function remove_tax( $tax_name ) {
539
+
540
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
541
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
542
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
543
+            unset( $this->taxes[ $tax_name ] );
544
+        }
545
+
546
+    }
547
+
548
+    /**
549
+     * Whether or not we'll use taxes for the submission.
550
+     *
551
+     * @since 1.0.19
552
+     */
553
+    public function use_taxes() {
554
+
555
+        $use_taxes = wpinv_use_taxes();
556
+
557
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
558
+            $use_taxes = false;
559
+        }
560
+
561
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
562
+
563
+    }
564
+
565
+    /**
566
+     * Returns the tax.
567
+     *
568
+     * @since 1.0.19
569
+     */
570
+    public function get_tax() {
571
+        return $this->totals['taxes']['initial'];
572
+    }
573
+
574
+    /**
575
+     * Returns the recurring tax.
576
+     *
577
+     * @since 1.0.19
578
+     */
579
+    public function get_recurring_tax() {
580
+        return $this->totals['taxes']['recurring'];
581
+    }
582
+
583
+    /**
584
+     * Returns all taxes.
585
+     *
586
+     * @since 1.0.19
587
+     */
588
+    public function get_taxes() {
589
+        return $this->taxes;
590
+    }
591
+
592
+    /*
593 593
 	|--------------------------------------------------------------------------
594 594
 	| Discounts
595 595
 	|--------------------------------------------------------------------------
@@ -598,99 +598,99 @@  discard block
 block discarded – undo
598 598
 	| or only one-time. They also do not have to come from a discount code.
599 599
     */
600 600
 
601
-	/**
602
-	 * Prepares the submission's discount.
603
-	 *
604
-	 * @since 1.0.19
605
-	 */
606
-	public function process_discount() {
607
-
608
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
609
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
610
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
611
-
612
-		foreach ( $processor->discounts as $discount ) {
613
-			$this->add_discount( $discount );
614
-		}
615
-
616
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
617
-	}
618
-
619
-	/**
620
-	 * Adds a discount to the submission.
621
-	 *
622
-	 * @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.
623
-	 * @since 1.0.19
624
-	 */
625
-	public function add_discount( $discount ) {
626
-		$this->discounts[ $discount['name'] ]   = $discount;
627
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
628
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
629
-	}
630
-
631
-	/**
632
-	 * Removes a discount from the submission.
633
-	 *
634
-	 * @since 1.0.19
635
-	 */
636
-	public function remove_discount( $name ) {
637
-
638
-		if ( isset( $this->discounts[ $name ] ) ) {
639
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
640
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
641
-			unset( $this->discounts[ $name ] );
642
-		}
643
-
644
-	}
645
-
646
-	/**
647
-	 * Checks whether there is a discount code associated with this submission.
648
-	 *
649
-	 * @since 1.0.19
650
-	 * @return bool
651
-	 */
652
-	public function has_discount_code() {
653
-		return ! empty( $this->discounts['discount_code'] );
654
-	}
655
-
656
-	/**
657
-	 * Returns the discount code.
658
-	 *
659
-	 * @since 1.0.19
660
-	 * @return string
661
-	 */
662
-	public function get_discount_code() {
663
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
664
-	}
665
-
666
-	/**
667
-	 * Returns the discount.
668
-	 *
669
-	 * @since 1.0.19
670
-	 */
671
-	public function get_discount() {
672
-		return $this->totals['discount']['initial'];
673
-	}
674
-
675
-	/**
676
-	 * Returns the recurring discount.
677
-	 *
678
-	 * @since 1.0.19
679
-	 */
680
-	public function get_recurring_discount() {
681
-		return $this->totals['discount']['recurring'];
682
-	}
683
-
684
-	/**
685
-	 * Returns all discounts.
686
-	 *
687
-	 * @since 1.0.19
688
-	 */
689
-	public function get_discounts() {
690
-		return $this->discounts;
691
-	}
692
-
693
-	/*
601
+    /**
602
+     * Prepares the submission's discount.
603
+     *
604
+     * @since 1.0.19
605
+     */
606
+    public function process_discount() {
607
+
608
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
609
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
610
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
611
+
612
+        foreach ( $processor->discounts as $discount ) {
613
+            $this->add_discount( $discount );
614
+        }
615
+
616
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
617
+    }
618
+
619
+    /**
620
+     * Adds a discount to the submission.
621
+     *
622
+     * @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.
623
+     * @since 1.0.19
624
+     */
625
+    public function add_discount( $discount ) {
626
+        $this->discounts[ $discount['name'] ]   = $discount;
627
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
628
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
629
+    }
630
+
631
+    /**
632
+     * Removes a discount from the submission.
633
+     *
634
+     * @since 1.0.19
635
+     */
636
+    public function remove_discount( $name ) {
637
+
638
+        if ( isset( $this->discounts[ $name ] ) ) {
639
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
640
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
641
+            unset( $this->discounts[ $name ] );
642
+        }
643
+
644
+    }
645
+
646
+    /**
647
+     * Checks whether there is a discount code associated with this submission.
648
+     *
649
+     * @since 1.0.19
650
+     * @return bool
651
+     */
652
+    public function has_discount_code() {
653
+        return ! empty( $this->discounts['discount_code'] );
654
+    }
655
+
656
+    /**
657
+     * Returns the discount code.
658
+     *
659
+     * @since 1.0.19
660
+     * @return string
661
+     */
662
+    public function get_discount_code() {
663
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
664
+    }
665
+
666
+    /**
667
+     * Returns the discount.
668
+     *
669
+     * @since 1.0.19
670
+     */
671
+    public function get_discount() {
672
+        return $this->totals['discount']['initial'];
673
+    }
674
+
675
+    /**
676
+     * Returns the recurring discount.
677
+     *
678
+     * @since 1.0.19
679
+     */
680
+    public function get_recurring_discount() {
681
+        return $this->totals['discount']['recurring'];
682
+    }
683
+
684
+    /**
685
+     * Returns all discounts.
686
+     *
687
+     * @since 1.0.19
688
+     */
689
+    public function get_discounts() {
690
+        return $this->discounts;
691
+    }
692
+
693
+    /*
694 694
 	|--------------------------------------------------------------------------
695 695
 	| Fees
696 696
 	|--------------------------------------------------------------------------
@@ -700,89 +700,89 @@  discard block
 block discarded – undo
700 700
 	| fees.
701 701
     */
702 702
 
703
-	/**
704
-	 * Prepares the submission's fees.
705
-	 *
706
-	 * @since 1.0.19
707
-	 */
708
-	public function process_fees() {
709
-
710
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
711
-
712
-		foreach ( $fees_processor->fees as $fee ) {
713
-			$this->add_fee( $fee );
714
-		}
715
-
716
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
717
-	}
718
-
719
-	/**
720
-	 * Adds a fee to the submission.
721
-	 *
722
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
723
-	 * @since 1.0.19
724
-	 */
725
-	public function add_fee( $fee ) {
726
-
727
-		$this->fees[ $fee['name'] ]         = $fee;
728
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
729
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
730
-
731
-	}
732
-
733
-	/**
734
-	 * Removes a fee from the submission.
735
-	 *
736
-	 * @since 1.0.19
737
-	 */
738
-	public function remove_fee( $name ) {
739
-
740
-		if ( isset( $this->fees[ $name ] ) ) {
741
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
742
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
743
-			unset( $this->fees[ $name ] );
744
-		}
745
-
746
-	}
747
-
748
-	/**
749
-	 * Returns the fees.
750
-	 *
751
-	 * @since 1.0.19
752
-	 */
753
-	public function get_fee() {
754
-		return $this->totals['fees']['initial'];
755
-	}
756
-
757
-	/**
758
-	 * Returns the recurring fees.
759
-	 *
760
-	 * @since 1.0.19
761
-	 */
762
-	public function get_recurring_fee() {
763
-		return $this->totals['fees']['recurring'];
764
-	}
765
-
766
-	/**
767
-	 * Returns all fees.
768
-	 *
769
-	 * @since 1.0.19
770
-	 */
771
-	public function get_fees() {
772
-		return $this->fees;
773
-	}
774
-
775
-	/**
776
-	 * Checks if there are any fees for the form.
777
-	 *
778
-	 * @return bool
779
-	 * @since 1.0.19
780
-	 */
781
-	public function has_fees() {
782
-		return count( $this->fees ) !== 0;
783
-	}
784
-
785
-	/*
703
+    /**
704
+     * Prepares the submission's fees.
705
+     *
706
+     * @since 1.0.19
707
+     */
708
+    public function process_fees() {
709
+
710
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
711
+
712
+        foreach ( $fees_processor->fees as $fee ) {
713
+            $this->add_fee( $fee );
714
+        }
715
+
716
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
717
+    }
718
+
719
+    /**
720
+     * Adds a fee to the submission.
721
+     *
722
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
723
+     * @since 1.0.19
724
+     */
725
+    public function add_fee( $fee ) {
726
+
727
+        $this->fees[ $fee['name'] ]         = $fee;
728
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
729
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
730
+
731
+    }
732
+
733
+    /**
734
+     * Removes a fee from the submission.
735
+     *
736
+     * @since 1.0.19
737
+     */
738
+    public function remove_fee( $name ) {
739
+
740
+        if ( isset( $this->fees[ $name ] ) ) {
741
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
742
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
743
+            unset( $this->fees[ $name ] );
744
+        }
745
+
746
+    }
747
+
748
+    /**
749
+     * Returns the fees.
750
+     *
751
+     * @since 1.0.19
752
+     */
753
+    public function get_fee() {
754
+        return $this->totals['fees']['initial'];
755
+    }
756
+
757
+    /**
758
+     * Returns the recurring fees.
759
+     *
760
+     * @since 1.0.19
761
+     */
762
+    public function get_recurring_fee() {
763
+        return $this->totals['fees']['recurring'];
764
+    }
765
+
766
+    /**
767
+     * Returns all fees.
768
+     *
769
+     * @since 1.0.19
770
+     */
771
+    public function get_fees() {
772
+        return $this->fees;
773
+    }
774
+
775
+    /**
776
+     * Checks if there are any fees for the form.
777
+     *
778
+     * @return bool
779
+     * @since 1.0.19
780
+     */
781
+    public function has_fees() {
782
+        return count( $this->fees ) !== 0;
783
+    }
784
+
785
+    /*
786 786
 	|--------------------------------------------------------------------------
787 787
 	| MISC
788 788
 	|--------------------------------------------------------------------------
@@ -790,119 +790,119 @@  discard block
 block discarded – undo
790 790
 	| Extra submission functions.
791 791
     */
792 792
 
793
-	/**
794
-	 * Checks if this is the initial fetch.
795
-	 *
796
-	 * @return bool
797
-	 * @since 1.0.19
798
-	 */
799
-	public function is_initial_fetch() {
800
-		return empty( $this->data['initial_state'] );
801
-	}
802
-
803
-	/**
804
-	 * Returns the total amount to collect for this submission.
805
-	 *
806
-	 * @since 1.0.19
807
-	 */
808
-	public function get_total() {
809
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
810
-		return max( $total, 0 );
811
-	}
812
-
813
-	/**
814
-	 * Returns the recurring total amount to collect for this submission.
815
-	 *
816
-	 * @since 1.0.19
817
-	 */
818
-	public function get_recurring_total() {
819
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
820
-		return max( $total, 0 );
821
-	}
822
-
823
-	/**
824
-	 * Whether payment details should be collected for this submission.
825
-	 *
826
-	 * @since 1.0.19
827
-	 */
828
-	public function should_collect_payment_details() {
829
-		$initial   = $this->get_total();
830
-		$recurring = $this->get_recurring_total();
831
-
832
-		if ( $this->has_recurring == 0 ) {
833
-			$recurring = 0;
834
-		}
835
-
836
-		$collect = $initial > 0 || $recurring > 0;
837
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
838
-	}
839
-
840
-	/**
841
-	 * Returns the billing email of the user.
842
-	 *
843
-	 * @since 1.0.19
844
-	 */
845
-	public function get_billing_email() {
846
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
847
-	}
848
-
849
-	/**
850
-	 * Checks if the submitter has a billing email.
851
-	 *
852
-	 * @since 1.0.19
853
-	 */
854
-	public function has_billing_email() {
855
-		$billing_email = $this->get_billing_email();
856
-		return ! empty( $billing_email ) && is_email( $billing_email );
857
-	}
858
-
859
-	/**
860
-	 * Returns the appropriate currency for the submission.
861
-	 *
862
-	 * @since 1.0.19
863
-	 * @return string
864
-	 */
865
-	public function get_currency() {
866
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
867
-    }
868
-
869
-    /**
870
-	 * Returns the raw submission data.
871
-	 *
872
-	 * @since 1.0.19
873
-	 * @return array
874
-	 */
875
-	public function get_data() {
876
-		return $this->data;
877
-	}
878
-
879
-	/**
880
-	 * Returns a field from the submission data
881
-	 *
882
-	 * @param string $field
883
-	 * @since 1.0.19
884
-	 * @return mixed|null
885
-	 */
886
-	public function get_field( $field, $sub_array_key = null ) {
887
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
888
-	}
889
-
890
-	/**
891
-	 * Checks if a required field is set.
892
-	 *
893
-	 * @since 1.0.19
894
-	 */
895
-	public function is_required_field_set( $field ) {
896
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
897
-	}
898
-
899
-	/**
900
-	 * Formats an amount
901
-	 *
902
-	 * @since 1.0.19
903
-	 */
904
-	public function format_amount( $amount ) {
905
-		return wpinv_price( $amount, $this->get_currency() );
906
-	}
793
+    /**
794
+     * Checks if this is the initial fetch.
795
+     *
796
+     * @return bool
797
+     * @since 1.0.19
798
+     */
799
+    public function is_initial_fetch() {
800
+        return empty( $this->data['initial_state'] );
801
+    }
802
+
803
+    /**
804
+     * Returns the total amount to collect for this submission.
805
+     *
806
+     * @since 1.0.19
807
+     */
808
+    public function get_total() {
809
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
810
+        return max( $total, 0 );
811
+    }
812
+
813
+    /**
814
+     * Returns the recurring total amount to collect for this submission.
815
+     *
816
+     * @since 1.0.19
817
+     */
818
+    public function get_recurring_total() {
819
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
820
+        return max( $total, 0 );
821
+    }
822
+
823
+    /**
824
+     * Whether payment details should be collected for this submission.
825
+     *
826
+     * @since 1.0.19
827
+     */
828
+    public function should_collect_payment_details() {
829
+        $initial   = $this->get_total();
830
+        $recurring = $this->get_recurring_total();
831
+
832
+        if ( $this->has_recurring == 0 ) {
833
+            $recurring = 0;
834
+        }
835
+
836
+        $collect = $initial > 0 || $recurring > 0;
837
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
838
+    }
839
+
840
+    /**
841
+     * Returns the billing email of the user.
842
+     *
843
+     * @since 1.0.19
844
+     */
845
+    public function get_billing_email() {
846
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
847
+    }
848
+
849
+    /**
850
+     * Checks if the submitter has a billing email.
851
+     *
852
+     * @since 1.0.19
853
+     */
854
+    public function has_billing_email() {
855
+        $billing_email = $this->get_billing_email();
856
+        return ! empty( $billing_email ) && is_email( $billing_email );
857
+    }
858
+
859
+    /**
860
+     * Returns the appropriate currency for the submission.
861
+     *
862
+     * @since 1.0.19
863
+     * @return string
864
+     */
865
+    public function get_currency() {
866
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
867
+    }
868
+
869
+    /**
870
+     * Returns the raw submission data.
871
+     *
872
+     * @since 1.0.19
873
+     * @return array
874
+     */
875
+    public function get_data() {
876
+        return $this->data;
877
+    }
878
+
879
+    /**
880
+     * Returns a field from the submission data
881
+     *
882
+     * @param string $field
883
+     * @since 1.0.19
884
+     * @return mixed|null
885
+     */
886
+    public function get_field( $field, $sub_array_key = null ) {
887
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
888
+    }
889
+
890
+    /**
891
+     * Checks if a required field is set.
892
+     *
893
+     * @since 1.0.19
894
+     */
895
+    public function is_required_field_set( $field ) {
896
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
897
+    }
898
+
899
+    /**
900
+     * Formats an amount
901
+     *
902
+     * @since 1.0.19
903
+     */
904
+    public function format_amount( $amount ) {
905
+        return wpinv_price( $amount, $this->get_currency() );
906
+    }
907 907
 
908 908
 }
Please login to merge, or discard this patch.
Spacing   +125 added lines, -125 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
 
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 		$this->state   = wpinv_get_default_state();
142 142
 
143 143
 		// Do we have an actual submission?
144
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
145
-			$this->load_data( $_POST );
144
+		if (isset($_POST['getpaid_payment_form_submission'])) {
145
+			$this->load_data($_POST);
146 146
 		}
147 147
 
148 148
 	}
@@ -152,19 +152,19 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @param array $data
154 154
 	 */
155
-	public function load_data( $data ) {
155
+	public function load_data($data) {
156 156
 
157 157
 		// Remove slashes from the submitted data...
158
-		$data       = wp_unslash( $data );
158
+		$data       = wp_unslash($data);
159 159
 
160 160
 		// Allow plugins to filter the data.
161
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
161
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
162 162
 
163 163
 		// Cache it...
164 164
 		$this->data = $data;
165 165
 
166 166
 		// Then generate a unique id from the data.
167
-		$this->id   = md5( wp_json_encode( $data ) );
167
+		$this->id   = md5(wp_json_encode($data));
168 168
 
169 169
 		// Finally, process the submission.
170 170
 		try {
@@ -174,30 +174,30 @@  discard block
 block discarded – undo
174 174
 			$processors = apply_filters(
175 175
 				'getpaid_payment_form_submission_processors',
176 176
 				array(
177
-					array( $this, 'process_payment_form' ),
178
-					array( $this, 'process_invoice' ),
179
-					array( $this, 'process_fees' ),
180
-					array( $this, 'process_items' ),
181
-					array( $this, 'process_discount' ),
182
-					array( $this, 'process_taxes' ),
177
+					array($this, 'process_payment_form'),
178
+					array($this, 'process_invoice'),
179
+					array($this, 'process_fees'),
180
+					array($this, 'process_items'),
181
+					array($this, 'process_discount'),
182
+					array($this, 'process_taxes'),
183 183
 				),
184 184
 				$this		
185 185
 			);
186 186
 
187
-			foreach ( $processors as $processor ) {
188
-				call_user_func_array( $processor, array( &$this ) );
187
+			foreach ($processors as $processor) {
188
+				call_user_func_array($processor, array(&$this));
189 189
 			}
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
 
@@ -218,18 +218,18 @@  discard block
 block discarded – undo
218 218
 	public function process_payment_form() {
219 219
 
220 220
 		// Every submission needs an active payment form.
221
-		if ( empty( $this->data['form_id'] ) ) {
222
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
221
+		if (empty($this->data['form_id'])) {
222
+			throw new Exception(__('Missing payment form', 'invoicing'));
223 223
 		}
224 224
 
225 225
 		// Fetch the payment form.
226
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
226
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
227 227
 
228
-		if ( ! $this->payment_form->is_active() ) {
229
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
228
+		if (!$this->payment_form->is_active()) {
229
+			throw new Exception(__('Payment form not active', 'invoicing'));
230 230
 		}
231 231
 
232
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
232
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
233 233
 	}
234 234
 
235 235
     /**
@@ -259,53 +259,53 @@  discard block
 block discarded – undo
259 259
 	public function process_invoice() {
260 260
 
261 261
 		// Abort if there is no invoice.
262
-		if ( empty( $this->data['invoice_id'] ) ) {
262
+		if (empty($this->data['invoice_id'])) {
263 263
 			return;
264 264
 		}
265 265
 
266 266
 		// If the submission is for an existing invoice, ensure that it exists
267 267
 		// and that it is not paid for.
268
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
268
+		$invoice = wpinv_get_invoice($this->data['invoice_id']);
269 269
 
270
-        if ( empty( $invoice ) ) {
271
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
270
+        if (empty($invoice)) {
271
+			throw new Exception(__('Invalid invoice', 'invoicing'));
272 272
 		}
273 273
 
274
-		if ( $invoice->is_paid() ) {
275
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
274
+		if ($invoice->is_paid()) {
275
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
276 276
 		}
277 277
 
278 278
 		$this->payment_form->invoice = $invoice;
279
-		if ( ! $this->payment_form->is_default() ) {
279
+		if (!$this->payment_form->is_default()) {
280 280
 
281 281
 			$items    = array();
282 282
 			$item_ids = array();
283 283
 	
284
-			foreach ( $invoice->get_items() as $item ) {
285
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
284
+			foreach ($invoice->get_items() as $item) {
285
+				if (!in_array($item->get_id(), $item_ids)) {
286 286
 					$item_ids[] = $item->get_id();
287 287
 					$items[]    = $item;
288 288
 				}
289 289
 			}
290 290
 	
291
-			foreach ( $this->payment_form->get_items() as $item ) {
292
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
291
+			foreach ($this->payment_form->get_items() as $item) {
292
+				if (!in_array($item->get_id(), $item_ids)) {
293 293
 					$item_ids[] = $item->get_id();
294 294
 					$items[]    = $item;
295 295
 				}
296 296
 			}
297 297
 	
298
-			$this->payment_form->set_items( $items );
298
+			$this->payment_form->set_items($items);
299 299
 	
300 300
 		} else {
301
-			$this->payment_form->set_items( $invoice->get_items() );
301
+			$this->payment_form->set_items($invoice->get_items());
302 302
 		}
303 303
 
304 304
 		$this->country = $invoice->get_country();
305 305
 		$this->state   = $invoice->get_state();
306 306
 		$this->invoice = $invoice;
307 307
 
308
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
308
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
309 309
 	}
310 310
 
311 311
 	/**
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 	 * @return bool
326 326
 	 */
327 327
 	public function has_invoice() {
328
-		return ! empty( $this->invoice );
328
+		return !empty($this->invoice);
329 329
 	}
330 330
 
331 331
 	/*
@@ -344,13 +344,13 @@  discard block
 block discarded – undo
344 344
 	 */
345 345
 	public function process_items() {
346 346
 
347
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
347
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
348 348
 
349
-		foreach ( $processor->items as $item ) {
350
-			$this->add_item( $item );
349
+		foreach ($processor->items as $item) {
350
+			$this->add_item($item);
351 351
 		}
352 352
 
353
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
353
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
354 354
 	}
355 355
 
356 356
 	/**
@@ -359,20 +359,20 @@  discard block
 block discarded – undo
359 359
 	 * @since 1.0.19
360 360
 	 * @param GetPaid_Form_Item $item
361 361
 	 */
362
-	public function add_item( $item ) {
362
+	public function add_item($item) {
363 363
 
364 364
 		// Make sure that it is available for purchase.
365
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
365
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
366 366
 			return;
367 367
 		}
368 368
 
369 369
 		// Each submission can only contain one recurring item.
370
-		if ( $item->is_recurring() ) {
370
+		if ($item->is_recurring()) {
371 371
 			$this->has_recurring = $item->get_id();
372 372
 		}
373 373
 
374 374
 		// Update the items and totals.
375
-		$this->items[ $item->get_id() ]         = $item;
375
+		$this->items[$item->get_id()]         = $item;
376 376
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
377 377
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
378 378
 
@@ -386,17 +386,17 @@  discard block
 block discarded – undo
386 386
 	 *
387 387
 	 * @since 1.0.19
388 388
 	 */
389
-	public function remove_item( $item_id ) {
389
+	public function remove_item($item_id) {
390 390
 
391
-		if ( isset( $this->items[ $item_id ] ) ) {
392
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
393
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
391
+		if (isset($this->items[$item_id])) {
392
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
393
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
394 394
 
395
-			if ( $this->items[ $item_id ]->is_recurring() ) {
395
+			if ($this->items[$item_id]->is_recurring()) {
396 396
 				$this->has_recurring = 0;
397 397
 			}
398 398
 
399
-			unset( $this->items[ $item_id ] );
399
+			unset($this->items[$item_id]);
400 400
 		}
401 401
 
402 402
 	}
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 	 */
409 409
 	public function get_subtotal() {
410 410
 
411
-		if ( wpinv_prices_include_tax() ) {
411
+		if (wpinv_prices_include_tax()) {
412 412
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
413 413
 		}
414 414
 
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 	 */
423 423
 	public function get_recurring_subtotal() {
424 424
 
425
-		if ( wpinv_prices_include_tax() ) {
425
+		if (wpinv_prices_include_tax()) {
426 426
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
427 427
 		}
428 428
 
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	 * @return bool
447 447
 	 */
448 448
 	public function has_subscription_group() {
449
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
449
+		return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this));
450 450
 	}
451 451
 
452 452
 	/**
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 	 * @return bool
457 457
 	 */
458 458
 	public function has_multiple_subscription_groups() {
459
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
459
+		return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this));
460 460
 	}
461 461
 
462 462
 	/*
@@ -476,39 +476,39 @@  discard block
 block discarded – undo
476 476
 	public function process_taxes() {
477 477
 
478 478
 		// Abort if we're not using taxes.
479
-		if ( ! $this->use_taxes() ) {
479
+		if (!$this->use_taxes()) {
480 480
 			return;
481 481
 		}
482 482
 
483 483
 		// If a custom country && state has been passed in, use it to calculate taxes.
484
-		$country = $this->get_field( 'wpinv_country', 'billing' );
485
-		if ( ! empty( $country ) ) {
484
+		$country = $this->get_field('wpinv_country', 'billing');
485
+		if (!empty($country)) {
486 486
 			$this->country = $country;
487 487
 		}
488 488
 
489
-		$state = $this->get_field( 'wpinv_state', 'billing' );
490
-		if ( ! empty( $state ) ) {
489
+		$state = $this->get_field('wpinv_state', 'billing');
490
+		if (!empty($state)) {
491 491
 			$this->state = $state;
492 492
 		}
493 493
 
494 494
 		// Confirm if the provided country and the ip country are similar.
495
-		$address_confirmed = $this->get_field( 'confirm-address' );
496
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
497
-			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' ) );
495
+		$address_confirmed = $this->get_field('confirm-address');
496
+		if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
497
+			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'));
498 498
 		}
499 499
 
500 500
 		// Abort if the country is not taxable.
501
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
501
+		if (!wpinv_is_country_taxable($this->country)) {
502 502
 			return;
503 503
 		}
504 504
 
505
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
505
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
506 506
 
507
-		foreach ( $processor->taxes as $tax ) {
508
-			$this->add_tax( $tax );
507
+		foreach ($processor->taxes as $tax) {
508
+			$this->add_tax($tax);
509 509
 		}
510 510
 
511
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
511
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
512 512
 	}
513 513
 
514 514
 	/**
@@ -517,16 +517,16 @@  discard block
 block discarded – undo
517 517
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
518 518
 	 * @since 1.0.19
519 519
 	 */
520
-	public function add_tax( $tax ) {
520
+	public function add_tax($tax) {
521 521
 
522
-		if ( wpinv_round_tax_per_tax_rate() ) {
523
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
524
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
522
+		if (wpinv_round_tax_per_tax_rate()) {
523
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
524
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
525 525
 		}
526 526
 
527
-		$this->taxes[ $tax['name'] ]         = $tax;
528
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
529
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
527
+		$this->taxes[$tax['name']]         = $tax;
528
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
529
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
530 530
 
531 531
 	}
532 532
 
@@ -535,12 +535,12 @@  discard block
 block discarded – undo
535 535
 	 *
536 536
 	 * @since 1.0.19
537 537
 	 */
538
-	public function remove_tax( $tax_name ) {
538
+	public function remove_tax($tax_name) {
539 539
 
540
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
541
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
542
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
543
-			unset( $this->taxes[ $tax_name ] );
540
+		if (isset($this->taxes[$tax_name])) {
541
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
542
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
543
+			unset($this->taxes[$tax_name]);
544 544
 		}
545 545
 
546 546
 	}
@@ -554,11 +554,11 @@  discard block
 block discarded – undo
554 554
 
555 555
 		$use_taxes = wpinv_use_taxes();
556 556
 
557
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
557
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
558 558
 			$use_taxes = false;
559 559
 		}
560 560
 
561
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
561
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
562 562
 
563 563
 	}
564 564
 
@@ -607,13 +607,13 @@  discard block
 block discarded – undo
607 607
 
608 608
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
609 609
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
610
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
610
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
611 611
 
612
-		foreach ( $processor->discounts as $discount ) {
613
-			$this->add_discount( $discount );
612
+		foreach ($processor->discounts as $discount) {
613
+			$this->add_discount($discount);
614 614
 		}
615 615
 
616
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
616
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
617 617
 	}
618 618
 
619 619
 	/**
@@ -622,10 +622,10 @@  discard block
 block discarded – undo
622 622
 	 * @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.
623 623
 	 * @since 1.0.19
624 624
 	 */
625
-	public function add_discount( $discount ) {
626
-		$this->discounts[ $discount['name'] ]   = $discount;
627
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
628
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
625
+	public function add_discount($discount) {
626
+		$this->discounts[$discount['name']]   = $discount;
627
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
628
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
629 629
 	}
630 630
 
631 631
 	/**
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
 	 *
634 634
 	 * @since 1.0.19
635 635
 	 */
636
-	public function remove_discount( $name ) {
636
+	public function remove_discount($name) {
637 637
 
638
-		if ( isset( $this->discounts[ $name ] ) ) {
639
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
640
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
641
-			unset( $this->discounts[ $name ] );
638
+		if (isset($this->discounts[$name])) {
639
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
640
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
641
+			unset($this->discounts[$name]);
642 642
 		}
643 643
 
644 644
 	}
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 	 * @return bool
651 651
 	 */
652 652
 	public function has_discount_code() {
653
-		return ! empty( $this->discounts['discount_code'] );
653
+		return !empty($this->discounts['discount_code']);
654 654
 	}
655 655
 
656 656
 	/**
@@ -707,13 +707,13 @@  discard block
 block discarded – undo
707 707
 	 */
708 708
 	public function process_fees() {
709 709
 
710
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
710
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
711 711
 
712
-		foreach ( $fees_processor->fees as $fee ) {
713
-			$this->add_fee( $fee );
712
+		foreach ($fees_processor->fees as $fee) {
713
+			$this->add_fee($fee);
714 714
 		}
715 715
 
716
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
716
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
717 717
 	}
718 718
 
719 719
 	/**
@@ -722,11 +722,11 @@  discard block
 block discarded – undo
722 722
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
723 723
 	 * @since 1.0.19
724 724
 	 */
725
-	public function add_fee( $fee ) {
725
+	public function add_fee($fee) {
726 726
 
727
-		$this->fees[ $fee['name'] ]         = $fee;
728
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
729
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
727
+		$this->fees[$fee['name']]         = $fee;
728
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
729
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
730 730
 
731 731
 	}
732 732
 
@@ -735,12 +735,12 @@  discard block
 block discarded – undo
735 735
 	 *
736 736
 	 * @since 1.0.19
737 737
 	 */
738
-	public function remove_fee( $name ) {
738
+	public function remove_fee($name) {
739 739
 
740
-		if ( isset( $this->fees[ $name ] ) ) {
741
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
742
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
743
-			unset( $this->fees[ $name ] );
740
+		if (isset($this->fees[$name])) {
741
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
742
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
743
+			unset($this->fees[$name]);
744 744
 		}
745 745
 
746 746
 	}
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 	 * @since 1.0.19
780 780
 	 */
781 781
 	public function has_fees() {
782
-		return count( $this->fees ) !== 0;
782
+		return count($this->fees) !== 0;
783 783
 	}
784 784
 
785 785
 	/*
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 	 * @since 1.0.19
798 798
 	 */
799 799
 	public function is_initial_fetch() {
800
-		return empty( $this->data['initial_state'] );
800
+		return empty($this->data['initial_state']);
801 801
 	}
802 802
 
803 803
 	/**
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
 	 */
808 808
 	public function get_total() {
809 809
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
810
-		return max( $total, 0 );
810
+		return max($total, 0);
811 811
 	}
812 812
 
813 813
 	/**
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
 	 */
818 818
 	public function get_recurring_total() {
819 819
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
820
-		return max( $total, 0 );
820
+		return max($total, 0);
821 821
 	}
822 822
 
823 823
 	/**
@@ -829,12 +829,12 @@  discard block
 block discarded – undo
829 829
 		$initial   = $this->get_total();
830 830
 		$recurring = $this->get_recurring_total();
831 831
 
832
-		if ( $this->has_recurring == 0 ) {
832
+		if ($this->has_recurring == 0) {
833 833
 			$recurring = 0;
834 834
 		}
835 835
 
836 836
 		$collect = $initial > 0 || $recurring > 0;
837
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
837
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
838 838
 	}
839 839
 
840 840
 	/**
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
 	 * @since 1.0.19
844 844
 	 */
845 845
 	public function get_billing_email() {
846
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
846
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
847 847
 	}
848 848
 
849 849
 	/**
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
 	 */
854 854
 	public function has_billing_email() {
855 855
 		$billing_email = $this->get_billing_email();
856
-		return ! empty( $billing_email ) && is_email( $billing_email );
856
+		return !empty($billing_email) && is_email($billing_email);
857 857
 	}
858 858
 
859 859
 	/**
@@ -883,8 +883,8 @@  discard block
 block discarded – undo
883 883
 	 * @since 1.0.19
884 884
 	 * @return mixed|null
885 885
 	 */
886
-	public function get_field( $field, $sub_array_key = null ) {
887
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
886
+	public function get_field($field, $sub_array_key = null) {
887
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
888 888
 	}
889 889
 
890 890
 	/**
@@ -892,8 +892,8 @@  discard block
 block discarded – undo
892 892
 	 *
893 893
 	 * @since 1.0.19
894 894
 	 */
895
-	public function is_required_field_set( $field ) {
896
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
895
+	public function is_required_field_set($field) {
896
+		return empty($field['required']) || !empty($this->data[$field['id']]);
897 897
 	}
898 898
 
899 899
 	/**
@@ -901,8 +901,8 @@  discard block
 block discarded – undo
901 901
 	 *
902 902
 	 * @since 1.0.19
903 903
 	 */
904
-	public function format_amount( $amount ) {
905
-		return wpinv_price( $amount, $this->get_currency() );
904
+	public function format_amount($amount) {
905
+		return wpinv_price($amount, $this->get_currency());
906 906
 	}
907 907
 
908 908
 }
Please login to merge, or discard this patch.
templates/payment-forms/elements/gateway_select.php 1 patch
Spacing   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -7,45 +7,45 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // The payment methods select title.
13
-if ( empty( $text ) ) {
14
-    $text = __( 'Select Payment Method', 'invoicing' );
13
+if (empty($text)) {
14
+    $text = __('Select Payment Method', 'invoicing');
15 15
 }
16 16
 
17 17
 // An array of active payment methods.
18
-$gateways = wpinv_get_enabled_payment_gateways( true );
18
+$gateways = wpinv_get_enabled_payment_gateways(true);
19 19
 
20 20
 // The current invoice id.
21 21
 $invoice_id     = 0;
22 22
 $chosen_gateway = wpinv_get_default_gateway();
23 23
 
24
-if ( ! empty( $form->invoice ) ) {
24
+if (!empty($form->invoice)) {
25 25
     $invoice_id = $form->invoice->get_id();
26 26
     $chosen_gateway = $form->invoice->get_gateway();
27 27
 }
28 28
 
29 29
 ?>
30 30
 
31
-    <?php do_action( 'getpaid_before_payment_form_gateway_select', $form ); ?>
31
+    <?php do_action('getpaid_before_payment_form_gateway_select', $form); ?>
32 32
     <div class="mt-4 mb-4 getpaid-gateways">
33 33
 
34
-        <?php do_action( 'wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form ); ?>
34
+        <?php do_action('wpinv_payment_mode_top', $invoice_id, $chosen_gateway, $gateways, $form); ?>
35 35
 
36 36
         <div class="getpaid-select-gateway-title-div">
37
-            <h6><?php echo sanitize_text_field( $text ); ?></h6>
37
+            <h6><?php echo sanitize_text_field($text); ?></h6>
38 38
         </div>
39 39
 
40 40
         <div class="getpaid-available-gateways-div">
41 41
 
42
-            <?php foreach ( array_keys( $gateways ) as $gateway ) : ?>
42
+            <?php foreach (array_keys($gateways) as $gateway) : ?>
43 43
 
44
-                <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class( $gateway ) ;?>" data-checkout-label='<?php echo esc_attr( apply_filters( "getpaid_gateway_{$gateway}_checkout_button_label", '' ) ); ?>'>
44
+                <div class="pt-1 pb-1 getpaid-gateway getpaid-gateway-<?php echo sanitize_html_class($gateway); ?>" data-checkout-label='<?php echo esc_attr(apply_filters("getpaid_gateway_{$gateway}_checkout_button_label", '')); ?>'>
45 45
 
46 46
                     <label class="d-block w-100 getpaid-gateway-radio">
47
-                        <input type="radio" value="<?php echo esc_attr( $gateway ) ;?>" <?php checked( $gateway, $chosen_gateway ) ;?> name="wpi-gateway">
48
-                        <span><?php echo sanitize_text_field( wpinv_get_gateway_checkout_label( $gateway ) ); ?></span>
47
+                        <input type="radio" value="<?php echo esc_attr($gateway); ?>" <?php checked($gateway, $chosen_gateway); ?> name="wpi-gateway">
48
+                        <span><?php echo sanitize_text_field(wpinv_get_gateway_checkout_label($gateway)); ?></span>
49 49
                     </label>
50 50
 
51 51
                 </div>
@@ -56,22 +56,22 @@  discard block
 block discarded – undo
56 56
 
57 57
         <div class="getpaid-gateway-descriptions-div">
58 58
 
59
-            <?php foreach ( array_keys( $gateways ) as $gateway ) : ?>
59
+            <?php foreach (array_keys($gateways) as $gateway) : ?>
60 60
 
61
-                <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class( $gateway ) ;?>" style="display: none;">
61
+                <div class="my-2 p-3 bg-light border getpaid-gateway-description getpaid-description-<?php echo sanitize_html_class($gateway); ?>" style="display: none;">
62 62
                     <?php
63 63
 
64
-                        $description = wpinv_get_gateway_description( $gateway );
64
+                        $description = wpinv_get_gateway_description($gateway);
65 65
 
66
-                        if ( wpinv_is_test_mode( $gateway ) ) {
67
-                            $sandbox_notice = apply_filters( "getpaid_{$gateway}_sandbox_notice", __( 'SANDBOX ENABLED: No real payments will occur.', 'invoicing' ) );
66
+                        if (wpinv_is_test_mode($gateway)) {
67
+                            $sandbox_notice = apply_filters("getpaid_{$gateway}_sandbox_notice", __('SANDBOX ENABLED: No real payments will occur.', 'invoicing'));
68 68
                             $description = "$description $sandbox_notice";
69 69
                         }
70 70
 
71
-                        echo wpautop( wp_kses_post( $description ) );
71
+                        echo wpautop(wp_kses_post($description));
72 72
 
73
-                        do_action( 'wpinv_' . $gateway . '_checkout_fields', $invoice_id ) ;
74
-                        do_action( 'wpinv_' . $gateway . '_cc_form', $invoice_id, $form ) ;
73
+                        do_action('wpinv_' . $gateway . '_checkout_fields', $invoice_id);
74
+                        do_action('wpinv_' . $gateway . '_cc_form', $invoice_id, $form);
75 75
 
76 76
                     ?>
77 77
                 </div>
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
             <?php
85 85
                 echo aui()->alert(
86 86
                     array(
87
-                        'content'     => __( 'None of the available payment gateways support purchasing recurring items.', 'invoicing' ),
87
+                        'content'     => __('None of the available payment gateways support purchasing recurring items.', 'invoicing'),
88 88
                         'type'        => 'danger',
89 89
                     )
90 90
                 );
@@ -95,7 +95,7 @@  discard block
 block discarded – undo
95 95
             <?php
96 96
                 echo aui()->alert(
97 97
                     array(
98
-                        'content'     => __( 'None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing' ),
98
+                        'content'     => __('None of the available payment gateways support purchasing multiple subscriptions in a single order.', 'invoicing'),
99 99
                         'type'        => 'danger',
100 100
                     )
101 101
                 );
@@ -106,7 +106,7 @@  discard block
 block discarded – undo
106 106
             <?php
107 107
                 echo aui()->alert(
108 108
                     array(
109
-                        'content'     => __( 'None of the available payment gateways support purchasing multiple subscriptions with different billing schedules in a single order.', 'invoicing' ),
109
+                        'content'     => __('None of the available payment gateways support purchasing multiple subscriptions with different billing schedules in a single order.', 'invoicing'),
110 110
                         'type'        => 'danger',
111 111
                     )
112 112
                 );
@@ -117,14 +117,14 @@  discard block
 block discarded – undo
117 117
             <?php
118 118
                 echo aui()->alert(
119 119
                     array(
120
-                        'content'     => __( 'There is no active payment gateway available to process your request.', 'invoicing' ),
120
+                        'content'     => __('There is no active payment gateway available to process your request.', 'invoicing'),
121 121
                         'type'        => 'danger',
122 122
                     )
123 123
                 );
124 124
             ?>
125 125
         </div>
126 126
 
127
-        <?php do_action( 'wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form ); ?>
127
+        <?php do_action('wpinv_payment_mode_bottom', $invoice_id, $chosen_gateway, $gateways, $form); ?>
128 128
 
129 129
     </div>
130
-    <?php do_action( 'getpaid_after_payment_form_gateway_select', $form ); ?>
130
+    <?php do_action('getpaid_after_payment_form_gateway_select', $form); ?>
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-gateway.php 2 patches
Indentation   +227 added lines, -227 removed lines patch added patch discarded remove patch
@@ -13,58 +13,58 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Authorize_Net_Gateway extends GetPaid_Authorize_Net_Legacy_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'authorizenet';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 4;
35 35
 
36 36
     /**
37
-	 * Endpoint for requests from Authorize.net.
38
-	 *
39
-	 * @var string
40
-	 */
41
-	protected $notify_url;
42
-
43
-	/**
44
-	 * Endpoint for requests to Authorize.net.
45
-	 *
46
-	 * @var string
47
-	 */
37
+     * Endpoint for requests from Authorize.net.
38
+     *
39
+     * @var string
40
+     */
41
+    protected $notify_url;
42
+
43
+    /**
44
+     * Endpoint for requests to Authorize.net.
45
+     *
46
+     * @var string
47
+     */
48 48
     protected $endpoint;
49 49
 
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
56 56
 
57 57
     /**
58
-	 * URL to view a transaction.
59
-	 *
60
-	 * @var string
61
-	 */
58
+     * URL to view a transaction.
59
+     *
60
+     * @var string
61
+     */
62 62
     public $view_transaction_url = 'https://{sandbox}authorize.net/ui/themes/sandbox/Transaction/TransactionReceipt.aspx?transid=%s';
63 63
 
64 64
     /**
65
-	 * Class constructor.
66
-	 */
67
-	public function __construct() {
65
+     * Class constructor.
66
+     */
67
+    public function __construct() {
68 68
 
69 69
         $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70 70
         $this->method_title         = __( 'Authorize.Net', 'invoicing' );
@@ -76,11 +76,11 @@  discard block
 block discarded – undo
76 76
     }
77 77
 
78 78
     /**
79
-	 * Displays the payment method select field.
80
-	 *
81
-	 * @param int $invoice_id 0 or invoice id.
82
-	 * @param GetPaid_Payment_Form $form Current payment form.
83
-	 */
79
+     * Displays the payment method select field.
80
+     *
81
+     * @param int $invoice_id 0 or invoice id.
82
+     * @param GetPaid_Payment_Form $form Current payment form.
83
+     */
84 84
     public function payment_fields( $invoice_id, $form ) {
85 85
 
86 86
         // Let the user select a payment method.
@@ -91,16 +91,16 @@  discard block
 block discarded – undo
91 91
     }
92 92
 
93 93
     /**
94
-	 * Creates a customer profile.
95
-	 *
96
-	 *
97
-	 * @param WPInv_Invoice $invoice Invoice.
94
+     * Creates a customer profile.
95
+     *
96
+     *
97
+     * @param WPInv_Invoice $invoice Invoice.
98 98
      * @param array $submission_data Posted checkout fields.
99 99
      * @param bool $save Whether or not to save the payment as a token.
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101
-	 * @return string|WP_Error Payment profile id.
102
-	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
101
+     * @return string|WP_Error Payment profile id.
102
+     */
103
+    public function create_customer_profile( $invoice, $submission_data, $save = true ) {
104 104
 
105 105
         // Remove non-digits from the number
106 106
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -167,14 +167,14 @@  discard block
 block discarded – undo
167 167
     }
168 168
 
169 169
     /**
170
-	 * Retrieves a customer profile.
171
-	 *
172
-	 *
173
-	 * @param string $profile_id profile id.
174
-	 * @return string|WP_Error Profile id.
170
+     * Retrieves a customer profile.
171
+     *
172
+     *
173
+     * @param string $profile_id profile id.
174
+     * @return string|WP_Error Profile id.
175 175
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
176
-	 */
177
-	public function get_customer_profile( $profile_id ) {
176
+     */
177
+    public function get_customer_profile( $profile_id ) {
178 178
 
179 179
         // Generate args.
180 180
         $args = array(
@@ -189,17 +189,17 @@  discard block
 block discarded – undo
189 189
     }
190 190
 
191 191
     /**
192
-	 * Creates a customer profile.
193
-	 *
194
-	 *
192
+     * Creates a customer profile.
193
+     *
194
+     *
195 195
      * @param string $profile_id profile id.
196
-	 * @param WPInv_Invoice $invoice Invoice.
196
+     * @param WPInv_Invoice $invoice Invoice.
197 197
      * @param array $submission_data Posted checkout fields.
198 198
      * @param bool $save Whether or not to save the payment as a token.
199 199
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
200
-	 * @return string|WP_Error Profile id.
201
-	 */
202
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
200
+     * @return string|WP_Error Profile id.
201
+     */
202
+    public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
203 203
 
204 204
         // Remove non-digits from the number
205 205
         $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
@@ -272,13 +272,13 @@  discard block
 block discarded – undo
272 272
     }
273 273
 
274 274
     /**
275
-	 * Retrieves payment details from cache.
276
-	 *
277
-	 *
275
+     * Retrieves payment details from cache.
276
+     *
277
+     *
278 278
      * @param array $payment_details.
279
-	 * @return array|false Profile id.
280
-	 */
281
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
279
+     * @return array|false Profile id.
280
+     */
281
+    public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
282 282
 
283 283
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
284 284
         $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
@@ -303,13 +303,13 @@  discard block
 block discarded – undo
303 303
     }
304 304
 
305 305
     /**
306
-	 * Securely adds payment details to cache.
307
-	 *
308
-	 *
306
+     * Securely adds payment details to cache.
307
+     *
308
+     *
309 309
      * @param array $payment_details.
310 310
      * @param string $payment_profile_id.
311
-	 */
312
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
311
+     */
312
+    public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
313 313
 
314 314
         $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
315 315
         $cached_information = is_array( $cached_information ) ? $cached_information : array();
@@ -321,15 +321,15 @@  discard block
 block discarded – undo
321 321
     }
322 322
 
323 323
     /**
324
-	 * Retrieves a customer payment profile.
325
-	 *
326
-	 *
327
-	 * @param string $customer_profile_id customer profile id.
324
+     * Retrieves a customer payment profile.
325
+     *
326
+     *
327
+     * @param string $customer_profile_id customer profile id.
328 328
      * @param string $payment_profile_id payment profile id.
329
-	 * @return string|WP_Error Profile id.
329
+     * @return string|WP_Error Profile id.
330 330
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
331
-	 */
332
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
331
+     */
332
+    public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
333 333
 
334 334
         // Generate args.
335 335
         $args = array(
@@ -345,15 +345,15 @@  discard block
 block discarded – undo
345 345
     }
346 346
 
347 347
     /**
348
-	 * Charges a customer payment profile.
349
-	 *
348
+     * Charges a customer payment profile.
349
+     *
350 350
      * @param string $customer_profile_id customer profile id.
351 351
      * @param string $payment_profile_id payment profile id.
352
-	 * @param WPInv_Invoice $invoice Invoice.
352
+     * @param WPInv_Invoice $invoice Invoice.
353 353
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
354
-	 * @return WP_Error|object
355
-	 */
356
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
354
+     * @return WP_Error|object
355
+     */
356
+    public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
357 357
 
358 358
         // Generate args.
359 359
         $args = array(
@@ -399,41 +399,41 @@  discard block
 block discarded – undo
399 399
     }
400 400
 
401 401
     /**
402
-	 * Processes a customer charge.
403
-	 *
402
+     * Processes a customer charge.
403
+     *
404 404
      * @param stdClass $result Api response.
405
-	 * @param WPInv_Invoice $invoice Invoice.
406
-	 */
407
-	public function process_charge_response( $result, $invoice ) {
405
+     * @param WPInv_Invoice $invoice Invoice.
406
+     */
407
+    public function process_charge_response( $result, $invoice ) {
408 408
 
409 409
         wpinv_clear_errors();
410
-		$response_code = (int) $result->transactionResponse->responseCode;
410
+        $response_code = (int) $result->transactionResponse->responseCode;
411 411
 
412
-		// Succeeded.
413
-		if ( 1 == $response_code || 4 == $response_code ) {
412
+        // Succeeded.
413
+        if ( 1 == $response_code || 4 == $response_code ) {
414 414
 
415
-			// Maybe set a transaction id.
416
-			if ( ! empty( $result->transactionResponse->transId ) ) {
417
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
418
-			}
415
+            // Maybe set a transaction id.
416
+            if ( ! empty( $result->transactionResponse->transId ) ) {
417
+                $invoice->set_transaction_id( $result->transactionResponse->transId );
418
+            }
419 419
 
420
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
420
+            $invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
421 421
 
422
-			if ( 1 == $response_code ) {
423
-				return $invoice->mark_paid();
424
-			}
422
+            if ( 1 == $response_code ) {
423
+                return $invoice->mark_paid();
424
+            }
425 425
 
426
-			$invoice->set_status( 'wpi-onhold' );
427
-        	$invoice->add_note(
426
+            $invoice->set_status( 'wpi-onhold' );
427
+            $invoice->add_note(
428 428
                 sprintf(
429 429
                     __( 'Held for review: %s', 'invoicing' ),
430 430
                     $result->transactionResponse->messages->message[0]->description
431 431
                 )
432
-			);
432
+            );
433 433
 
434
-			return $invoice->save();
434
+            return $invoice->save();
435 435
 
436
-		}
436
+        }
437 437
 
438 438
         wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
439 439
 
@@ -445,13 +445,13 @@  discard block
 block discarded – undo
445 445
     }
446 446
 
447 447
     /**
448
-	 * Returns payment information.
449
-	 *
450
-	 *
451
-	 * @param array $card Card details.
452
-	 * @return array
453
-	 */
454
-	public function get_payment_information( $card ) {
448
+     * Returns payment information.
449
+     *
450
+     *
451
+     * @param array $card Card details.
452
+     * @return array
453
+     */
454
+    public function get_payment_information( $card ) {
455 455
         return array(
456 456
 
457 457
             'creditCard'         => array (
@@ -464,25 +464,25 @@  discard block
 block discarded – undo
464 464
     }
465 465
 
466 466
     /**
467
-	 * Returns the customer profile meta name.
468
-	 *
469
-	 *
470
-	 * @param WPInv_Invoice $invoice Invoice.
471
-	 * @return string
472
-	 */
473
-	public function get_customer_profile_meta_name( $invoice ) {
467
+     * Returns the customer profile meta name.
468
+     *
469
+     *
470
+     * @param WPInv_Invoice $invoice Invoice.
471
+     * @return string
472
+     */
473
+    public function get_customer_profile_meta_name( $invoice ) {
474 474
         return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
475 475
     }
476 476
 
477 477
     /**
478
-	 * Validates the submitted data.
479
-	 *
480
-	 *
481
-	 * @param array $submission_data Posted checkout fields.
478
+     * Validates the submitted data.
479
+     *
480
+     *
481
+     * @param array $submission_data Posted checkout fields.
482 482
      * @param WPInv_Invoice $invoice
483
-	 * @return WP_Error|string The payment profile id
484
-	 */
485
-	public function validate_submission_data( $submission_data, $invoice ) {
483
+     * @return WP_Error|string The payment profile id
484
+     */
485
+    public function validate_submission_data( $submission_data, $invoice ) {
486 486
 
487 487
         // Validate authentication details.
488 488
         $auth = $this->get_auth_params();
@@ -514,13 +514,13 @@  discard block
 block discarded – undo
514 514
     }
515 515
 
516 516
     /**
517
-	 * Returns invoice line items.
518
-	 *
519
-	 *
520
-	 * @param WPInv_Invoice $invoice Invoice.
521
-	 * @return array
522
-	 */
523
-	public function get_line_items( $invoice ) {
517
+     * Returns invoice line items.
518
+     *
519
+     *
520
+     * @param WPInv_Invoice $invoice Invoice.
521
+     * @return array
522
+     */
523
+    public function get_line_items( $invoice ) {
524 524
         $items = array();
525 525
 
526 526
         foreach ( $invoice->get_items() as $item ) {
@@ -558,15 +558,15 @@  discard block
 block discarded – undo
558 558
     }
559 559
 
560 560
     /**
561
-	 * Process Payment.
562
-	 *
563
-	 *
564
-	 * @param WPInv_Invoice $invoice Invoice.
565
-	 * @param array $submission_data Posted checkout fields.
566
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
567
-	 * @return array
568
-	 */
569
-	public function process_payment( $invoice, $submission_data, $submission ) {
561
+     * Process Payment.
562
+     *
563
+     *
564
+     * @param WPInv_Invoice $invoice Invoice.
565
+     * @param array $submission_data Posted checkout fields.
566
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
567
+     * @return array
568
+     */
569
+    public function process_payment( $invoice, $submission_data, $submission ) {
570 570
 
571 571
         // Validate the submitted data.
572 572
         $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
@@ -599,45 +599,45 @@  discard block
 block discarded – undo
599 599
 
600 600
         exit;
601 601
 
602
-	}
602
+    }
603 603
 	
604
-	/**
605
-	 * Processes the initial payment.
606
-	 *
604
+    /**
605
+     * Processes the initial payment.
606
+     *
607 607
      * @param WPInv_Invoice $invoice Invoice.
608
-	 */
609
-	protected function process_initial_payment( $invoice ) {
608
+     */
609
+    protected function process_initial_payment( $invoice ) {
610 610
 
611
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
611
+        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
612 612
         $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
613
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
613
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
614 614
 
615
-		// Do we have an error?
616
-		if ( is_wp_error( $result ) ) {
617
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
618
-			wpinv_send_back_to_checkout( $invoice );
619
-		}
615
+        // Do we have an error?
616
+        if ( is_wp_error( $result ) ) {
617
+            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
618
+            wpinv_send_back_to_checkout( $invoice );
619
+        }
620 620
 
621
-		// Process the response.
622
-		$this->process_charge_response( $result, $invoice );
621
+        // Process the response.
622
+        $this->process_charge_response( $result, $invoice );
623 623
 
624
-		if ( wpinv_get_errors() ) {
625
-			wpinv_send_back_to_checkout( $invoice );
626
-		}
624
+        if ( wpinv_get_errors() ) {
625
+            wpinv_send_back_to_checkout( $invoice );
626
+        }
627 627
 
628
-	}
628
+    }
629 629
 
630 630
     /**
631
-	 * Processes recurring payments.
632
-	 *
631
+     * Processes recurring payments.
632
+     *
633 633
      * @param WPInv_Invoice $invoice Invoice.
634 634
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
635
-	 */
636
-	public function process_subscription( $invoice, $subscriptions ) {
635
+     */
636
+    public function process_subscription( $invoice, $subscriptions ) {
637 637
 
638 638
         // Check if there is an initial amount to charge.
639 639
         if ( (float) $invoice->get_total() > 0 ) {
640
-			$this->process_initial_payment( $invoice );
640
+            $this->process_initial_payment( $invoice );
641 641
         }
642 642
 
643 643
         // Activate the subscriptions.
@@ -655,19 +655,19 @@  discard block
 block discarded – undo
655 655
             }
656 656
         }
657 657
 
658
-		// Redirect to the success page.
658
+        // Redirect to the success page.
659 659
         wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
660 660
 
661 661
     }
662 662
 
663
-	/**
664
-	 * (Maybe) renews an authorize.net subscription profile.
665
-	 *
666
-	 *
667
-	 * @param bool $should_expire
663
+    /**
664
+     * (Maybe) renews an authorize.net subscription profile.
665
+     *
666
+     *
667
+     * @param bool $should_expire
668 668
      * @param WPInv_Subscription $subscription
669
-	 */
670
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
669
+     */
670
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
671 671
 
672 672
         // Ensure its our subscription && it's active.
673 673
         if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -684,18 +684,18 @@  discard block
 block discarded – undo
684 684
 
685 685
         return false;
686 686
 
687
-	}
687
+    }
688 688
 
689 689
     /**
690
-	 * Renews a subscription.
691
-	 *
690
+     * Renews a subscription.
691
+     *
692 692
      * @param WPInv_Subscription $subscription
693
-	 */
694
-	public function renew_subscription( $subscription ) {
693
+     */
694
+    public function renew_subscription( $subscription ) {
695 695
 
696
-		// Generate the renewal invoice.
697
-		$new_invoice = $subscription->create_payment();
698
-		$old_invoice = $subscription->get_parent_payment();
696
+        // Generate the renewal invoice.
697
+        $new_invoice = $subscription->create_payment();
698
+        $old_invoice = $subscription->get_parent_payment();
699 699
 
700 700
         if ( empty( $new_invoice ) ) {
701 701
             $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
@@ -704,37 +704,37 @@  discard block
 block discarded – undo
704 704
         }
705 705
 
706 706
         // Charge the payment method.
707
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
708
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
709
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
707
+        $payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
708
+        $customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
709
+        $result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
710 710
 
711
-		// Do we have an error?
712
-		if ( is_wp_error( $result ) ) {
711
+        // Do we have an error?
712
+        if ( is_wp_error( $result ) ) {
713 713
 
714
-			$old_invoice->add_note(
715
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
716
-				true,
717
-				false,
718
-				true
719
-			);
720
-			$subscription->failing();
721
-			return;
714
+            $old_invoice->add_note(
715
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
716
+                true,
717
+                false,
718
+                true
719
+            );
720
+            $subscription->failing();
721
+            return;
722 722
 
723
-		}
723
+        }
724 724
 
725
-		// Process the response.
726
-		$this->process_charge_response( $result, $new_invoice );
725
+        // Process the response.
726
+        $this->process_charge_response( $result, $new_invoice );
727 727
 
728
-		if ( wpinv_get_errors() ) {
728
+        if ( wpinv_get_errors() ) {
729 729
 
730
-			$old_invoice->add_note(
731
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
732
-				true,
733
-				false,
734
-				true
735
-			);
736
-			$subscription->failing();
737
-			return;
730
+            $old_invoice->add_note(
731
+                sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
732
+                true,
733
+                false,
734
+                true
735
+            );
736
+            $subscription->failing();
737
+            return;
738 738
 
739 739
         }
740 740
 
@@ -743,13 +743,13 @@  discard block
 block discarded – undo
743 743
     }
744 744
 
745 745
     /**
746
-	 * Processes invoice addons.
747
-	 *
748
-	 * @param WPInv_Invoice $invoice
749
-	 * @param GetPaid_Form_Item[] $items
750
-	 * @return WPInv_Invoice
751
-	 */
752
-	public function process_addons( $invoice, $items ) {
746
+     * Processes invoice addons.
747
+     *
748
+     * @param WPInv_Invoice $invoice
749
+     * @param GetPaid_Form_Item[] $items
750
+     * @return WPInv_Invoice
751
+     */
752
+    public function process_addons( $invoice, $items ) {
753 753
 
754 754
         global $getpaid_authorize_addons;
755 755
 
@@ -769,7 +769,7 @@  discard block
 block discarded – undo
769 769
         $invoice->recalculate_total();
770 770
 
771 771
         $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
772
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
772
+        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
773 773
 
774 774
         add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
775 775
         $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
@@ -784,11 +784,11 @@  discard block
 block discarded – undo
784 784
     }
785 785
 
786 786
     /**
787
-	 * Processes invoice addons.
788
-	 *
787
+     * Processes invoice addons.
788
+     *
789 789
      * @param array $args
790
-	 * @return array
791
-	 */
790
+     * @return array
791
+     */
792 792
     public function filter_addons_request( $args ) {
793 793
 
794 794
         global $getpaid_authorize_addons;
@@ -822,11 +822,11 @@  discard block
 block discarded – undo
822 822
     }
823 823
 
824 824
     /**
825
-	 * Filters the gateway settings.
826
-	 *
827
-	 * @param array $admin_settings
828
-	 */
829
-	public function admin_settings( $admin_settings ) {
825
+     * Filters the gateway settings.
826
+     *
827
+     * @param array $admin_settings
828
+     */
829
+    public function admin_settings( $admin_settings ) {
830 830
 
831 831
         $currencies = sprintf(
832 832
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -866,7 +866,7 @@  discard block
 block discarded – undo
866 866
             'readonly' => true,
867 867
         );
868 868
 
869
-		return $admin_settings;
870
-	}
869
+        return $admin_settings;
870
+    }
871 871
 
872 872
 }
Please login to merge, or discard this patch.
Spacing   +198 added lines, -198 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
  * Authorize.net Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
27
+    protected $supports = array('subscription', 'sandbox', 'tokens', 'addons', 'single_subscription_group', 'multiple_subscription_groups');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -52,7 +52,7 @@  discard block
 block discarded – undo
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD' );
55
+	public $currencies = array('USD', 'CAD', 'GBP', 'DKK', 'NOK', 'PLN', 'SEK', 'AUD', 'EUR', 'NZD');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -66,12 +66,12 @@  discard block
 block discarded – undo
66 66
 	 */
67 67
 	public function __construct() {
68 68
 
69
-        $this->title                = __( 'Credit Card / Debit Card', 'invoicing' );
70
-        $this->method_title         = __( 'Authorize.Net', 'invoicing' );
71
-        $this->notify_url           = getpaid_get_non_query_string_ipn_url( $this->id );
69
+        $this->title                = __('Credit Card / Debit Card', 'invoicing');
70
+        $this->method_title         = __('Authorize.Net', 'invoicing');
71
+        $this->notify_url           = getpaid_get_non_query_string_ipn_url($this->id);
72 72
 
73
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
74
-        add_filter( 'getpaid_authorizenet_sandbox_notice', array( $this, 'sandbox_notice' ) );
73
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
74
+        add_filter('getpaid_authorizenet_sandbox_notice', array($this, 'sandbox_notice'));
75 75
         parent::__construct();
76 76
     }
77 77
 
@@ -81,13 +81,13 @@  discard block
 block discarded – undo
81 81
 	 * @param int $invoice_id 0 or invoice id.
82 82
 	 * @param GetPaid_Payment_Form $form Current payment form.
83 83
 	 */
84
-    public function payment_fields( $invoice_id, $form ) {
84
+    public function payment_fields($invoice_id, $form) {
85 85
 
86 86
         // Let the user select a payment method.
87 87
         echo $this->saved_payment_methods();
88 88
 
89 89
         // Show the credit card entry form.
90
-        echo $this->new_payment_method_entry( $this->get_cc_form( true ) );
90
+        echo $this->new_payment_method_entry($this->get_cc_form(true));
91 91
     }
92 92
 
93 93
     /**
@@ -100,72 +100,72 @@  discard block
 block discarded – undo
100 100
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
101 101
 	 * @return string|WP_Error Payment profile id.
102 102
 	 */
103
-	public function create_customer_profile( $invoice, $submission_data, $save = true ) {
103
+	public function create_customer_profile($invoice, $submission_data, $save = true) {
104 104
 
105 105
         // Remove non-digits from the number
106
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
106
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
107 107
 
108 108
         // Generate args.
109 109
         $args = array(
110 110
             'createCustomerProfileRequest' => array(
111 111
                 'merchantAuthentication'   => $this->get_auth_params(),
112 112
                 'profile'                  => array(
113
-                    'merchantCustomerId'   => getpaid_limit_length( $invoice->get_user_id(), 20 ),
114
-                    'description'          => getpaid_limit_length( $invoice->get_full_name(), 255 ),
115
-                    'email'                => getpaid_limit_length( $invoice->get_email(), 255 ),
113
+                    'merchantCustomerId'   => getpaid_limit_length($invoice->get_user_id(), 20),
114
+                    'description'          => getpaid_limit_length($invoice->get_full_name(), 255),
115
+                    'email'                => getpaid_limit_length($invoice->get_email(), 255),
116 116
                     'paymentProfiles'      => array(
117 117
                         'customerType'     => 'individual',
118 118
 
119 119
                         // Billing information.
120 120
                         'billTo'           => array(
121
-                            'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
122
-                            'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
123
-                            'address'      => getpaid_limit_length( $invoice->get_address(), 60 ),
124
-                            'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
125
-                            'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
126
-                            'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
127
-                            'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
121
+                            'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
122
+                            'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
123
+                            'address'      => getpaid_limit_length($invoice->get_address(), 60),
124
+                            'city'         => getpaid_limit_length($invoice->get_city(), 40),
125
+                            'state'        => getpaid_limit_length($invoice->get_state(), 40),
126
+                            'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
127
+                            'country'      => getpaid_limit_length($invoice->get_country(), 60),
128 128
                         ),
129 129
 
130 130
                         // Payment information.
131
-                        'payment'          => $this->get_payment_information( $submission_data['authorizenet'] ),
131
+                        'payment'          => $this->get_payment_information($submission_data['authorizenet']),
132 132
                     )
133 133
                 ),
134
-                'validationMode'           => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
134
+                'validationMode'           => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
135 135
             )
136 136
         );
137 137
 
138
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_customer_profile_args', $args, $invoice ), $invoice );
138
+        $response = $this->post(apply_filters('getpaid_authorizenet_customer_profile_args', $args, $invoice), $invoice);
139 139
 
140
-        if ( is_wp_error( $response ) ) {
140
+        if (is_wp_error($response)) {
141 141
 
142 142
             // In case the customer profile already exists remotely.
143
-            if ( 'E00039' == $response->get_error_code() ) {
144
-                $customer_profile_id = str_replace( 'A duplicate record with ID ', '', $response->get_error_message() );
145
-                $customer_profile_id = str_replace( ' already exists.', '', $customer_profile_id );
146
-                return $this->create_customer_payment_profile( trim( $customer_profile_id ), $invoice, $submission_data, $save );
143
+            if ('E00039' == $response->get_error_code()) {
144
+                $customer_profile_id = str_replace('A duplicate record with ID ', '', $response->get_error_message());
145
+                $customer_profile_id = str_replace(' already exists.', '', $customer_profile_id);
146
+                return $this->create_customer_payment_profile(trim($customer_profile_id), $invoice, $submission_data, $save);
147 147
             }
148 148
 
149 149
             return $response;
150 150
         }
151 151
 
152
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $response->customerProfileId );
152
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $response->customerProfileId);
153 153
 
154 154
         // Save the payment token.
155
-        if ( $save ) {
155
+        if ($save) {
156 156
             $this->save_token(
157 157
                 array(
158 158
                     'id'      => $response->customerPaymentProfileIdList[0],
159
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . '&middot;&middot;&middot;&middot;' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
159
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . '&middot;&middot;&middot;&middot;' . substr($submission_data['authorizenet']['cc_number'], -4),
160 160
                     'default' => true,
161
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
161
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
162 162
                 )
163 163
             );
164 164
         }
165 165
 
166 166
         // Add a note about the validation response.
167 167
         $invoice->add_note(
168
-            sprintf( __( 'Created Authorize.NET customer profile: %s', 'invoicing' ), $response->validationDirectResponseList[0] ),
168
+            sprintf(__('Created Authorize.NET customer profile: %s', 'invoicing'), $response->validationDirectResponseList[0]),
169 169
             false,
170 170
             false,
171 171
             true
@@ -182,7 +182,7 @@  discard block
 block discarded – undo
182 182
 	 * @return string|WP_Error Profile id.
183 183
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-profile
184 184
 	 */
185
-	public function get_customer_profile( $profile_id ) {
185
+	public function get_customer_profile($profile_id) {
186 186
 
187 187
         // Generate args.
188 188
         $args = array(
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
             )
193 193
         );
194 194
 
195
-        return $this->post( $args, false );
195
+        return $this->post($args, false);
196 196
 
197 197
     }
198 198
 
@@ -207,18 +207,18 @@  discard block
 block discarded – undo
207 207
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-create-customer-profile
208 208
 	 * @return string|WP_Error Profile id.
209 209
 	 */
210
-	public function create_customer_payment_profile( $customer_profile, $invoice, $submission_data, $save ) {
210
+	public function create_customer_payment_profile($customer_profile, $invoice, $submission_data, $save) {
211 211
 
212 212
         // Remove non-digits from the number
213
-        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number'] );
213
+        $submission_data['authorizenet']['cc_number'] = preg_replace('/\D/', '', $submission_data['authorizenet']['cc_number']);
214 214
 
215 215
         // Prepare card details.
216
-        $payment_information                          = $this->get_payment_information( $submission_data['authorizenet'] );
216
+        $payment_information                          = $this->get_payment_information($submission_data['authorizenet']);
217 217
 
218 218
         // Authorize.NET does not support saving the same card twice.
219
-        $cached_information                           = $this->retrieve_payment_profile_from_cache( $payment_information, $customer_profile, $invoice );
219
+        $cached_information                           = $this->retrieve_payment_profile_from_cache($payment_information, $customer_profile, $invoice);
220 220
 
221
-        if ( $cached_information ) {
221
+        if ($cached_information) {
222 222
             return $cached_information;
223 223
         }
224 224
 
@@ -231,52 +231,52 @@  discard block
 block discarded – undo
231 231
 
232 232
                     // Billing information.
233 233
                     'billTo'           => array(
234
-                        'firstName'    => getpaid_limit_length( $invoice->get_first_name(), 50 ),
235
-                        'lastName'     => getpaid_limit_length( $invoice->get_last_name(), 50 ),
236
-                        'address'      => getpaid_limit_length( $invoice->get_address(), 60 ),
237
-                        'city'         => getpaid_limit_length( $invoice->get_city(), 40 ),
238
-                        'state'        => getpaid_limit_length( $invoice->get_state(), 40 ),
239
-                        'zip'          => getpaid_limit_length( $invoice->get_zip(), 20 ),
240
-                        'country'      => getpaid_limit_length( $invoice->get_country(), 60 ),
234
+                        'firstName'    => getpaid_limit_length($invoice->get_first_name(), 50),
235
+                        'lastName'     => getpaid_limit_length($invoice->get_last_name(), 50),
236
+                        'address'      => getpaid_limit_length($invoice->get_address(), 60),
237
+                        'city'         => getpaid_limit_length($invoice->get_city(), 40),
238
+                        'state'        => getpaid_limit_length($invoice->get_state(), 40),
239
+                        'zip'          => getpaid_limit_length($invoice->get_zip(), 20),
240
+                        'country'      => getpaid_limit_length($invoice->get_country(), 60),
241 241
                     ),
242 242
 
243 243
                     // Payment information.
244 244
                     'payment'          => $payment_information
245 245
                 ),
246
-                'validationMode'       => $this->is_sandbox( $invoice ) ? 'testMode' : 'liveMode',
246
+                'validationMode'       => $this->is_sandbox($invoice) ? 'testMode' : 'liveMode',
247 247
             )
248 248
         );
249 249
 
250
-        $response = $this->post( apply_filters( 'getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice ), $invoice );
250
+        $response = $this->post(apply_filters('getpaid_authorizenet_create_customer_payment_profile_args', $args, $invoice), $invoice);
251 251
 
252
-        if ( is_wp_error( $response ) ) {
252
+        if (is_wp_error($response)) {
253 253
             return $response;
254 254
         }
255 255
 
256 256
         // Save the payment token.
257
-        if ( $save ) {
257
+        if ($save) {
258 258
             $this->save_token(
259 259
                 array(
260 260
                     'id'      => $response->customerPaymentProfileId,
261
-                    'name'    => getpaid_get_card_name( $submission_data['authorizenet']['cc_number'] ) . ' &middot;&middot;&middot;&middot; ' . substr( $submission_data['authorizenet']['cc_number'], -4 ),
261
+                    'name'    => getpaid_get_card_name($submission_data['authorizenet']['cc_number']) . ' &middot;&middot;&middot;&middot; ' . substr($submission_data['authorizenet']['cc_number'], -4),
262 262
                     'default' => true,
263
-                    'type'    => $this->is_sandbox( $invoice ) ? 'sandbox' : 'live',
263
+                    'type'    => $this->is_sandbox($invoice) ? 'sandbox' : 'live',
264 264
                 )
265 265
             );
266 266
         }
267 267
 
268 268
         // Cache payment profile id.
269
-        $this->add_payment_profile_to_cache( $payment_information, $response->customerPaymentProfileId );
269
+        $this->add_payment_profile_to_cache($payment_information, $response->customerPaymentProfileId);
270 270
 
271 271
         // Add a note about the validation response.
272 272
         $invoice->add_note(
273
-            sprintf( __( 'Saved Authorize.NET payment profile: %s', 'invoicing' ), $response->validationDirectResponse ),
273
+            sprintf(__('Saved Authorize.NET payment profile: %s', 'invoicing'), $response->validationDirectResponse),
274 274
             false,
275 275
             false,
276 276
             true
277 277
         );
278 278
 
279
-        update_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), $customer_profile );
279
+        update_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), $customer_profile);
280 280
 
281 281
         return $response->customerPaymentProfileId;
282 282
     }
@@ -288,12 +288,12 @@  discard block
 block discarded – undo
288 288
      * @param array $payment_details.
289 289
 	 * @return array|false Profile id.
290 290
 	 */
291
-	public function retrieve_payment_profile_from_cache( $payment_details, $customer_profile, $invoice ) {
291
+	public function retrieve_payment_profile_from_cache($payment_details, $customer_profile, $invoice) {
292 292
 
293
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
294
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
293
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
294
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
295 295
 
296
-        if ( ! is_array( $cached_information ) || ! array_key_exists( $payment_details, $cached_information ) ) {
296
+        if (!is_array($cached_information) || !array_key_exists($payment_details, $cached_information)) {
297 297
             return false;
298 298
         }
299 299
 
@@ -302,13 +302,13 @@  discard block
 block discarded – undo
302 302
             'getCustomerPaymentProfileRequest' => array(
303 303
                 'merchantAuthentication'   => $this->get_auth_params(),
304 304
                 'customerProfileId'        => $customer_profile,
305
-                'customerPaymentProfileId' => $cached_information[ $payment_details ],
305
+                'customerPaymentProfileId' => $cached_information[$payment_details],
306 306
             )
307 307
         );
308 308
 
309
-        $response = $this->post( $args, $invoice );
309
+        $response = $this->post($args, $invoice);
310 310
 
311
-        return is_wp_error( $response ) ? false : $cached_information[ $payment_details ];
311
+        return is_wp_error($response) ? false : $cached_information[$payment_details];
312 312
 
313 313
     }
314 314
 
@@ -319,14 +319,14 @@  discard block
 block discarded – undo
319 319
      * @param array $payment_details.
320 320
      * @param string $payment_profile_id.
321 321
 	 */
322
-	public function add_payment_profile_to_cache( $payment_details, $payment_profile_id ) {
322
+	public function add_payment_profile_to_cache($payment_details, $payment_profile_id) {
323 323
 
324
-        $cached_information = get_option( 'getpaid_authorize_net_cached_profiles', array() );
325
-        $cached_information = is_array( $cached_information ) ? $cached_information : array();
326
-        $payment_details    = hash_hmac( 'sha256', json_encode( $payment_details ), SECURE_AUTH_KEY );
324
+        $cached_information = get_option('getpaid_authorize_net_cached_profiles', array());
325
+        $cached_information = is_array($cached_information) ? $cached_information : array();
326
+        $payment_details    = hash_hmac('sha256', json_encode($payment_details), SECURE_AUTH_KEY);
327 327
 
328
-        $cached_information[ $payment_details ] = $payment_profile_id;
329
-        update_option( 'getpaid_authorize_net_cached_profiles', $cached_information );
328
+        $cached_information[$payment_details] = $payment_profile_id;
329
+        update_option('getpaid_authorize_net_cached_profiles', $cached_information);
330 330
 
331 331
     }
332 332
 
@@ -339,7 +339,7 @@  discard block
 block discarded – undo
339 339
 	 * @return string|WP_Error Profile id.
340 340
      * @link https://developer.authorize.net/api/reference/index.html#customer-profiles-get-customer-payment-profile
341 341
 	 */
342
-	public function get_customer_payment_profile( $customer_profile_id, $payment_profile_id ) {
342
+	public function get_customer_payment_profile($customer_profile_id, $payment_profile_id) {
343 343
 
344 344
         // Generate args.
345 345
         $args = array(
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             )
351 351
         );
352 352
 
353
-        return $this->post( $args, false );
353
+        return $this->post($args, false);
354 354
 
355 355
     }
356 356
 
@@ -363,7 +363,7 @@  discard block
 block discarded – undo
363 363
      * @link https://developer.authorize.net/api/reference/index.html#payment-transactions-charge-a-customer-profile
364 364
 	 * @return WP_Error|object
365 365
 	 */
366
-	public function charge_customer_payment_profile( $customer_profile_id, $payment_profile_id, $invoice ) {
366
+	public function charge_customer_payment_profile($customer_profile_id, $payment_profile_id, $invoice) {
367 367
 
368 368
         // Generate args.
369 369
         $args = array(
@@ -383,28 +383,28 @@  discard block
 block discarded – undo
383 383
                         )
384 384
                     ),
385 385
                     'order'                    => array(
386
-                        'invoiceNumber'        => getpaid_limit_length( $invoice->get_number(), 20 ),
386
+                        'invoiceNumber'        => getpaid_limit_length($invoice->get_number(), 20),
387 387
                     ),
388
-                    'lineItems'                => array( 'lineItem' => $this->get_line_items( $invoice ) ),
388
+                    'lineItems'                => array('lineItem' => $this->get_line_items($invoice)),
389 389
                     'tax'                      => array(
390 390
                         'amount'               => $invoice->get_total_tax(),
391
-                        'name'                 => __( 'TAX', 'invoicing' ),
391
+                        'name'                 => __('TAX', 'invoicing'),
392 392
                     ),
393
-                    'poNumber'                 => getpaid_limit_length( $invoice->get_number(), 25 ),
393
+                    'poNumber'                 => getpaid_limit_length($invoice->get_number(), 25),
394 394
                     'customer'                 => array(
395
-                        'id'                   => getpaid_limit_length( $invoice->get_user_id(), 25 ),
396
-                        'email'                => getpaid_limit_length( $invoice->get_email(), 25 ),
395
+                        'id'                   => getpaid_limit_length($invoice->get_user_id(), 25),
396
+                        'email'                => getpaid_limit_length($invoice->get_email(), 25),
397 397
                     ),
398 398
                     'customerIP'               => $invoice->get_ip(),
399 399
                 )
400 400
             )
401 401
         );
402 402
 
403
-        if ( 0 == $invoice->get_total_tax() ) {
404
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
403
+        if (0 == $invoice->get_total_tax()) {
404
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
405 405
         }
406 406
 
407
-        return $this->post( apply_filters( 'getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice ), $invoice );
407
+        return $this->post(apply_filters('getpaid_authorizenet_charge_customer_payment_profile_args', $args, $invoice), $invoice);
408 408
 
409 409
     }
410 410
 
@@ -414,29 +414,29 @@  discard block
 block discarded – undo
414 414
      * @param stdClass $result Api response.
415 415
 	 * @param WPInv_Invoice $invoice Invoice.
416 416
 	 */
417
-	public function process_charge_response( $result, $invoice ) {
417
+	public function process_charge_response($result, $invoice) {
418 418
 
419 419
         wpinv_clear_errors();
420 420
 		$response_code = (int) $result->transactionResponse->responseCode;
421 421
 
422 422
 		// Succeeded.
423
-		if ( 1 == $response_code || 4 == $response_code ) {
423
+		if (1 == $response_code || 4 == $response_code) {
424 424
 
425 425
 			// Maybe set a transaction id.
426
-			if ( ! empty( $result->transactionResponse->transId ) ) {
427
-				$invoice->set_transaction_id( $result->transactionResponse->transId );
426
+			if (!empty($result->transactionResponse->transId)) {
427
+				$invoice->set_transaction_id($result->transactionResponse->transId);
428 428
 			}
429 429
 
430
-			$invoice->add_note( sprintf( __( 'Authentication code: %s (%s).', 'invoicing' ), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber ), false, false, true );
430
+			$invoice->add_note(sprintf(__('Authentication code: %s (%s).', 'invoicing'), $result->transactionResponse->authCode, $result->transactionResponse->accountNumber), false, false, true);
431 431
 
432
-			if ( 1 == $response_code ) {
432
+			if (1 == $response_code) {
433 433
 				return $invoice->mark_paid();
434 434
 			}
435 435
 
436
-			$invoice->set_status( 'wpi-onhold' );
436
+			$invoice->set_status('wpi-onhold');
437 437
         	$invoice->add_note(
438 438
                 sprintf(
439
-                    __( 'Held for review: %s', 'invoicing' ),
439
+                    __('Held for review: %s', 'invoicing'),
440 440
                     $result->transactionResponse->messages->message[0]->description
441 441
                 )
442 442
 			);
@@ -445,11 +445,11 @@  discard block
 block discarded – undo
445 445
 
446 446
 		}
447 447
 
448
-        wpinv_set_error( 'card_declined', __( 'Credit card declined.', 'invoicing' ) );
448
+        wpinv_set_error('card_declined', __('Credit card declined.', 'invoicing'));
449 449
 
450
-        if ( ! empty( $result->transactionResponse->errors ) ) {
450
+        if (!empty($result->transactionResponse->errors)) {
451 451
             $errors = (object) $result->transactionResponse->errors;
452
-            wpinv_set_error( $errors->error[0]->errorCode, esc_html( $errors->error[0]->errorText ) );
452
+            wpinv_set_error($errors->error[0]->errorCode, esc_html($errors->error[0]->errorText));
453 453
         }
454 454
 
455 455
     }
@@ -461,10 +461,10 @@  discard block
 block discarded – undo
461 461
 	 * @param array $card Card details.
462 462
 	 * @return array
463 463
 	 */
464
-	public function get_payment_information( $card ) {
464
+	public function get_payment_information($card) {
465 465
         return array(
466 466
 
467
-            'creditCard'         => array (
467
+            'creditCard'         => array(
468 468
                 'cardNumber'     => $card['cc_number'],
469 469
                 'expirationDate' => $card['cc_expire_year'] . '-' . $card['cc_expire_month'],
470 470
                 'cardCode'       => $card['cc_cvv2'],
@@ -480,8 +480,8 @@  discard block
 block discarded – undo
480 480
 	 * @param WPInv_Invoice $invoice Invoice.
481 481
 	 * @return string
482 482
 	 */
483
-	public function get_customer_profile_meta_name( $invoice ) {
484
-        return $this->is_sandbox( $invoice ) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
483
+	public function get_customer_profile_meta_name($invoice) {
484
+        return $this->is_sandbox($invoice) ? 'getpaid_authorizenet_sandbox_customer_profile_id' : 'getpaid_authorizenet_customer_profile_id';
485 485
     }
486 486
 
487 487
     /**
@@ -492,34 +492,34 @@  discard block
 block discarded – undo
492 492
      * @param WPInv_Invoice $invoice
493 493
 	 * @return WP_Error|string The payment profile id
494 494
 	 */
495
-	public function validate_submission_data( $submission_data, $invoice ) {
495
+	public function validate_submission_data($submission_data, $invoice) {
496 496
 
497 497
         // Validate authentication details.
498 498
         $auth = $this->get_auth_params();
499 499
 
500
-        if ( empty( $auth['name'] ) || empty( $auth['transactionKey'] ) ) {
501
-            return new WP_Error( 'invalid_settings', __( 'Please set-up your login id and transaction key before using this gateway.', 'invoicing') );
500
+        if (empty($auth['name']) || empty($auth['transactionKey'])) {
501
+            return new WP_Error('invalid_settings', __('Please set-up your login id and transaction key before using this gateway.', 'invoicing'));
502 502
         }
503 503
 
504 504
         // Validate the payment method.
505
-        if ( empty( $submission_data['getpaid-authorizenet-payment-method'] ) ) {
506
-            return new WP_Error( 'invalid_payment_method', __( 'Please select a different payment method or add a new card.', 'invoicing') );
505
+        if (empty($submission_data['getpaid-authorizenet-payment-method'])) {
506
+            return new WP_Error('invalid_payment_method', __('Please select a different payment method or add a new card.', 'invoicing'));
507 507
         }
508 508
 
509 509
         // Are we adding a new payment method?
510
-        if ( 'new' != $submission_data['getpaid-authorizenet-payment-method'] ) {
510
+        if ('new' != $submission_data['getpaid-authorizenet-payment-method']) {
511 511
             return $submission_data['getpaid-authorizenet-payment-method'];
512 512
         }
513 513
 
514 514
         // Retrieve the customer profile id.
515
-        $profile_id = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
515
+        $profile_id = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
516 516
 
517 517
         // Create payment method.
518
-        if ( empty( $profile_id ) ) {
519
-            return $this->create_customer_profile( $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
518
+        if (empty($profile_id)) {
519
+            return $this->create_customer_profile($invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
520 520
         }
521 521
 
522
-        return $this->create_customer_payment_profile( $profile_id, $invoice, $submission_data, ! empty( $submission_data['getpaid-authorizenet-new-payment-method'] ) );
522
+        return $this->create_customer_payment_profile($profile_id, $invoice, $submission_data, !empty($submission_data['getpaid-authorizenet-new-payment-method']));
523 523
 
524 524
     }
525 525
 
@@ -530,32 +530,32 @@  discard block
 block discarded – undo
530 530
 	 * @param WPInv_Invoice $invoice Invoice.
531 531
 	 * @return array
532 532
 	 */
533
-	public function get_line_items( $invoice ) {
533
+	public function get_line_items($invoice) {
534 534
         $items = array();
535 535
 
536
-        foreach ( $invoice->get_items() as $item ) {
536
+        foreach ($invoice->get_items() as $item) {
537 537
 
538 538
             $amount  = $invoice->is_renewal() ? $item->get_price() : $item->get_initial_price();
539 539
             $items[] = array(
540
-                'itemId'      => getpaid_limit_length( $item->get_id(), 31 ),
541
-                'name'        => getpaid_limit_length( $item->get_raw_name(), 31 ),
542
-                'description' => getpaid_limit_length( $item->get_description(), 255 ),
543
-                'quantity'    => (string) ( $invoice->get_template() == 'amount' ? 1 : $item->get_quantity() ),
540
+                'itemId'      => getpaid_limit_length($item->get_id(), 31),
541
+                'name'        => getpaid_limit_length($item->get_raw_name(), 31),
542
+                'description' => getpaid_limit_length($item->get_description(), 255),
543
+                'quantity'    => (string) ($invoice->get_template() == 'amount' ? 1 : $item->get_quantity()),
544 544
                 'unitPrice'   => (float) $amount,
545 545
                 'taxable'     => wpinv_use_taxes() && $invoice->is_taxable() && 'tax-exempt' != $item->get_vat_rule(),
546 546
             );
547 547
 
548 548
         }
549 549
 
550
-        foreach ( $invoice->get_fees() as $fee_name => $fee ) {
550
+        foreach ($invoice->get_fees() as $fee_name => $fee) {
551 551
 
552
-            $amount  = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
552
+            $amount = $invoice->is_renewal() ? $fee['recurring_fee'] : $fee['initial_fee'];
553 553
 
554
-            if ( $amount > 0 ) {
554
+            if ($amount > 0) {
555 555
                 $items[] = array(
556
-                    'itemId'      => getpaid_limit_length( $fee_name, 31 ),
557
-                    'name'        => getpaid_limit_length( $fee_name, 31 ),
558
-                    'description' => getpaid_limit_length( $fee_name, 255 ),
556
+                    'itemId'      => getpaid_limit_length($fee_name, 31),
557
+                    'name'        => getpaid_limit_length($fee_name, 31),
558
+                    'description' => getpaid_limit_length($fee_name, 255),
559 559
                     'quantity'    => '1',
560 560
                     'unitPrice'   => (float) $amount,
561 561
                     'taxable'     => false,
@@ -576,36 +576,36 @@  discard block
 block discarded – undo
576 576
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
577 577
 	 * @return array
578 578
 	 */
579
-	public function process_payment( $invoice, $submission_data, $submission ) {
579
+	public function process_payment($invoice, $submission_data, $submission) {
580 580
 
581 581
         // Validate the submitted data.
582
-        $payment_profile_id = $this->validate_submission_data( $submission_data, $invoice );
582
+        $payment_profile_id = $this->validate_submission_data($submission_data, $invoice);
583 583
 
584 584
         // Do we have an error?
585
-        if ( is_wp_error( $payment_profile_id ) ) {
586
-            wpinv_set_error( $payment_profile_id->get_error_code(), $payment_profile_id->get_error_message() );
587
-            wpinv_send_back_to_checkout( $invoice );
585
+        if (is_wp_error($payment_profile_id)) {
586
+            wpinv_set_error($payment_profile_id->get_error_code(), $payment_profile_id->get_error_message());
587
+            wpinv_send_back_to_checkout($invoice);
588 588
         }
589 589
 
590 590
         // Save the payment method to the order.
591
-        update_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id );
591
+        update_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', $payment_profile_id);
592 592
 
593 593
         // Check if this is a subscription or not.
594
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
595
-        if ( ! empty( $subscriptions ) ) {
596
-            $this->process_subscription( $invoice, $subscriptions );
594
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
595
+        if (!empty($subscriptions)) {
596
+            $this->process_subscription($invoice, $subscriptions);
597 597
         }
598 598
 
599 599
         // If it is free, send to the success page.
600
-        if ( ! $invoice->needs_payment() ) {
600
+        if (!$invoice->needs_payment()) {
601 601
             $invoice->mark_paid();
602
-            wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
602
+            wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
603 603
         }
604 604
 
605 605
         // Charge the payment profile.
606
-        $this->process_initial_payment( $invoice );
606
+        $this->process_initial_payment($invoice);
607 607
 
608
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
608
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
609 609
 
610 610
         exit;
611 611
 
@@ -616,23 +616,23 @@  discard block
 block discarded – undo
616 616
 	 *
617 617
      * @param WPInv_Invoice $invoice Invoice.
618 618
 	 */
619
-	protected function process_initial_payment( $invoice ) {
619
+	protected function process_initial_payment($invoice) {
620 620
 
621
-		$payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
622
-        $customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
623
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
621
+		$payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
622
+        $customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
623
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
624 624
 
625 625
 		// Do we have an error?
626
-		if ( is_wp_error( $result ) ) {
627
-			wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
628
-			wpinv_send_back_to_checkout( $invoice );
626
+		if (is_wp_error($result)) {
627
+			wpinv_set_error($result->get_error_code(), $result->get_error_message());
628
+			wpinv_send_back_to_checkout($invoice);
629 629
 		}
630 630
 
631 631
 		// Process the response.
632
-		$this->process_charge_response( $result, $invoice );
632
+		$this->process_charge_response($result, $invoice);
633 633
 
634
-		if ( wpinv_get_errors() ) {
635
-			wpinv_send_back_to_checkout( $invoice );
634
+		if (wpinv_get_errors()) {
635
+			wpinv_send_back_to_checkout($invoice);
636 636
 		}
637 637
 
638 638
 	}
@@ -643,30 +643,30 @@  discard block
 block discarded – undo
643 643
      * @param WPInv_Invoice $invoice Invoice.
644 644
      * @param WPInv_Subscription[]|WPInv_Subscription $subscriptions Subscriptions.
645 645
 	 */
646
-	public function process_subscription( $invoice, $subscriptions ) {
646
+	public function process_subscription($invoice, $subscriptions) {
647 647
 
648 648
         // Check if there is an initial amount to charge.
649
-        if ( (float) $invoice->get_total() > 0 ) {
650
-			$this->process_initial_payment( $invoice );
649
+        if ((float) $invoice->get_total() > 0) {
650
+			$this->process_initial_payment($invoice);
651 651
         }
652 652
 
653 653
         // Activate the subscriptions.
654
-        $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
654
+        $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
655 655
 
656
-        foreach ( $subscriptions as $subscription ) {
657
-            if ( $subscription->exists() ) {
658
-                $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
659
-                $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
656
+        foreach ($subscriptions as $subscription) {
657
+            if ($subscription->exists()) {
658
+                $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
659
+                $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
660 660
 
661
-                $subscription->set_next_renewal_date( $expiry );
662
-                $subscription->set_date_created( current_time( 'mysql' ) );
663
-                $subscription->set_profile_id( $invoice->generate_key( 'authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) );
661
+                $subscription->set_next_renewal_date($expiry);
662
+                $subscription->set_date_created(current_time('mysql'));
663
+                $subscription->set_profile_id($invoice->generate_key('authnet_sub_' . $invoice->get_id() . '_' . $subscription->get_id()));
664 664
                 $subscription->activate();
665 665
             }
666 666
         }
667 667
 
668 668
 		// Redirect to the success page.
669
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
669
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
670 670
 
671 671
     }
672 672
 
@@ -677,20 +677,20 @@  discard block
 block discarded – undo
677 677
 	 * @param bool $should_expire
678 678
      * @param WPInv_Subscription $subscription
679 679
 	 */
680
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
680
+	public function maybe_renew_subscription($should_expire, $subscription) {
681 681
 
682 682
         // Ensure its our subscription && it's active.
683
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
683
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
684 684
             return $should_expire;
685 685
         }
686 686
 
687 687
         // If this is the last renewal, complete the subscription.
688
-        if ( $subscription->is_last_renewal() ) {
688
+        if ($subscription->is_last_renewal()) {
689 689
             $subscription->complete();
690 690
             return false;
691 691
         }
692 692
 
693
-        $this->renew_subscription( $subscription );
693
+        $this->renew_subscription($subscription);
694 694
 
695 695
         return false;
696 696
 
@@ -701,28 +701,28 @@  discard block
 block discarded – undo
701 701
 	 *
702 702
      * @param WPInv_Subscription $subscription
703 703
 	 */
704
-	public function renew_subscription( $subscription ) {
704
+	public function renew_subscription($subscription) {
705 705
 
706 706
 		// Generate the renewal invoice.
707 707
 		$new_invoice = $subscription->create_payment();
708 708
 		$old_invoice = $subscription->get_parent_payment();
709 709
 
710
-        if ( empty( $new_invoice ) ) {
711
-            $old_invoice->add_note( __( 'Error generating a renewal invoice.', 'invoicing' ), false, false, false );
710
+        if (empty($new_invoice)) {
711
+            $old_invoice->add_note(__('Error generating a renewal invoice.', 'invoicing'), false, false, false);
712 712
             $subscription->failing();
713 713
             return;
714 714
         }
715 715
 
716 716
         // Charge the payment method.
717
-		$payment_profile_id = get_post_meta( $old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
718
-		$customer_profile   = get_user_meta( $old_invoice->get_user_id(), $this->get_customer_profile_meta_name( $old_invoice ), true );
719
-		$result             = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $new_invoice );
717
+		$payment_profile_id = get_post_meta($old_invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
718
+		$customer_profile   = get_user_meta($old_invoice->get_user_id(), $this->get_customer_profile_meta_name($old_invoice), true);
719
+		$result             = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $new_invoice);
720 720
 
721 721
 		// Do we have an error?
722
-		if ( is_wp_error( $result ) ) {
722
+		if (is_wp_error($result)) {
723 723
 
724 724
 			$old_invoice->add_note(
725
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), $result->get_error_message() ),
725
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), $result->get_error_message()),
726 726
 				true,
727 727
 				false,
728 728
 				true
@@ -733,12 +733,12 @@  discard block
 block discarded – undo
733 733
 		}
734 734
 
735 735
 		// Process the response.
736
-		$this->process_charge_response( $result, $new_invoice );
736
+		$this->process_charge_response($result, $new_invoice);
737 737
 
738
-		if ( wpinv_get_errors() ) {
738
+		if (wpinv_get_errors()) {
739 739
 
740 740
 			$old_invoice->add_note(
741
-				sprintf( __( 'Error renewing subscription : ( %s ).', 'invoicing' ), getpaid_get_errors_html() ),
741
+				sprintf(__('Error renewing subscription : ( %s ).', 'invoicing'), getpaid_get_errors_html()),
742 742
 				true,
743 743
 				false,
744 744
 				true
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 
749 749
         }
750 750
 
751
-        $subscription->add_payment( array(), $new_invoice );
751
+        $subscription->add_payment(array(), $new_invoice);
752 752
         $subscription->renew();
753 753
     }
754 754
 
@@ -759,34 +759,34 @@  discard block
 block discarded – undo
759 759
 	 * @param GetPaid_Form_Item[] $items
760 760
 	 * @return WPInv_Invoice
761 761
 	 */
762
-	public function process_addons( $invoice, $items ) {
762
+	public function process_addons($invoice, $items) {
763 763
 
764 764
         global $getpaid_authorize_addons;
765 765
 
766 766
         $getpaid_authorize_addons = array();
767
-        foreach ( $items as $item ) {
767
+        foreach ($items as $item) {
768 768
 
769
-            if ( is_null( $invoice->get_item( $item->get_id() ) ) && ! is_wp_error( $invoice->add_item( $item ) ) ) {
769
+            if (is_null($invoice->get_item($item->get_id())) && !is_wp_error($invoice->add_item($item))) {
770 770
                 $getpaid_authorize_addons[] = $item;
771 771
             }
772 772
 
773 773
         }
774 774
 
775
-        if ( empty( $getpaid_authorize_addons ) ) {
775
+        if (empty($getpaid_authorize_addons)) {
776 776
             return;
777 777
         }
778 778
 
779 779
         $invoice->recalculate_total();
780 780
 
781
-        $payment_profile_id = get_post_meta( $invoice->get_id(), 'getpaid_authorizenet_profile_id', true );
782
-		$customer_profile   = get_user_meta( $invoice->get_user_id(), $this->get_customer_profile_meta_name( $invoice ), true );
781
+        $payment_profile_id = get_post_meta($invoice->get_id(), 'getpaid_authorizenet_profile_id', true);
782
+		$customer_profile = get_user_meta($invoice->get_user_id(), $this->get_customer_profile_meta_name($invoice), true);
783 783
 
784
-        add_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ), 10, 2 );
785
-        $result = $this->charge_customer_payment_profile( $customer_profile, $payment_profile_id, $invoice );
786
-        remove_filter( 'getpaid_authorizenet_charge_customer_payment_profile_args', array( $this, 'filter_addons_request' ) );
784
+        add_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'), 10, 2);
785
+        $result = $this->charge_customer_payment_profile($customer_profile, $payment_profile_id, $invoice);
786
+        remove_filter('getpaid_authorizenet_charge_customer_payment_profile_args', array($this, 'filter_addons_request'));
787 787
 
788
-        if ( is_wp_error( $result ) ) {
789
-            wpinv_set_error( $result->get_error_code(), $result->get_error_message() );
788
+        if (is_wp_error($result)) {
789
+            wpinv_set_error($result->get_error_code(), $result->get_error_message());
790 790
             return;
791 791
         }
792 792
 
@@ -799,19 +799,19 @@  discard block
 block discarded – undo
799 799
      * @param array $args
800 800
 	 * @return array
801 801
 	 */
802
-    public function filter_addons_request( $args ) {
802
+    public function filter_addons_request($args) {
803 803
 
804 804
         global $getpaid_authorize_addons;
805 805
         $total = 0;
806 806
 
807
-        foreach ( $getpaid_authorize_addons as $addon ) {
807
+        foreach ($getpaid_authorize_addons as $addon) {
808 808
             $total += $addon->get_sub_total();
809 809
         }
810 810
 
811 811
         $args['createTransactionRequest']['transactionRequest']['amount'] = $total;
812 812
 
813
-        if ( isset( $args['createTransactionRequest']['transactionRequest']['tax'] ) ) {
814
-            unset( $args['createTransactionRequest']['transactionRequest']['tax'] );
813
+        if (isset($args['createTransactionRequest']['transactionRequest']['tax'])) {
814
+            unset($args['createTransactionRequest']['transactionRequest']['tax']);
815 815
         }
816 816
 
817 817
         return $args;
@@ -824,7 +824,7 @@  discard block
 block discarded – undo
824 824
     public function sandbox_notice() {
825 825
 
826 826
         return sprintf(
827
-            __( 'SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing' ),
827
+            __('SANDBOX ENABLED. You can use sandbox testing details only. See the %sAuthorize.NET Sandbox Testing Guide%s for more details.', 'invoicing'),
828 828
             '<a href="https://developer.authorize.net/hello_world/testing_guide.html">',
829 829
             '</a>'
830 830
         );
@@ -836,42 +836,42 @@  discard block
 block discarded – undo
836 836
 	 *
837 837
 	 * @param array $admin_settings
838 838
 	 */
839
-	public function admin_settings( $admin_settings ) {
839
+	public function admin_settings($admin_settings) {
840 840
 
841 841
         $currencies = sprintf(
842
-            __( 'Supported Currencies: %s', 'invoicing' ),
843
-            implode( ', ', $this->currencies )
842
+            __('Supported Currencies: %s', 'invoicing'),
843
+            implode(', ', $this->currencies)
844 844
         );
845 845
 
846 846
         $admin_settings['authorizenet_active']['desc'] .= " ($currencies)";
847
-        $admin_settings['authorizenet_desc']['std']     = __( 'Pay securely using your credit or debit card.', 'invoicing' );
847
+        $admin_settings['authorizenet_desc']['std']     = __('Pay securely using your credit or debit card.', 'invoicing');
848 848
 
849 849
         $admin_settings['authorizenet_login_id'] = array(
850 850
             'type' => 'text',
851 851
             'id'   => 'authorizenet_login_id',
852
-            'name' => __( 'API Login ID', 'invoicing' ),
853
-            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __( 'How do I obtain my API Login ID and Transaction Key?', 'invoicing' ) . '</em></a>',
852
+            'name' => __('API Login ID', 'invoicing'),
853
+            'desc' => '<a href="https://support.authorize.net/s/article/How-do-I-obtain-my-API-Login-ID-and-Transaction-Key"><em>' . __('How do I obtain my API Login ID and Transaction Key?', 'invoicing') . '</em></a>',
854 854
         );
855 855
 
856 856
         $admin_settings['authorizenet_transaction_key'] = array(
857 857
             'type' => 'text',
858 858
             'id'   => 'authorizenet_transaction_key',
859
-            'name' => __( 'Transaction Key', 'invoicing' ),
859
+            'name' => __('Transaction Key', 'invoicing'),
860 860
         );
861 861
 
862 862
         $admin_settings['authorizenet_signature_key'] = array(
863 863
             'type' => 'text',
864 864
             'id'   => 'authorizenet_signature_key',
865
-            'name' => __( 'Signature Key', 'invoicing' ),
866
-            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
865
+            'name' => __('Signature Key', 'invoicing'),
866
+            'desc' => '<a href="https://support.authorize.net/s/article/What-is-a-Signature-Key"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
867 867
         );
868 868
 
869 869
         $admin_settings['authorizenet_ipn_url'] = array(
870 870
             'type'     => 'ipn_url',
871 871
             'id'       => 'authorizenet_ipn_url',
872
-            'name'     => __( 'Webhook URL', 'invoicing' ),
872
+            'name'     => __('Webhook URL', 'invoicing'),
873 873
             'std'      => $this->notify_url,
874
-            'desc'     => __( 'Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing' ) . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __( 'Learn more.', 'invoicing' ) . '</em></a>',
874
+            'desc'     => __('Create a new webhook using this URL as the endpoint URL and set it to receive all payment events.', 'invoicing') . ' <a href="https://support.authorize.net/s/article/How-do-I-add-edit-Webhook-notification-end-points"><em>' . __('Learn more.', 'invoicing') . '</em></a>',
875 875
             'custom'   => 'authorizenet',
876 876
             'readonly' => true,
877 877
         );
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-manual-gateway.php 2 patches
Indentation   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -13,30 +13,30 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Manual_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'manual';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
34
-	public $order = 11;
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34
+    public $order = 11;
35 35
 
36 36
     /**
37
-	 * Class constructor.
38
-	 */
39
-	public function __construct() {
37
+     * Class constructor.
38
+     */
39
+    public function __construct() {
40 40
         parent::__construct();
41 41
 
42 42
         $this->title        = __( 'Test Gateway', 'invoicing' );
@@ -46,15 +46,15 @@  discard block
 block discarded – undo
46 46
     }
47 47
 
48 48
     /**
49
-	 * Process Payment.
50
-	 *
51
-	 *
52
-	 * @param WPInv_Invoice $invoice Invoice.
53
-	 * @param array $submission_data Posted checkout fields.
54
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
-	 * @return array
56
-	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
49
+     * Process Payment.
50
+     *
51
+     *
52
+     * @param WPInv_Invoice $invoice Invoice.
53
+     * @param array $submission_data Posted checkout fields.
54
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55
+     * @return array
56
+     */
57
+    public function process_payment( $invoice, $submission_data, $submission ) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
@@ -85,13 +85,13 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     /**
88
-	 * (Maybe) renews a manual subscription profile.
89
-	 *
90
-	 *
91
-	 * @param bool $should_expire
88
+     * (Maybe) renews a manual subscription profile.
89
+     *
90
+     *
91
+     * @param bool $should_expire
92 92
      * @param WPInv_Subscription $subscription
93
-	 */
94
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
93
+     */
94
+    public function maybe_renew_subscription( $should_expire, $subscription ) {
95 95
 
96 96
         // Ensure its our subscription && it's active.
97 97
         if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
@@ -119,13 +119,13 @@  discard block
 block discarded – undo
119 119
     }
120 120
 
121 121
     /**
122
-	 * Processes invoice addons.
123
-	 *
124
-	 * @param WPInv_Invoice $invoice
125
-	 * @param GetPaid_Form_Item[] $items
126
-	 * @return WPInv_Invoice
127
-	 */
128
-	public function process_addons( $invoice, $items ) {
122
+     * Processes invoice addons.
123
+     *
124
+     * @param WPInv_Invoice $invoice
125
+     * @param GetPaid_Form_Item[] $items
126
+     * @return WPInv_Invoice
127
+     */
128
+    public function process_addons( $invoice, $items ) {
129 129
 
130 130
         foreach ( $items as $item ) {
131 131
             $invoice->add_item( $item );
Please login to merge, or discard this patch.
Spacing   +23 added lines, -23 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
  * Manual Payment Gateway class.
@@ -24,7 +24,7 @@  discard block
 block discarded – undo
24 24
 	 *
25 25
 	 * @var array
26 26
 	 */
27
-    protected $supports = array( 'subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups' );
27
+    protected $supports = array('subscription', 'addons', 'single_subscription_group', 'multiple_subscription_groups');
28 28
 
29 29
     /**
30 30
 	 * Payment method order.
@@ -39,10 +39,10 @@  discard block
 block discarded – undo
39 39
 	public function __construct() {
40 40
         parent::__construct();
41 41
 
42
-        $this->title        = __( 'Test Gateway', 'invoicing' );
43
-        $this->method_title = __( 'Test Gateway', 'invoicing' );
42
+        $this->title        = __('Test Gateway', 'invoicing');
43
+        $this->method_title = __('Test Gateway', 'invoicing');
44 44
 
45
-        add_filter( 'getpaid_daily_maintenance_should_expire_subscription', array( $this, 'maybe_renew_subscription' ), 10, 2 );
45
+        add_filter('getpaid_daily_maintenance_should_expire_subscription', array($this, 'maybe_renew_subscription'), 10, 2);
46 46
     }
47 47
 
48 48
     /**
@@ -54,25 +54,25 @@  discard block
 block discarded – undo
54 54
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
55 55
 	 * @return array
56 56
 	 */
57
-	public function process_payment( $invoice, $submission_data, $submission ) {
57
+	public function process_payment($invoice, $submission_data, $submission) {
58 58
 
59 59
         // Mark it as paid.
60 60
         $invoice->mark_paid();
61 61
 
62 62
         // (Maybe) activate subscriptions.
63
-        $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
63
+        $subscriptions = getpaid_get_invoice_subscriptions($invoice);
64 64
 
65
-        if ( ! empty( $subscriptions ) ) {
66
-            $subscriptions = is_array( $subscriptions ) ? $subscriptions : array( $subscriptions );
65
+        if (!empty($subscriptions)) {
66
+            $subscriptions = is_array($subscriptions) ? $subscriptions : array($subscriptions);
67 67
 
68
-            foreach ( $subscriptions as $subscription ) {
69
-                if ( $subscription->exists() ) {
70
-                    $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
71
-                    $expiry   = date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) );
68
+            foreach ($subscriptions as $subscription) {
69
+                if ($subscription->exists()) {
70
+                    $duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
71
+                    $expiry   = date('Y-m-d H:i:s', (current_time('timestamp') + $duration));
72 72
 
73
-                    $subscription->set_next_renewal_date( $expiry );
74
-                    $subscription->set_date_created( current_time( 'mysql' ) );
75
-                    $subscription->set_profile_id( $invoice->generate_key( 'manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id() ) );
73
+                    $subscription->set_next_renewal_date($expiry);
74
+                    $subscription->set_date_created(current_time('mysql'));
75
+                    $subscription->set_profile_id($invoice->generate_key('manual_sub_' . $invoice->get_id() . '_' . $subscription->get_id()));
76 76
                     $subscription->activate();
77 77
                 }
78 78
             }
@@ -80,7 +80,7 @@  discard block
 block discarded – undo
80 80
         }
81 81
 
82 82
         // Send to the success page.
83
-        wpinv_send_to_success_page( array( 'invoice_key' => $invoice->get_key() ) );
83
+        wpinv_send_to_success_page(array('invoice_key' => $invoice->get_key()));
84 84
 
85 85
     }
86 86
 
@@ -91,15 +91,15 @@  discard block
 block discarded – undo
91 91
 	 * @param bool $should_expire
92 92
      * @param WPInv_Subscription $subscription
93 93
 	 */
94
-	public function maybe_renew_subscription( $should_expire, $subscription ) {
94
+	public function maybe_renew_subscription($should_expire, $subscription) {
95 95
 
96 96
         // Ensure its our subscription && it's active.
97
-        if ( $this->id != $subscription->get_gateway() || ! $subscription->has_status( 'active trialling' ) ) {
97
+        if ($this->id != $subscription->get_gateway() || !$subscription->has_status('active trialling')) {
98 98
             return $should_expire;
99 99
         }
100 100
 
101 101
         // If this is the last renewal, complete the subscription.
102
-        if ( $subscription->is_last_renewal() ) {
102
+        if ($subscription->is_last_renewal()) {
103 103
             $subscription->complete();
104 104
             return false;
105 105
         }
@@ -125,10 +125,10 @@  discard block
 block discarded – undo
125 125
 	 * @param GetPaid_Form_Item[] $items
126 126
 	 * @return WPInv_Invoice
127 127
 	 */
128
-	public function process_addons( $invoice, $items ) {
128
+	public function process_addons($invoice, $items) {
129 129
 
130
-        foreach ( $items as $item ) {
131
-            $invoice->add_item( $item );
130
+        foreach ($items as $item) {
131
+            $invoice->add_item($item);
132 132
         }
133 133
 
134 134
         $invoice->recalculate_total();
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 2 patches
Indentation   +732 added lines, -732 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 class WPInv_Item  extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'item';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'item';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'item';
25 25
 
26 26
     /**
27
-	 * Item Data array. This is the core item data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'parent_id'            => 0,
34
-		'status'               => 'draft',
35
-		'version'              => '',
36
-		'date_created'         => null,
27
+     * Item Data array. This is the core item data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'parent_id'            => 0,
34
+        'status'               => 'draft',
35
+        'version'              => '',
36
+        'date_created'         => null,
37 37
         'date_modified'        => null,
38 38
         'name'                 => '',
39 39
         'description'          => '',
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     );
59 59
 
60 60
     /**
61
-	 * Stores meta in cache for future reads.
62
-	 *
63
-	 * A group must be set to to enable caching.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	protected $cache_group = 'getpaid_items';
61
+     * Stores meta in cache for future reads.
62
+     *
63
+     * A group must be set to to enable caching.
64
+     *
65
+     * @var string
66
+     */
67
+    protected $cache_group = 'getpaid_items';
68 68
 
69 69
     /**
70 70
      * Stores a reference to the original WP_Post object
@@ -74,37 +74,37 @@  discard block
 block discarded – undo
74 74
     protected $post = null;
75 75
 
76 76
     /**
77
-	 * Get the item if ID is passed, otherwise the item is new and empty.
78
-	 *
79
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
-	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
94
-		} else {
95
-			$this->set_object_read( true );
96
-		}
77
+     * Get the item if ID is passed, otherwise the item is new and empty.
78
+     *
79
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
+     */
81
+    public function __construct( $item = 0 ) {
82
+        parent::__construct( $item );
83
+
84
+        if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
+            $this->set_id( $item );
86
+        } elseif ( $item instanceof self ) {
87
+            $this->set_id( $item->get_id() );
88
+        } elseif ( ! empty( $item->ID ) ) {
89
+            $this->set_id( $item->ID );
90
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
+            $this->set_id( $item_id );
92
+        } elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
+            $this->set_id( $item_id );
94
+        } else {
95
+            $this->set_object_read( true );
96
+        }
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
100 100
 
101
-		if ( $this->get_id() > 0 ) {
101
+        if ( $this->get_id() > 0 ) {
102 102
             $this->post = get_post( $this->get_id() );
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+            $this->data_store->read( $this );
105 105
         }
106 106
 
107
-	}
107
+    }
108 108
 
109 109
     /*
110 110
 	|--------------------------------------------------------------------------
@@ -122,401 +122,401 @@  discard block
 block discarded – undo
122 122
     */
123 123
 
124 124
     /**
125
-	 * Get parent item ID.
126
-	 *
127
-	 * @since 1.0.19
128
-	 * @param  string $context View or edit context.
129
-	 * @return int
130
-	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
125
+     * Get parent item ID.
126
+     *
127
+     * @since 1.0.19
128
+     * @param  string $context View or edit context.
129
+     * @return int
130
+     */
131
+    public function get_parent_id( $context = 'view' ) {
132
+        return (int) $this->get_prop( 'parent_id', $context );
133 133
     }
134 134
 
135 135
     /**
136
-	 * Get item status.
137
-	 *
138
-	 * @since 1.0.19
139
-	 * @param  string $context View or edit context.
140
-	 * @return string
141
-	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
136
+     * Get item status.
137
+     *
138
+     * @since 1.0.19
139
+     * @param  string $context View or edit context.
140
+     * @return string
141
+     */
142
+    public function get_status( $context = 'view' ) {
143
+        return $this->get_prop( 'status', $context );
144 144
     }
145 145
 
146 146
     /**
147
-	 * Get plugin version when the item was created.
148
-	 *
149
-	 * @since 1.0.19
150
-	 * @param  string $context View or edit context.
151
-	 * @return string
152
-	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
147
+     * Get plugin version when the item was created.
148
+     *
149
+     * @since 1.0.19
150
+     * @param  string $context View or edit context.
151
+     * @return string
152
+     */
153
+    public function get_version( $context = 'view' ) {
154
+        return $this->get_prop( 'version', $context );
155 155
     }
156 156
 
157 157
     /**
158
-	 * Get date when the item was created.
159
-	 *
160
-	 * @since 1.0.19
161
-	 * @param  string $context View or edit context.
162
-	 * @return string
163
-	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
158
+     * Get date when the item was created.
159
+     *
160
+     * @since 1.0.19
161
+     * @param  string $context View or edit context.
162
+     * @return string
163
+     */
164
+    public function get_date_created( $context = 'view' ) {
165
+        return $this->get_prop( 'date_created', $context );
166 166
     }
167 167
 
168 168
     /**
169
-	 * Get GMT date when the item was created.
170
-	 *
171
-	 * @since 1.0.19
172
-	 * @param  string $context View or edit context.
173
-	 * @return string
174
-	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
169
+     * Get GMT date when the item was created.
170
+     *
171
+     * @since 1.0.19
172
+     * @param  string $context View or edit context.
173
+     * @return string
174
+     */
175
+    public function get_date_created_gmt( $context = 'view' ) {
176 176
         $date = $this->get_date_created( $context );
177 177
 
178 178
         if ( $date ) {
179 179
             $date = get_gmt_from_date( $date );
180 180
         }
181
-		return $date;
181
+        return $date;
182 182
     }
183 183
 
184 184
     /**
185
-	 * Get date when the item was last modified.
186
-	 *
187
-	 * @since 1.0.19
188
-	 * @param  string $context View or edit context.
189
-	 * @return string
190
-	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
185
+     * Get date when the item was last modified.
186
+     *
187
+     * @since 1.0.19
188
+     * @param  string $context View or edit context.
189
+     * @return string
190
+     */
191
+    public function get_date_modified( $context = 'view' ) {
192
+        return $this->get_prop( 'date_modified', $context );
193 193
     }
194 194
 
195 195
     /**
196
-	 * Get GMT date when the item was last modified.
197
-	 *
198
-	 * @since 1.0.19
199
-	 * @param  string $context View or edit context.
200
-	 * @return string
201
-	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
196
+     * Get GMT date when the item was last modified.
197
+     *
198
+     * @since 1.0.19
199
+     * @param  string $context View or edit context.
200
+     * @return string
201
+     */
202
+    public function get_date_modified_gmt( $context = 'view' ) {
203 203
         $date = $this->get_date_modified( $context );
204 204
 
205 205
         if ( $date ) {
206 206
             $date = get_gmt_from_date( $date );
207 207
         }
208
-		return $date;
208
+        return $date;
209 209
     }
210 210
 
211 211
     /**
212
-	 * Get the item name.
213
-	 *
214
-	 * @since 1.0.19
215
-	 * @param  string $context View or edit context.
216
-	 * @return string
217
-	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
212
+     * Get the item name.
213
+     *
214
+     * @since 1.0.19
215
+     * @param  string $context View or edit context.
216
+     * @return string
217
+     */
218
+    public function get_name( $context = 'view' ) {
219
+        return $this->get_prop( 'name', $context );
220 220
     }
221 221
 
222 222
     /**
223
-	 * Alias of self::get_name().
224
-	 *
225
-	 * @since 1.0.19
226
-	 * @param  string $context View or edit context.
227
-	 * @return string
228
-	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
223
+     * Alias of self::get_name().
224
+     *
225
+     * @since 1.0.19
226
+     * @param  string $context View or edit context.
227
+     * @return string
228
+     */
229
+    public function get_title( $context = 'view' ) {
230
+        return $this->get_name( $context );
231 231
     }
232 232
 
233 233
     /**
234
-	 * Get the item description.
235
-	 *
236
-	 * @since 1.0.19
237
-	 * @param  string $context View or edit context.
238
-	 * @return string
239
-	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
234
+     * Get the item description.
235
+     *
236
+     * @since 1.0.19
237
+     * @param  string $context View or edit context.
238
+     * @return string
239
+     */
240
+    public function get_description( $context = 'view' ) {
241
+        return $this->get_prop( 'description', $context );
242 242
     }
243 243
 
244 244
     /**
245
-	 * Alias of self::get_description().
246
-	 *
247
-	 * @since 1.0.19
248
-	 * @param  string $context View or edit context.
249
-	 * @return string
250
-	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
245
+     * Alias of self::get_description().
246
+     *
247
+     * @since 1.0.19
248
+     * @param  string $context View or edit context.
249
+     * @return string
250
+     */
251
+    public function get_excerpt( $context = 'view' ) {
252
+        return $this->get_description( $context );
253 253
     }
254 254
 
255 255
     /**
256
-	 * Alias of self::get_description().
257
-	 *
258
-	 * @since 1.0.19
259
-	 * @param  string $context View or edit context.
260
-	 * @return string
261
-	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
256
+     * Alias of self::get_description().
257
+     *
258
+     * @since 1.0.19
259
+     * @param  string $context View or edit context.
260
+     * @return string
261
+     */
262
+    public function get_summary( $context = 'view' ) {
263
+        return $this->get_description( $context );
264 264
     }
265 265
 
266 266
     /**
267
-	 * Get the owner of the item.
268
-	 *
269
-	 * @since 1.0.19
270
-	 * @param  string $context View or edit context.
271
-	 * @return int
272
-	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
275
-	}
267
+     * Get the owner of the item.
268
+     *
269
+     * @since 1.0.19
270
+     * @param  string $context View or edit context.
271
+     * @return int
272
+     */
273
+    public function get_author( $context = 'view' ) {
274
+        return (int) $this->get_prop( 'author', $context );
275
+    }
276 276
 	
277
-	/**
278
-	 * Alias of self::get_author().
279
-	 *
280
-	 * @since 1.0.19
281
-	 * @param  string $context View or edit context.
282
-	 * @return int
283
-	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
286
-    }
287
-
288
-    /**
289
-	 * Get the price of the item.
290
-	 *
291
-	 * @since 1.0.19
292
-	 * @param  string $context View or edit context.
293
-	 * @return float
294
-	 */
295
-	public function get_price( $context = 'view' ) {
277
+    /**
278
+     * Alias of self::get_author().
279
+     *
280
+     * @since 1.0.19
281
+     * @param  string $context View or edit context.
282
+     * @return int
283
+     */
284
+    public function get_owner( $context = 'view' ) {
285
+        return $this->get_author( $context );
286
+    }
287
+
288
+    /**
289
+     * Get the price of the item.
290
+     *
291
+     * @since 1.0.19
292
+     * @param  string $context View or edit context.
293
+     * @return float
294
+     */
295
+    public function get_price( $context = 'view' ) {
296 296
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
297
-	}
297
+    }
298 298
 	
299
-	/**
300
-	 * Get the inital price of the item.
301
-	 *
302
-	 * @since 1.0.19
303
-	 * @param  string $context View or edit context.
304
-	 * @return float
305
-	 */
306
-	public function get_initial_price( $context = 'view' ) {
299
+    /**
300
+     * Get the inital price of the item.
301
+     *
302
+     * @since 1.0.19
303
+     * @param  string $context View or edit context.
304
+     * @return float
305
+     */
306
+    public function get_initial_price( $context = 'view' ) {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+        $price = (float) $this->get_price( $context );
309 309
 
310
-		if ( $this->has_free_trial() ) {
311
-			$price = 0;
312
-		}
310
+        if ( $this->has_free_trial() ) {
311
+            $price = 0;
312
+        }
313 313
 
314 314
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
315 315
     }
316 316
 
317 317
     /**
318
-	 * Returns a formated price.
319
-	 *
320
-	 * @since 1.0.19
321
-	 * @param  string $context View or edit context.
322
-	 * @return string
323
-	 */
318
+     * Returns a formated price.
319
+     *
320
+     * @since 1.0.19
321
+     * @param  string $context View or edit context.
322
+     * @return string
323
+     */
324 324
     public function get_the_price() {
325 325
         return wpinv_price( $this->get_price() );
326
-	}
327
-
328
-	/**
329
-	 * Returns the formated initial price.
330
-	 *
331
-	 * @since 1.0.19
332
-	 * @param  string $context View or edit context.
333
-	 * @return string
334
-	 */
326
+    }
327
+
328
+    /**
329
+     * Returns the formated initial price.
330
+     *
331
+     * @since 1.0.19
332
+     * @param  string $context View or edit context.
333
+     * @return string
334
+     */
335 335
     public function get_the_initial_price() {
336 336
         return wpinv_price( $this->get_initial_price() );
337 337
     }
338 338
 
339 339
     /**
340
-	 * Get the VAT rule of the item.
341
-	 *
342
-	 * @since 1.0.19
343
-	 * @param  string $context View or edit context.
344
-	 * @return string
345
-	 */
346
-	public function get_vat_rule( $context = 'view' ) {
340
+     * Get the VAT rule of the item.
341
+     *
342
+     * @since 1.0.19
343
+     * @param  string $context View or edit context.
344
+     * @return string
345
+     */
346
+    public function get_vat_rule( $context = 'view' ) {
347 347
         return $this->get_prop( 'vat_rule', $context );
348 348
     }
349 349
 
350 350
     /**
351
-	 * Get the VAT class of the item.
352
-	 *
353
-	 * @since 1.0.19
354
-	 * @param  string $context View or edit context.
355
-	 * @return string
356
-	 */
357
-	public function get_vat_class( $context = 'view' ) {
351
+     * Get the VAT class of the item.
352
+     *
353
+     * @since 1.0.19
354
+     * @param  string $context View or edit context.
355
+     * @return string
356
+     */
357
+    public function get_vat_class( $context = 'view' ) {
358 358
         return $this->get_prop( 'vat_class', $context );
359 359
     }
360 360
 
361 361
     /**
362
-	 * Get the type of the item.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @param  string $context View or edit context.
366
-	 * @return string
367
-	 */
368
-	public function get_type( $context = 'view' ) {
362
+     * Get the type of the item.
363
+     *
364
+     * @since 1.0.19
365
+     * @param  string $context View or edit context.
366
+     * @return string
367
+     */
368
+    public function get_type( $context = 'view' ) {
369 369
         return $this->get_prop( 'type', $context );
370 370
     }
371 371
 
372 372
     /**
373
-	 * Get the custom id of the item.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $context View or edit context.
377
-	 * @return string
378
-	 */
379
-	public function get_custom_id( $context = 'view' ) {
373
+     * Get the custom id of the item.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $context View or edit context.
377
+     * @return string
378
+     */
379
+    public function get_custom_id( $context = 'view' ) {
380 380
         return $this->get_prop( 'custom_id', $context );
381 381
     }
382 382
 
383 383
     /**
384
-	 * Get the custom name of the item.
385
-	 *
386
-	 * @since 1.0.19
387
-	 * @param  string $context View or edit context.
388
-	 * @return string
389
-	 */
390
-	public function get_custom_name( $context = 'view' ) {
384
+     * Get the custom name of the item.
385
+     *
386
+     * @since 1.0.19
387
+     * @param  string $context View or edit context.
388
+     * @return string
389
+     */
390
+    public function get_custom_name( $context = 'view' ) {
391 391
         return $this->get_prop( 'custom_name', $context );
392 392
     }
393 393
 
394 394
     /**
395
-	 * Get the custom singular name of the item.
396
-	 *
397
-	 * @since 1.0.19
398
-	 * @param  string $context View or edit context.
399
-	 * @return string
400
-	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
395
+     * Get the custom singular name of the item.
396
+     *
397
+     * @since 1.0.19
398
+     * @param  string $context View or edit context.
399
+     * @return string
400
+     */
401
+    public function get_custom_singular_name( $context = 'view' ) {
402 402
         return $this->get_prop( 'custom_singular_name', $context );
403 403
     }
404 404
 
405 405
     /**
406
-	 * Checks if an item is editable..
407
-	 *
408
-	 * @since 1.0.19
409
-	 * @param  string $context View or edit context.
410
-	 * @return int
411
-	 */
412
-	public function get_is_editable( $context = 'view' ) {
406
+     * Checks if an item is editable..
407
+     *
408
+     * @since 1.0.19
409
+     * @param  string $context View or edit context.
410
+     * @return int
411
+     */
412
+    public function get_is_editable( $context = 'view' ) {
413 413
         return (int) $this->get_prop( 'is_editable', $context );
414 414
     }
415 415
 
416 416
     /**
417
-	 * Alias of self::get_is_editable().
418
-	 *
419
-	 * @since 1.0.19
420
-	 * @param  string $context View or edit context.
421
-	 * @return int
422
-	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
417
+     * Alias of self::get_is_editable().
418
+     *
419
+     * @since 1.0.19
420
+     * @param  string $context View or edit context.
421
+     * @return int
422
+     */
423
+    public function get_editable( $context = 'view' ) {
424
+        return $this->get_is_editable( $context );
425 425
     }
426 426
 
427 427
     /**
428
-	 * Checks if dynamic pricing is enabled.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $context View or edit context.
432
-	 * @return int
433
-	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
428
+     * Checks if dynamic pricing is enabled.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $context View or edit context.
432
+     * @return int
433
+     */
434
+    public function get_is_dynamic_pricing( $context = 'view' ) {
435 435
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
436 436
     }
437 437
 
438 438
     /**
439
-	 * Returns the minimum price if dynamic pricing is enabled.
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @param  string $context View or edit context.
443
-	 * @return float
444
-	 */
445
-	public function get_minimum_price( $context = 'view' ) {
439
+     * Returns the minimum price if dynamic pricing is enabled.
440
+     *
441
+     * @since 1.0.19
442
+     * @param  string $context View or edit context.
443
+     * @return float
444
+     */
445
+    public function get_minimum_price( $context = 'view' ) {
446 446
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
447 447
     }
448 448
 
449 449
     /**
450
-	 * Checks if this is a recurring item.
451
-	 *
452
-	 * @since 1.0.19
453
-	 * @param  string $context View or edit context.
454
-	 * @return int
455
-	 */
456
-	public function get_is_recurring( $context = 'view' ) {
450
+     * Checks if this is a recurring item.
451
+     *
452
+     * @since 1.0.19
453
+     * @param  string $context View or edit context.
454
+     * @return int
455
+     */
456
+    public function get_is_recurring( $context = 'view' ) {
457 457
         return (int) $this->get_prop( 'is_recurring', $context );
458
-	}
458
+    }
459 459
 	
460
-	/**
461
-	 * Get the recurring price of the item.
462
-	 *
463
-	 * @since 1.0.19
464
-	 * @param  string $context View or edit context.
465
-	 * @return float
466
-	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
460
+    /**
461
+     * Get the recurring price of the item.
462
+     *
463
+     * @since 1.0.19
464
+     * @param  string $context View or edit context.
465
+     * @return float
466
+     */
467
+    public function get_recurring_price( $context = 'view' ) {
468
+        $price = $this->get_price( $context );
469 469
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
470
-	}
471
-
472
-	/**
473
-	 * Get the formatted recurring price of the item.
474
-	 *
475
-	 * @since 1.0.19
476
-	 * @param  string $context View or edit context.
477
-	 * @return string
478
-	 */
470
+    }
471
+
472
+    /**
473
+     * Get the formatted recurring price of the item.
474
+     *
475
+     * @since 1.0.19
476
+     * @param  string $context View or edit context.
477
+     * @return string
478
+     */
479 479
     public function get_the_recurring_price() {
480 480
         return wpinv_price( $this->get_recurring_price() );
481
-	}
482
-
483
-	/**
484
-	 * Get the first renewal date (in timestamps) of the item.
485
-	 *
486
-	 * @since 1.0.19
487
-	 * @return int
488
-	 */
489
-	public function get_first_renewal_date() {
490
-
491
-		$periods = array(
492
-			'D' => 'days',
493
-			'W' => 'weeks',
494
-			'M' => 'months',
495
-			'Y' => 'years',
496
-		);
497
-
498
-		$period   = $this->get_recurring_period();
499
-		$interval = $this->get_recurring_interval();
500
-
501
-		if ( $this->has_free_trial() ) {
502
-			$period   = $this->get_trial_period();
503
-			$interval = $this->get_trial_interval();
504
-		}
505
-
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
481
+    }
482
+
483
+    /**
484
+     * Get the first renewal date (in timestamps) of the item.
485
+     *
486
+     * @since 1.0.19
487
+     * @return int
488
+     */
489
+    public function get_first_renewal_date() {
490
+
491
+        $periods = array(
492
+            'D' => 'days',
493
+            'W' => 'weeks',
494
+            'M' => 'months',
495
+            'Y' => 'years',
496
+        );
497
+
498
+        $period   = $this->get_recurring_period();
499
+        $interval = $this->get_recurring_interval();
500
+
501
+        if ( $this->has_free_trial() ) {
502
+            $period   = $this->get_trial_period();
503
+            $interval = $this->get_trial_interval();
504
+        }
505
+
506
+        $period       = $periods[ $period ];
507
+        $interval     = empty( $interval ) ? 1 : $interval;
508
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509 509
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
510 510
     }
511 511
 
512 512
     /**
513
-	 * Get the recurring period.
514
-	 *
515
-	 * @since 1.0.19
516
-	 * @param  bool $full Return abbreviation or in full.
517
-	 * @return string
518
-	 */
519
-	public function get_recurring_period( $full = false ) {
513
+     * Get the recurring period.
514
+     *
515
+     * @since 1.0.19
516
+     * @param  bool $full Return abbreviation or in full.
517
+     * @return string
518
+     */
519
+    public function get_recurring_period( $full = false ) {
520 520
         $period = $this->get_prop( 'recurring_period', 'view' );
521 521
 
522 522
         if ( $full && ! is_bool( $full ) ) {
@@ -527,58 +527,58 @@  discard block
 block discarded – undo
527 527
     }
528 528
 
529 529
     /**
530
-	 * Get the recurring interval.
531
-	 *
532
-	 * @since 1.0.19
533
-	 * @param  string $context View or edit context.
534
-	 * @return int
535
-	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
-		return max( 1, $interval );
530
+     * Get the recurring interval.
531
+     *
532
+     * @since 1.0.19
533
+     * @param  string $context View or edit context.
534
+     * @return int
535
+     */
536
+    public function get_recurring_interval( $context = 'view' ) {
537
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
+        return max( 1, $interval );
539 539
     }
540 540
 
541 541
     /**
542
-	 * Get the recurring limit.
543
-	 *
544
-	 * @since 1.0.19
545
-	 * @param  string $context View or edit context.
546
-	 * @return int
547
-	 */
548
-	public function get_recurring_limit( $context = 'view' ) {
542
+     * Get the recurring limit.
543
+     *
544
+     * @since 1.0.19
545
+     * @param  string $context View or edit context.
546
+     * @return int
547
+     */
548
+    public function get_recurring_limit( $context = 'view' ) {
549 549
         return (int) $this->get_prop( 'recurring_limit', $context );
550 550
     }
551 551
 
552 552
     /**
553
-	 * Checks if we have a free trial.
554
-	 *
555
-	 * @since 1.0.19
556
-	 * @param  string $context View or edit context.
557
-	 * @return int
558
-	 */
559
-	public function get_is_free_trial( $context = 'view' ) {
553
+     * Checks if we have a free trial.
554
+     *
555
+     * @since 1.0.19
556
+     * @param  string $context View or edit context.
557
+     * @return int
558
+     */
559
+    public function get_is_free_trial( $context = 'view' ) {
560 560
         return (int) $this->get_prop( 'is_free_trial', $context );
561 561
     }
562 562
 
563 563
     /**
564
-	 * Alias for self::get_is_free_trial().
565
-	 *
566
-	 * @since 1.0.19
567
-	 * @param  string $context View or edit context.
568
-	 * @return int
569
-	 */
570
-	public function get_free_trial( $context = 'view' ) {
564
+     * Alias for self::get_is_free_trial().
565
+     *
566
+     * @since 1.0.19
567
+     * @param  string $context View or edit context.
568
+     * @return int
569
+     */
570
+    public function get_free_trial( $context = 'view' ) {
571 571
         return $this->get_is_free_trial( $context );
572 572
     }
573 573
 
574 574
     /**
575
-	 * Get the trial period.
576
-	 *
577
-	 * @since 1.0.19
578
-	 * @param  bool $full Return abbreviation or in full.
579
-	 * @return string
580
-	 */
581
-	public function get_trial_period( $full = false ) {
575
+     * Get the trial period.
576
+     *
577
+     * @since 1.0.19
578
+     * @param  bool $full Return abbreviation or in full.
579
+     * @return string
580
+     */
581
+    public function get_trial_period( $full = false ) {
582 582
         $period = $this->get_prop( 'trial_period', 'view' );
583 583
 
584 584
         if ( $full && ! is_bool( $full ) ) {
@@ -589,104 +589,104 @@  discard block
 block discarded – undo
589 589
     }
590 590
 
591 591
     /**
592
-	 * Get the trial interval.
593
-	 *
594
-	 * @since 1.0.19
595
-	 * @param  string $context View or edit context.
596
-	 * @return int
597
-	 */
598
-	public function get_trial_interval( $context = 'view' ) {
592
+     * Get the trial interval.
593
+     *
594
+     * @since 1.0.19
595
+     * @param  string $context View or edit context.
596
+     * @return int
597
+     */
598
+    public function get_trial_interval( $context = 'view' ) {
599 599
         return (int) $this->get_prop( 'trial_interval', $context );
600
-	}
600
+    }
601 601
 	
602
-	/**
603
-	 * Get the item's edit url.
604
-	 *
605
-	 * @since 1.0.19
606
-	 * @return string
607
-	 */
608
-	public function get_edit_url() {
602
+    /**
603
+     * Get the item's edit url.
604
+     *
605
+     * @since 1.0.19
606
+     * @return string
607
+     */
608
+    public function get_edit_url() {
609 609
         return get_edit_post_link( $this->get_id(), 'edit' );
610
-	}
611
-
612
-	/**
613
-	 * Given an item's name/custom id, it returns its id.
614
-	 *
615
-	 *
616
-	 * @static
617
-	 * @param string $value The item name or custom id.
618
-	 * @param string $field Either name or custom_id.
619
-	 * @param string $type in case you need to search for a given type.
620
-	 * @since 1.0.15
621
-	 * @return int
622
-	 */
623
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
624
-
625
-		// Trim the value.
626
-		$value = sanitize_text_field( $value );
627
-		if ( empty( $value ) ) {
628
-			return 0;
629
-		}
610
+    }
611
+
612
+    /**
613
+     * Given an item's name/custom id, it returns its id.
614
+     *
615
+     *
616
+     * @static
617
+     * @param string $value The item name or custom id.
618
+     * @param string $field Either name or custom_id.
619
+     * @param string $type in case you need to search for a given type.
620
+     * @since 1.0.15
621
+     * @return int
622
+     */
623
+    public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
624
+
625
+        // Trim the value.
626
+        $value = sanitize_text_field( $value );
627
+        if ( empty( $value ) ) {
628
+            return 0;
629
+        }
630 630
 
631 631
         // Valid fields.
632 632
         $fields = array( 'custom_id', 'name', 'slug' );
633 633
 
634
-		// Ensure a field has been passed.
635
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
636
-			return 0;
637
-		}
638
-
639
-		if ( $field == 'name' ) {
640
-			$field = 'slug';
641
-		}
642
-
643
-		// Maybe retrieve from the cache.
644
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
-		if ( ! empty( $item_id ) ) {
646
-			return $item_id;
647
-		}
648
-
649
-		// Fetch from the db.
650
-		$items = array();
651
-		if ( $field == 'slug' ) {
652
-			$items = get_posts(
653
-				array(
654
-					'post_type'      => 'wpi_item',
655
-					'name'           => $value,
656
-					'posts_per_page' => 1,
657
-					'post_status'    => 'any',
658
-				)
659
-			);
660
-		}
661
-
662
-		if ( $field =='custom_id' ) {
663
-			$items = get_posts(
664
-				array(
665
-					'post_type'      => 'wpi_item',
666
-					'posts_per_page' => 1,
667
-					'post_status'    => 'any',
668
-					'meta_query'     => array(
669
-						array(
670
-							'key'   => '_wpinv_type',
671
-                			'value' => $type,
672
-						),
673
-						array(
674
-							'key'   => '_wpinv_custom_id',
675
-                			'value' => $value,
676
-						)
677
-					)
678
-				)
679
-			);
680
-		}
681
-
682
-		if ( empty( $items ) ) {
683
-			return 0;
684
-		}
685
-
686
-		// Update the cache with our data
687
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
688
-
689
-		return $items[0]->ID;
634
+        // Ensure a field has been passed.
635
+        if ( empty( $field ) || ! in_array( $field, $fields ) ) {
636
+            return 0;
637
+        }
638
+
639
+        if ( $field == 'name' ) {
640
+            $field = 'slug';
641
+        }
642
+
643
+        // Maybe retrieve from the cache.
644
+        $item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
+        if ( ! empty( $item_id ) ) {
646
+            return $item_id;
647
+        }
648
+
649
+        // Fetch from the db.
650
+        $items = array();
651
+        if ( $field == 'slug' ) {
652
+            $items = get_posts(
653
+                array(
654
+                    'post_type'      => 'wpi_item',
655
+                    'name'           => $value,
656
+                    'posts_per_page' => 1,
657
+                    'post_status'    => 'any',
658
+                )
659
+            );
660
+        }
661
+
662
+        if ( $field =='custom_id' ) {
663
+            $items = get_posts(
664
+                array(
665
+                    'post_type'      => 'wpi_item',
666
+                    'posts_per_page' => 1,
667
+                    'post_status'    => 'any',
668
+                    'meta_query'     => array(
669
+                        array(
670
+                            'key'   => '_wpinv_type',
671
+                            'value' => $type,
672
+                        ),
673
+                        array(
674
+                            'key'   => '_wpinv_custom_id',
675
+                            'value' => $value,
676
+                        )
677
+                    )
678
+                )
679
+            );
680
+        }
681
+
682
+        if ( empty( $items ) ) {
683
+            return 0;
684
+        }
685
+
686
+        // Update the cache with our data
687
+        wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
688
+
689
+        return $items[0]->ID;
690 690
     }
691 691
 
692 692
     /**
@@ -719,52 +719,52 @@  discard block
 block discarded – undo
719 719
     */
720 720
 
721 721
     /**
722
-	 * Set parent order ID.
723
-	 *
724
-	 * @since 1.0.19
725
-	 */
726
-	public function set_parent_id( $value ) {
727
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
728
-			return;
729
-		}
730
-		$this->set_prop( 'parent_id', absint( $value ) );
731
-	}
732
-
733
-    /**
734
-	 * Sets item status.
735
-	 *
736
-	 * @since 1.0.19
737
-	 * @param  string $status New status.
738
-	 * @return array details of change.
739
-	 */
740
-	public function set_status( $status ) {
722
+     * Set parent order ID.
723
+     *
724
+     * @since 1.0.19
725
+     */
726
+    public function set_parent_id( $value ) {
727
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
728
+            return;
729
+        }
730
+        $this->set_prop( 'parent_id', absint( $value ) );
731
+    }
732
+
733
+    /**
734
+     * Sets item status.
735
+     *
736
+     * @since 1.0.19
737
+     * @param  string $status New status.
738
+     * @return array details of change.
739
+     */
740
+    public function set_status( $status ) {
741 741
         $old_status = $this->get_status();
742 742
 
743 743
         $this->set_prop( 'status', $status );
744 744
 
745
-		return array(
746
-			'from' => $old_status,
747
-			'to'   => $status,
748
-		);
745
+        return array(
746
+            'from' => $old_status,
747
+            'to'   => $status,
748
+        );
749 749
     }
750 750
 
751 751
     /**
752
-	 * Set plugin version when the item was created.
753
-	 *
754
-	 * @since 1.0.19
755
-	 */
756
-	public function set_version( $value ) {
757
-		$this->set_prop( 'version', $value );
752
+     * Set plugin version when the item was created.
753
+     *
754
+     * @since 1.0.19
755
+     */
756
+    public function set_version( $value ) {
757
+        $this->set_prop( 'version', $value );
758 758
     }
759 759
 
760 760
     /**
761
-	 * Set date when the item was created.
762
-	 *
763
-	 * @since 1.0.19
764
-	 * @param string $value Value to set.
761
+     * Set date when the item was created.
762
+     *
763
+     * @since 1.0.19
764
+     * @param string $value Value to set.
765 765
      * @return bool Whether or not the date was set.
766
-	 */
767
-	public function set_date_created( $value ) {
766
+     */
767
+    public function set_date_created( $value ) {
768 768
         $date = strtotime( $value );
769 769
 
770 770
         if ( $date ) {
@@ -777,13 +777,13 @@  discard block
 block discarded – undo
777 777
     }
778 778
 
779 779
     /**
780
-	 * Set date when the item was last modified.
781
-	 *
782
-	 * @since 1.0.19
783
-	 * @param string $value Value to set.
780
+     * Set date when the item was last modified.
781
+     *
782
+     * @since 1.0.19
783
+     * @param string $value Value to set.
784 784
      * @return bool Whether or not the date was set.
785
-	 */
786
-	public function set_date_modified( $value ) {
785
+     */
786
+    public function set_date_modified( $value ) {
787 787
         $date = strtotime( $value );
788 788
 
789 789
         if ( $date ) {
@@ -796,115 +796,115 @@  discard block
 block discarded – undo
796 796
     }
797 797
 
798 798
     /**
799
-	 * Set the item name.
800
-	 *
801
-	 * @since 1.0.19
802
-	 * @param  string $value New name.
803
-	 */
804
-	public function set_name( $value ) {
799
+     * Set the item name.
800
+     *
801
+     * @since 1.0.19
802
+     * @param  string $value New name.
803
+     */
804
+    public function set_name( $value ) {
805 805
         $name = sanitize_text_field( $value );
806
-		$this->set_prop( 'name', $name );
806
+        $this->set_prop( 'name', $name );
807 807
     }
808 808
 
809 809
     /**
810
-	 * Alias of self::set_name().
811
-	 *
812
-	 * @since 1.0.19
813
-	 * @param  string $value New name.
814
-	 */
815
-	public function set_title( $value ) {
816
-		$this->set_name( $value );
810
+     * Alias of self::set_name().
811
+     *
812
+     * @since 1.0.19
813
+     * @param  string $value New name.
814
+     */
815
+    public function set_title( $value ) {
816
+        $this->set_name( $value );
817 817
     }
818 818
 
819 819
     /**
820
-	 * Set the item description.
821
-	 *
822
-	 * @since 1.0.19
823
-	 * @param  string $value New description.
824
-	 */
825
-	public function set_description( $value ) {
826
-		$description = wp_kses_post( $value );
827
-		return $this->set_prop( 'description', $description );
820
+     * Set the item description.
821
+     *
822
+     * @since 1.0.19
823
+     * @param  string $value New description.
824
+     */
825
+    public function set_description( $value ) {
826
+        $description = wp_kses_post( $value );
827
+        return $this->set_prop( 'description', $description );
828 828
     }
829 829
 
830 830
     /**
831
-	 * Alias of self::set_description().
832
-	 *
833
-	 * @since 1.0.19
834
-	 * @param  string $value New description.
835
-	 */
836
-	public function set_excerpt( $value ) {
837
-		$this->set_description( $value );
831
+     * Alias of self::set_description().
832
+     *
833
+     * @since 1.0.19
834
+     * @param  string $value New description.
835
+     */
836
+    public function set_excerpt( $value ) {
837
+        $this->set_description( $value );
838 838
     }
839 839
 
840 840
     /**
841
-	 * Alias of self::set_description().
842
-	 *
843
-	 * @since 1.0.19
844
-	 * @param  string $value New description.
845
-	 */
846
-	public function set_summary( $value ) {
847
-		$this->set_description( $value );
841
+     * Alias of self::set_description().
842
+     *
843
+     * @since 1.0.19
844
+     * @param  string $value New description.
845
+     */
846
+    public function set_summary( $value ) {
847
+        $this->set_description( $value );
848 848
     }
849 849
 
850 850
     /**
851
-	 * Set the owner of the item.
852
-	 *
853
-	 * @since 1.0.19
854
-	 * @param  int $value New author.
855
-	 */
856
-	public function set_author( $value ) {
857
-		$this->set_prop( 'author', (int) $value );
858
-	}
851
+     * Set the owner of the item.
852
+     *
853
+     * @since 1.0.19
854
+     * @param  int $value New author.
855
+     */
856
+    public function set_author( $value ) {
857
+        $this->set_prop( 'author', (int) $value );
858
+    }
859 859
 	
860
-	/**
861
-	 * Alias of self::set_author().
862
-	 *
863
-	 * @since 1.0.19
864
-	 * @param  int $value New author.
865
-	 */
866
-	public function set_owner( $value ) {
867
-		$this->set_author( $value );
868
-    }
869
-
870
-    /**
871
-	 * Set the price of the item.
872
-	 *
873
-	 * @since 1.0.19
874
-	 * @param  float $value New price.
875
-	 */
876
-	public function set_price( $value ) {
860
+    /**
861
+     * Alias of self::set_author().
862
+     *
863
+     * @since 1.0.19
864
+     * @param  int $value New author.
865
+     */
866
+    public function set_owner( $value ) {
867
+        $this->set_author( $value );
868
+    }
869
+
870
+    /**
871
+     * Set the price of the item.
872
+     *
873
+     * @since 1.0.19
874
+     * @param  float $value New price.
875
+     */
876
+    public function set_price( $value ) {
877 877
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
878 878
     }
879 879
 
880 880
     /**
881
-	 * Set the VAT rule of the item.
882
-	 *
883
-	 * @since 1.0.19
884
-	 * @param  string $value new rule.
885
-	 */
886
-	public function set_vat_rule( $value ) {
881
+     * Set the VAT rule of the item.
882
+     *
883
+     * @since 1.0.19
884
+     * @param  string $value new rule.
885
+     */
886
+    public function set_vat_rule( $value ) {
887 887
         $this->set_prop( 'vat_rule', $value );
888 888
     }
889 889
 
890 890
     /**
891
-	 * Set the VAT class of the item.
892
-	 *
893
-	 * @since 1.0.19
894
-	 * @param  string $value new class.
895
-	 */
896
-	public function set_vat_class( $value ) {
891
+     * Set the VAT class of the item.
892
+     *
893
+     * @since 1.0.19
894
+     * @param  string $value new class.
895
+     */
896
+    public function set_vat_class( $value ) {
897 897
         $this->set_prop( 'vat_class', $value );
898 898
     }
899 899
 
900 900
     /**
901
-	 * Set the type of the item.
902
-	 *
903
-	 * @since 1.0.19
904
-	 * @param  string $value new item type.
905
-	 * @return string
906
-	 */
907
-	public function set_type( $value ) {
901
+     * Set the type of the item.
902
+     *
903
+     * @since 1.0.19
904
+     * @param  string $value new item type.
905
+     * @return string
906
+     */
907
+    public function set_type( $value ) {
908 908
 
909 909
         if ( empty( $value ) ) {
910 910
             $value = 'custom';
@@ -914,132 +914,132 @@  discard block
 block discarded – undo
914 914
     }
915 915
 
916 916
     /**
917
-	 * Set the custom id of the item.
918
-	 *
919
-	 * @since 1.0.19
920
-	 * @param  string $value new custom id.
921
-	 */
922
-	public function set_custom_id( $value ) {
917
+     * Set the custom id of the item.
918
+     *
919
+     * @since 1.0.19
920
+     * @param  string $value new custom id.
921
+     */
922
+    public function set_custom_id( $value ) {
923 923
         $this->set_prop( 'custom_id', $value );
924 924
     }
925 925
 
926 926
     /**
927
-	 * Set the custom name of the item.
928
-	 *
929
-	 * @since 1.0.19
930
-	 * @param  string $value new custom name.
931
-	 */
932
-	public function set_custom_name( $value ) {
927
+     * Set the custom name of the item.
928
+     *
929
+     * @since 1.0.19
930
+     * @param  string $value new custom name.
931
+     */
932
+    public function set_custom_name( $value ) {
933 933
         $this->set_prop( 'custom_name', $value );
934 934
     }
935 935
 
936 936
     /**
937
-	 * Set the custom singular name of the item.
938
-	 *
939
-	 * @since 1.0.19
940
-	 * @param  string $value new custom singular name.
941
-	 */
942
-	public function set_custom_singular_name( $value ) {
937
+     * Set the custom singular name of the item.
938
+     *
939
+     * @since 1.0.19
940
+     * @param  string $value new custom singular name.
941
+     */
942
+    public function set_custom_singular_name( $value ) {
943 943
         $this->set_prop( 'custom_singular_name', $value );
944 944
     }
945 945
 
946 946
     /**
947
-	 * Sets if an item is editable..
948
-	 *
949
-	 * @since 1.0.19
950
-	 * @param  int|bool $value whether or not the item is editable.
951
-	 */
952
-	public function set_is_editable( $value ) {
953
-		$this->set_prop( 'is_editable', (int) $value );
947
+     * Sets if an item is editable..
948
+     *
949
+     * @since 1.0.19
950
+     * @param  int|bool $value whether or not the item is editable.
951
+     */
952
+    public function set_is_editable( $value ) {
953
+        $this->set_prop( 'is_editable', (int) $value );
954 954
     }
955 955
 
956 956
     /**
957
-	 * Sets if dynamic pricing is enabled.
958
-	 *
959
-	 * @since 1.0.19
960
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
961
-	 */
962
-	public function set_is_dynamic_pricing( $value ) {
957
+     * Sets if dynamic pricing is enabled.
958
+     *
959
+     * @since 1.0.19
960
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
961
+     */
962
+    public function set_is_dynamic_pricing( $value ) {
963 963
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
964 964
     }
965 965
 
966 966
     /**
967
-	 * Sets the minimum price if dynamic pricing is enabled.
968
-	 *
969
-	 * @since 1.0.19
970
-	 * @param  float $value minimum price.
971
-	 */
972
-	public function set_minimum_price( $value ) {
967
+     * Sets the minimum price if dynamic pricing is enabled.
968
+     *
969
+     * @since 1.0.19
970
+     * @param  float $value minimum price.
971
+     */
972
+    public function set_minimum_price( $value ) {
973 973
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
974 974
     }
975 975
 
976 976
     /**
977
-	 * Sets if this is a recurring item.
978
-	 *
979
-	 * @since 1.0.19
980
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
981
-	 */
982
-	public function set_is_recurring( $value ) {
977
+     * Sets if this is a recurring item.
978
+     *
979
+     * @since 1.0.19
980
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
981
+     */
982
+    public function set_is_recurring( $value ) {
983 983
         $this->set_prop( 'is_recurring', (int) $value );
984 984
     }
985 985
 
986 986
     /**
987
-	 * Set the recurring period.
988
-	 *
989
-	 * @since 1.0.19
990
-	 * @param  string $value new period.
991
-	 */
992
-	public function set_recurring_period( $value ) {
987
+     * Set the recurring period.
988
+     *
989
+     * @since 1.0.19
990
+     * @param  string $value new period.
991
+     */
992
+    public function set_recurring_period( $value ) {
993 993
         $this->set_prop( 'recurring_period', $value );
994 994
     }
995 995
 
996 996
     /**
997
-	 * Set the recurring interval.
998
-	 *
999
-	 * @since 1.0.19
1000
-	 * @param  int $value recurring interval.
1001
-	 */
1002
-	public function set_recurring_interval( $value ) {
997
+     * Set the recurring interval.
998
+     *
999
+     * @since 1.0.19
1000
+     * @param  int $value recurring interval.
1001
+     */
1002
+    public function set_recurring_interval( $value ) {
1003 1003
         return $this->set_prop( 'recurring_interval', (int) $value );
1004 1004
     }
1005 1005
 
1006 1006
     /**
1007
-	 * Get the recurring limit.
1008
-	 * @since 1.0.19
1009
-	 * @param  int $value The recurring limit.
1010
-	 * @return int
1011
-	 */
1012
-	public function set_recurring_limit( $value ) {
1007
+     * Get the recurring limit.
1008
+     * @since 1.0.19
1009
+     * @param  int $value The recurring limit.
1010
+     * @return int
1011
+     */
1012
+    public function set_recurring_limit( $value ) {
1013 1013
         $this->set_prop( 'recurring_limit', (int) $value );
1014 1014
     }
1015 1015
 
1016 1016
     /**
1017
-	 * Checks if we have a free trial.
1018
-	 *
1019
-	 * @since 1.0.19
1020
-	 * @param  int|bool $value whether or not it has a free trial.
1021
-	 */
1022
-	public function set_is_free_trial( $value ) {
1017
+     * Checks if we have a free trial.
1018
+     *
1019
+     * @since 1.0.19
1020
+     * @param  int|bool $value whether or not it has a free trial.
1021
+     */
1022
+    public function set_is_free_trial( $value ) {
1023 1023
         $this->set_prop( 'is_free_trial', (int) $value );
1024 1024
     }
1025 1025
 
1026 1026
     /**
1027
-	 * Set the trial period.
1028
-	 *
1029
-	 * @since 1.0.19
1030
-	 * @param  string $value trial period.
1031
-	 */
1032
-	public function set_trial_period( $value ) {
1027
+     * Set the trial period.
1028
+     *
1029
+     * @since 1.0.19
1030
+     * @param  string $value trial period.
1031
+     */
1032
+    public function set_trial_period( $value ) {
1033 1033
         $this->set_prop( 'trial_period', $value );
1034 1034
     }
1035 1035
 
1036 1036
     /**
1037
-	 * Set the trial interval.
1038
-	 *
1039
-	 * @since 1.0.19
1040
-	 * @param  int $value trial interval.
1041
-	 */
1042
-	public function set_trial_interval( $value ) {
1037
+     * Set the trial interval.
1038
+     *
1039
+     * @since 1.0.19
1040
+     * @param  int $value trial interval.
1041
+     */
1042
+    public function set_trial_interval( $value ) {
1043 1043
         $this->set_prop( 'trial_interval', $value );
1044 1044
     }
1045 1045
 
@@ -1047,17 +1047,17 @@  discard block
 block discarded – undo
1047 1047
      * Create an item. For backwards compatibilty.
1048 1048
      * 
1049 1049
      * @deprecated
1050
-	 * @return int item id
1050
+     * @return int item id
1051 1051
      */
1052 1052
     public function create( $data = array() ) {
1053 1053
 
1054
-		// Set the properties.
1055
-		if ( is_array( $data ) ) {
1056
-			$this->set_props( $data );
1057
-		}
1054
+        // Set the properties.
1055
+        if ( is_array( $data ) ) {
1056
+            $this->set_props( $data );
1057
+        }
1058 1058
 
1059
-		// Save the item.
1060
-		return $this->save();
1059
+        // Save the item.
1060
+        return $this->save();
1061 1061
 
1062 1062
     }
1063 1063
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
      * Updates an item. For backwards compatibilty.
1066 1066
      * 
1067 1067
      * @deprecated
1068
-	 * @return int item id
1068
+     * @return int item id
1069 1069
      */
1070 1070
     public function update( $data = array() ) {
1071 1071
         return $this->create( $data );
@@ -1081,93 +1081,93 @@  discard block
 block discarded – undo
1081 1081
 	*/
1082 1082
 
1083 1083
     /**
1084
-	 * Checks whether the item has enabled dynamic pricing.
1085
-	 *
1086
-	 * @since 1.0.19
1087
-	 * @return bool
1088
-	 */
1089
-	public function user_can_set_their_price() {
1084
+     * Checks whether the item has enabled dynamic pricing.
1085
+     *
1086
+     * @since 1.0.19
1087
+     * @return bool
1088
+     */
1089
+    public function user_can_set_their_price() {
1090 1090
         return (bool) $this->get_is_dynamic_pricing();
1091
-	}
1091
+    }
1092 1092
 	
1093
-	/**
1094
-	 * Checks whether the item is recurring.
1095
-	 *
1096
-	 * @since 1.0.19
1097
-	 * @return bool
1098
-	 */
1099
-	public function is_recurring() {
1093
+    /**
1094
+     * Checks whether the item is recurring.
1095
+     *
1096
+     * @since 1.0.19
1097
+     * @return bool
1098
+     */
1099
+    public function is_recurring() {
1100 1100
         return (bool) $this->get_is_recurring();
1101 1101
     }
1102 1102
 
1103 1103
     /**
1104
-	 * Checks whether the item has a free trial.
1105
-	 *
1106
-	 * @since 1.0.19
1107
-	 * @return bool
1108
-	 */
1104
+     * Checks whether the item has a free trial.
1105
+     *
1106
+     * @since 1.0.19
1107
+     * @return bool
1108
+     */
1109 1109
     public function has_free_trial() {
1110 1110
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1111 1111
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1112 1112
     }
1113 1113
 
1114 1114
     /**
1115
-	 * Checks whether the item is free.
1116
-	 *
1117
-	 * @since 1.0.19
1118
-	 * @return bool
1119
-	 */
1115
+     * Checks whether the item is free.
1116
+     *
1117
+     * @since 1.0.19
1118
+     * @return bool
1119
+     */
1120 1120
     public function is_free() {
1121 1121
         $is_free   = $this->get_price() == 0;
1122 1122
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1123 1123
     }
1124 1124
 
1125 1125
     /**
1126
-	 * Checks the item status against a passed in status.
1127
-	 *
1128
-	 * @param array|string $status Status to check.
1129
-	 * @return bool
1130
-	 */
1131
-	public function has_status( $status ) {
1132
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1126
+     * Checks the item status against a passed in status.
1127
+     *
1128
+     * @param array|string $status Status to check.
1129
+     * @return bool
1130
+     */
1131
+    public function has_status( $status ) {
1132
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1134 1134
     }
1135 1135
 
1136 1136
     /**
1137
-	 * Checks the item type against a passed in types.
1138
-	 *
1139
-	 * @param array|string $type Type to check.
1140
-	 * @return bool
1141
-	 */
1142
-	public function is_type( $type ) {
1143
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1145
-	}
1137
+     * Checks the item type against a passed in types.
1138
+     *
1139
+     * @param array|string $type Type to check.
1140
+     * @return bool
1141
+     */
1142
+    public function is_type( $type ) {
1143
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1145
+    }
1146 1146
 
1147 1147
     /**
1148
-	 * Checks whether the item is editable.
1149
-	 *
1150
-	 * @since 1.0.19
1151
-	 * @return bool
1152
-	 */
1148
+     * Checks whether the item is editable.
1149
+     *
1150
+     * @since 1.0.19
1151
+     * @return bool
1152
+     */
1153 1153
     public function is_editable() {
1154 1154
         $is_editable = $this->get_is_editable();
1155 1155
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1156
-	}
1156
+    }
1157 1157
 
1158
-	/**
1159
-	 * Returns an array of cart fees.
1160
-	 */
1161
-	public function get_fees() {
1158
+    /**
1159
+     * Returns an array of cart fees.
1160
+     */
1161
+    public function get_fees() {
1162 1162
         return array();
1163 1163
     }
1164 1164
 
1165 1165
     /**
1166
-	 * Checks whether the item is purchasable.
1167
-	 *
1168
-	 * @since 1.0.19
1169
-	 * @return bool
1170
-	 */
1166
+     * Checks whether the item is purchasable.
1167
+     *
1168
+     * @since 1.0.19
1169
+     * @return bool
1170
+     */
1171 1171
     public function can_purchase() {
1172 1172
         $can_purchase = $this->exists();
1173 1173
 
@@ -1179,11 +1179,11 @@  discard block
 block discarded – undo
1179 1179
     }
1180 1180
 
1181 1181
     /**
1182
-	 * Checks whether the item supports dynamic pricing.
1183
-	 *
1184
-	 * @since 1.0.19
1185
-	 * @return bool
1186
-	 */
1182
+     * Checks whether the item supports dynamic pricing.
1183
+     *
1184
+     * @since 1.0.19
1185
+     * @return bool
1186
+     */
1187 1187
     public function supports_dynamic_pricing() {
1188 1188
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1189 1189
     }
Please login to merge, or discard this patch.
Spacing   +211 added lines, -211 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
 
@@ -78,30 +78,30 @@  discard block
 block discarded – undo
78 78
 	 *
79 79
 	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80 80
 	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( ! empty( $item ) && is_numeric( $item ) && 'wpi_item' == get_post_type( $item ) ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'custom_id' ) ) {
91
-			$this->set_id( $item_id );
92
-		} elseif ( is_scalar( $item ) && $item_id = self::get_item_id_by_field( $item, 'name' ) ) {
93
-			$this->set_id( $item_id );
81
+	public function __construct($item = 0) {
82
+		parent::__construct($item);
83
+
84
+		if (!empty($item) && is_numeric($item) && 'wpi_item' == get_post_type($item)) {
85
+			$this->set_id($item);
86
+		} elseif ($item instanceof self) {
87
+			$this->set_id($item->get_id());
88
+		} elseif (!empty($item->ID)) {
89
+			$this->set_id($item->ID);
90
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'custom_id')) {
91
+			$this->set_id($item_id);
92
+		} elseif (is_scalar($item) && $item_id = self::get_item_id_by_field($item, 'name')) {
93
+			$this->set_id($item_id);
94 94
 		} else {
95
-			$this->set_object_read( true );
95
+			$this->set_object_read(true);
96 96
 		}
97 97
 
98 98
         // Load the datastore.
99
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
99
+		$this->data_store = GetPaid_Data_Store::load($this->data_store_name);
100 100
 
101
-		if ( $this->get_id() > 0 ) {
102
-            $this->post = get_post( $this->get_id() );
101
+		if ($this->get_id() > 0) {
102
+            $this->post = get_post($this->get_id());
103 103
             $this->ID   = $this->get_id();
104
-			$this->data_store->read( $this );
104
+			$this->data_store->read($this);
105 105
         }
106 106
 
107 107
 	}
@@ -128,8 +128,8 @@  discard block
 block discarded – undo
128 128
 	 * @param  string $context View or edit context.
129 129
 	 * @return int
130 130
 	 */
131
-	public function get_parent_id( $context = 'view' ) {
132
-		return (int) $this->get_prop( 'parent_id', $context );
131
+	public function get_parent_id($context = 'view') {
132
+		return (int) $this->get_prop('parent_id', $context);
133 133
     }
134 134
 
135 135
     /**
@@ -139,8 +139,8 @@  discard block
 block discarded – undo
139 139
 	 * @param  string $context View or edit context.
140 140
 	 * @return string
141 141
 	 */
142
-	public function get_status( $context = 'view' ) {
143
-		return $this->get_prop( 'status', $context );
142
+	public function get_status($context = 'view') {
143
+		return $this->get_prop('status', $context);
144 144
     }
145 145
 
146 146
     /**
@@ -150,8 +150,8 @@  discard block
 block discarded – undo
150 150
 	 * @param  string $context View or edit context.
151 151
 	 * @return string
152 152
 	 */
153
-	public function get_version( $context = 'view' ) {
154
-		return $this->get_prop( 'version', $context );
153
+	public function get_version($context = 'view') {
154
+		return $this->get_prop('version', $context);
155 155
     }
156 156
 
157 157
     /**
@@ -161,8 +161,8 @@  discard block
 block discarded – undo
161 161
 	 * @param  string $context View or edit context.
162 162
 	 * @return string
163 163
 	 */
164
-	public function get_date_created( $context = 'view' ) {
165
-		return $this->get_prop( 'date_created', $context );
164
+	public function get_date_created($context = 'view') {
165
+		return $this->get_prop('date_created', $context);
166 166
     }
167 167
 
168 168
     /**
@@ -172,11 +172,11 @@  discard block
 block discarded – undo
172 172
 	 * @param  string $context View or edit context.
173 173
 	 * @return string
174 174
 	 */
175
-	public function get_date_created_gmt( $context = 'view' ) {
176
-        $date = $this->get_date_created( $context );
175
+	public function get_date_created_gmt($context = 'view') {
176
+        $date = $this->get_date_created($context);
177 177
 
178
-        if ( $date ) {
179
-            $date = get_gmt_from_date( $date );
178
+        if ($date) {
179
+            $date = get_gmt_from_date($date);
180 180
         }
181 181
 		return $date;
182 182
     }
@@ -188,8 +188,8 @@  discard block
 block discarded – undo
188 188
 	 * @param  string $context View or edit context.
189 189
 	 * @return string
190 190
 	 */
191
-	public function get_date_modified( $context = 'view' ) {
192
-		return $this->get_prop( 'date_modified', $context );
191
+	public function get_date_modified($context = 'view') {
192
+		return $this->get_prop('date_modified', $context);
193 193
     }
194 194
 
195 195
     /**
@@ -199,11 +199,11 @@  discard block
 block discarded – undo
199 199
 	 * @param  string $context View or edit context.
200 200
 	 * @return string
201 201
 	 */
202
-	public function get_date_modified_gmt( $context = 'view' ) {
203
-        $date = $this->get_date_modified( $context );
202
+	public function get_date_modified_gmt($context = 'view') {
203
+        $date = $this->get_date_modified($context);
204 204
 
205
-        if ( $date ) {
206
-            $date = get_gmt_from_date( $date );
205
+        if ($date) {
206
+            $date = get_gmt_from_date($date);
207 207
         }
208 208
 		return $date;
209 209
     }
@@ -215,8 +215,8 @@  discard block
 block discarded – undo
215 215
 	 * @param  string $context View or edit context.
216 216
 	 * @return string
217 217
 	 */
218
-	public function get_name( $context = 'view' ) {
219
-		return $this->get_prop( 'name', $context );
218
+	public function get_name($context = 'view') {
219
+		return $this->get_prop('name', $context);
220 220
     }
221 221
 
222 222
     /**
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
 	 * @param  string $context View or edit context.
227 227
 	 * @return string
228 228
 	 */
229
-	public function get_title( $context = 'view' ) {
230
-		return $this->get_name( $context );
229
+	public function get_title($context = 'view') {
230
+		return $this->get_name($context);
231 231
     }
232 232
 
233 233
     /**
@@ -237,8 +237,8 @@  discard block
 block discarded – undo
237 237
 	 * @param  string $context View or edit context.
238 238
 	 * @return string
239 239
 	 */
240
-	public function get_description( $context = 'view' ) {
241
-		return $this->get_prop( 'description', $context );
240
+	public function get_description($context = 'view') {
241
+		return $this->get_prop('description', $context);
242 242
     }
243 243
 
244 244
     /**
@@ -248,8 +248,8 @@  discard block
 block discarded – undo
248 248
 	 * @param  string $context View or edit context.
249 249
 	 * @return string
250 250
 	 */
251
-	public function get_excerpt( $context = 'view' ) {
252
-		return $this->get_description( $context );
251
+	public function get_excerpt($context = 'view') {
252
+		return $this->get_description($context);
253 253
     }
254 254
 
255 255
     /**
@@ -259,8 +259,8 @@  discard block
 block discarded – undo
259 259
 	 * @param  string $context View or edit context.
260 260
 	 * @return string
261 261
 	 */
262
-	public function get_summary( $context = 'view' ) {
263
-		return $this->get_description( $context );
262
+	public function get_summary($context = 'view') {
263
+		return $this->get_description($context);
264 264
     }
265 265
 
266 266
     /**
@@ -270,8 +270,8 @@  discard block
 block discarded – undo
270 270
 	 * @param  string $context View or edit context.
271 271
 	 * @return int
272 272
 	 */
273
-	public function get_author( $context = 'view' ) {
274
-		return (int) $this->get_prop( 'author', $context );
273
+	public function get_author($context = 'view') {
274
+		return (int) $this->get_prop('author', $context);
275 275
 	}
276 276
 	
277 277
 	/**
@@ -281,8 +281,8 @@  discard block
 block discarded – undo
281 281
 	 * @param  string $context View or edit context.
282 282
 	 * @return int
283 283
 	 */
284
-	public function get_owner( $context = 'view' ) {
285
-		return $this->get_author( $context );
284
+	public function get_owner($context = 'view') {
285
+		return $this->get_author($context);
286 286
     }
287 287
 
288 288
     /**
@@ -292,8 +292,8 @@  discard block
 block discarded – undo
292 292
 	 * @param  string $context View or edit context.
293 293
 	 * @return float
294 294
 	 */
295
-	public function get_price( $context = 'view' ) {
296
-        return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
295
+	public function get_price($context = 'view') {
296
+        return wpinv_sanitize_amount($this->get_prop('price', $context));
297 297
 	}
298 298
 	
299 299
 	/**
@@ -303,15 +303,15 @@  discard block
 block discarded – undo
303 303
 	 * @param  string $context View or edit context.
304 304
 	 * @return float
305 305
 	 */
306
-	public function get_initial_price( $context = 'view' ) {
306
+	public function get_initial_price($context = 'view') {
307 307
 
308
-		$price = (float) $this->get_price( $context );
308
+		$price = (float) $this->get_price($context);
309 309
 
310
-		if ( $this->has_free_trial() ) {
310
+		if ($this->has_free_trial()) {
311 311
 			$price = 0;
312 312
 		}
313 313
 
314
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
314
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_initial_item_price', $price, $this));
315 315
     }
316 316
 
317 317
     /**
@@ -322,7 +322,7 @@  discard block
 block discarded – undo
322 322
 	 * @return string
323 323
 	 */
324 324
     public function get_the_price() {
325
-        return wpinv_price( $this->get_price() );
325
+        return wpinv_price($this->get_price());
326 326
 	}
327 327
 
328 328
 	/**
@@ -333,7 +333,7 @@  discard block
 block discarded – undo
333 333
 	 * @return string
334 334
 	 */
335 335
     public function get_the_initial_price() {
336
-        return wpinv_price( $this->get_initial_price() );
336
+        return wpinv_price($this->get_initial_price());
337 337
     }
338 338
 
339 339
     /**
@@ -343,8 +343,8 @@  discard block
 block discarded – undo
343 343
 	 * @param  string $context View or edit context.
344 344
 	 * @return string
345 345
 	 */
346
-	public function get_vat_rule( $context = 'view' ) {
347
-        return $this->get_prop( 'vat_rule', $context );
346
+	public function get_vat_rule($context = 'view') {
347
+        return $this->get_prop('vat_rule', $context);
348 348
     }
349 349
 
350 350
     /**
@@ -354,8 +354,8 @@  discard block
 block discarded – undo
354 354
 	 * @param  string $context View or edit context.
355 355
 	 * @return string
356 356
 	 */
357
-	public function get_vat_class( $context = 'view' ) {
358
-        return $this->get_prop( 'vat_class', $context );
357
+	public function get_vat_class($context = 'view') {
358
+        return $this->get_prop('vat_class', $context);
359 359
     }
360 360
 
361 361
     /**
@@ -365,8 +365,8 @@  discard block
 block discarded – undo
365 365
 	 * @param  string $context View or edit context.
366 366
 	 * @return string
367 367
 	 */
368
-	public function get_type( $context = 'view' ) {
369
-        return $this->get_prop( 'type', $context );
368
+	public function get_type($context = 'view') {
369
+        return $this->get_prop('type', $context);
370 370
     }
371 371
 
372 372
     /**
@@ -376,8 +376,8 @@  discard block
 block discarded – undo
376 376
 	 * @param  string $context View or edit context.
377 377
 	 * @return string
378 378
 	 */
379
-	public function get_custom_id( $context = 'view' ) {
380
-        return $this->get_prop( 'custom_id', $context );
379
+	public function get_custom_id($context = 'view') {
380
+        return $this->get_prop('custom_id', $context);
381 381
     }
382 382
 
383 383
     /**
@@ -387,8 +387,8 @@  discard block
 block discarded – undo
387 387
 	 * @param  string $context View or edit context.
388 388
 	 * @return string
389 389
 	 */
390
-	public function get_custom_name( $context = 'view' ) {
391
-        return $this->get_prop( 'custom_name', $context );
390
+	public function get_custom_name($context = 'view') {
391
+        return $this->get_prop('custom_name', $context);
392 392
     }
393 393
 
394 394
     /**
@@ -398,8 +398,8 @@  discard block
 block discarded – undo
398 398
 	 * @param  string $context View or edit context.
399 399
 	 * @return string
400 400
 	 */
401
-	public function get_custom_singular_name( $context = 'view' ) {
402
-        return $this->get_prop( 'custom_singular_name', $context );
401
+	public function get_custom_singular_name($context = 'view') {
402
+        return $this->get_prop('custom_singular_name', $context);
403 403
     }
404 404
 
405 405
     /**
@@ -409,8 +409,8 @@  discard block
 block discarded – undo
409 409
 	 * @param  string $context View or edit context.
410 410
 	 * @return int
411 411
 	 */
412
-	public function get_is_editable( $context = 'view' ) {
413
-        return (int) $this->get_prop( 'is_editable', $context );
412
+	public function get_is_editable($context = 'view') {
413
+        return (int) $this->get_prop('is_editable', $context);
414 414
     }
415 415
 
416 416
     /**
@@ -420,8 +420,8 @@  discard block
 block discarded – undo
420 420
 	 * @param  string $context View or edit context.
421 421
 	 * @return int
422 422
 	 */
423
-	public function get_editable( $context = 'view' ) {
424
-		return $this->get_is_editable( $context );
423
+	public function get_editable($context = 'view') {
424
+		return $this->get_is_editable($context);
425 425
     }
426 426
 
427 427
     /**
@@ -431,8 +431,8 @@  discard block
 block discarded – undo
431 431
 	 * @param  string $context View or edit context.
432 432
 	 * @return int
433 433
 	 */
434
-	public function get_is_dynamic_pricing( $context = 'view' ) {
435
-        return (int) $this->get_prop( 'is_dynamic_pricing', $context );
434
+	public function get_is_dynamic_pricing($context = 'view') {
435
+        return (int) $this->get_prop('is_dynamic_pricing', $context);
436 436
     }
437 437
 
438 438
     /**
@@ -442,8 +442,8 @@  discard block
 block discarded – undo
442 442
 	 * @param  string $context View or edit context.
443 443
 	 * @return float
444 444
 	 */
445
-	public function get_minimum_price( $context = 'view' ) {
446
-        return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
445
+	public function get_minimum_price($context = 'view') {
446
+        return wpinv_sanitize_amount($this->get_prop('minimum_price', $context));
447 447
     }
448 448
 
449 449
     /**
@@ -453,8 +453,8 @@  discard block
 block discarded – undo
453 453
 	 * @param  string $context View or edit context.
454 454
 	 * @return int
455 455
 	 */
456
-	public function get_is_recurring( $context = 'view' ) {
457
-        return (int) $this->get_prop( 'is_recurring', $context );
456
+	public function get_is_recurring($context = 'view') {
457
+        return (int) $this->get_prop('is_recurring', $context);
458 458
 	}
459 459
 	
460 460
 	/**
@@ -464,9 +464,9 @@  discard block
 block discarded – undo
464 464
 	 * @param  string $context View or edit context.
465 465
 	 * @return float
466 466
 	 */
467
-	public function get_recurring_price( $context = 'view' ) {
468
-		$price = $this->get_price( $context );
469
-        return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
467
+	public function get_recurring_price($context = 'view') {
468
+		$price = $this->get_price($context);
469
+        return wpinv_sanitize_amount(apply_filters('wpinv_get_recurring_item_price', $price, $this->ID));
470 470
 	}
471 471
 
472 472
 	/**
@@ -477,7 +477,7 @@  discard block
 block discarded – undo
477 477
 	 * @return string
478 478
 	 */
479 479
     public function get_the_recurring_price() {
480
-        return wpinv_price( $this->get_recurring_price() );
480
+        return wpinv_price($this->get_recurring_price());
481 481
 	}
482 482
 
483 483
 	/**
@@ -498,15 +498,15 @@  discard block
 block discarded – undo
498 498
 		$period   = $this->get_recurring_period();
499 499
 		$interval = $this->get_recurring_interval();
500 500
 
501
-		if ( $this->has_free_trial() ) {
501
+		if ($this->has_free_trial()) {
502 502
 			$period   = $this->get_trial_period();
503 503
 			$interval = $this->get_trial_interval();
504 504
 		}
505 505
 
506
-		$period       = $periods[ $period ];
507
-		$interval     = empty( $interval ) ? 1 : $interval;
508
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
509
-        return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
506
+		$period       = $periods[$period];
507
+		$interval     = empty($interval) ? 1 : $interval;
508
+		$next_renewal = strtotime("+$interval $period", current_time('timestamp'));
509
+        return apply_filters('wpinv_get_first_renewal_date', $next_renewal, $this);
510 510
     }
511 511
 
512 512
     /**
@@ -516,14 +516,14 @@  discard block
 block discarded – undo
516 516
 	 * @param  bool $full Return abbreviation or in full.
517 517
 	 * @return string
518 518
 	 */
519
-	public function get_recurring_period( $full = false ) {
520
-        $period = $this->get_prop( 'recurring_period', 'view' );
519
+	public function get_recurring_period($full = false) {
520
+        $period = $this->get_prop('recurring_period', 'view');
521 521
 
522
-        if ( $full && ! is_bool( $full ) ) {
522
+        if ($full && !is_bool($full)) {
523 523
             $full = false;
524 524
         }
525 525
 
526
-        return getpaid_sanitize_recurring_period( $period, $full );
526
+        return getpaid_sanitize_recurring_period($period, $full);
527 527
     }
528 528
 
529 529
     /**
@@ -533,9 +533,9 @@  discard block
 block discarded – undo
533 533
 	 * @param  string $context View or edit context.
534 534
 	 * @return int
535 535
 	 */
536
-	public function get_recurring_interval( $context = 'view' ) {
537
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
538
-		return max( 1, $interval );
536
+	public function get_recurring_interval($context = 'view') {
537
+		$interval = absint($this->get_prop('recurring_interval', $context));
538
+		return max(1, $interval);
539 539
     }
540 540
 
541 541
     /**
@@ -545,8 +545,8 @@  discard block
 block discarded – undo
545 545
 	 * @param  string $context View or edit context.
546 546
 	 * @return int
547 547
 	 */
548
-	public function get_recurring_limit( $context = 'view' ) {
549
-        return (int) $this->get_prop( 'recurring_limit', $context );
548
+	public function get_recurring_limit($context = 'view') {
549
+        return (int) $this->get_prop('recurring_limit', $context);
550 550
     }
551 551
 
552 552
     /**
@@ -556,8 +556,8 @@  discard block
 block discarded – undo
556 556
 	 * @param  string $context View or edit context.
557 557
 	 * @return int
558 558
 	 */
559
-	public function get_is_free_trial( $context = 'view' ) {
560
-        return (int) $this->get_prop( 'is_free_trial', $context );
559
+	public function get_is_free_trial($context = 'view') {
560
+        return (int) $this->get_prop('is_free_trial', $context);
561 561
     }
562 562
 
563 563
     /**
@@ -567,8 +567,8 @@  discard block
 block discarded – undo
567 567
 	 * @param  string $context View or edit context.
568 568
 	 * @return int
569 569
 	 */
570
-	public function get_free_trial( $context = 'view' ) {
571
-        return $this->get_is_free_trial( $context );
570
+	public function get_free_trial($context = 'view') {
571
+        return $this->get_is_free_trial($context);
572 572
     }
573 573
 
574 574
     /**
@@ -578,14 +578,14 @@  discard block
 block discarded – undo
578 578
 	 * @param  bool $full Return abbreviation or in full.
579 579
 	 * @return string
580 580
 	 */
581
-	public function get_trial_period( $full = false ) {
582
-        $period = $this->get_prop( 'trial_period', 'view' );
581
+	public function get_trial_period($full = false) {
582
+        $period = $this->get_prop('trial_period', 'view');
583 583
 
584
-        if ( $full && ! is_bool( $full ) ) {
584
+        if ($full && !is_bool($full)) {
585 585
             $full = false;
586 586
         }
587 587
 
588
-        return getpaid_sanitize_recurring_period( $period, $full );
588
+        return getpaid_sanitize_recurring_period($period, $full);
589 589
     }
590 590
 
591 591
     /**
@@ -595,8 +595,8 @@  discard block
 block discarded – undo
595 595
 	 * @param  string $context View or edit context.
596 596
 	 * @return int
597 597
 	 */
598
-	public function get_trial_interval( $context = 'view' ) {
599
-        return (int) $this->get_prop( 'trial_interval', $context );
598
+	public function get_trial_interval($context = 'view') {
599
+        return (int) $this->get_prop('trial_interval', $context);
600 600
 	}
601 601
 	
602 602
 	/**
@@ -606,7 +606,7 @@  discard block
 block discarded – undo
606 606
 	 * @return string
607 607
 	 */
608 608
 	public function get_edit_url() {
609
-        return get_edit_post_link( $this->get_id(), 'edit' );
609
+        return get_edit_post_link($this->get_id(), 'edit');
610 610
 	}
611 611
 
612 612
 	/**
@@ -620,35 +620,35 @@  discard block
 block discarded – undo
620 620
 	 * @since 1.0.15
621 621
 	 * @return int
622 622
 	 */
623
-	public static function get_item_id_by_field( $value, $field = 'custom_id', $type = '' ) {
623
+	public static function get_item_id_by_field($value, $field = 'custom_id', $type = '') {
624 624
 
625 625
 		// Trim the value.
626
-		$value = sanitize_text_field( $value );
627
-		if ( empty( $value ) ) {
626
+		$value = sanitize_text_field($value);
627
+		if (empty($value)) {
628 628
 			return 0;
629 629
 		}
630 630
 
631 631
         // Valid fields.
632
-        $fields = array( 'custom_id', 'name', 'slug' );
632
+        $fields = array('custom_id', 'name', 'slug');
633 633
 
634 634
 		// Ensure a field has been passed.
635
-		if ( empty( $field ) || ! in_array( $field, $fields ) ) {
635
+		if (empty($field) || !in_array($field, $fields)) {
636 636
 			return 0;
637 637
 		}
638 638
 
639
-		if ( $field == 'name' ) {
639
+		if ($field == 'name') {
640 640
 			$field = 'slug';
641 641
 		}
642 642
 
643 643
 		// Maybe retrieve from the cache.
644
-		$item_id = wp_cache_get( $value, "getpaid_{$type}_item_{$field}s_to_item_ids" );
645
-		if ( ! empty( $item_id ) ) {
644
+		$item_id = wp_cache_get($value, "getpaid_{$type}_item_{$field}s_to_item_ids");
645
+		if (!empty($item_id)) {
646 646
 			return $item_id;
647 647
 		}
648 648
 
649 649
 		// Fetch from the db.
650 650
 		$items = array();
651
-		if ( $field == 'slug' ) {
651
+		if ($field == 'slug') {
652 652
 			$items = get_posts(
653 653
 				array(
654 654
 					'post_type'      => 'wpi_item',
@@ -659,7 +659,7 @@  discard block
 block discarded – undo
659 659
 			);
660 660
 		}
661 661
 
662
-		if ( $field =='custom_id' ) {
662
+		if ($field == 'custom_id') {
663 663
 			$items = get_posts(
664 664
 				array(
665 665
 					'post_type'      => 'wpi_item',
@@ -679,12 +679,12 @@  discard block
 block discarded – undo
679 679
 			);
680 680
 		}
681 681
 
682
-		if ( empty( $items ) ) {
682
+		if (empty($items)) {
683 683
 			return 0;
684 684
 		}
685 685
 
686 686
 		// Update the cache with our data
687
-		wp_cache_set( $value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids" );
687
+		wp_cache_set($value, $items[0]->ID, "getpaid_{$type}_item_{$field}s_to_item_ids");
688 688
 
689 689
 		return $items[0]->ID;
690 690
     }
@@ -692,19 +692,19 @@  discard block
 block discarded – undo
692 692
     /**
693 693
      * Margic method for retrieving a property.
694 694
      */
695
-    public function __get( $key ) {
695
+    public function __get($key) {
696 696
 
697 697
         // Check if we have a helper method for that.
698
-        if ( method_exists( $this, 'get_' . $key ) ) {
699
-            return call_user_func( array( $this, 'get_' . $key ) );
698
+        if (method_exists($this, 'get_' . $key)) {
699
+            return call_user_func(array($this, 'get_' . $key));
700 700
         }
701 701
 
702 702
         // Check if the key is in the associated $post object.
703
-        if ( ! empty( $this->post ) && isset( $this->post->$key ) ) {
703
+        if (!empty($this->post) && isset($this->post->$key)) {
704 704
             return $this->post->$key;
705 705
         }
706 706
 
707
-        return $this->get_prop( $key );
707
+        return $this->get_prop($key);
708 708
 
709 709
     }
710 710
 
@@ -723,11 +723,11 @@  discard block
 block discarded – undo
723 723
 	 *
724 724
 	 * @since 1.0.19
725 725
 	 */
726
-	public function set_parent_id( $value ) {
727
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
726
+	public function set_parent_id($value) {
727
+		if ($value && ($value === $this->get_id() || !get_post($value))) {
728 728
 			return;
729 729
 		}
730
-		$this->set_prop( 'parent_id', absint( $value ) );
730
+		$this->set_prop('parent_id', absint($value));
731 731
 	}
732 732
 
733 733
     /**
@@ -737,10 +737,10 @@  discard block
 block discarded – undo
737 737
 	 * @param  string $status New status.
738 738
 	 * @return array details of change.
739 739
 	 */
740
-	public function set_status( $status ) {
740
+	public function set_status($status) {
741 741
         $old_status = $this->get_status();
742 742
 
743
-        $this->set_prop( 'status', $status );
743
+        $this->set_prop('status', $status);
744 744
 
745 745
 		return array(
746 746
 			'from' => $old_status,
@@ -753,8 +753,8 @@  discard block
 block discarded – undo
753 753
 	 *
754 754
 	 * @since 1.0.19
755 755
 	 */
756
-	public function set_version( $value ) {
757
-		$this->set_prop( 'version', $value );
756
+	public function set_version($value) {
757
+		$this->set_prop('version', $value);
758 758
     }
759 759
 
760 760
     /**
@@ -764,11 +764,11 @@  discard block
 block discarded – undo
764 764
 	 * @param string $value Value to set.
765 765
      * @return bool Whether or not the date was set.
766 766
 	 */
767
-	public function set_date_created( $value ) {
768
-        $date = strtotime( $value );
767
+	public function set_date_created($value) {
768
+        $date = strtotime($value);
769 769
 
770
-        if ( $date ) {
771
-            $this->set_prop( 'date_created', date( 'Y-m-d H:i:s', $date ) );
770
+        if ($date) {
771
+            $this->set_prop('date_created', date('Y-m-d H:i:s', $date));
772 772
             return true;
773 773
         }
774 774
 
@@ -783,11 +783,11 @@  discard block
 block discarded – undo
783 783
 	 * @param string $value Value to set.
784 784
      * @return bool Whether or not the date was set.
785 785
 	 */
786
-	public function set_date_modified( $value ) {
787
-        $date = strtotime( $value );
786
+	public function set_date_modified($value) {
787
+        $date = strtotime($value);
788 788
 
789
-        if ( $date ) {
790
-            $this->set_prop( 'date_modified', date( 'Y-m-d H:i:s', $date ) );
789
+        if ($date) {
790
+            $this->set_prop('date_modified', date('Y-m-d H:i:s', $date));
791 791
             return true;
792 792
         }
793 793
 
@@ -801,9 +801,9 @@  discard block
 block discarded – undo
801 801
 	 * @since 1.0.19
802 802
 	 * @param  string $value New name.
803 803
 	 */
804
-	public function set_name( $value ) {
805
-        $name = sanitize_text_field( $value );
806
-		$this->set_prop( 'name', $name );
804
+	public function set_name($value) {
805
+        $name = sanitize_text_field($value);
806
+		$this->set_prop('name', $name);
807 807
     }
808 808
 
809 809
     /**
@@ -812,8 +812,8 @@  discard block
 block discarded – undo
812 812
 	 * @since 1.0.19
813 813
 	 * @param  string $value New name.
814 814
 	 */
815
-	public function set_title( $value ) {
816
-		$this->set_name( $value );
815
+	public function set_title($value) {
816
+		$this->set_name($value);
817 817
     }
818 818
 
819 819
     /**
@@ -822,9 +822,9 @@  discard block
 block discarded – undo
822 822
 	 * @since 1.0.19
823 823
 	 * @param  string $value New description.
824 824
 	 */
825
-	public function set_description( $value ) {
826
-		$description = wp_kses_post( $value );
827
-		return $this->set_prop( 'description', $description );
825
+	public function set_description($value) {
826
+		$description = wp_kses_post($value);
827
+		return $this->set_prop('description', $description);
828 828
     }
829 829
 
830 830
     /**
@@ -833,8 +833,8 @@  discard block
 block discarded – undo
833 833
 	 * @since 1.0.19
834 834
 	 * @param  string $value New description.
835 835
 	 */
836
-	public function set_excerpt( $value ) {
837
-		$this->set_description( $value );
836
+	public function set_excerpt($value) {
837
+		$this->set_description($value);
838 838
     }
839 839
 
840 840
     /**
@@ -843,8 +843,8 @@  discard block
 block discarded – undo
843 843
 	 * @since 1.0.19
844 844
 	 * @param  string $value New description.
845 845
 	 */
846
-	public function set_summary( $value ) {
847
-		$this->set_description( $value );
846
+	public function set_summary($value) {
847
+		$this->set_description($value);
848 848
     }
849 849
 
850 850
     /**
@@ -853,8 +853,8 @@  discard block
 block discarded – undo
853 853
 	 * @since 1.0.19
854 854
 	 * @param  int $value New author.
855 855
 	 */
856
-	public function set_author( $value ) {
857
-		$this->set_prop( 'author', (int) $value );
856
+	public function set_author($value) {
857
+		$this->set_prop('author', (int) $value);
858 858
 	}
859 859
 	
860 860
 	/**
@@ -863,8 +863,8 @@  discard block
 block discarded – undo
863 863
 	 * @since 1.0.19
864 864
 	 * @param  int $value New author.
865 865
 	 */
866
-	public function set_owner( $value ) {
867
-		$this->set_author( $value );
866
+	public function set_owner($value) {
867
+		$this->set_author($value);
868 868
     }
869 869
 
870 870
     /**
@@ -873,8 +873,8 @@  discard block
 block discarded – undo
873 873
 	 * @since 1.0.19
874 874
 	 * @param  float $value New price.
875 875
 	 */
876
-	public function set_price( $value ) {
877
-        $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
876
+	public function set_price($value) {
877
+        $this->set_prop('price', (float) wpinv_sanitize_amount($value));
878 878
     }
879 879
 
880 880
     /**
@@ -883,8 +883,8 @@  discard block
 block discarded – undo
883 883
 	 * @since 1.0.19
884 884
 	 * @param  string $value new rule.
885 885
 	 */
886
-	public function set_vat_rule( $value ) {
887
-        $this->set_prop( 'vat_rule', $value );
886
+	public function set_vat_rule($value) {
887
+        $this->set_prop('vat_rule', $value);
888 888
     }
889 889
 
890 890
     /**
@@ -893,8 +893,8 @@  discard block
 block discarded – undo
893 893
 	 * @since 1.0.19
894 894
 	 * @param  string $value new class.
895 895
 	 */
896
-	public function set_vat_class( $value ) {
897
-        $this->set_prop( 'vat_class', $value );
896
+	public function set_vat_class($value) {
897
+        $this->set_prop('vat_class', $value);
898 898
     }
899 899
 
900 900
     /**
@@ -904,13 +904,13 @@  discard block
 block discarded – undo
904 904
 	 * @param  string $value new item type.
905 905
 	 * @return string
906 906
 	 */
907
-	public function set_type( $value ) {
907
+	public function set_type($value) {
908 908
 
909
-        if ( empty( $value ) ) {
909
+        if (empty($value)) {
910 910
             $value = 'custom';
911 911
         }
912 912
 
913
-        $this->set_prop( 'type', $value );
913
+        $this->set_prop('type', $value);
914 914
     }
915 915
 
916 916
     /**
@@ -919,8 +919,8 @@  discard block
 block discarded – undo
919 919
 	 * @since 1.0.19
920 920
 	 * @param  string $value new custom id.
921 921
 	 */
922
-	public function set_custom_id( $value ) {
923
-        $this->set_prop( 'custom_id', $value );
922
+	public function set_custom_id($value) {
923
+        $this->set_prop('custom_id', $value);
924 924
     }
925 925
 
926 926
     /**
@@ -929,8 +929,8 @@  discard block
 block discarded – undo
929 929
 	 * @since 1.0.19
930 930
 	 * @param  string $value new custom name.
931 931
 	 */
932
-	public function set_custom_name( $value ) {
933
-        $this->set_prop( 'custom_name', $value );
932
+	public function set_custom_name($value) {
933
+        $this->set_prop('custom_name', $value);
934 934
     }
935 935
 
936 936
     /**
@@ -939,8 +939,8 @@  discard block
 block discarded – undo
939 939
 	 * @since 1.0.19
940 940
 	 * @param  string $value new custom singular name.
941 941
 	 */
942
-	public function set_custom_singular_name( $value ) {
943
-        $this->set_prop( 'custom_singular_name', $value );
942
+	public function set_custom_singular_name($value) {
943
+        $this->set_prop('custom_singular_name', $value);
944 944
     }
945 945
 
946 946
     /**
@@ -949,8 +949,8 @@  discard block
 block discarded – undo
949 949
 	 * @since 1.0.19
950 950
 	 * @param  int|bool $value whether or not the item is editable.
951 951
 	 */
952
-	public function set_is_editable( $value ) {
953
-		$this->set_prop( 'is_editable', (int) $value );
952
+	public function set_is_editable($value) {
953
+		$this->set_prop('is_editable', (int) $value);
954 954
     }
955 955
 
956 956
     /**
@@ -959,8 +959,8 @@  discard block
 block discarded – undo
959 959
 	 * @since 1.0.19
960 960
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
961 961
 	 */
962
-	public function set_is_dynamic_pricing( $value ) {
963
-        $this->set_prop( 'is_dynamic_pricing', (int) $value );
962
+	public function set_is_dynamic_pricing($value) {
963
+        $this->set_prop('is_dynamic_pricing', (int) $value);
964 964
     }
965 965
 
966 966
     /**
@@ -969,8 +969,8 @@  discard block
 block discarded – undo
969 969
 	 * @since 1.0.19
970 970
 	 * @param  float $value minimum price.
971 971
 	 */
972
-	public function set_minimum_price( $value ) {
973
-        $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
972
+	public function set_minimum_price($value) {
973
+        $this->set_prop('minimum_price', (float) wpinv_sanitize_amount($value));
974 974
     }
975 975
 
976 976
     /**
@@ -979,8 +979,8 @@  discard block
 block discarded – undo
979 979
 	 * @since 1.0.19
980 980
 	 * @param  int|bool $value whether or not dynamic pricing is allowed.
981 981
 	 */
982
-	public function set_is_recurring( $value ) {
983
-        $this->set_prop( 'is_recurring', (int) $value );
982
+	public function set_is_recurring($value) {
983
+        $this->set_prop('is_recurring', (int) $value);
984 984
     }
985 985
 
986 986
     /**
@@ -989,8 +989,8 @@  discard block
 block discarded – undo
989 989
 	 * @since 1.0.19
990 990
 	 * @param  string $value new period.
991 991
 	 */
992
-	public function set_recurring_period( $value ) {
993
-        $this->set_prop( 'recurring_period', $value );
992
+	public function set_recurring_period($value) {
993
+        $this->set_prop('recurring_period', $value);
994 994
     }
995 995
 
996 996
     /**
@@ -999,8 +999,8 @@  discard block
 block discarded – undo
999 999
 	 * @since 1.0.19
1000 1000
 	 * @param  int $value recurring interval.
1001 1001
 	 */
1002
-	public function set_recurring_interval( $value ) {
1003
-        return $this->set_prop( 'recurring_interval', (int) $value );
1002
+	public function set_recurring_interval($value) {
1003
+        return $this->set_prop('recurring_interval', (int) $value);
1004 1004
     }
1005 1005
 
1006 1006
     /**
@@ -1009,8 +1009,8 @@  discard block
 block discarded – undo
1009 1009
 	 * @param  int $value The recurring limit.
1010 1010
 	 * @return int
1011 1011
 	 */
1012
-	public function set_recurring_limit( $value ) {
1013
-        $this->set_prop( 'recurring_limit', (int) $value );
1012
+	public function set_recurring_limit($value) {
1013
+        $this->set_prop('recurring_limit', (int) $value);
1014 1014
     }
1015 1015
 
1016 1016
     /**
@@ -1019,8 +1019,8 @@  discard block
 block discarded – undo
1019 1019
 	 * @since 1.0.19
1020 1020
 	 * @param  int|bool $value whether or not it has a free trial.
1021 1021
 	 */
1022
-	public function set_is_free_trial( $value ) {
1023
-        $this->set_prop( 'is_free_trial', (int) $value );
1022
+	public function set_is_free_trial($value) {
1023
+        $this->set_prop('is_free_trial', (int) $value);
1024 1024
     }
1025 1025
 
1026 1026
     /**
@@ -1029,8 +1029,8 @@  discard block
 block discarded – undo
1029 1029
 	 * @since 1.0.19
1030 1030
 	 * @param  string $value trial period.
1031 1031
 	 */
1032
-	public function set_trial_period( $value ) {
1033
-        $this->set_prop( 'trial_period', $value );
1032
+	public function set_trial_period($value) {
1033
+        $this->set_prop('trial_period', $value);
1034 1034
     }
1035 1035
 
1036 1036
     /**
@@ -1039,8 +1039,8 @@  discard block
 block discarded – undo
1039 1039
 	 * @since 1.0.19
1040 1040
 	 * @param  int $value trial interval.
1041 1041
 	 */
1042
-	public function set_trial_interval( $value ) {
1043
-        $this->set_prop( 'trial_interval', $value );
1042
+	public function set_trial_interval($value) {
1043
+        $this->set_prop('trial_interval', $value);
1044 1044
     }
1045 1045
 
1046 1046
     /**
@@ -1049,11 +1049,11 @@  discard block
 block discarded – undo
1049 1049
      * @deprecated
1050 1050
 	 * @return int item id
1051 1051
      */
1052
-    public function create( $data = array() ) {
1052
+    public function create($data = array()) {
1053 1053
 
1054 1054
 		// Set the properties.
1055
-		if ( is_array( $data ) ) {
1056
-			$this->set_props( $data );
1055
+		if (is_array($data)) {
1056
+			$this->set_props($data);
1057 1057
 		}
1058 1058
 
1059 1059
 		// Save the item.
@@ -1067,8 +1067,8 @@  discard block
 block discarded – undo
1067 1067
      * @deprecated
1068 1068
 	 * @return int item id
1069 1069
      */
1070
-    public function update( $data = array() ) {
1071
-        return $this->create( $data );
1070
+    public function update($data = array()) {
1071
+        return $this->create($data);
1072 1072
     }
1073 1073
 
1074 1074
     /*
@@ -1108,7 +1108,7 @@  discard block
 block discarded – undo
1108 1108
 	 */
1109 1109
     public function has_free_trial() {
1110 1110
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1111
-        return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1111
+        return (bool) apply_filters('wpinv_item_has_free_trial', $has_trial, $this->ID, $this);
1112 1112
     }
1113 1113
 
1114 1114
     /**
@@ -1118,8 +1118,8 @@  discard block
 block discarded – undo
1118 1118
 	 * @return bool
1119 1119
 	 */
1120 1120
     public function is_free() {
1121
-        $is_free   = $this->get_price() == 0;
1122
-        return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1121
+        $is_free = $this->get_price() == 0;
1122
+        return (bool) apply_filters('wpinv_is_free_item', $is_free, $this->ID, $this);
1123 1123
     }
1124 1124
 
1125 1125
     /**
@@ -1128,9 +1128,9 @@  discard block
 block discarded – undo
1128 1128
 	 * @param array|string $status Status to check.
1129 1129
 	 * @return bool
1130 1130
 	 */
1131
-	public function has_status( $status ) {
1132
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1133
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1131
+	public function has_status($status) {
1132
+		$has_status = (is_array($status) && in_array($this->get_status(), $status, true)) || $this->get_status() === $status;
1133
+		return (bool) apply_filters('getpaid_item_has_status', $has_status, $this, $status);
1134 1134
     }
1135 1135
 
1136 1136
     /**
@@ -1139,9 +1139,9 @@  discard block
 block discarded – undo
1139 1139
 	 * @param array|string $type Type to check.
1140 1140
 	 * @return bool
1141 1141
 	 */
1142
-	public function is_type( $type ) {
1143
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1144
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1142
+	public function is_type($type) {
1143
+		$is_type = (is_array($type) && in_array($this->get_type(), $type, true)) || $this->get_type() === $type;
1144
+		return (bool) apply_filters('getpaid_item_is_type', $is_type, $this, $type);
1145 1145
 	}
1146 1146
 
1147 1147
     /**
@@ -1152,7 +1152,7 @@  discard block
 block discarded – undo
1152 1152
 	 */
1153 1153
     public function is_editable() {
1154 1154
         $is_editable = $this->get_is_editable();
1155
-        return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1155
+        return (bool) apply_filters('wpinv_item_is_editable', $is_editable, $this->ID, $this);
1156 1156
 	}
1157 1157
 
1158 1158
 	/**
@@ -1171,11 +1171,11 @@  discard block
 block discarded – undo
1171 1171
     public function can_purchase() {
1172 1172
         $can_purchase = $this->exists();
1173 1173
 
1174
-        if ( ! current_user_can( 'edit_post', $this->ID ) && $this->post_status != 'publish' ) {
1174
+        if (!current_user_can('edit_post', $this->ID) && $this->post_status != 'publish') {
1175 1175
             $can_purchase = false;
1176 1176
         }
1177 1177
 
1178
-        return (bool) apply_filters( 'wpinv_can_purchase_item', $can_purchase, $this );
1178
+        return (bool) apply_filters('wpinv_can_purchase_item', $can_purchase, $this);
1179 1179
     }
1180 1180
 
1181 1181
     /**
@@ -1185,6 +1185,6 @@  discard block
 block discarded – undo
1185 1185
 	 * @return bool
1186 1186
 	 */
1187 1187
     public function supports_dynamic_pricing() {
1188
-        return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1188
+        return (bool) apply_filters('wpinv_item_supports_dynamic_pricing', true, $this);
1189 1189
     }
1190 1190
 }
Please login to merge, or discard this patch.
includes/class-getpaid-daily-maintenance.php 2 patches
Indentation   +103 added lines, -103 removed lines patch added patch discarded remove patch
@@ -12,108 +12,108 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Daily_Maintenance {
14 14
 
15
-	/**
16
-	 * Class constructor.
17
-	 */
18
-	public function __construct(){
19
-
20
-		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
-
23
-		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
-
26
-		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
31
-
32
-	}
33
-
34
-	/**
35
-	 * Schedules a cron to run every day at 7 a.m
36
-	 *
37
-	 */
38
-	public function maybe_create_scheduled_event() {
39
-
40
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
43
-		}
44
-
45
-	}
46
-
47
-	/**
48
-	 * Clears deprecated events.
49
-	 *
50
-	 */
51
-	public function maybe_clear_deprecated_events() {
52
-
53
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
-			update_option( 'wpinv_cleared_old_events', 1 );
57
-		}
58
-
59
-	}
60
-
61
-	/**
62
-	 * Fires the old hook for backwards compatibility.
63
-	 *
64
-	 */
65
-	public function backwards_compat() {
66
-		do_action( 'wpinv_register_schedule_event_daily' );
67
-	}
68
-
69
-	/**
70
-	 * Expires expired subscriptions.
71
-	 *
72
-	 */
73
-	public function maybe_expire_subscriptions() {
74
-
75
-		// Fetch expired subscriptions (skips those that expire today).
76
-		$args  = array(
77
-			'number'             => -1,
78
-			'count_total'        => false,
79
-			'status'             => 'trialling active failing cancelled',
80
-			'date_expires_query' => array(
81
-				'before'    => 'today',
82
-				'inclusive' => false,
83
-			),
84
-		);
85
-
86
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
87
-
88
-		foreach ( $subscriptions->get_results() as $subscription ) {
89
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
-				$subscription->set_status( 'expired' );
91
-				$subscription->save();
92
-			}
93
-		}
94
-
95
-	}
96
-
97
-	/**
98
-	 * Logs cron runs.
99
-	 *
100
-	 */
101
-	public function log_cron_run() {
102
-		wpinv_error_log( 'GetPaid Daily Cron', false );
103
-	}
104
-
105
-	/**
106
-	 * Updates GeoIP databases.
107
-	 *
108
-	 */
109
-	public function maybe_update_geoip_databases() {
110
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
111
-
112
-		if ( false === $updated ) {
113
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
-			do_action( 'getpaid_update_geoip_databases' );
115
-		}
116
-
117
-	}
15
+    /**
16
+     * Class constructor.
17
+     */
18
+    public function __construct(){
19
+
20
+        // Clear deprecated events.
21
+        add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
22
+
23
+        // (Maybe) schedule a cron that runs daily.
24
+        add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
25
+
26
+        // Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
+        add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
+        add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
+        add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
31
+
32
+    }
33
+
34
+    /**
35
+     * Schedules a cron to run every day at 7 a.m
36
+     *
37
+     */
38
+    public function maybe_create_scheduled_event() {
39
+
40
+        if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
+            $timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
+            wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
43
+        }
44
+
45
+    }
46
+
47
+    /**
48
+     * Clears deprecated events.
49
+     *
50
+     */
51
+    public function maybe_clear_deprecated_events() {
52
+
53
+        if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
+            wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
+            update_option( 'wpinv_cleared_old_events', 1 );
57
+        }
58
+
59
+    }
60
+
61
+    /**
62
+     * Fires the old hook for backwards compatibility.
63
+     *
64
+     */
65
+    public function backwards_compat() {
66
+        do_action( 'wpinv_register_schedule_event_daily' );
67
+    }
68
+
69
+    /**
70
+     * Expires expired subscriptions.
71
+     *
72
+     */
73
+    public function maybe_expire_subscriptions() {
74
+
75
+        // Fetch expired subscriptions (skips those that expire today).
76
+        $args  = array(
77
+            'number'             => -1,
78
+            'count_total'        => false,
79
+            'status'             => 'trialling active failing cancelled',
80
+            'date_expires_query' => array(
81
+                'before'    => 'today',
82
+                'inclusive' => false,
83
+            ),
84
+        );
85
+
86
+        $subscriptions = new GetPaid_Subscriptions_Query( $args );
87
+
88
+        foreach ( $subscriptions->get_results() as $subscription ) {
89
+            if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
+                $subscription->set_status( 'expired' );
91
+                $subscription->save();
92
+            }
93
+        }
94
+
95
+    }
96
+
97
+    /**
98
+     * Logs cron runs.
99
+     *
100
+     */
101
+    public function log_cron_run() {
102
+        wpinv_error_log( 'GetPaid Daily Cron', false );
103
+    }
104
+
105
+    /**
106
+     * Updates GeoIP databases.
107
+     *
108
+     */
109
+    public function maybe_update_geoip_databases() {
110
+        $updated = get_transient( 'getpaid_updated_geoip_databases' );
111
+
112
+        if ( false === $updated ) {
113
+            set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
+            do_action( 'getpaid_update_geoip_databases' );
115
+        }
116
+
117
+    }
118 118
 
119 119
 }
Please login to merge, or discard this patch.
Spacing   +26 added lines, -26 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
  * Daily maintenance class.
@@ -15,19 +15,19 @@  discard block
 block discarded – undo
15 15
 	/**
16 16
 	 * Class constructor.
17 17
 	 */
18
-	public function __construct(){
18
+	public function __construct() {
19 19
 
20 20
 		// Clear deprecated events.
21
-		add_action( 'wp', array( $this, 'maybe_clear_deprecated_events' ) );
21
+		add_action('wp', array($this, 'maybe_clear_deprecated_events'));
22 22
 
23 23
 		// (Maybe) schedule a cron that runs daily.
24
-		add_action( 'wp', array( $this, 'maybe_create_scheduled_event' ) );
24
+		add_action('wp', array($this, 'maybe_create_scheduled_event'));
25 25
 
26 26
 		// Fired everyday at 7 a.m (this might vary for sites with few visitors)
27
-		add_action( 'getpaid_daily_maintenance', array( $this, 'log_cron_run' ) );
28
-		add_action( 'getpaid_daily_maintenance', array( $this, 'backwards_compat' ) );
29
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_expire_subscriptions' ) );
30
-		add_action( 'getpaid_daily_maintenance', array( $this, 'maybe_update_geoip_databases' ) );
27
+		add_action('getpaid_daily_maintenance', array($this, 'log_cron_run'));
28
+		add_action('getpaid_daily_maintenance', array($this, 'backwards_compat'));
29
+		add_action('getpaid_daily_maintenance', array($this, 'maybe_expire_subscriptions'));
30
+		add_action('getpaid_daily_maintenance', array($this, 'maybe_update_geoip_databases'));
31 31
 
32 32
 	}
33 33
 
@@ -37,9 +37,9 @@  discard block
 block discarded – undo
37 37
 	 */
38 38
 	public function maybe_create_scheduled_event() {
39 39
 
40
-		if ( ! wp_next_scheduled( 'getpaid_daily_maintenance' ) ) {
41
-			$timestamp = strtotime( 'tomorrow 07:00:00', current_time( 'timestamp' ) );
42
-			wp_schedule_event( $timestamp, 'daily', 'getpaid_daily_maintenance' );
40
+		if (!wp_next_scheduled('getpaid_daily_maintenance')) {
41
+			$timestamp = strtotime('tomorrow 07:00:00', current_time('timestamp'));
42
+			wp_schedule_event($timestamp, 'daily', 'getpaid_daily_maintenance');
43 43
 		}
44 44
 
45 45
 	}
@@ -50,10 +50,10 @@  discard block
 block discarded – undo
50 50
 	 */
51 51
 	public function maybe_clear_deprecated_events() {
52 52
 
53
-		if ( ! get_option( 'wpinv_cleared_old_events' ) ) {
54
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_twicedaily' );
55
-			wp_clear_scheduled_hook( 'wpinv_register_schedule_event_daily' );
56
-			update_option( 'wpinv_cleared_old_events', 1 );
53
+		if (!get_option('wpinv_cleared_old_events')) {
54
+			wp_clear_scheduled_hook('wpinv_register_schedule_event_twicedaily');
55
+			wp_clear_scheduled_hook('wpinv_register_schedule_event_daily');
56
+			update_option('wpinv_cleared_old_events', 1);
57 57
 		}
58 58
 
59 59
 	}
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
 	 *
64 64
 	 */
65 65
 	public function backwards_compat() {
66
-		do_action( 'wpinv_register_schedule_event_daily' );
66
+		do_action('wpinv_register_schedule_event_daily');
67 67
 	}
68 68
 
69 69
 	/**
@@ -73,7 +73,7 @@  discard block
 block discarded – undo
73 73
 	public function maybe_expire_subscriptions() {
74 74
 
75 75
 		// Fetch expired subscriptions (skips those that expire today).
76
-		$args  = array(
76
+		$args = array(
77 77
 			'number'             => -1,
78 78
 			'count_total'        => false,
79 79
 			'status'             => 'trialling active failing cancelled',
@@ -83,11 +83,11 @@  discard block
 block discarded – undo
83 83
 			),
84 84
 		);
85 85
 
86
-		$subscriptions = new GetPaid_Subscriptions_Query( $args );
86
+		$subscriptions = new GetPaid_Subscriptions_Query($args);
87 87
 
88
-		foreach ( $subscriptions->get_results() as $subscription ) {
89
-			if ( apply_filters( 'getpaid_daily_maintenance_should_expire_subscription', true, $subscription ) ) {
90
-				$subscription->set_status( 'expired' );
88
+		foreach ($subscriptions->get_results() as $subscription) {
89
+			if (apply_filters('getpaid_daily_maintenance_should_expire_subscription', true, $subscription)) {
90
+				$subscription->set_status('expired');
91 91
 				$subscription->save();
92 92
 			}
93 93
 		}
@@ -99,7 +99,7 @@  discard block
 block discarded – undo
99 99
 	 *
100 100
 	 */
101 101
 	public function log_cron_run() {
102
-		wpinv_error_log( 'GetPaid Daily Cron', false );
102
+		wpinv_error_log('GetPaid Daily Cron', false);
103 103
 	}
104 104
 
105 105
 	/**
@@ -107,11 +107,11 @@  discard block
 block discarded – undo
107 107
 	 *
108 108
 	 */
109 109
 	public function maybe_update_geoip_databases() {
110
-		$updated = get_transient( 'getpaid_updated_geoip_databases' );
110
+		$updated = get_transient('getpaid_updated_geoip_databases');
111 111
 
112
-		if ( false === $updated ) {
113
-			set_transient( 'getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS );
114
-			do_action( 'getpaid_update_geoip_databases' );
112
+		if (false === $updated) {
113
+			set_transient('getpaid_updated_geoip_databases', 1, 15 * DAY_IN_SECONDS);
114
+			do_action('getpaid_update_geoip_databases');
115 115
 		}
116 116
 
117 117
 	}
Please login to merge, or discard this patch.
templates/invoice-receipt.php 1 patch
Spacing   +38 added lines, -38 removed lines patch added patch discarded remove patch
@@ -7,64 +7,64 @@  discard block
 block discarded – undo
7 7
  * @version 1.0.19
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 // Fetch the invoice.
13
-$invoice = new WPInv_Invoice( $invoice );
13
+$invoice = new WPInv_Invoice($invoice);
14 14
 
15 15
 // @deprecated
16
-do_action( 'wpinv_success_content_before', $invoice );
17
-do_action( 'wpinv_before_receipt', $invoice );
16
+do_action('wpinv_success_content_before', $invoice);
17
+do_action('wpinv_before_receipt', $invoice);
18 18
 
19 19
 wpinv_print_errors();
20 20
 
21 21
 // Prepare header text.
22
-if ( $invoice->is_paid() ) {
22
+if ($invoice->is_paid()) {
23 23
 
24 24
     $alert = aui()->alert(
25 25
         array(
26 26
             'type'    => 'success',
27
-            'content' => __( 'Thank you for your payment!', 'invoicing' ),
27
+            'content' => __('Thank you for your payment!', 'invoicing'),
28 28
         )
29 29
     );
30 30
 
31
-} else if ( $invoice->is_refunded() ) {
31
+} else if ($invoice->is_refunded()) {
32 32
 
33 33
     $alert = aui()->alert(
34 34
         array(
35 35
             'type'    => 'info',
36
-            'content' => __( 'This invoice was refunded.', 'invoicing' ),
36
+            'content' => __('This invoice was refunded.', 'invoicing'),
37 37
         )
38 38
     );
39 39
 
40
-} else if ( $invoice->is_held() ) {
40
+} else if ($invoice->is_held()) {
41 41
 
42 42
     $alert = aui()->alert(
43 43
         array(
44 44
             'type'    => 'info',
45
-            'content' => __( 'This invoice will be processed as soon we verify your payment.', 'invoicing' ),
45
+            'content' => __('This invoice will be processed as soon we verify your payment.', 'invoicing'),
46 46
         )
47 47
     );
48 48
 
49
-} else if ( $invoice->needs_payment() ) {
49
+} else if ($invoice->needs_payment()) {
50 50
 
51
-    if ( ! empty( $_GET['token'] ) ) {
51
+    if (!empty($_GET['token'])) {
52 52
 
53 53
         $alert = aui()->alert(
54 54
             array(
55 55
                 'type'    => 'info',
56
-                'content' => __( "Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing' ),
56
+                'content' => __("Sometimes it takes a few minutes for us to verify your payment. We'll notify you as soon as we've verified the payment.", 'invoicing'),
57 57
             )
58 58
         );
59 59
 
60
-    } else if ( $invoice->is_due() ) {
60
+    } else if ($invoice->is_due()) {
61 61
 
62 62
         $alert = aui()->alert(
63 63
             array(
64 64
                 'type'    => 'danger',
65 65
                 'content' => sprintf(
66
-                    __( 'This invoice was due on %.', 'invoicing' ),
67
-                    getpaid_format_date_value( $invoice->get_due_date() )
66
+                    __('This invoice was due on %.', 'invoicing'),
67
+                    getpaid_format_date_value($invoice->get_due_date())
68 68
                 ),
69 69
             )
70 70
         );
@@ -74,7 +74,7 @@  discard block
 block discarded – undo
74 74
         $alert = aui()->alert(
75 75
             array(
76 76
                 'type'    => 'warning',
77
-                'content' => __( 'This invoice needs payment.', 'invoicing' ),
77
+                'content' => __('This invoice needs payment.', 'invoicing'),
78 78
             )
79 79
         );
80 80
 
@@ -89,19 +89,19 @@  discard block
 block discarded – undo
89 89
 
90 90
         'pay' => array(
91 91
             'url'   => $invoice->get_checkout_payment_url(),
92
-            'name'  => __( 'Pay For Invoice', 'invoicing' ),
92
+            'name'  => __('Pay For Invoice', 'invoicing'),
93 93
             'class' => 'btn-success',
94 94
         ),
95 95
 
96 96
         'view' => array(
97 97
             'url'   => $invoice->get_view_url(),
98
-            'name'  => __( 'View Invoice', 'invoicing' ),
98
+            'name'  => __('View Invoice', 'invoicing'),
99 99
             'class' => 'btn-primary',
100 100
         ),
101 101
 
102 102
         'history' => array(
103 103
             'url'   => wpinv_get_history_page_uri(),
104
-            'name'  => __( 'Invoice History', 'invoicing' ),
104
+            'name'  => __('Invoice History', 'invoicing'),
105 105
             'class' => 'btn-warning',
106 106
         ),
107 107
 
@@ -110,12 +110,12 @@  discard block
 block discarded – undo
110 110
 
111 111
 );
112 112
 
113
-if ( ( ! $invoice->needs_payment() || $invoice->is_held() ) && isset( $actions['pay'] ) ) {
114
-    unset( $actions['pay'] );
113
+if ((!$invoice->needs_payment() || $invoice->is_held()) && isset($actions['pay'])) {
114
+    unset($actions['pay']);
115 115
 }
116 116
 
117
-if ( ! is_user_logged_in() && isset( $actions['history'] ) ) {
118
-    unset( $actions['history'] );
117
+if (!is_user_logged_in() && isset($actions['history'])) {
118
+    unset($actions['history']);
119 119
 }
120 120
 
121 121
 ?>
@@ -124,19 +124,19 @@  discard block
 block discarded – undo
124 124
 
125 125
         <?php
126 126
         
127
-            do_action( 'wpinv_receipt_start', $invoice );
127
+            do_action('wpinv_receipt_start', $invoice);
128 128
 
129
-            if ( ! empty( $actions ) ) {
129
+            if (!empty($actions)) {
130 130
 
131 131
                 echo '<div class="wpinv-receipt-actions text-right mt-1 mb-4">';
132 132
 
133
-                foreach ( $actions as $key => $action ) {
133
+                foreach ($actions as $key => $action) {
134 134
 
135
-                    $key    = sanitize_html_class( $key );
136
-                    $class  = empty( $action['class'] ) ? 'btn-dark' : sanitize_html_class( $action['class'] );
137
-                    $url    = empty( $action['url'] ) ? '#' : esc_url( $action['url'] );
138
-                    $attrs  = empty( $action['attrs'] ) ? '' : $action['attrs'];
139
-                    $anchor = sanitize_text_field( $action['name'] );
135
+                    $key    = sanitize_html_class($key);
136
+                    $class  = empty($action['class']) ? 'btn-dark' : sanitize_html_class($action['class']);
137
+                    $url    = empty($action['url']) ? '#' : esc_url($action['url']);
138
+                    $attrs  = empty($action['attrs']) ? '' : $action['attrs'];
139
+                    $anchor = sanitize_text_field($action['name']);
140 140
 
141 141
                     echo "<a href='$url' class='btn btn-sm ml-1 $class $key' $attrs>$anchor</a>";
142 142
                 }
@@ -152,21 +152,21 @@  discard block
 block discarded – undo
152 152
         <div class="wpinv-receipt-details">
153 153
 
154 154
             <h4 class="wpinv-details-t mb-3 mt-3">
155
-                <?php echo apply_filters( 'wpinv_receipt_details_title', __( 'Invoice Details', 'invoicing' ), $invoice ); ?>
155
+                <?php echo apply_filters('wpinv_receipt_details_title', __('Invoice Details', 'invoicing'), $invoice); ?>
156 156
             </h4>
157 157
 
158
-            <?php getpaid_invoice_meta( $invoice ); ?>
158
+            <?php getpaid_invoice_meta($invoice); ?>
159 159
 
160 160
         </div>
161 161
 
162
-        <?php echo getpaid_display_invoice_subscriptions( $invoice ); ?>
162
+        <?php echo getpaid_display_invoice_subscriptions($invoice); ?>
163 163
 
164
-        <?php do_action( 'wpinv_receipt_end', $invoice ); ?>
164
+        <?php do_action('wpinv_receipt_end', $invoice); ?>
165 165
 
166 166
     </div>
167 167
 
168 168
 <?php
169 169
 
170 170
 // @deprecated
171
-do_action( 'wpinv_success_content_after', $invoice );
172
-do_action( 'wpinv_after_receipt', $invoice );
171
+do_action('wpinv_success_content_after', $invoice);
172
+do_action('wpinv_after_receipt', $invoice);
Please login to merge, or discard this patch.
templates/wpinv-payment-processing.php 1 patch
Spacing   +3 added lines, -3 removed lines patch added patch discarded remove patch
@@ -4,8 +4,8 @@  discard block
 block discarded – undo
4 4
         <?php 
5 5
             echo
6 6
             wp_sprintf(
7
-                __( 'Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing' ),
8
-                esc_url_raw( remove_query_arg( 'payment-confirm' ) )
7
+                __('Your payment is processing. This page will reload automatically in 10 seconds. If it does not, click <a href="%s">here</a>.', 'invoicing'),
8
+                esc_url_raw(remove_query_arg('payment-confirm'))
9 9
             );
10 10
         ?>
11 11
         <i class="fa fa-spin fa-refresh"></i>
@@ -14,7 +14,7 @@  discard block
 block discarded – undo
14 14
     <script type="text/javascript">
15 15
         setTimeout(
16 16
             function(){
17
-                window.location.href = '<?php echo esc_url_raw( remove_query_arg( 'payment-confirm' ) ) ;?>';
17
+                window.location.href = '<?php echo esc_url_raw(remove_query_arg('payment-confirm')); ?>';
18 18
             },
19 19
             10000
20 20
         );
Please login to merge, or discard this patch.
includes/admin/class-getpaid-metaboxes.php 2 patches
Indentation   +240 added lines, -240 removed lines patch added patch discarded remove patch
@@ -12,276 +12,276 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Metaboxes {
14 14
 
15
-	/**
16
-	 * Only save metaboxes once.
17
-	 *
18
-	 * @var boolean
19
-	 */
20
-	private static $saved_meta_boxes = false;
21
-
22 15
     /**
23
-	 * Hook in methods.
24
-	 */
25
-	public static function init() {
26
-
27
-		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
29
-
30
-		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
32
-
33
-		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
35
-
36
-		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
-	}
39
-
40
-	/**
41
-	 * Register core metaboxes.
42
-	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
16
+     * Only save metaboxes once.
17
+     *
18
+     * @var boolean
19
+     */
20
+    private static $saved_meta_boxes = false;
44 21
 
45
-		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
47
-
48
-		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type );
50
-
51
-		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
53
-
54
-		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
-		}
58
-
59
-	}
22
+    /**
23
+     * Hook in methods.
24
+     */
25
+    public static function init() {
60 26
 
61
-	/**
62
-	 * Register core metaboxes.
63
-	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type ) {
27
+        // Register metaboxes.
28
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
65 29
 
66
-		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
30
+        // Remove metaboxes.
31
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
68 32
 
69
-			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
33
+        // Rename metaboxes.
34
+        add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
71 35
 
72
-			// Payment form information.
73
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
36
+        // Save metaboxes.
37
+        add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
38
+    }
74 39
 
75
-		}
40
+    /**
41
+     * Register core metaboxes.
42
+     */
43
+    public static function add_meta_boxes( $post_type, $post ) {
76 44
 
77
-	}
45
+        // For invoices...
46
+        self::add_invoice_meta_boxes( $post_type, $post );
78 47
 
79
-	/**
80
-	 * Register core metaboxes.
81
-	 */
82
-	protected static function add_item_meta_boxes( $post_type ) {
48
+        // For payment forms.
49
+        self::add_payment_form_meta_boxes( $post_type );
83 50
 
84
-		if ( $post_type == 'wpi_item' ) {
51
+        // For invoice items.
52
+        self::add_item_meta_boxes( $post_type );
85 53
 
86
-			// Item details.
87
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
54
+        // For invoice discounts.
55
+        if ( $post_type == 'wpi_discount' ) {
56
+            add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
57
+        }
88 58
 
89
-			// If taxes are enabled, register the tax metabox.
90
-			if ( wpinv_use_taxes() ) {
91
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
-			}
59
+    }
93 60
 
94
-			// Item info.
95
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
61
+    /**
62
+     * Register core metaboxes.
63
+     */
64
+    protected static function add_payment_form_meta_boxes( $post_type ) {
96 65
 
97
-		}
66
+        // For payment forms.
67
+        if ( $post_type == 'wpi_payment_form' ) {
98 68
 
99
-	}
69
+            // Design payment form.
70
+            add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
100 71
 
101
-	/**
102
-	 * Register invoice metaboxes.
103
-	 */
104
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
72
+            // Payment form information.
73
+            add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
105 74
 
106
-		// For invoices...
107
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
-			$invoice = new WPInv_Invoice( $post );
75
+        }
109 76
 
110
-			// Resend invoice.
111
-			if ( ! $invoice->is_draft() ) {
77
+    }
112 78
 
113
-				add_meta_box(
114
-					'wpinv-mb-resend-invoice',
115
-					sprintf(
116
-						__( 'Resend %s', 'invoicing' ),
117
-						ucfirst( $invoice->get_invoice_quote_type() )
118
-					),
119
-					'GetPaid_Meta_Box_Resend_Invoice::output',
120
-					$post_type,
121
-					'side',
122
-					'low'
123
-				);
79
+    /**
80
+     * Register core metaboxes.
81
+     */
82
+    protected static function add_item_meta_boxes( $post_type ) {
124 83
 
125
-			}
84
+        if ( $post_type == 'wpi_item' ) {
126 85
 
127
-			// Subscriptions.
128
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
129
-			if ( ! empty( $subscriptions ) ) {
86
+            // Item details.
87
+            add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
130 88
 
131
-				if ( is_array( $subscriptions ) ) {
132
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
133
-				} else {
134
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
135
-				}
89
+            // If taxes are enabled, register the tax metabox.
90
+            if ( wpinv_use_taxes() ) {
91
+                add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
92
+            }
136 93
 
137
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
138
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
139
-				}
94
+            // Item info.
95
+            add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
140 96
 
141
-			}
97
+        }
142 98
 
143
-			// Invoice details.
144
-			add_meta_box(
145
-				'wpinv-details',
146
-				sprintf(
147
-					__( '%s Details', 'invoicing' ),
148
-					ucfirst( $invoice->get_invoice_quote_type() )
149
-				),
150
-				'GetPaid_Meta_Box_Invoice_Details::output',
151
-				$post_type,
152
-				'side'
153
-			);
154
-
155
-			// Payment details.
156
-			if ( ! $invoice->is_draft() ) {
157
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
158
-			}
99
+    }
159 100
 
160
-			// Billing details.
161
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
101
+    /**
102
+     * Register invoice metaboxes.
103
+     */
104
+    protected static function add_invoice_meta_boxes( $post_type, $post ) {
105
+
106
+        // For invoices...
107
+        if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
+            $invoice = new WPInv_Invoice( $post );
109
+
110
+            // Resend invoice.
111
+            if ( ! $invoice->is_draft() ) {
112
+
113
+                add_meta_box(
114
+                    'wpinv-mb-resend-invoice',
115
+                    sprintf(
116
+                        __( 'Resend %s', 'invoicing' ),
117
+                        ucfirst( $invoice->get_invoice_quote_type() )
118
+                    ),
119
+                    'GetPaid_Meta_Box_Resend_Invoice::output',
120
+                    $post_type,
121
+                    'side',
122
+                    'low'
123
+                );
124
+
125
+            }
126
+
127
+            // Subscriptions.
128
+            $subscriptions = getpaid_get_invoice_subscriptions( $invoice );
129
+            if ( ! empty( $subscriptions ) ) {
130
+
131
+                if ( is_array( $subscriptions ) ) {
132
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
133
+                } else {
134
+                    add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
135
+                }
136
+
137
+                if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
138
+                    add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
139
+                }
140
+
141
+            }
142
+
143
+            // Invoice details.
144
+            add_meta_box(
145
+                'wpinv-details',
146
+                sprintf(
147
+                    __( '%s Details', 'invoicing' ),
148
+                    ucfirst( $invoice->get_invoice_quote_type() )
149
+                ),
150
+                'GetPaid_Meta_Box_Invoice_Details::output',
151
+                $post_type,
152
+                'side'
153
+            );
154
+
155
+            // Payment details.
156
+            if ( ! $invoice->is_draft() ) {
157
+                add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
158
+            }
159
+
160
+            // Billing details.
161
+            add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
162 162
 			
163
-			// Invoice items.
164
-			add_meta_box(
165
-				'wpinv-items',
166
-				sprintf(
167
-					__( '%s Items', 'invoicing' ),
168
-					ucfirst( $invoice->get_invoice_quote_type() )
169
-				),
170
-				'GetPaid_Meta_Box_Invoice_Items::output',
171
-				$post_type,
172
-				'normal',
173
-				'high'
174
-			);
163
+            // Invoice items.
164
+            add_meta_box(
165
+                'wpinv-items',
166
+                sprintf(
167
+                    __( '%s Items', 'invoicing' ),
168
+                    ucfirst( $invoice->get_invoice_quote_type() )
169
+                ),
170
+                'GetPaid_Meta_Box_Invoice_Items::output',
171
+                $post_type,
172
+                'normal',
173
+                'high'
174
+            );
175 175
 			
176
-			// Invoice notes.
177
-			add_meta_box(
178
-				'wpinv-notes',
179
-				sprintf(
180
-					__( '%s Notes', 'invoicing' ),
181
-					ucfirst( $invoice->get_invoice_quote_type() )
182
-				),
183
-				'WPInv_Meta_Box_Notes::output',
184
-				$post_type,
185
-				'side',
186
-				'low'
187
-			);
188
-
189
-			// Shipping Address.
190
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
192
-			}
193
-
194
-			// Payment form information.
195
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
197
-			}
198
-
199
-		}
200
-
201
-	}
202
-
203
-	/**
204
-	 * Remove some metaboxes.
205
-	 */
206
-	public static function remove_meta_boxes() {
207
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
208
-	}
209
-
210
-	/**
211
-	 * Rename other metaboxes.
212
-	 */
213
-	public static function rename_meta_boxes() {
176
+            // Invoice notes.
177
+            add_meta_box(
178
+                'wpinv-notes',
179
+                sprintf(
180
+                    __( '%s Notes', 'invoicing' ),
181
+                    ucfirst( $invoice->get_invoice_quote_type() )
182
+                ),
183
+                'WPInv_Meta_Box_Notes::output',
184
+                $post_type,
185
+                'side',
186
+                'low'
187
+            );
188
+
189
+            // Shipping Address.
190
+            if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
+                add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
192
+            }
193
+
194
+            // Payment form information.
195
+            if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
+                add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
197
+            }
198
+
199
+        }
200
+
201
+    }
202
+
203
+    /**
204
+     * Remove some metaboxes.
205
+     */
206
+    public static function remove_meta_boxes() {
207
+        remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
208
+    }
209
+
210
+    /**
211
+     * Rename other metaboxes.
212
+     */
213
+    public static function rename_meta_boxes() {
214 214
 		
215
-	}
216
-
217
-	/**
218
-	 * Check if we're saving, then trigger an action based on the post type.
219
-	 *
220
-	 * @param  int    $post_id Post ID.
221
-	 * @param  object $post Post object.
222
-	 */
223
-	public static function save_meta_boxes( $post_id, $post ) {
224
-		$post_id = absint( $post_id );
225
-		$data    = wp_unslash( $_POST );
226
-
227
-		// Do not save for ajax requests.
228
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
229
-			return;
230
-		}
231
-
232
-		// $post_id and $post are required
233
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
234
-			return;
235
-		}
236
-
237
-		// Dont' save meta boxes for revisions or autosaves.
238
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
239
-			return;
240
-		}
241
-
242
-		// Check the nonce.
243
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
244
-			return;
245
-		}
246
-
247
-		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
249
-			return;
250
-		}
251
-
252
-		// Check user has permission to edit.
253
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
254
-			return;
255
-		}
256
-
257
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
258
-
259
-			// We need this save event to run once to avoid potential endless loops.
260
-			self::$saved_meta_boxes = true;
261
-
262
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
263
-
264
-		}
265
-
266
-		// Ensure this is our post type.
267
-		$post_types_map = array(
268
-			'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
269
-			'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
270
-			'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
271
-		);
272
-
273
-		// Is this our post type?
274
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
275
-			return;
276
-		}
277
-
278
-		// We need this save event to run once to avoid potential endless loops.
279
-		self::$saved_meta_boxes = true;
215
+    }
216
+
217
+    /**
218
+     * Check if we're saving, then trigger an action based on the post type.
219
+     *
220
+     * @param  int    $post_id Post ID.
221
+     * @param  object $post Post object.
222
+     */
223
+    public static function save_meta_boxes( $post_id, $post ) {
224
+        $post_id = absint( $post_id );
225
+        $data    = wp_unslash( $_POST );
226
+
227
+        // Do not save for ajax requests.
228
+        if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
229
+            return;
230
+        }
231
+
232
+        // $post_id and $post are required
233
+        if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
234
+            return;
235
+        }
236
+
237
+        // Dont' save meta boxes for revisions or autosaves.
238
+        if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
239
+            return;
240
+        }
241
+
242
+        // Check the nonce.
243
+        if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
244
+            return;
245
+        }
246
+
247
+        // Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
+        if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
249
+            return;
250
+        }
251
+
252
+        // Check user has permission to edit.
253
+        if ( ! current_user_can( 'edit_post', $post_id ) ) {
254
+            return;
255
+        }
256
+
257
+        if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
258
+
259
+            // We need this save event to run once to avoid potential endless loops.
260
+            self::$saved_meta_boxes = true;
261
+
262
+            return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
263
+
264
+        }
265
+
266
+        // Ensure this is our post type.
267
+        $post_types_map = array(
268
+            'wpi_item'         => 'GetPaid_Meta_Box_Item_Details',
269
+            'wpi_payment_form' => 'GetPaid_Meta_Box_Payment_Form',
270
+            'wpi_discount'     => 'GetPaid_Meta_Box_Discount_Details',
271
+        );
272
+
273
+        // Is this our post type?
274
+        if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
275
+            return;
276
+        }
277
+
278
+        // We need this save event to run once to avoid potential endless loops.
279
+        self::$saved_meta_boxes = true;
280 280
 		
281
-		// Save the post.
282
-		$class = $post_types_map[ $post->post_type ];
283
-		$class::save( $post_id, $_POST, $post );
281
+        // Save the post.
282
+        $class = $post_types_map[ $post->post_type ];
283
+        $class::save( $post_id, $_POST, $post );
284 284
 
285
-	}
285
+    }
286 286
 
287 287
 }
Please login to merge, or discard this patch.
Spacing   +62 added lines, -62 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
  * Metaboxes Admin Class
@@ -25,35 +25,35 @@  discard block
 block discarded – undo
25 25
 	public static function init() {
26 26
 
27 27
 		// Register metaboxes.
28
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2 );
28
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::add_meta_boxes', 5, 2);
29 29
 
30 30
 		// Remove metaboxes.
31
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30 );
31
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::remove_meta_boxes', 30);
32 32
 
33 33
 		// Rename metaboxes.
34
-		add_action( 'add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45 );
34
+		add_action('add_meta_boxes', 'GetPaid_Metaboxes::rename_meta_boxes', 45);
35 35
 
36 36
 		// Save metaboxes.
37
-		add_action( 'save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2 );
37
+		add_action('save_post', 'GetPaid_Metaboxes::save_meta_boxes', 1, 2);
38 38
 	}
39 39
 
40 40
 	/**
41 41
 	 * Register core metaboxes.
42 42
 	 */
43
-	public static function add_meta_boxes( $post_type, $post ) {
43
+	public static function add_meta_boxes($post_type, $post) {
44 44
 
45 45
 		// For invoices...
46
-		self::add_invoice_meta_boxes( $post_type, $post );
46
+		self::add_invoice_meta_boxes($post_type, $post);
47 47
 
48 48
 		// For payment forms.
49
-		self::add_payment_form_meta_boxes( $post_type );
49
+		self::add_payment_form_meta_boxes($post_type);
50 50
 
51 51
 		// For invoice items.
52
-		self::add_item_meta_boxes( $post_type );
52
+		self::add_item_meta_boxes($post_type);
53 53
 
54 54
 		// For invoice discounts.
55
-		if ( $post_type == 'wpi_discount' ) {
56
-			add_meta_box( 'wpinv_discount_details', __( 'Discount Details', 'invoicing' ), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high' );
55
+		if ($post_type == 'wpi_discount') {
56
+			add_meta_box('wpinv_discount_details', __('Discount Details', 'invoicing'), 'GetPaid_Meta_Box_Discount_Details::output', 'wpi_discount', 'normal', 'high');
57 57
 		}
58 58
 
59 59
 	}
@@ -61,16 +61,16 @@  discard block
 block discarded – undo
61 61
 	/**
62 62
 	 * Register core metaboxes.
63 63
 	 */
64
-	protected static function add_payment_form_meta_boxes( $post_type ) {
64
+	protected static function add_payment_form_meta_boxes($post_type) {
65 65
 
66 66
 		// For payment forms.
67
-		if ( $post_type == 'wpi_payment_form' ) {
67
+		if ($post_type == 'wpi_payment_form') {
68 68
 
69 69
 			// Design payment form.
70
-			add_meta_box( 'wpinv-payment-form-design', __( 'Payment Form', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal' );
70
+			add_meta_box('wpinv-payment-form-design', __('Payment Form', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form::output', 'wpi_payment_form', 'normal');
71 71
 
72 72
 			// Payment form information.
73
-			add_meta_box( 'wpinv-payment-form-info', __( 'Details', 'invoicing' ), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side' );
73
+			add_meta_box('wpinv-payment-form-info', __('Details', 'invoicing'), 'GetPaid_Meta_Box_Payment_Form_Info::output', 'wpi_payment_form', 'side');
74 74
 
75 75
 		}
76 76
 
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
 	/**
80 80
 	 * Register core metaboxes.
81 81
 	 */
82
-	protected static function add_item_meta_boxes( $post_type ) {
82
+	protected static function add_item_meta_boxes($post_type) {
83 83
 
84
-		if ( $post_type == 'wpi_item' ) {
84
+		if ($post_type == 'wpi_item') {
85 85
 
86 86
 			// Item details.
87
-			add_meta_box( 'wpinv_item_details', __( 'Item Details', 'invoicing' ), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high' );
87
+			add_meta_box('wpinv_item_details', __('Item Details', 'invoicing'), 'GetPaid_Meta_Box_Item_Details::output', 'wpi_item', 'normal', 'high');
88 88
 
89 89
 			// If taxes are enabled, register the tax metabox.
90
-			if ( wpinv_use_taxes() ) {
91
-				add_meta_box( 'wpinv_item_vat', __( 'Tax', 'invoicing' ), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high' );
90
+			if (wpinv_use_taxes()) {
91
+				add_meta_box('wpinv_item_vat', __('Tax', 'invoicing'), 'GetPaid_Meta_Box_Item_VAT::output', 'wpi_item', 'normal', 'high');
92 92
 			}
93 93
 
94 94
 			// Item info.
95
-			add_meta_box( 'wpinv_field_item_info', __( 'Item info', 'invoicing' ), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core' );
95
+			add_meta_box('wpinv_field_item_info', __('Item info', 'invoicing'), 'GetPaid_Meta_Box_Item_Info::output', 'wpi_item', 'side', 'core');
96 96
 
97 97
 		}
98 98
 
@@ -101,20 +101,20 @@  discard block
 block discarded – undo
101 101
 	/**
102 102
 	 * Register invoice metaboxes.
103 103
 	 */
104
-	protected static function add_invoice_meta_boxes( $post_type, $post ) {
104
+	protected static function add_invoice_meta_boxes($post_type, $post) {
105 105
 
106 106
 		// For invoices...
107
-		if ( getpaid_is_invoice_post_type( $post_type ) ) {
108
-			$invoice = new WPInv_Invoice( $post );
107
+		if (getpaid_is_invoice_post_type($post_type)) {
108
+			$invoice = new WPInv_Invoice($post);
109 109
 
110 110
 			// Resend invoice.
111
-			if ( ! $invoice->is_draft() ) {
111
+			if (!$invoice->is_draft()) {
112 112
 
113 113
 				add_meta_box(
114 114
 					'wpinv-mb-resend-invoice',
115 115
 					sprintf(
116
-						__( 'Resend %s', 'invoicing' ),
117
-						ucfirst( $invoice->get_invoice_quote_type() )
116
+						__('Resend %s', 'invoicing'),
117
+						ucfirst($invoice->get_invoice_quote_type())
118 118
 					),
119 119
 					'GetPaid_Meta_Box_Resend_Invoice::output',
120 120
 					$post_type,
@@ -125,17 +125,17 @@  discard block
 block discarded – undo
125 125
 			}
126 126
 
127 127
 			// Subscriptions.
128
-			$subscriptions = getpaid_get_invoice_subscriptions( $invoice );
129
-			if ( ! empty( $subscriptions ) ) {
128
+			$subscriptions = getpaid_get_invoice_subscriptions($invoice);
129
+			if (!empty($subscriptions)) {
130 130
 
131
-				if ( is_array( $subscriptions ) ) {
132
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Related Subscriptions', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced' );
131
+				if (is_array($subscriptions)) {
132
+					add_meta_box('wpinv-mb-subscriptions', __('Related Subscriptions', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_related', $post_type, 'advanced');
133 133
 				} else {
134
-					add_meta_box( 'wpinv-mb-subscriptions', __( 'Subscription Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced' );
134
+					add_meta_box('wpinv-mb-subscriptions', __('Subscription Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output', $post_type, 'advanced');
135 135
 				}
136 136
 
137
-				if ( getpaid_count_subscription_invoices( $invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id() ) > 1 ) {
138
-					add_meta_box( 'wpinv-mb-subscription-invoices', __( 'Related Payments', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced' );
137
+				if (getpaid_count_subscription_invoices($invoice->is_renewal() ? $invoice->get_parent_id() : $invoice->get_id()) > 1) {
138
+					add_meta_box('wpinv-mb-subscription-invoices', __('Related Payments', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Subscription::output_invoices', $post_type, 'advanced');
139 139
 				}
140 140
 
141 141
 			}
@@ -144,8 +144,8 @@  discard block
 block discarded – undo
144 144
 			add_meta_box(
145 145
 				'wpinv-details',
146 146
 				sprintf(
147
-					__( '%s Details', 'invoicing' ),
148
-					ucfirst( $invoice->get_invoice_quote_type() )
147
+					__('%s Details', 'invoicing'),
148
+					ucfirst($invoice->get_invoice_quote_type())
149 149
 				),
150 150
 				'GetPaid_Meta_Box_Invoice_Details::output',
151 151
 				$post_type,
@@ -153,19 +153,19 @@  discard block
 block discarded – undo
153 153
 			);
154 154
 
155 155
 			// Payment details.
156
-			if ( ! $invoice->is_draft() ) {
157
-				add_meta_box( 'wpinv-payment-meta', __( 'Payment Meta', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default' );
156
+			if (!$invoice->is_draft()) {
157
+				add_meta_box('wpinv-payment-meta', __('Payment Meta', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Payment_Meta::output', $post_type, 'side', 'default');
158 158
 			}
159 159
 
160 160
 			// Billing details.
161
-			add_meta_box( 'wpinv-address', __( 'Billing Details', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high' );
161
+			add_meta_box('wpinv-address', __('Billing Details', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Address::output', $post_type, 'normal', 'high');
162 162
 			
163 163
 			// Invoice items.
164 164
 			add_meta_box(
165 165
 				'wpinv-items',
166 166
 				sprintf(
167
-					__( '%s Items', 'invoicing' ),
168
-					ucfirst( $invoice->get_invoice_quote_type() )
167
+					__('%s Items', 'invoicing'),
168
+					ucfirst($invoice->get_invoice_quote_type())
169 169
 				),
170 170
 				'GetPaid_Meta_Box_Invoice_Items::output',
171 171
 				$post_type,
@@ -177,8 +177,8 @@  discard block
 block discarded – undo
177 177
 			add_meta_box(
178 178
 				'wpinv-notes',
179 179
 				sprintf(
180
-					__( '%s Notes', 'invoicing' ),
181
-					ucfirst( $invoice->get_invoice_quote_type() )
180
+					__('%s Notes', 'invoicing'),
181
+					ucfirst($invoice->get_invoice_quote_type())
182 182
 				),
183 183
 				'WPInv_Meta_Box_Notes::output',
184 184
 				$post_type,
@@ -187,13 +187,13 @@  discard block
 block discarded – undo
187 187
 			);
188 188
 
189 189
 			// Shipping Address.
190
-			if ( get_post_meta( $invoice->get_id(), 'shipping_address', true ) ) {
191
-				add_meta_box( 'wpinv-invoice-shipping-details', __( 'Shipping Address', 'invoicing' ), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high' );
190
+			if (get_post_meta($invoice->get_id(), 'shipping_address', true)) {
191
+				add_meta_box('wpinv-invoice-shipping-details', __('Shipping Address', 'invoicing'), 'GetPaid_Meta_Box_Invoice_Shipping_Address::output', $post_type, 'side', 'high');
192 192
 			}
193 193
 
194 194
 			// Payment form information.
195
-			if ( get_post_meta( $invoice->get_id(), 'payment_form_data', true ) ) {
196
-				add_meta_box( 'wpinv-invoice-payment-form-details', __( 'Payment Form Details', 'invoicing' ), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high' );
195
+			if (get_post_meta($invoice->get_id(), 'payment_form_data', true)) {
196
+				add_meta_box('wpinv-invoice-payment-form-details', __('Payment Form Details', 'invoicing'), 'WPInv_Meta_Box_Payment_Form::output_details', $post_type, 'side', 'high');
197 197
 			}
198 198
 
199 199
 		}
@@ -204,7 +204,7 @@  discard block
 block discarded – undo
204 204
 	 * Remove some metaboxes.
205 205
 	 */
206 206
 	public static function remove_meta_boxes() {
207
-		remove_meta_box( 'wpseo_meta', 'wpi_invoice', 'normal' );
207
+		remove_meta_box('wpseo_meta', 'wpi_invoice', 'normal');
208 208
 	}
209 209
 
210 210
 	/**
@@ -220,46 +220,46 @@  discard block
 block discarded – undo
220 220
 	 * @param  int    $post_id Post ID.
221 221
 	 * @param  object $post Post object.
222 222
 	 */
223
-	public static function save_meta_boxes( $post_id, $post ) {
224
-		$post_id = absint( $post_id );
225
-		$data    = wp_unslash( $_POST );
223
+	public static function save_meta_boxes($post_id, $post) {
224
+		$post_id = absint($post_id);
225
+		$data    = wp_unslash($_POST);
226 226
 
227 227
 		// Do not save for ajax requests.
228
-		if ( ( defined( 'DOING_AJAX') && DOING_AJAX ) || isset( $_REQUEST['bulk_edit'] ) ) {
228
+		if ((defined('DOING_AJAX') && DOING_AJAX) || isset($_REQUEST['bulk_edit'])) {
229 229
 			return;
230 230
 		}
231 231
 
232 232
 		// $post_id and $post are required
233
-		if ( empty( $post_id ) || empty( $post ) || self::$saved_meta_boxes ) {
233
+		if (empty($post_id) || empty($post) || self::$saved_meta_boxes) {
234 234
 			return;
235 235
 		}
236 236
 
237 237
 		// Dont' save meta boxes for revisions or autosaves.
238
-		if ( ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) || is_int( wp_is_post_revision( $post ) ) || is_int( wp_is_post_autosave( $post ) ) ) {
238
+		if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || is_int(wp_is_post_revision($post)) || is_int(wp_is_post_autosave($post))) {
239 239
 			return;
240 240
 		}
241 241
 
242 242
 		// Check the nonce.
243
-		if ( empty( $data['getpaid_meta_nonce'] ) || ! wp_verify_nonce( $data['getpaid_meta_nonce'], 'getpaid_meta_nonce' ) ) {
243
+		if (empty($data['getpaid_meta_nonce']) || !wp_verify_nonce($data['getpaid_meta_nonce'], 'getpaid_meta_nonce')) {
244 244
 			return;
245 245
 		}
246 246
 
247 247
 		// Check the post being saved == the $post_id to prevent triggering this call for other save_post events.
248
-		if ( empty( $data['post_ID'] ) || absint( $data['post_ID'] ) !== $post_id ) {
248
+		if (empty($data['post_ID']) || absint($data['post_ID']) !== $post_id) {
249 249
 			return;
250 250
 		}
251 251
 
252 252
 		// Check user has permission to edit.
253
-		if ( ! current_user_can( 'edit_post', $post_id ) ) {
253
+		if (!current_user_can('edit_post', $post_id)) {
254 254
 			return;
255 255
 		}
256 256
 
257
-		if ( getpaid_is_invoice_post_type( $post->post_type ) ) {
257
+		if (getpaid_is_invoice_post_type($post->post_type)) {
258 258
 
259 259
 			// We need this save event to run once to avoid potential endless loops.
260 260
 			self::$saved_meta_boxes = true;
261 261
 
262
-			return GetPaid_Meta_Box_Invoice_Address::save( $post_id );
262
+			return GetPaid_Meta_Box_Invoice_Address::save($post_id);
263 263
 
264 264
 		}
265 265
 
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
 		);
272 272
 
273 273
 		// Is this our post type?
274
-		if ( ! isset( $post_types_map[ $post->post_type ] ) ) {
274
+		if (!isset($post_types_map[$post->post_type])) {
275 275
 			return;
276 276
 		}
277 277
 
@@ -279,8 +279,8 @@  discard block
 block discarded – undo
279 279
 		self::$saved_meta_boxes = true;
280 280
 		
281 281
 		// Save the post.
282
-		$class = $post_types_map[ $post->post_type ];
283
-		$class::save( $post_id, $_POST, $post );
282
+		$class = $post_types_map[$post->post_type];
283
+		$class::save($post_id, $_POST, $post);
284 284
 
285 285
 	}
286 286
 
Please login to merge, or discard this patch.