Passed
Push — master ( 55a972...5862ec )
by Brian
06:29
created
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +804 added lines, -804 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,115 +337,115 @@  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
-
372
-			if ( $this->has_recurring != 0 ) {
373
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
374
-			}
375
-
376
-			$this->has_recurring = $item->get_id();
377
-
378
-		}
379
-
380
-		// Update the items and totals.
381
-		$this->items[ $item->get_id() ]         = $item;
382
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
383
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
384
-
385
-	}
386
-
387
-	/**
388
-	 * Removes a specific item.
389
-	 * 
390
-	 * You should not call this method after the discounts and taxes
391
-	 * have been calculated.
392
-	 *
393
-	 * @since 1.0.19
394
-	 */
395
-	public function remove_item( $item_id ) {
396
-
397
-		if ( isset( $this->items[ $item_id ] ) ) {
398
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
399
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
400
-
401
-			if ( $this->items[ $item_id ]->is_recurring() ) {
402
-				$this->has_recurring = 0;
403
-			}
404
-
405
-			unset( $this->items[ $item_id ] );
406
-		}
407
-
408
-	}
409
-
410
-	/**
411
-	 * Returns the subtotal.
412
-	 *
413
-	 * @since 1.0.19
414
-	 */
415
-	public function get_subtotal() {
416
-
417
-		if ( wpinv_prices_include_tax() ) {
418
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
419
-		}
420
-
421
-		return $this->totals['subtotal']['initial'];
422
-	}
423
-
424
-	/**
425
-	 * Returns the recurring subtotal.
426
-	 *
427
-	 * @since 1.0.19
428
-	 */
429
-	public function get_recurring_subtotal() {
430
-
431
-		if ( wpinv_prices_include_tax() ) {
432
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
433
-		}
434
-
435
-		return $this->totals['subtotal']['recurring'];
436
-	}
437
-
438
-	/**
439
-	 * Returns all items.
440
-	 *
441
-	 * @since 1.0.19
442
-	 * @return GetPaid_Form_Item[]
443
-	 */
444
-	public function get_items() {
445
-		return $this->items;
446
-	}
447
-
448
-	/*
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
+
372
+            if ( $this->has_recurring != 0 ) {
373
+                throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
374
+            }
375
+
376
+            $this->has_recurring = $item->get_id();
377
+
378
+        }
379
+
380
+        // Update the items and totals.
381
+        $this->items[ $item->get_id() ]         = $item;
382
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
383
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
384
+
385
+    }
386
+
387
+    /**
388
+     * Removes a specific item.
389
+     * 
390
+     * You should not call this method after the discounts and taxes
391
+     * have been calculated.
392
+     *
393
+     * @since 1.0.19
394
+     */
395
+    public function remove_item( $item_id ) {
396
+
397
+        if ( isset( $this->items[ $item_id ] ) ) {
398
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
399
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
400
+
401
+            if ( $this->items[ $item_id ]->is_recurring() ) {
402
+                $this->has_recurring = 0;
403
+            }
404
+
405
+            unset( $this->items[ $item_id ] );
406
+        }
407
+
408
+    }
409
+
410
+    /**
411
+     * Returns the subtotal.
412
+     *
413
+     * @since 1.0.19
414
+     */
415
+    public function get_subtotal() {
416
+
417
+        if ( wpinv_prices_include_tax() ) {
418
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
419
+        }
420
+
421
+        return $this->totals['subtotal']['initial'];
422
+    }
423
+
424
+    /**
425
+     * Returns the recurring subtotal.
426
+     *
427
+     * @since 1.0.19
428
+     */
429
+    public function get_recurring_subtotal() {
430
+
431
+        if ( wpinv_prices_include_tax() ) {
432
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
433
+        }
434
+
435
+        return $this->totals['subtotal']['recurring'];
436
+    }
437
+
438
+    /**
439
+     * Returns all items.
440
+     *
441
+     * @since 1.0.19
442
+     * @return GetPaid_Form_Item[]
443
+     */
444
+    public function get_items() {
445
+        return $this->items;
446
+    }
447
+
448
+    /*
449 449
 	|--------------------------------------------------------------------------
450 450
 	| Taxes
451 451
 	|--------------------------------------------------------------------------
@@ -454,128 +454,128 @@  discard block
 block discarded – undo
454 454
 	| or only one-time.
455 455
     */
456 456
 
457
-	/**
458
-	 * Prepares the submission's taxes.
459
-	 *
460
-	 * @since 1.0.19
461
-	 */
462
-	public function process_taxes() {
463
-
464
-		// Abort if we're not using taxes.
465
-		if ( ! $this->use_taxes() ) {
466
-			return;
467
-		}
468
-
469
-		// If a custom country && state has been passed in, use it to calculate taxes.
470
-		$country = $this->get_field( 'wpinv_country', 'billing' );
471
-		if ( ! empty( $country ) ) {
472
-			$this->country = $country;
473
-		}
474
-
475
-		$state = $this->get_field( 'wpinv_state', 'billing' );
476
-		if ( ! empty( $state ) ) {
477
-			$this->state = $state;
478
-		}
479
-
480
-		// Confirm if the provided country and the ip country are similar.
481
-		$address_confirmed = $this->get_field( 'confirm-address' );
482
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
483
-			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' ) );
484
-		}
485
-
486
-		// Abort if the country is not taxable.
487
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
488
-			return;
489
-		}
490
-
491
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
492
-
493
-		foreach ( $processor->taxes as $tax ) {
494
-			$this->add_tax( $tax );
495
-		}
496
-
497
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
498
-	}
499
-
500
-	/**
501
-	 * Adds a tax to the submission.
502
-	 *
503
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
504
-	 * @since 1.0.19
505
-	 */
506
-	public function add_tax( $tax ) {
507
-
508
-		if ( wpinv_round_tax_per_tax_rate() ) {
509
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
510
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
511
-		}
512
-
513
-		$this->taxes[ $tax['name'] ]         = $tax;
514
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
515
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
516
-
517
-	}
518
-
519
-	/**
520
-	 * Removes a specific tax.
521
-	 *
522
-	 * @since 1.0.19
523
-	 */
524
-	public function remove_tax( $tax_name ) {
525
-
526
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
527
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
528
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
529
-			unset( $this->taxes[ $tax_name ] );
530
-		}
531
-
532
-	}
533
-
534
-	/**
535
-	 * Whether or not we'll use taxes for the submission.
536
-	 *
537
-	 * @since 1.0.19
538
-	 */
539
-	public function use_taxes() {
540
-
541
-		$use_taxes = wpinv_use_taxes();
542
-
543
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
544
-			$use_taxes = false;
545
-		}
546
-
547
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
548
-
549
-	}
550
-
551
-	/**
552
-	 * Returns the tax.
553
-	 *
554
-	 * @since 1.0.19
555
-	 */
556
-	public function get_tax() {
557
-		return $this->totals['taxes']['initial'];
558
-	}
559
-
560
-	/**
561
-	 * Returns the recurring tax.
562
-	 *
563
-	 * @since 1.0.19
564
-	 */
565
-	public function get_recurring_tax() {
566
-		return $this->totals['taxes']['recurring'];
567
-	}
568
-
569
-	/**
570
-	 * Returns all taxes.
571
-	 *
572
-	 * @since 1.0.19
573
-	 */
574
-	public function get_taxes() {
575
-		return $this->taxes;
576
-	}
577
-
578
-	/*
457
+    /**
458
+     * Prepares the submission's taxes.
459
+     *
460
+     * @since 1.0.19
461
+     */
462
+    public function process_taxes() {
463
+
464
+        // Abort if we're not using taxes.
465
+        if ( ! $this->use_taxes() ) {
466
+            return;
467
+        }
468
+
469
+        // If a custom country && state has been passed in, use it to calculate taxes.
470
+        $country = $this->get_field( 'wpinv_country', 'billing' );
471
+        if ( ! empty( $country ) ) {
472
+            $this->country = $country;
473
+        }
474
+
475
+        $state = $this->get_field( 'wpinv_state', 'billing' );
476
+        if ( ! empty( $state ) ) {
477
+            $this->state = $state;
478
+        }
479
+
480
+        // Confirm if the provided country and the ip country are similar.
481
+        $address_confirmed = $this->get_field( 'confirm-address' );
482
+        if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
483
+            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' ) );
484
+        }
485
+
486
+        // Abort if the country is not taxable.
487
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
488
+            return;
489
+        }
490
+
491
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
492
+
493
+        foreach ( $processor->taxes as $tax ) {
494
+            $this->add_tax( $tax );
495
+        }
496
+
497
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
498
+    }
499
+
500
+    /**
501
+     * Adds a tax to the submission.
502
+     *
503
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
504
+     * @since 1.0.19
505
+     */
506
+    public function add_tax( $tax ) {
507
+
508
+        if ( wpinv_round_tax_per_tax_rate() ) {
509
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
510
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
511
+        }
512
+
513
+        $this->taxes[ $tax['name'] ]         = $tax;
514
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
515
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
516
+
517
+    }
518
+
519
+    /**
520
+     * Removes a specific tax.
521
+     *
522
+     * @since 1.0.19
523
+     */
524
+    public function remove_tax( $tax_name ) {
525
+
526
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
527
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
528
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
529
+            unset( $this->taxes[ $tax_name ] );
530
+        }
531
+
532
+    }
533
+
534
+    /**
535
+     * Whether or not we'll use taxes for the submission.
536
+     *
537
+     * @since 1.0.19
538
+     */
539
+    public function use_taxes() {
540
+
541
+        $use_taxes = wpinv_use_taxes();
542
+
543
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
544
+            $use_taxes = false;
545
+        }
546
+
547
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
548
+
549
+    }
550
+
551
+    /**
552
+     * Returns the tax.
553
+     *
554
+     * @since 1.0.19
555
+     */
556
+    public function get_tax() {
557
+        return $this->totals['taxes']['initial'];
558
+    }
559
+
560
+    /**
561
+     * Returns the recurring tax.
562
+     *
563
+     * @since 1.0.19
564
+     */
565
+    public function get_recurring_tax() {
566
+        return $this->totals['taxes']['recurring'];
567
+    }
568
+
569
+    /**
570
+     * Returns all taxes.
571
+     *
572
+     * @since 1.0.19
573
+     */
574
+    public function get_taxes() {
575
+        return $this->taxes;
576
+    }
577
+
578
+    /*
579 579
 	|--------------------------------------------------------------------------
580 580
 	| Discounts
581 581
 	|--------------------------------------------------------------------------
@@ -584,99 +584,99 @@  discard block
 block discarded – undo
584 584
 	| or only one-time. They also do not have to come from a discount code.
585 585
     */
586 586
 
587
-	/**
588
-	 * Prepares the submission's discount.
589
-	 *
590
-	 * @since 1.0.19
591
-	 */
592
-	public function process_discount() {
593
-
594
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
595
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
596
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
597
-
598
-		foreach ( $processor->discounts as $discount ) {
599
-			$this->add_discount( $discount );
600
-		}
601
-
602
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
603
-	}
604
-
605
-	/**
606
-	 * Adds a discount to the submission.
607
-	 *
608
-	 * @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.
609
-	 * @since 1.0.19
610
-	 */
611
-	public function add_discount( $discount ) {
612
-		$this->discounts[ $discount['name'] ]   = $discount;
613
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
614
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
615
-	}
616
-
617
-	/**
618
-	 * Removes a discount from the submission.
619
-	 *
620
-	 * @since 1.0.19
621
-	 */
622
-	public function remove_discount( $name ) {
623
-
624
-		if ( isset( $this->discounts[ $name ] ) ) {
625
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
626
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
627
-			unset( $this->discounts[ $name ] );
628
-		}
629
-
630
-	}
631
-
632
-	/**
633
-	 * Checks whether there is a discount code associated with this submission.
634
-	 *
635
-	 * @since 1.0.19
636
-	 * @return bool
637
-	 */
638
-	public function has_discount_code() {
639
-		return ! empty( $this->discounts['discount_code'] );
640
-	}
641
-
642
-	/**
643
-	 * Returns the discount code.
644
-	 *
645
-	 * @since 1.0.19
646
-	 * @return string
647
-	 */
648
-	public function get_discount_code() {
649
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
650
-	}
651
-
652
-	/**
653
-	 * Returns the discount.
654
-	 *
655
-	 * @since 1.0.19
656
-	 */
657
-	public function get_discount() {
658
-		return $this->totals['discount']['initial'];
659
-	}
660
-
661
-	/**
662
-	 * Returns the recurring discount.
663
-	 *
664
-	 * @since 1.0.19
665
-	 */
666
-	public function get_recurring_discount() {
667
-		return $this->totals['discount']['recurring'];
668
-	}
669
-
670
-	/**
671
-	 * Returns all discounts.
672
-	 *
673
-	 * @since 1.0.19
674
-	 */
675
-	public function get_discounts() {
676
-		return $this->discounts;
677
-	}
678
-
679
-	/*
587
+    /**
588
+     * Prepares the submission's discount.
589
+     *
590
+     * @since 1.0.19
591
+     */
592
+    public function process_discount() {
593
+
594
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
595
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
596
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
597
+
598
+        foreach ( $processor->discounts as $discount ) {
599
+            $this->add_discount( $discount );
600
+        }
601
+
602
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
603
+    }
604
+
605
+    /**
606
+     * Adds a discount to the submission.
607
+     *
608
+     * @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.
609
+     * @since 1.0.19
610
+     */
611
+    public function add_discount( $discount ) {
612
+        $this->discounts[ $discount['name'] ]   = $discount;
613
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
614
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
615
+    }
616
+
617
+    /**
618
+     * Removes a discount from the submission.
619
+     *
620
+     * @since 1.0.19
621
+     */
622
+    public function remove_discount( $name ) {
623
+
624
+        if ( isset( $this->discounts[ $name ] ) ) {
625
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
626
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
627
+            unset( $this->discounts[ $name ] );
628
+        }
629
+
630
+    }
631
+
632
+    /**
633
+     * Checks whether there is a discount code associated with this submission.
634
+     *
635
+     * @since 1.0.19
636
+     * @return bool
637
+     */
638
+    public function has_discount_code() {
639
+        return ! empty( $this->discounts['discount_code'] );
640
+    }
641
+
642
+    /**
643
+     * Returns the discount code.
644
+     *
645
+     * @since 1.0.19
646
+     * @return string
647
+     */
648
+    public function get_discount_code() {
649
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
650
+    }
651
+
652
+    /**
653
+     * Returns the discount.
654
+     *
655
+     * @since 1.0.19
656
+     */
657
+    public function get_discount() {
658
+        return $this->totals['discount']['initial'];
659
+    }
660
+
661
+    /**
662
+     * Returns the recurring discount.
663
+     *
664
+     * @since 1.0.19
665
+     */
666
+    public function get_recurring_discount() {
667
+        return $this->totals['discount']['recurring'];
668
+    }
669
+
670
+    /**
671
+     * Returns all discounts.
672
+     *
673
+     * @since 1.0.19
674
+     */
675
+    public function get_discounts() {
676
+        return $this->discounts;
677
+    }
678
+
679
+    /*
680 680
 	|--------------------------------------------------------------------------
681 681
 	| Fees
682 682
 	|--------------------------------------------------------------------------
@@ -686,89 +686,89 @@  discard block
 block discarded – undo
686 686
 	| fees.
687 687
     */
688 688
 
689
-	/**
690
-	 * Prepares the submission's fees.
691
-	 *
692
-	 * @since 1.0.19
693
-	 */
694
-	public function process_fees() {
695
-
696
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
697
-
698
-		foreach ( $fees_processor->fees as $fee ) {
699
-			$this->add_fee( $fee );
700
-		}
701
-
702
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
703
-	}
704
-
705
-	/**
706
-	 * Adds a fee to the submission.
707
-	 *
708
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
709
-	 * @since 1.0.19
710
-	 */
711
-	public function add_fee( $fee ) {
712
-
713
-		$this->fees[ $fee['name'] ]         = $fee;
714
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
715
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
716
-
717
-	}
718
-
719
-	/**
720
-	 * Removes a fee from the submission.
721
-	 *
722
-	 * @since 1.0.19
723
-	 */
724
-	public function remove_fee( $name ) {
725
-
726
-		if ( isset( $this->fees[ $name ] ) ) {
727
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
728
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
729
-			unset( $this->fees[ $name ] );
730
-		}
731
-
732
-	}
733
-
734
-	/**
735
-	 * Returns the fees.
736
-	 *
737
-	 * @since 1.0.19
738
-	 */
739
-	public function get_fee() {
740
-		return $this->totals['fees']['initial'];
741
-	}
742
-
743
-	/**
744
-	 * Returns the recurring fees.
745
-	 *
746
-	 * @since 1.0.19
747
-	 */
748
-	public function get_recurring_fee() {
749
-		return $this->totals['fees']['recurring'];
750
-	}
751
-
752
-	/**
753
-	 * Returns all fees.
754
-	 *
755
-	 * @since 1.0.19
756
-	 */
757
-	public function get_fees() {
758
-		return $this->fees;
759
-	}
760
-
761
-	/**
762
-	 * Checks if there are any fees for the form.
763
-	 *
764
-	 * @return bool
765
-	 * @since 1.0.19
766
-	 */
767
-	public function has_fees() {
768
-		return count( $this->fees ) !== 0;
769
-	}
770
-
771
-	/*
689
+    /**
690
+     * Prepares the submission's fees.
691
+     *
692
+     * @since 1.0.19
693
+     */
694
+    public function process_fees() {
695
+
696
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
697
+
698
+        foreach ( $fees_processor->fees as $fee ) {
699
+            $this->add_fee( $fee );
700
+        }
701
+
702
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
703
+    }
704
+
705
+    /**
706
+     * Adds a fee to the submission.
707
+     *
708
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
709
+     * @since 1.0.19
710
+     */
711
+    public function add_fee( $fee ) {
712
+
713
+        $this->fees[ $fee['name'] ]         = $fee;
714
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
715
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
716
+
717
+    }
718
+
719
+    /**
720
+     * Removes a fee from the submission.
721
+     *
722
+     * @since 1.0.19
723
+     */
724
+    public function remove_fee( $name ) {
725
+
726
+        if ( isset( $this->fees[ $name ] ) ) {
727
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
728
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
729
+            unset( $this->fees[ $name ] );
730
+        }
731
+
732
+    }
733
+
734
+    /**
735
+     * Returns the fees.
736
+     *
737
+     * @since 1.0.19
738
+     */
739
+    public function get_fee() {
740
+        return $this->totals['fees']['initial'];
741
+    }
742
+
743
+    /**
744
+     * Returns the recurring fees.
745
+     *
746
+     * @since 1.0.19
747
+     */
748
+    public function get_recurring_fee() {
749
+        return $this->totals['fees']['recurring'];
750
+    }
751
+
752
+    /**
753
+     * Returns all fees.
754
+     *
755
+     * @since 1.0.19
756
+     */
757
+    public function get_fees() {
758
+        return $this->fees;
759
+    }
760
+
761
+    /**
762
+     * Checks if there are any fees for the form.
763
+     *
764
+     * @return bool
765
+     * @since 1.0.19
766
+     */
767
+    public function has_fees() {
768
+        return count( $this->fees ) !== 0;
769
+    }
770
+
771
+    /*
772 772
 	|--------------------------------------------------------------------------
773 773
 	| MISC
774 774
 	|--------------------------------------------------------------------------
@@ -776,119 +776,119 @@  discard block
 block discarded – undo
776 776
 	| Extra submission functions.
777 777
     */
778 778
 
779
-	/**
780
-	 * Checks if this is the initial fetch.
781
-	 *
782
-	 * @return bool
783
-	 * @since 1.0.19
784
-	 */
785
-	public function is_initial_fetch() {
786
-		return empty( $this->data['initial_state'] );
787
-	}
788
-
789
-	/**
790
-	 * Returns the total amount to collect for this submission.
791
-	 *
792
-	 * @since 1.0.19
793
-	 */
794
-	public function get_total() {
795
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
796
-		return max( $total, 0 );
797
-	}
798
-
799
-	/**
800
-	 * Returns the recurring total amount to collect for this submission.
801
-	 *
802
-	 * @since 1.0.19
803
-	 */
804
-	public function get_recurring_total() {
805
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
806
-		return max( $total, 0 );
807
-	}
808
-
809
-	/**
810
-	 * Whether payment details should be collected for this submission.
811
-	 *
812
-	 * @since 1.0.19
813
-	 */
814
-	public function should_collect_payment_details() {
815
-		$initial   = $this->get_total();
816
-		$recurring = $this->get_recurring_total();
817
-
818
-		if ( $this->has_recurring == 0 ) {
819
-			$recurring = 0;
820
-		}
821
-
822
-		$collect = $initial > 0 || $recurring > 0;
823
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
824
-	}
825
-
826
-	/**
827
-	 * Returns the billing email of the user.
828
-	 *
829
-	 * @since 1.0.19
830
-	 */
831
-	public function get_billing_email() {
832
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
833
-	}
834
-
835
-	/**
836
-	 * Checks if the submitter has a billing email.
837
-	 *
838
-	 * @since 1.0.19
839
-	 */
840
-	public function has_billing_email() {
841
-		$billing_email = $this->get_billing_email();
842
-		return ! empty( $billing_email ) && is_email( $billing_email );
843
-	}
844
-
845
-	/**
846
-	 * Returns the appropriate currency for the submission.
847
-	 *
848
-	 * @since 1.0.19
849
-	 * @return string
850
-	 */
851
-	public function get_currency() {
852
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
853
-    }
854
-
855
-    /**
856
-	 * Returns the raw submission data.
857
-	 *
858
-	 * @since 1.0.19
859
-	 * @return array
860
-	 */
861
-	public function get_data() {
862
-		return $this->data;
863
-	}
864
-
865
-	/**
866
-	 * Returns a field from the submission data
867
-	 *
868
-	 * @param string $field
869
-	 * @since 1.0.19
870
-	 * @return mixed|null
871
-	 */
872
-	public function get_field( $field, $sub_array_key = null ) {
873
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
874
-	}
875
-
876
-	/**
877
-	 * Checks if a required field is set.
878
-	 *
879
-	 * @since 1.0.19
880
-	 */
881
-	public function is_required_field_set( $field ) {
882
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
883
-	}
884
-
885
-	/**
886
-	 * Formats an amount
887
-	 *
888
-	 * @since 1.0.19
889
-	 */
890
-	public function format_amount( $amount ) {
891
-		return wpinv_price( $amount, $this->get_currency() );
892
-	}
779
+    /**
780
+     * Checks if this is the initial fetch.
781
+     *
782
+     * @return bool
783
+     * @since 1.0.19
784
+     */
785
+    public function is_initial_fetch() {
786
+        return empty( $this->data['initial_state'] );
787
+    }
788
+
789
+    /**
790
+     * Returns the total amount to collect for this submission.
791
+     *
792
+     * @since 1.0.19
793
+     */
794
+    public function get_total() {
795
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
796
+        return max( $total, 0 );
797
+    }
798
+
799
+    /**
800
+     * Returns the recurring total amount to collect for this submission.
801
+     *
802
+     * @since 1.0.19
803
+     */
804
+    public function get_recurring_total() {
805
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
806
+        return max( $total, 0 );
807
+    }
808
+
809
+    /**
810
+     * Whether payment details should be collected for this submission.
811
+     *
812
+     * @since 1.0.19
813
+     */
814
+    public function should_collect_payment_details() {
815
+        $initial   = $this->get_total();
816
+        $recurring = $this->get_recurring_total();
817
+
818
+        if ( $this->has_recurring == 0 ) {
819
+            $recurring = 0;
820
+        }
821
+
822
+        $collect = $initial > 0 || $recurring > 0;
823
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
824
+    }
825
+
826
+    /**
827
+     * Returns the billing email of the user.
828
+     *
829
+     * @since 1.0.19
830
+     */
831
+    public function get_billing_email() {
832
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
833
+    }
834
+
835
+    /**
836
+     * Checks if the submitter has a billing email.
837
+     *
838
+     * @since 1.0.19
839
+     */
840
+    public function has_billing_email() {
841
+        $billing_email = $this->get_billing_email();
842
+        return ! empty( $billing_email ) && is_email( $billing_email );
843
+    }
844
+
845
+    /**
846
+     * Returns the appropriate currency for the submission.
847
+     *
848
+     * @since 1.0.19
849
+     * @return string
850
+     */
851
+    public function get_currency() {
852
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
853
+    }
854
+
855
+    /**
856
+     * Returns the raw submission data.
857
+     *
858
+     * @since 1.0.19
859
+     * @return array
860
+     */
861
+    public function get_data() {
862
+        return $this->data;
863
+    }
864
+
865
+    /**
866
+     * Returns a field from the submission data
867
+     *
868
+     * @param string $field
869
+     * @since 1.0.19
870
+     * @return mixed|null
871
+     */
872
+    public function get_field( $field, $sub_array_key = null ) {
873
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
874
+    }
875
+
876
+    /**
877
+     * Checks if a required field is set.
878
+     *
879
+     * @since 1.0.19
880
+     */
881
+    public function is_required_field_set( $field ) {
882
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
883
+    }
884
+
885
+    /**
886
+     * Formats an amount
887
+     *
888
+     * @since 1.0.19
889
+     */
890
+    public function format_amount( $amount ) {
891
+        return wpinv_price( $amount, $this->get_currency() );
892
+    }
893 893
 
894 894
 }
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,18 +359,18 @@  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
 
372
-			if ( $this->has_recurring != 0 ) {
373
-				throw new Exception( __( 'You can only buy one recurring item at a time.', 'invoicing' ) );
372
+			if ($this->has_recurring != 0) {
373
+				throw new Exception(__('You can only buy one recurring item at a time.', 'invoicing'));
374 374
 			}
375 375
 
376 376
 			$this->has_recurring = $item->get_id();
@@ -378,7 +378,7 @@  discard block
 block discarded – undo
378 378
 		}
379 379
 
380 380
 		// Update the items and totals.
381
-		$this->items[ $item->get_id() ]         = $item;
381
+		$this->items[$item->get_id()]         = $item;
382 382
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
383 383
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
384 384
 
@@ -392,17 +392,17 @@  discard block
 block discarded – undo
392 392
 	 *
393 393
 	 * @since 1.0.19
394 394
 	 */
395
-	public function remove_item( $item_id ) {
395
+	public function remove_item($item_id) {
396 396
 
397
-		if ( isset( $this->items[ $item_id ] ) ) {
398
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
399
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
397
+		if (isset($this->items[$item_id])) {
398
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
399
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
400 400
 
401
-			if ( $this->items[ $item_id ]->is_recurring() ) {
401
+			if ($this->items[$item_id]->is_recurring()) {
402 402
 				$this->has_recurring = 0;
403 403
 			}
404 404
 
405
-			unset( $this->items[ $item_id ] );
405
+			unset($this->items[$item_id]);
406 406
 		}
407 407
 
408 408
 	}
@@ -414,7 +414,7 @@  discard block
 block discarded – undo
414 414
 	 */
415 415
 	public function get_subtotal() {
416 416
 
417
-		if ( wpinv_prices_include_tax() ) {
417
+		if (wpinv_prices_include_tax()) {
418 418
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
419 419
 		}
420 420
 
@@ -428,7 +428,7 @@  discard block
 block discarded – undo
428 428
 	 */
429 429
 	public function get_recurring_subtotal() {
430 430
 
431
-		if ( wpinv_prices_include_tax() ) {
431
+		if (wpinv_prices_include_tax()) {
432 432
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
433 433
 		}
434 434
 
@@ -462,39 +462,39 @@  discard block
 block discarded – undo
462 462
 	public function process_taxes() {
463 463
 
464 464
 		// Abort if we're not using taxes.
465
-		if ( ! $this->use_taxes() ) {
465
+		if (!$this->use_taxes()) {
466 466
 			return;
467 467
 		}
468 468
 
469 469
 		// If a custom country && state has been passed in, use it to calculate taxes.
470
-		$country = $this->get_field( 'wpinv_country', 'billing' );
471
-		if ( ! empty( $country ) ) {
470
+		$country = $this->get_field('wpinv_country', 'billing');
471
+		if (!empty($country)) {
472 472
 			$this->country = $country;
473 473
 		}
474 474
 
475
-		$state = $this->get_field( 'wpinv_state', 'billing' );
476
-		if ( ! empty( $state ) ) {
475
+		$state = $this->get_field('wpinv_state', 'billing');
476
+		if (!empty($state)) {
477 477
 			$this->state = $state;
478 478
 		}
479 479
 
480 480
 		// Confirm if the provided country and the ip country are similar.
481
-		$address_confirmed = $this->get_field( 'confirm-address' );
482
-		if ( wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
483
-			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' ) );
481
+		$address_confirmed = $this->get_field('confirm-address');
482
+		if (wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
483
+			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'));
484 484
 		}
485 485
 
486 486
 		// Abort if the country is not taxable.
487
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
487
+		if (!wpinv_is_country_taxable($this->country)) {
488 488
 			return;
489 489
 		}
490 490
 
491
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
491
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
492 492
 
493
-		foreach ( $processor->taxes as $tax ) {
494
-			$this->add_tax( $tax );
493
+		foreach ($processor->taxes as $tax) {
494
+			$this->add_tax($tax);
495 495
 		}
496 496
 
497
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
497
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
498 498
 	}
499 499
 
500 500
 	/**
@@ -503,16 +503,16 @@  discard block
 block discarded – undo
503 503
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
504 504
 	 * @since 1.0.19
505 505
 	 */
506
-	public function add_tax( $tax ) {
506
+	public function add_tax($tax) {
507 507
 
508
-		if ( wpinv_round_tax_per_tax_rate() ) {
509
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
510
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
508
+		if (wpinv_round_tax_per_tax_rate()) {
509
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
510
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
511 511
 		}
512 512
 
513
-		$this->taxes[ $tax['name'] ]         = $tax;
514
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
515
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
513
+		$this->taxes[$tax['name']]         = $tax;
514
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
515
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
516 516
 
517 517
 	}
518 518
 
@@ -521,12 +521,12 @@  discard block
 block discarded – undo
521 521
 	 *
522 522
 	 * @since 1.0.19
523 523
 	 */
524
-	public function remove_tax( $tax_name ) {
524
+	public function remove_tax($tax_name) {
525 525
 
526
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
527
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
528
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
529
-			unset( $this->taxes[ $tax_name ] );
526
+		if (isset($this->taxes[$tax_name])) {
527
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
528
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
529
+			unset($this->taxes[$tax_name]);
530 530
 		}
531 531
 
532 532
 	}
@@ -540,11 +540,11 @@  discard block
 block discarded – undo
540 540
 
541 541
 		$use_taxes = wpinv_use_taxes();
542 542
 
543
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
543
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
544 544
 			$use_taxes = false;
545 545
 		}
546 546
 
547
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
547
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
548 548
 
549 549
 	}
550 550
 
@@ -593,13 +593,13 @@  discard block
 block discarded – undo
593 593
 
594 594
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
595 595
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
596
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
596
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
597 597
 
598
-		foreach ( $processor->discounts as $discount ) {
599
-			$this->add_discount( $discount );
598
+		foreach ($processor->discounts as $discount) {
599
+			$this->add_discount($discount);
600 600
 		}
601 601
 
602
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
602
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
603 603
 	}
604 604
 
605 605
 	/**
@@ -608,10 +608,10 @@  discard block
 block discarded – undo
608 608
 	 * @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.
609 609
 	 * @since 1.0.19
610 610
 	 */
611
-	public function add_discount( $discount ) {
612
-		$this->discounts[ $discount['name'] ]   = $discount;
613
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
614
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
611
+	public function add_discount($discount) {
612
+		$this->discounts[$discount['name']]   = $discount;
613
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
614
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
615 615
 	}
616 616
 
617 617
 	/**
@@ -619,12 +619,12 @@  discard block
 block discarded – undo
619 619
 	 *
620 620
 	 * @since 1.0.19
621 621
 	 */
622
-	public function remove_discount( $name ) {
622
+	public function remove_discount($name) {
623 623
 
624
-		if ( isset( $this->discounts[ $name ] ) ) {
625
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
626
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
627
-			unset( $this->discounts[ $name ] );
624
+		if (isset($this->discounts[$name])) {
625
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
626
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
627
+			unset($this->discounts[$name]);
628 628
 		}
629 629
 
630 630
 	}
@@ -636,7 +636,7 @@  discard block
 block discarded – undo
636 636
 	 * @return bool
637 637
 	 */
638 638
 	public function has_discount_code() {
639
-		return ! empty( $this->discounts['discount_code'] );
639
+		return !empty($this->discounts['discount_code']);
640 640
 	}
641 641
 
642 642
 	/**
@@ -693,13 +693,13 @@  discard block
 block discarded – undo
693 693
 	 */
694 694
 	public function process_fees() {
695 695
 
696
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
696
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
697 697
 
698
-		foreach ( $fees_processor->fees as $fee ) {
699
-			$this->add_fee( $fee );
698
+		foreach ($fees_processor->fees as $fee) {
699
+			$this->add_fee($fee);
700 700
 		}
701 701
 
702
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
702
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
703 703
 	}
704 704
 
705 705
 	/**
@@ -708,11 +708,11 @@  discard block
 block discarded – undo
708 708
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
709 709
 	 * @since 1.0.19
710 710
 	 */
711
-	public function add_fee( $fee ) {
711
+	public function add_fee($fee) {
712 712
 
713
-		$this->fees[ $fee['name'] ]         = $fee;
714
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
715
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
713
+		$this->fees[$fee['name']]         = $fee;
714
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
715
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
716 716
 
717 717
 	}
718 718
 
@@ -721,12 +721,12 @@  discard block
 block discarded – undo
721 721
 	 *
722 722
 	 * @since 1.0.19
723 723
 	 */
724
-	public function remove_fee( $name ) {
724
+	public function remove_fee($name) {
725 725
 
726
-		if ( isset( $this->fees[ $name ] ) ) {
727
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
728
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
729
-			unset( $this->fees[ $name ] );
726
+		if (isset($this->fees[$name])) {
727
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
728
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
729
+			unset($this->fees[$name]);
730 730
 		}
731 731
 
732 732
 	}
@@ -765,7 +765,7 @@  discard block
 block discarded – undo
765 765
 	 * @since 1.0.19
766 766
 	 */
767 767
 	public function has_fees() {
768
-		return count( $this->fees ) !== 0;
768
+		return count($this->fees) !== 0;
769 769
 	}
770 770
 
771 771
 	/*
@@ -783,7 +783,7 @@  discard block
 block discarded – undo
783 783
 	 * @since 1.0.19
784 784
 	 */
785 785
 	public function is_initial_fetch() {
786
-		return empty( $this->data['initial_state'] );
786
+		return empty($this->data['initial_state']);
787 787
 	}
788 788
 
789 789
 	/**
@@ -793,7 +793,7 @@  discard block
 block discarded – undo
793 793
 	 */
794 794
 	public function get_total() {
795 795
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
796
-		return max( $total, 0 );
796
+		return max($total, 0);
797 797
 	}
798 798
 
799 799
 	/**
@@ -803,7 +803,7 @@  discard block
 block discarded – undo
803 803
 	 */
804 804
 	public function get_recurring_total() {
805 805
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
806
-		return max( $total, 0 );
806
+		return max($total, 0);
807 807
 	}
808 808
 
809 809
 	/**
@@ -815,12 +815,12 @@  discard block
 block discarded – undo
815 815
 		$initial   = $this->get_total();
816 816
 		$recurring = $this->get_recurring_total();
817 817
 
818
-		if ( $this->has_recurring == 0 ) {
818
+		if ($this->has_recurring == 0) {
819 819
 			$recurring = 0;
820 820
 		}
821 821
 
822 822
 		$collect = $initial > 0 || $recurring > 0;
823
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
823
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
824 824
 	}
825 825
 
826 826
 	/**
@@ -829,7 +829,7 @@  discard block
 block discarded – undo
829 829
 	 * @since 1.0.19
830 830
 	 */
831 831
 	public function get_billing_email() {
832
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
832
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
833 833
 	}
834 834
 
835 835
 	/**
@@ -839,7 +839,7 @@  discard block
 block discarded – undo
839 839
 	 */
840 840
 	public function has_billing_email() {
841 841
 		$billing_email = $this->get_billing_email();
842
-		return ! empty( $billing_email ) && is_email( $billing_email );
842
+		return !empty($billing_email) && is_email($billing_email);
843 843
 	}
844 844
 
845 845
 	/**
@@ -869,8 +869,8 @@  discard block
 block discarded – undo
869 869
 	 * @since 1.0.19
870 870
 	 * @return mixed|null
871 871
 	 */
872
-	public function get_field( $field, $sub_array_key = null ) {
873
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
872
+	public function get_field($field, $sub_array_key = null) {
873
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
874 874
 	}
875 875
 
876 876
 	/**
@@ -878,8 +878,8 @@  discard block
 block discarded – undo
878 878
 	 *
879 879
 	 * @since 1.0.19
880 880
 	 */
881
-	public function is_required_field_set( $field ) {
882
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
881
+	public function is_required_field_set($field) {
882
+		return empty($field['required']) || !empty($this->data[$field['id']]);
883 883
 	}
884 884
 
885 885
 	/**
@@ -887,8 +887,8 @@  discard block
 block discarded – undo
887 887
 	 *
888 888
 	 * @since 1.0.19
889 889
 	 */
890
-	public function format_amount( $amount ) {
891
-		return wpinv_price( $amount, $this->get_currency() );
890
+	public function format_amount($amount) {
891
+		return wpinv_price($amount, $this->get_currency());
892 892
 	}
893 893
 
894 894
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-exception.php 2 patches
Indentation   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -14,51 +14,51 @@
 block discarded – undo
14 14
  */
15 15
 class GetPaid_Payment_Exception extends Exception {
16 16
 
17
-	/**
18
-	 * Sanitized error code.
19
-	 *
20
-	 * @var string
21
-	 */
22
-	protected $error_code;
17
+    /**
18
+     * Sanitized error code.
19
+     *
20
+     * @var string
21
+     */
22
+    protected $error_code;
23 23
 
24
-	/**
25
-	 * Error extra data.
26
-	 *
27
-	 * @var array
28
-	 */
29
-	protected $error_data;
24
+    /**
25
+     * Error extra data.
26
+     *
27
+     * @var array
28
+     */
29
+    protected $error_data;
30 30
 
31
-	/**
32
-	 * Setup exception.
33
-	 *
34
-	 * @param string $code             Machine-readable error code, e.g `getpaid-discount-error`.
35
-	 * @param string $message          User-friendly translated error message, e.g. 'Discount is invalid'.
36
-	 * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
37
-	 * @param array  $data             Extra error data.
38
-	 */
39
-	public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
40
-		$this->error_code = $code;
41
-		$this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
31
+    /**
32
+     * Setup exception.
33
+     *
34
+     * @param string $code             Machine-readable error code, e.g `getpaid-discount-error`.
35
+     * @param string $message          User-friendly translated error message, e.g. 'Discount is invalid'.
36
+     * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
37
+     * @param array  $data             Extra error data.
38
+     */
39
+    public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
40
+        $this->error_code = $code;
41
+        $this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
42 42
 
43
-		parent::__construct( $message, $http_status_code );
44
-	}
43
+        parent::__construct( $message, $http_status_code );
44
+    }
45 45
 
46
-	/**
47
-	 * Returns the error code.
48
-	 *
49
-	 * @return string
50
-	 */
51
-	public function getErrorCode() {
52
-		return $this->error_code;
53
-	}
46
+    /**
47
+     * Returns the error code.
48
+     *
49
+     * @return string
50
+     */
51
+    public function getErrorCode() {
52
+        return $this->error_code;
53
+    }
54 54
 
55
-	/**
56
-	 * Returns error data.
57
-	 *
58
-	 * @return array
59
-	 */
60
-	public function getErrorData() {
61
-		return $this->error_data;
62
-	}
55
+    /**
56
+     * Returns error data.
57
+     *
58
+     * @return array
59
+     */
60
+    public function getErrorData() {
61
+        return $this->error_data;
62
+    }
63 63
 
64 64
 }
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  * @since   2.2.2
8 8
  */
9 9
 
10
-defined( 'ABSPATH' ) || exit;
10
+defined('ABSPATH') || exit;
11 11
 
12 12
 /**
13 13
  * Payment exception class.
@@ -36,11 +36,11 @@  discard block
 block discarded – undo
36 36
 	 * @param int    $http_status_code Proper HTTP status code to respond with, e.g. 400.
37 37
 	 * @param array  $data             Extra error data.
38 38
 	 */
39
-	public function __construct( $code, $message, $http_status_code = 400, $data = array() ) {
39
+	public function __construct($code, $message, $http_status_code = 400, $data = array()) {
40 40
 		$this->error_code = $code;
41
-		$this->error_data = array_merge( array( 'status' => $http_status_code ), $data );
41
+		$this->error_data = array_merge(array('status' => $http_status_code), $data);
42 42
 
43
-		parent::__construct( $message, $http_status_code );
43
+		parent::__construct($message, $http_status_code);
44 44
 	}
45 45
 
46 46
 	/**
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-discount.php 2 patches
Indentation   +154 added lines, -154 removed lines patch added patch discarded remove patch
@@ -12,162 +12,162 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Discount {
14 14
 
15
-	/**
16
-	 * Submission discounts.
17
-	 * @var array
18
-	 */
19
-	public $discounts = array();
15
+    /**
16
+     * Submission discounts.
17
+     * @var array
18
+     */
19
+    public $discounts = array();
20
+
21
+    /**
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     * @param float                           $initial_total
26
+     * @param float                           $recurring_total
27
+     */
28
+    public function __construct( $submission, $initial_total, $recurring_total ) {
29
+
30
+        // Process any existing invoice discounts.
31
+        if ( $submission->has_invoice() ) {
32
+            $this->discounts = $submission->get_invoice()->get_discounts();
33
+        }
34
+
35
+        // Do we have a discount?
36
+        $discount = $submission->get_field( 'discount' );
37
+
38
+        if ( empty( $discount ) ) {
39
+
40
+            if ( isset( $this->discounts['discount_code'] ) ) {
41
+                unset( $this->discounts['discount_code'] );
42
+            }
43
+
44
+            return;
45
+        }
46
+
47
+        // Processes the discount code.
48
+        $amount = max( $initial_total, $recurring_total );
49
+        $this->process_discount( $submission, $discount, $amount );
50
+
51
+    }
20 52
 
21 53
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 * @param float                           $initial_total
26
-	 * @param float                           $recurring_total
27
-	 */
28
-	public function __construct( $submission, $initial_total, $recurring_total ) {
29
-
30
-		// Process any existing invoice discounts.
31
-		if ( $submission->has_invoice() ) {
32
-			$this->discounts = $submission->get_invoice()->get_discounts();
33
-		}
34
-
35
-		// Do we have a discount?
36
-		$discount = $submission->get_field( 'discount' );
37
-
38
-		if ( empty( $discount ) ) {
39
-
40
-			if ( isset( $this->discounts['discount_code'] ) ) {
41
-				unset( $this->discounts['discount_code'] );
42
-			}
43
-
44
-			return;
45
-		}
46
-
47
-		// Processes the discount code.
48
-		$amount = max( $initial_total, $recurring_total );
49
-		$this->process_discount( $submission, $discount, $amount );
50
-
51
-	}
52
-
53
-	/**
54
-	 * Processes a submission discount.
55
-	 *
56
-	 * @param GetPaid_Payment_Form_Submission $submission
57
-	 * @param string                          $discount
58
-	 * @param float                           $amount
59
-	 */
60
-	public function process_discount( $submission, $discount, $amount ) {
61
-
62
-		// Fetch the discount.
63
-		$discount = new WPInv_Discount( $discount );
64
-
65
-		// Ensure it is active.
54
+     * Processes a submission discount.
55
+     *
56
+     * @param GetPaid_Payment_Form_Submission $submission
57
+     * @param string                          $discount
58
+     * @param float                           $amount
59
+     */
60
+    public function process_discount( $submission, $discount, $amount ) {
61
+
62
+        // Fetch the discount.
63
+        $discount = new WPInv_Discount( $discount );
64
+
65
+        // Ensure it is active.
66 66
         if ( ! $this->is_discount_active( $discount ) ) {
67
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) );
68
-		}
69
-
70
-		// Exceeded limit.
71
-		if ( $discount->has_exceeded_limit() ) {
72
-			throw new Exception( __( 'This discount code has been used up', 'invoicing' ) );
73
-		}
74
-
75
-		// Validate usages.
76
-		$this->validate_single_use_discount( $submission, $discount );
77
-
78
-		// Validate amount.
79
-		$this->validate_discount_amount( $submission, $discount, $amount );
80
-
81
-		// Save the discount.
82
-		$this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
-	}
84
-
85
-	/**
86
-	 * Validates a single use discount.
87
-	 *
88
-	 * @param WPInv_Discount                  $discount
89
-	 * @return bool
90
-	 */
91
-	public function is_discount_active(  $discount ) {
92
-		return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
-	}
94
-
95
-	/**
96
-	 * Returns a user's id or email.
97
-	 *
98
-	 * @param string $email
99
-	 * @return int|string|false
100
-	 */
101
-	public function get_user_id_or_email( $email ) {
102
-
103
-		if ( is_user_logged_in() ) {
104
-			return get_current_user_id();
105
-		}
106
-
107
-		return empty( $email ) ? false : sanitize_email( $email );
108
-	}
109
-
110
-	/**
111
-	 * Validates a single use discount.
112
-	 *
113
-	 * @param GetPaid_Payment_Form_Submission $submission
114
-	 * @param WPInv_Discount                  $discount
115
-	 */
116
-	public function validate_single_use_discount( $submission, $discount ) {
117
-
118
-		// Abort if it is not a single use discount.
119
-		if ( ! $discount->is_single_use() ) {
120
-			return;
121
-		}
122
-
123
-		// Ensure there is a valid billing email.
124
-		$user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
-
126
-		if ( empty( $user ) ) {
127
-			throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
128
-		}
129
-
130
-		// Has the user used this discount code before?
131
-		if ( ! $discount->is_valid_for_user( $user ) ) {
132
-			throw new Exception( __( 'You have already used this discount', 'invoicing' ) );
133
-		}
134
-
135
-	}
136
-
137
-	/**
138
-	 * Validates the discount's amount.
139
-	 *
140
-	 * @param GetPaid_Payment_Form_Submission $submission
141
-	 * @param WPInv_Discount         $discount
142
-	 * @param float                  $amount
143
-	 */
144
-	public function validate_discount_amount( $submission, $discount, $amount ) {
145
-
146
-		// Validate minimum amount.
147
-		if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
-			$min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
-			throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
150
-		}
151
-
152
-		// Validate the maximum amount.
153
-		if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
-			$max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
-			throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
156
-		}
157
-
158
-	}
159
-
160
-	/**
161
-	 * Calculates the discount code's amount.
162
-	 *
163
-	 * Ensure that the discount exists and has been validated before calling this method.
164
-	 *
165
-	 * @param GetPaid_Payment_Form_Submission $submission
166
-	 * @param WPInv_Discount                  $discount
167
-	 * @return array
168
-	 */
169
-	public function calculate_discount( $submission, $discount ) {
170
-		return getpaid_calculate_invoice_discount( $submission, $discount );
171
-	}
67
+            throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) );
68
+        }
69
+
70
+        // Exceeded limit.
71
+        if ( $discount->has_exceeded_limit() ) {
72
+            throw new Exception( __( 'This discount code has been used up', 'invoicing' ) );
73
+        }
74
+
75
+        // Validate usages.
76
+        $this->validate_single_use_discount( $submission, $discount );
77
+
78
+        // Validate amount.
79
+        $this->validate_discount_amount( $submission, $discount, $amount );
80
+
81
+        // Save the discount.
82
+        $this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
83
+    }
84
+
85
+    /**
86
+     * Validates a single use discount.
87
+     *
88
+     * @param WPInv_Discount                  $discount
89
+     * @return bool
90
+     */
91
+    public function is_discount_active(  $discount ) {
92
+        return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
93
+    }
94
+
95
+    /**
96
+     * Returns a user's id or email.
97
+     *
98
+     * @param string $email
99
+     * @return int|string|false
100
+     */
101
+    public function get_user_id_or_email( $email ) {
102
+
103
+        if ( is_user_logged_in() ) {
104
+            return get_current_user_id();
105
+        }
106
+
107
+        return empty( $email ) ? false : sanitize_email( $email );
108
+    }
109
+
110
+    /**
111
+     * Validates a single use discount.
112
+     *
113
+     * @param GetPaid_Payment_Form_Submission $submission
114
+     * @param WPInv_Discount                  $discount
115
+     */
116
+    public function validate_single_use_discount( $submission, $discount ) {
117
+
118
+        // Abort if it is not a single use discount.
119
+        if ( ! $discount->is_single_use() ) {
120
+            return;
121
+        }
122
+
123
+        // Ensure there is a valid billing email.
124
+        $user = $this->get_user_id_or_email( $submission->get_billing_email() );
125
+
126
+        if ( empty( $user ) ) {
127
+            throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
128
+        }
129
+
130
+        // Has the user used this discount code before?
131
+        if ( ! $discount->is_valid_for_user( $user ) ) {
132
+            throw new Exception( __( 'You have already used this discount', 'invoicing' ) );
133
+        }
134
+
135
+    }
136
+
137
+    /**
138
+     * Validates the discount's amount.
139
+     *
140
+     * @param GetPaid_Payment_Form_Submission $submission
141
+     * @param WPInv_Discount         $discount
142
+     * @param float                  $amount
143
+     */
144
+    public function validate_discount_amount( $submission, $discount, $amount ) {
145
+
146
+        // Validate minimum amount.
147
+        if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
+            $min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
+            throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
150
+        }
151
+
152
+        // Validate the maximum amount.
153
+        if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
+            $max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
+            throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
156
+        }
157
+
158
+    }
159
+
160
+    /**
161
+     * Calculates the discount code's amount.
162
+     *
163
+     * Ensure that the discount exists and has been validated before calling this method.
164
+     *
165
+     * @param GetPaid_Payment_Form_Submission $submission
166
+     * @param WPInv_Discount                  $discount
167
+     * @return array
168
+     */
169
+    public function calculate_discount( $submission, $discount ) {
170
+        return getpaid_calculate_invoice_discount( $submission, $discount );
171
+    }
172 172
 
173 173
 }
Please login to merge, or discard this patch.
Spacing   +39 added lines, -39 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission discount class
@@ -25,28 +25,28 @@  discard block
 block discarded – undo
25 25
 	 * @param float                           $initial_total
26 26
 	 * @param float                           $recurring_total
27 27
 	 */
28
-	public function __construct( $submission, $initial_total, $recurring_total ) {
28
+	public function __construct($submission, $initial_total, $recurring_total) {
29 29
 
30 30
 		// Process any existing invoice discounts.
31
-		if ( $submission->has_invoice() ) {
31
+		if ($submission->has_invoice()) {
32 32
 			$this->discounts = $submission->get_invoice()->get_discounts();
33 33
 		}
34 34
 
35 35
 		// Do we have a discount?
36
-		$discount = $submission->get_field( 'discount' );
36
+		$discount = $submission->get_field('discount');
37 37
 
38
-		if ( empty( $discount ) ) {
38
+		if (empty($discount)) {
39 39
 
40
-			if ( isset( $this->discounts['discount_code'] ) ) {
41
-				unset( $this->discounts['discount_code'] );
40
+			if (isset($this->discounts['discount_code'])) {
41
+				unset($this->discounts['discount_code']);
42 42
 			}
43 43
 
44 44
 			return;
45 45
 		}
46 46
 
47 47
 		// Processes the discount code.
48
-		$amount = max( $initial_total, $recurring_total );
49
-		$this->process_discount( $submission, $discount, $amount );
48
+		$amount = max($initial_total, $recurring_total);
49
+		$this->process_discount($submission, $discount, $amount);
50 50
 
51 51
 	}
52 52
 
@@ -57,29 +57,29 @@  discard block
 block discarded – undo
57 57
 	 * @param string                          $discount
58 58
 	 * @param float                           $amount
59 59
 	 */
60
-	public function process_discount( $submission, $discount, $amount ) {
60
+	public function process_discount($submission, $discount, $amount) {
61 61
 
62 62
 		// Fetch the discount.
63
-		$discount = new WPInv_Discount( $discount );
63
+		$discount = new WPInv_Discount($discount);
64 64
 
65 65
 		// Ensure it is active.
66
-        if ( ! $this->is_discount_active( $discount ) ) {
67
-			throw new GetPaid_Payment_Exception( '.getpaid-discount-field .getpaid-custom-payment-form-errors', __( 'Invalid or expired discount code', 'invoicing' ) );
66
+        if (!$this->is_discount_active($discount)) {
67
+			throw new GetPaid_Payment_Exception('.getpaid-discount-field .getpaid-custom-payment-form-errors', __('Invalid or expired discount code', 'invoicing'));
68 68
 		}
69 69
 
70 70
 		// Exceeded limit.
71
-		if ( $discount->has_exceeded_limit() ) {
72
-			throw new Exception( __( 'This discount code has been used up', 'invoicing' ) );
71
+		if ($discount->has_exceeded_limit()) {
72
+			throw new Exception(__('This discount code has been used up', 'invoicing'));
73 73
 		}
74 74
 
75 75
 		// Validate usages.
76
-		$this->validate_single_use_discount( $submission, $discount );
76
+		$this->validate_single_use_discount($submission, $discount);
77 77
 
78 78
 		// Validate amount.
79
-		$this->validate_discount_amount( $submission, $discount, $amount );
79
+		$this->validate_discount_amount($submission, $discount, $amount);
80 80
 
81 81
 		// Save the discount.
82
-		$this->discounts['discount_code'] = $this->calculate_discount( $submission, $discount );
82
+		$this->discounts['discount_code'] = $this->calculate_discount($submission, $discount);
83 83
 	}
84 84
 
85 85
 	/**
@@ -88,8 +88,8 @@  discard block
 block discarded – undo
88 88
 	 * @param WPInv_Discount                  $discount
89 89
 	 * @return bool
90 90
 	 */
91
-	public function is_discount_active(  $discount ) {
92
-		return $discount->exists() && $discount->is_active() && $discount->has_started() && ! $discount->is_expired();
91
+	public function is_discount_active($discount) {
92
+		return $discount->exists() && $discount->is_active() && $discount->has_started() && !$discount->is_expired();
93 93
 	}
94 94
 
95 95
 	/**
@@ -98,13 +98,13 @@  discard block
 block discarded – undo
98 98
 	 * @param string $email
99 99
 	 * @return int|string|false
100 100
 	 */
101
-	public function get_user_id_or_email( $email ) {
101
+	public function get_user_id_or_email($email) {
102 102
 
103
-		if ( is_user_logged_in() ) {
103
+		if (is_user_logged_in()) {
104 104
 			return get_current_user_id();
105 105
 		}
106 106
 
107
-		return empty( $email ) ? false : sanitize_email( $email );
107
+		return empty($email) ? false : sanitize_email($email);
108 108
 	}
109 109
 
110 110
 	/**
@@ -113,23 +113,23 @@  discard block
 block discarded – undo
113 113
 	 * @param GetPaid_Payment_Form_Submission $submission
114 114
 	 * @param WPInv_Discount                  $discount
115 115
 	 */
116
-	public function validate_single_use_discount( $submission, $discount ) {
116
+	public function validate_single_use_discount($submission, $discount) {
117 117
 
118 118
 		// Abort if it is not a single use discount.
119
-		if ( ! $discount->is_single_use() ) {
119
+		if (!$discount->is_single_use()) {
120 120
 			return;
121 121
 		}
122 122
 
123 123
 		// Ensure there is a valid billing email.
124
-		$user = $this->get_user_id_or_email( $submission->get_billing_email() );
124
+		$user = $this->get_user_id_or_email($submission->get_billing_email());
125 125
 
126
-		if ( empty( $user ) ) {
127
-			throw new Exception( __( 'You need to either log in or enter your billing email before applying this discount', 'invoicing' ) );
126
+		if (empty($user)) {
127
+			throw new Exception(__('You need to either log in or enter your billing email before applying this discount', 'invoicing'));
128 128
 		}
129 129
 
130 130
 		// Has the user used this discount code before?
131
-		if ( ! $discount->is_valid_for_user( $user ) ) {
132
-			throw new Exception( __( 'You have already used this discount', 'invoicing' ) );
131
+		if (!$discount->is_valid_for_user($user)) {
132
+			throw new Exception(__('You have already used this discount', 'invoicing'));
133 133
 		}
134 134
 
135 135
 	}
@@ -141,18 +141,18 @@  discard block
 block discarded – undo
141 141
 	 * @param WPInv_Discount         $discount
142 142
 	 * @param float                  $amount
143 143
 	 */
144
-	public function validate_discount_amount( $submission, $discount, $amount ) {
144
+	public function validate_discount_amount($submission, $discount, $amount) {
145 145
 
146 146
 		// Validate minimum amount.
147
-		if ( ! $discount->is_minimum_amount_met( $amount ) ) {
148
-			$min = wpinv_price( $discount->get_minimum_total(), $submission->get_currency() );
149
-			throw new Exception( sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min ) );
147
+		if (!$discount->is_minimum_amount_met($amount)) {
148
+			$min = wpinv_price($discount->get_minimum_total(), $submission->get_currency());
149
+			throw new Exception(sprintf(__('The minimum total for using this discount is %s', 'invoicing'), $min));
150 150
 		}
151 151
 
152 152
 		// Validate the maximum amount.
153
-		if ( ! $discount->is_maximum_amount_met( $amount ) ) {
154
-			$max = wpinv_price( $discount->get_maximum_total(), $submission->get_currency() );
155
-			throw new Exception( sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max ) );
153
+		if (!$discount->is_maximum_amount_met($amount)) {
154
+			$max = wpinv_price($discount->get_maximum_total(), $submission->get_currency());
155
+			throw new Exception(sprintf(__('The maximum total for using this discount is %s', 'invoicing'), $max));
156 156
 		}
157 157
 
158 158
 	}
@@ -166,8 +166,8 @@  discard block
 block discarded – undo
166 166
 	 * @param WPInv_Discount                  $discount
167 167
 	 * @return array
168 168
 	 */
169
-	public function calculate_discount( $submission, $discount ) {
170
-		return getpaid_calculate_invoice_discount( $submission, $discount );
169
+	public function calculate_discount($submission, $discount) {
170
+		return getpaid_calculate_invoice_discount($submission, $discount);
171 171
 	}
172 172
 
173 173
 }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 1 patch
Spacing   +217 added lines, -217 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  * @package Invoicing
7 7
  */
8 8
  
9
-defined( 'ABSPATH' ) || exit;
9
+defined('ABSPATH') || exit;
10 10
 
11 11
 /**
12 12
  * WPInv_Ajax class.
@@ -17,8 +17,8 @@  discard block
 block discarded – undo
17 17
 	 * Hook in ajax handlers.
18 18
 	 */
19 19
 	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
20
+		add_action('init', array(__CLASS__, 'define_ajax'), 0);
21
+		add_action('template_redirect', array(__CLASS__, 'do_wpinv_ajax'), 0);
22 22
 		self::add_ajax_events();
23 23
     }
24 24
 
@@ -27,11 +27,11 @@  discard block
 block discarded – undo
27 27
 	 */
28 28
 	public static function define_ajax() {
29 29
 
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
30
+		if (!empty($_GET['wpinv-ajax'])) {
31
+			getpaid_maybe_define_constant('DOING_AJAX', true);
32
+			getpaid_maybe_define_constant('WPInv_DOING_AJAX', true);
33
+			if (!WP_DEBUG || (WP_DEBUG && !WP_DEBUG_DISPLAY)) {
34
+				/** @scrutinizer ignore-unhandled */ @ini_set('display_errors', 0);
35 35
 			}
36 36
 			$GLOBALS['wpdb']->hide_errors();
37 37
 		}
@@ -44,13 +44,13 @@  discard block
 block discarded – undo
44 44
 	 * @since 1.0.18
45 45
 	 */
46 46
 	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
47
+		if (!headers_sent()) {
48 48
 			send_origin_headers();
49 49
 			send_nosniff_header();
50 50
 			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
51
+			header('Content-Type: text/html; charset=' . get_option('blog_charset'));
52
+			header('X-Robots-Tag: noindex');
53
+			status_header(200);
54 54
 		}
55 55
     }
56 56
     
@@ -60,16 +60,16 @@  discard block
 block discarded – undo
60 60
 	public static function do_wpinv_ajax() {
61 61
 		global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
63
+		if (!empty($_GET['wpinv-ajax'])) {
64
+			$wp_query->set('wpinv-ajax', sanitize_text_field(wp_unslash($_GET['wpinv-ajax'])));
65 65
 		}
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+		$action = $wp_query->get('wpinv-ajax');
68 68
 
69
-		if ( $action ) {
69
+		if ($action) {
70 70
 			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
71
+			$action = sanitize_text_field($action);
72
+			do_action('wpinv_ajax_' . $action);
73 73
 			wp_die();
74 74
 		}
75 75
 
@@ -102,36 +102,36 @@  discard block
 block discarded – undo
102 102
             'payment_form_refresh_prices' => true,
103 103
         );
104 104
 
105
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
106
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
107
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
105
+        foreach ($ajax_events as $ajax_event => $nopriv) {
106
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
107
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
108 108
 
109
-            if ( $nopriv ) {
110
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
111
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
112
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
109
+            if ($nopriv) {
110
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
111
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
112
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
113 113
             }
114 114
         }
115 115
     }
116 116
     
117 117
     public static function add_note() {
118
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
118
+        check_ajax_referer('add-invoice-note', '_nonce');
119 119
 
120
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
120
+        if (!wpinv_current_user_can_manage_invoicing()) {
121 121
             die(-1);
122 122
         }
123 123
 
124
-        $post_id   = absint( $_POST['post_id'] );
125
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
126
-        $note_type = sanitize_text_field( $_POST['note_type'] );
124
+        $post_id   = absint($_POST['post_id']);
125
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
126
+        $note_type = sanitize_text_field($_POST['note_type']);
127 127
 
128 128
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
129 129
 
130
-        if ( $post_id > 0 ) {
131
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
130
+        if ($post_id > 0) {
131
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
132 132
 
133
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
134
-                wpinv_get_invoice_note_line_item( $note_id );
133
+            if ($note_id > 0 && !is_wp_error($note_id)) {
134
+                wpinv_get_invoice_note_line_item($note_id);
135 135
             }
136 136
         }
137 137
 
@@ -139,16 +139,16 @@  discard block
 block discarded – undo
139 139
     }
140 140
 
141 141
     public static function delete_note() {
142
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
142
+        check_ajax_referer('delete-invoice-note', '_nonce');
143 143
 
144
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
144
+        if (!wpinv_current_user_can_manage_invoicing()) {
145 145
             die(-1);
146 146
         }
147 147
 
148
-        $note_id = (int)$_POST['note_id'];
148
+        $note_id = (int) $_POST['note_id'];
149 149
 
150
-        if ( $note_id > 0 ) {
151
-            wp_delete_comment( $note_id, true );
150
+        if ($note_id > 0) {
151
+            wp_delete_comment($note_id, true);
152 152
         }
153 153
 
154 154
         die();
@@ -166,34 +166,34 @@  discard block
 block discarded – undo
166 166
     public static function get_billing_details() {
167 167
 
168 168
         // Verify nonce.
169
-        check_ajax_referer( 'wpinv-nonce' );
169
+        check_ajax_referer('wpinv-nonce');
170 170
 
171 171
         // Can the user manage the plugin?
172
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
172
+        if (!wpinv_current_user_can_manage_invoicing()) {
173 173
             die(-1);
174 174
         }
175 175
 
176 176
         // Do we have a user id?
177 177
         $user_id = $_GET['user_id'];
178 178
 
179
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
179
+        if (empty($user_id) || !is_numeric($user_id)) {
180 180
             die(-1);
181 181
         }
182 182
 
183 183
         // Fetch the billing details.
184
-        $billing_details    = wpinv_get_user_address( $user_id );
185
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
184
+        $billing_details    = wpinv_get_user_address($user_id);
185
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
186 186
 
187 187
         // unset the user id and email.
188
-        $to_ignore = array( 'user_id', 'email' );
188
+        $to_ignore = array('user_id', 'email');
189 189
 
190
-        foreach ( $to_ignore as $key ) {
191
-            if ( isset( $billing_details[ $key ] ) ) {
192
-                unset( $billing_details[ $key ] );
190
+        foreach ($to_ignore as $key) {
191
+            if (isset($billing_details[$key])) {
192
+                unset($billing_details[$key]);
193 193
             }
194 194
         }
195 195
 
196
-        wp_send_json_success( $billing_details );
196
+        wp_send_json_success($billing_details);
197 197
 
198 198
     }
199 199
 
@@ -203,47 +203,47 @@  discard block
 block discarded – undo
203 203
     public static function check_new_user_email() {
204 204
 
205 205
         // Verify nonce.
206
-        check_ajax_referer( 'wpinv-nonce' );
206
+        check_ajax_referer('wpinv-nonce');
207 207
 
208 208
         // Can the user manage the plugin?
209
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
209
+        if (!wpinv_current_user_can_manage_invoicing()) {
210 210
             die(-1);
211 211
         }
212 212
 
213 213
         // We need an email address.
214
-        if ( empty( $_GET['email'] ) ) {
215
-            _e( "Provide the new user's email address", 'invoicing' );
214
+        if (empty($_GET['email'])) {
215
+            _e("Provide the new user's email address", 'invoicing');
216 216
             exit;
217 217
         }
218 218
 
219 219
         // Ensure the email is valid.
220
-        $email = sanitize_text_field( $_GET['email'] );
221
-        if ( ! is_email( $email ) ) {
222
-            _e( 'Invalid email address', 'invoicing' );
220
+        $email = sanitize_text_field($_GET['email']);
221
+        if (!is_email($email)) {
222
+            _e('Invalid email address', 'invoicing');
223 223
             exit;
224 224
         }
225 225
 
226 226
         // And it does not exist.
227
-        if ( email_exists( $email ) ) {
228
-            _e( 'A user with this email address already exists', 'invoicing' );
227
+        if (email_exists($email)) {
228
+            _e('A user with this email address already exists', 'invoicing');
229 229
             exit;
230 230
         }
231 231
 
232
-        wp_send_json_success( true );
232
+        wp_send_json_success(true);
233 233
     }
234 234
     
235 235
     public static function run_tool() {
236
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
237
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
236
+        check_ajax_referer('wpinv-nonce', '_nonce');
237
+        if (!wpinv_current_user_can_manage_invoicing()) {
238 238
             die(-1);
239 239
         }
240 240
         
241
-        $tool = sanitize_text_field( $_POST['tool'] );
241
+        $tool = sanitize_text_field($_POST['tool']);
242 242
         
243
-        do_action( 'wpinv_run_tool' );
243
+        do_action('wpinv_run_tool');
244 244
         
245
-        if ( !empty( $tool ) ) {
246
-            do_action( 'wpinv_tool_' . $tool );
245
+        if (!empty($tool)) {
246
+            do_action('wpinv_tool_' . $tool);
247 247
         }
248 248
     }
249 249
 
@@ -253,27 +253,27 @@  discard block
 block discarded – undo
253 253
     public static function get_payment_form() {
254 254
 
255 255
         // Check nonce.
256
-        check_ajax_referer( 'getpaid_form_nonce' );
256
+        check_ajax_referer('getpaid_form_nonce');
257 257
 
258 258
         // Is the request set up correctly?
259
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) ) {
259
+		if (empty($_GET['form']) && empty($_GET['item'])) {
260 260
 			echo aui()->alert(
261 261
 				array(
262 262
 					'type'    => 'warning',
263
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
263
+					'content' => __('No payment form or item provided', 'invoicing'),
264 264
 				)
265 265
             );
266 266
             exit;
267 267
         }
268 268
 
269 269
         // Payment form or button?
270
-		if ( ! empty( $_GET['form'] ) ) {
271
-            getpaid_display_payment_form( urldecode( $_GET['form'] ) );
272
-		} else if( ! empty( $_GET['invoice'] ) ) {
273
-		    getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
270
+		if (!empty($_GET['form'])) {
271
+            getpaid_display_payment_form(urldecode($_GET['form']));
272
+		} else if (!empty($_GET['invoice'])) {
273
+		    getpaid_display_invoice_payment_form(urldecode($_GET['invoice']));
274 274
         } else {
275
-			$items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
276
-		    getpaid_display_item_payment_form( $items );
275
+			$items = getpaid_convert_items_to_array(urldecode($_GET['item']));
276
+		    getpaid_display_item_payment_form($items);
277 277
         }
278 278
 
279 279
         exit;
@@ -288,17 +288,17 @@  discard block
 block discarded – undo
288 288
     public static function payment_form() {
289 289
 
290 290
         // Check nonce.
291
-        check_ajax_referer( 'getpaid_form_nonce' );
291
+        check_ajax_referer('getpaid_form_nonce');
292 292
 
293 293
         // ... form fields...
294
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
295
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
294
+        if (empty($_POST['getpaid_payment_form_submission'])) {
295
+            _e('Error: Reload the page and try again.', 'invoicing');
296 296
             exit;
297 297
         }
298 298
 
299 299
         // Process the payment form.
300
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
301
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
300
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
301
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
302 302
         $checkout->process_checkout();
303 303
 
304 304
         exit;
@@ -311,55 +311,55 @@  discard block
 block discarded – undo
311 311
      */
312 312
     public static function get_payment_form_states_field() {
313 313
 
314
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
314
+        if (empty($_GET['country']) || empty($_GET['form'])) {
315 315
             exit;
316 316
         }
317 317
 
318
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
318
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
319 319
 
320
-        if ( empty( $elements ) ) {
320
+        if (empty($elements)) {
321 321
             exit;
322 322
         }
323 323
 
324 324
         $address_fields = array();
325
-        foreach ( $elements as $element ) {
326
-            if ( 'address' === $element['type'] ) {
325
+        foreach ($elements as $element) {
326
+            if ('address' === $element['type']) {
327 327
                 $address_fields = $element;
328 328
                 break;
329 329
             }
330 330
         }
331 331
 
332
-        if ( empty( $address_fields ) ) {
332
+        if (empty($address_fields)) {
333 333
             exit;
334 334
         }
335 335
 
336
-        foreach ( $address_fields['fields'] as $address_field ) {
336
+        foreach ($address_fields['fields'] as $address_field) {
337 337
 
338
-            if ( 'wpinv_state' == $address_field['name'] ) {
338
+            if ('wpinv_state' == $address_field['name']) {
339 339
 
340
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
341
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
342
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
343
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
344
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
345
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
340
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
341
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
342
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
343
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
344
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
345
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
346 346
 
347
-                if ( ! empty( $address_field['required'] ) ) {
347
+                if (!empty($address_field['required'])) {
348 348
                     $label .= "<span class='text-danger'> *</span>";
349 349
                 }
350 350
 
351
-                $html = getpaid_get_states_select_markup (
352
-                    sanitize_text_field( $_GET['country'] ),
351
+                $html = getpaid_get_states_select_markup(
352
+                    sanitize_text_field($_GET['country']),
353 353
                     $value,
354 354
                     $placeholder,
355 355
                     $label,
356 356
                     $description,
357
-                    ! empty( $address_field['required'] ),
357
+                    !empty($address_field['required']),
358 358
                     $wrap_class,
359
-                    wpinv_clean( $_GET['name'] )
359
+                    wpinv_clean($_GET['name'])
360 360
                 );
361 361
 
362
-                wp_send_json_success( $html );
362
+                wp_send_json_success($html);
363 363
                 exit;
364 364
 
365 365
             }
@@ -375,66 +375,66 @@  discard block
 block discarded – undo
375 375
     public static function recalculate_invoice_totals() {
376 376
 
377 377
         // Verify nonce.
378
-        check_ajax_referer( 'wpinv-nonce' );
378
+        check_ajax_referer('wpinv-nonce');
379 379
 
380
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
380
+        if (!wpinv_current_user_can_manage_invoicing()) {
381 381
             exit;
382 382
         }
383 383
 
384 384
         // We need an invoice.
385
-        if ( empty( $_POST['post_id'] ) ) {
385
+        if (empty($_POST['post_id'])) {
386 386
             exit;
387 387
         }
388 388
 
389 389
         // Fetch the invoice.
390
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
390
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
391 391
 
392 392
         // Ensure it exists.
393
-        if ( ! $invoice->get_id() ) {
393
+        if (!$invoice->get_id()) {
394 394
             exit;
395 395
         }
396 396
 
397 397
         // Maybe set the country, state, currency.
398
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
399
-            if ( isset( $_POST[ $key ] ) ) {
398
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
399
+            if (isset($_POST[$key])) {
400 400
                 $method = "set_$key";
401
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
401
+                $invoice->$method(sanitize_text_field($_POST[$key]));
402 402
             }
403 403
         }
404 404
 
405 405
         // Maybe disable taxes.
406
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
406
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
407 407
 
408 408
         // Discount code.
409
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
410
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
411
-            if ( $discount->exists() ) {
412
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
409
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
410
+            $discount = new WPInv_Discount($invoice->get_discount_code());
411
+            if ($discount->exists()) {
412
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
413 413
             } else {
414
-                $invoice->remove_discount( 'discount_code' );
414
+                $invoice->remove_discount('discount_code');
415 415
             }
416 416
         }
417 417
 
418 418
         // Recalculate totals.
419 419
         $invoice->recalculate_total();
420 420
 
421
-        $total = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
421
+        $total = wpinv_price($invoice->get_total(), $invoice->get_currency());
422 422
 
423
-        if ( $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
424
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
425
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
423
+        if ($invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
424
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
425
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
426 426
         }
427 427
 
428 428
         $totals = array(
429
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
430
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
431
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
429
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
430
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
431
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
432 432
             'total'    => $total,
433 433
         );
434 434
 
435
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
435
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
436 436
 
437
-        wp_send_json_success( compact( 'totals' ) );
437
+        wp_send_json_success(compact('totals'));
438 438
     }
439 439
 
440 440
     /**
@@ -443,33 +443,33 @@  discard block
 block discarded – undo
443 443
     public static function get_invoice_items() {
444 444
 
445 445
         // Verify nonce.
446
-        check_ajax_referer( 'wpinv-nonce' );
446
+        check_ajax_referer('wpinv-nonce');
447 447
 
448
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
448
+        if (!wpinv_current_user_can_manage_invoicing()) {
449 449
             exit;
450 450
         }
451 451
 
452 452
         // We need an invoice and items.
453
-        if ( empty( $_POST['post_id'] ) ) {
453
+        if (empty($_POST['post_id'])) {
454 454
             exit;
455 455
         }
456 456
 
457 457
         // Fetch the invoice.
458
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
458
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
459 459
 
460 460
         // Ensure it exists.
461
-        if ( ! $invoice->get_id() ) {
461
+        if (!$invoice->get_id()) {
462 462
             exit;
463 463
         }
464 464
 
465 465
         // Return an array of invoice items.
466 466
         $items = array();
467 467
 
468
-        foreach ( $invoice->get_items() as $item ) {
469
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency(), $invoice->is_renewal()  );
468
+        foreach ($invoice->get_items() as $item) {
469
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
470 470
         }
471 471
 
472
-        wp_send_json_success( compact( 'items' ) );
472
+        wp_send_json_success(compact('items'));
473 473
     }
474 474
 
475 475
     /**
@@ -478,50 +478,50 @@  discard block
 block discarded – undo
478 478
     public static function edit_invoice_item() {
479 479
 
480 480
         // Verify nonce.
481
-        check_ajax_referer( 'wpinv-nonce' );
481
+        check_ajax_referer('wpinv-nonce');
482 482
 
483
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
483
+        if (!wpinv_current_user_can_manage_invoicing()) {
484 484
             exit;
485 485
         }
486 486
 
487 487
         // We need an invoice and item details.
488
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
488
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
489 489
             exit;
490 490
         }
491 491
 
492 492
         // Fetch the invoice.
493
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
493
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
494 494
 
495 495
         // Ensure it exists and its not been paid for.
496
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
496
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
497 497
             exit;
498 498
         }
499 499
 
500 500
         // Format the data.
501
-        $data = wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) );
501
+        $data = wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field'));
502 502
 
503 503
         // Ensure that we have an item id.
504
-        if ( empty( $data['id'] ) ) {
504
+        if (empty($data['id'])) {
505 505
             exit;
506 506
         }
507 507
 
508 508
         // Abort if the invoice does not have the specified item.
509
-        $item = $invoice->get_item( (int) $data['id'] );
509
+        $item = $invoice->get_item((int) $data['id']);
510 510
 
511
-        if ( empty( $item ) ) {
511
+        if (empty($item)) {
512 512
             exit;
513 513
         }
514 514
 
515 515
         // Update the item.
516
-        $item->set_price( floatval( $data['price'] ) );
517
-        $item->set_name( sanitize_text_field( $data['name'] ) );
518
-        $item->set_description( wp_kses_post( $data['description'] ) );
519
-        $item->set_quantity( intval( $data['quantity'] ) );
516
+        $item->set_price(floatval($data['price']));
517
+        $item->set_name(sanitize_text_field($data['name']));
518
+        $item->set_description(wp_kses_post($data['description']));
519
+        $item->set_quantity(intval($data['quantity']));
520 520
 
521 521
         // Add it to the invoice.
522
-        $error = $invoice->add_item( $item );
522
+        $error = $invoice->add_item($item);
523 523
         $alert = false;
524
-        if ( is_wp_error( $error ) ) {
524
+        if (is_wp_error($error)) {
525 525
             $alert = $error->get_error_message();
526 526
         }
527 527
 
@@ -534,11 +534,11 @@  discard block
 block discarded – undo
534 534
         // Return an array of invoice items.
535 535
         $items = array();
536 536
 
537
-        foreach ( $invoice->get_items() as $item ) {
538
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
537
+        foreach ($invoice->get_items() as $item) {
538
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
539 539
         }
540 540
 
541
-        wp_send_json_success( compact( 'items', 'alert' ) );
541
+        wp_send_json_success(compact('items', 'alert'));
542 542
     }
543 543
 
544 544
     /**
@@ -547,33 +547,33 @@  discard block
 block discarded – undo
547 547
     public static function remove_invoice_item() {
548 548
 
549 549
         // Verify nonce.
550
-        check_ajax_referer( 'wpinv-nonce' );
550
+        check_ajax_referer('wpinv-nonce');
551 551
 
552
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
552
+        if (!wpinv_current_user_can_manage_invoicing()) {
553 553
             exit;
554 554
         }
555 555
 
556 556
         // We need an invoice and an item.
557
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
557
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
558 558
             exit;
559 559
         }
560 560
 
561 561
         // Fetch the invoice.
562
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
562
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
563 563
 
564 564
         // Ensure it exists and its not been paid for.
565
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
565
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
566 566
             exit;
567 567
         }
568 568
 
569 569
         // Abort if the invoice does not have the specified item.
570
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
570
+        $item = $invoice->get_item((int) $_POST['item_id']);
571 571
 
572
-        if ( empty( $item ) ) {
572
+        if (empty($item)) {
573 573
             exit;
574 574
         }
575 575
 
576
-        $invoice->remove_item( (int) $_POST['item_id'] );
576
+        $invoice->remove_item((int) $_POST['item_id']);
577 577
 
578 578
         // Update totals.
579 579
         $invoice->recalculate_total();
@@ -584,11 +584,11 @@  discard block
 block discarded – undo
584 584
         // Return an array of invoice items.
585 585
         $items = array();
586 586
 
587
-        foreach ( $invoice->get_items() as $item ) {
588
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
587
+        foreach ($invoice->get_items() as $item) {
588
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
589 589
         }
590 590
 
591
-        wp_send_json_success( compact( 'items' ) );
591
+        wp_send_json_success(compact('items'));
592 592
     }
593 593
 
594 594
     /**
@@ -597,39 +597,39 @@  discard block
 block discarded – undo
597 597
     public static function add_invoice_items() {
598 598
 
599 599
         // Verify nonce.
600
-        check_ajax_referer( 'wpinv-nonce' );
600
+        check_ajax_referer('wpinv-nonce');
601 601
 
602
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
602
+        if (!wpinv_current_user_can_manage_invoicing()) {
603 603
             exit;
604 604
         }
605 605
 
606 606
         // We need an invoice and items.
607
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
607
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
608 608
             exit;
609 609
         }
610 610
 
611 611
         // Fetch the invoice.
612
-        $invoice = new WPInv_Invoice( trim( $_POST['post_id'] ) );
612
+        $invoice = new WPInv_Invoice(trim($_POST['post_id']));
613 613
         $alert   = false;
614 614
 
615 615
         // Ensure it exists and its not been paid for.
616
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
616
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
617 617
             exit;
618 618
         }
619 619
 
620 620
         // Add the items.
621
-        foreach ( $_POST['items'] as $data ) {
621
+        foreach ($_POST['items'] as $data) {
622 622
 
623
-            $item = new GetPaid_Form_Item( $data[ 'id' ] );
623
+            $item = new GetPaid_Form_Item($data['id']);
624 624
 
625
-            if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) {
626
-                $item->set_quantity( $data[ 'qty' ] );
625
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
626
+                $item->set_quantity($data['qty']);
627 627
             }
628 628
 
629
-            if ( $item->get_id() > 0 ) {
630
-                $error = $invoice->add_item( $item );
629
+            if ($item->get_id() > 0) {
630
+                $error = $invoice->add_item($item);
631 631
 
632
-                if ( is_wp_error( $error ) ) {
632
+                if (is_wp_error($error)) {
633 633
                     $alert = $error->get_error_message();
634 634
                 }
635 635
 
@@ -644,11 +644,11 @@  discard block
 block discarded – undo
644 644
         // Return an array of invoice items.
645 645
         $items = array();
646 646
 
647
-        foreach ( $invoice->get_items() as $item ) {
648
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
647
+        foreach ($invoice->get_items() as $item) {
648
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
649 649
         }
650 650
 
651
-        wp_send_json_success( compact( 'items', 'alert' ) );
651
+        wp_send_json_success(compact('items', 'alert'));
652 652
     }
653 653
 
654 654
     /**
@@ -657,15 +657,15 @@  discard block
 block discarded – undo
657 657
     public static function get_invoicing_items() {
658 658
 
659 659
         // Verify nonce.
660
-        check_ajax_referer( 'wpinv-nonce' );
660
+        check_ajax_referer('wpinv-nonce');
661 661
 
662
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
662
+        if (!wpinv_current_user_can_manage_invoicing()) {
663 663
             exit;
664 664
         }
665 665
 
666 666
         // We need a search term.
667
-        if ( empty( $_GET['search'] ) ) {
668
-            wp_send_json_success( array() );
667
+        if (empty($_GET['search'])) {
668
+            wp_send_json_success(array());
669 669
         }
670 670
 
671 671
         // Retrieve items.
@@ -674,8 +674,8 @@  discard block
 block discarded – undo
674 674
             'orderby'        => 'title',
675 675
             'order'          => 'ASC',
676 676
             'posts_per_page' => -1,
677
-            'post_status'    => array( 'publish' ),
678
-            's'              => trim( $_GET['search'] ),
677
+            'post_status'    => array('publish'),
678
+            's'              => trim($_GET['search']),
679 679
             'meta_query'     => array(
680 680
                 array(
681 681
                     'key'       => '_wpinv_type',
@@ -685,22 +685,22 @@  discard block
 block discarded – undo
685 685
             )
686 686
         );
687 687
 
688
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
688
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
689 689
         $data  = array();
690 690
 
691 691
 
692
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
692
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
693 693
 
694
-        foreach ( $items as $item ) {
695
-            $item      = new GetPaid_Form_Item( $item );
694
+        foreach ($items as $item) {
695
+            $item = new GetPaid_Form_Item($item);
696 696
             $data[] = array(
697 697
                 'id'        => (int) $item->get_id(),
698
-                'text'      => strip_tags( $item->get_name() ),
699
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
698
+                'text'      => strip_tags($item->get_name()),
699
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
700 700
             );
701 701
         }
702 702
 
703
-        wp_send_json_success( $data );
703
+        wp_send_json_success($data);
704 704
 
705 705
     }
706 706
 
@@ -710,37 +710,37 @@  discard block
 block discarded – undo
710 710
     public static function get_customers() {
711 711
 
712 712
         // Verify nonce.
713
-        check_ajax_referer( 'wpinv-nonce' );
713
+        check_ajax_referer('wpinv-nonce');
714 714
 
715
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
715
+        if (!wpinv_current_user_can_manage_invoicing()) {
716 716
             exit;
717 717
         }
718 718
 
719 719
         // We need a search term.
720
-        if ( empty( $_GET['search'] ) ) {
721
-            wp_send_json_success( array() );
720
+        if (empty($_GET['search'])) {
721
+            wp_send_json_success(array());
722 722
         }
723 723
 
724 724
         // Retrieve customers.
725 725
     
726 726
         $customer_args = array(
727
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
727
+            'fields'         => array('ID', 'user_email', 'display_name'),
728 728
             'orderby'        => 'display_name',
729
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
730
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
729
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
730
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
731 731
         );
732 732
 
733
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
733
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
734 734
         $data      = array();
735 735
 
736
-        foreach ( $customers as $customer ) {
736
+        foreach ($customers as $customer) {
737 737
             $data[] = array(
738 738
                 'id'        => (int) $customer->ID,
739
-                'text'      => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
739
+                'text'      => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
740 740
             );
741 741
         }
742 742
 
743
-        wp_send_json_success( $data );
743
+        wp_send_json_success($data);
744 744
 
745 745
     }
746 746
 
@@ -750,28 +750,28 @@  discard block
 block discarded – undo
750 750
     public static function get_aui_states_field() {
751 751
 
752 752
         // Verify nonce.
753
-        check_ajax_referer( 'wpinv-nonce' );
753
+        check_ajax_referer('wpinv-nonce');
754 754
 
755 755
         // We need a country.
756
-        if ( empty( $_GET['country'] ) ) {
756
+        if (empty($_GET['country'])) {
757 757
             exit;
758 758
         }
759 759
 
760
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
761
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
762
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
763
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
760
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
761
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
762
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
763
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
764 764
 
765
-        if ( empty( $states ) ) {
765
+        if (empty($states)) {
766 766
 
767 767
             $html = aui()->input(
768 768
                 array(
769 769
                     'type'        => 'text',
770 770
                     'id'          => 'wpinv_state',
771 771
                     'name'        => $name,
772
-                    'label'       => __( 'State', 'invoicing' ),
772
+                    'label'       => __('State', 'invoicing'),
773 773
                     'label_type'  => 'vertical',
774
-                    'placeholder' => __( 'State', 'invoicing' ),
774
+                    'placeholder' => __('State', 'invoicing'),
775 775
                     'class'       => $class,
776 776
                     'value'       => $state,
777 777
                 )
@@ -783,9 +783,9 @@  discard block
 block discarded – undo
783 783
                 array(
784 784
                     'id'          => 'wpinv_state',
785 785
                     'name'        => $name,
786
-                    'label'       => __( 'State', 'invoicing' ),
786
+                    'label'       => __('State', 'invoicing'),
787 787
                     'label_type'  => 'vertical',
788
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
788
+                    'placeholder' => __('Select a state', 'invoicing'),
789 789
                     'class'       => $class,
790 790
                     'value'       => $state,
791 791
                     'options'     => $states,
@@ -799,7 +799,7 @@  discard block
 block discarded – undo
799 799
         wp_send_json_success(
800 800
             array(
801 801
                 'html'   => $html,
802
-                'select' => ! empty ( $states )
802
+                'select' => !empty ($states)
803 803
             )
804 804
         );
805 805
 
@@ -813,11 +813,11 @@  discard block
 block discarded – undo
813 813
     public static function payment_form_refresh_prices() {
814 814
 
815 815
         // Check nonce.
816
-        check_ajax_referer( 'getpaid_form_nonce' );
816
+        check_ajax_referer('getpaid_form_nonce');
817 817
 
818 818
         // ... form fields...
819
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
820
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
819
+        if (empty($_POST['getpaid_payment_form_submission'])) {
820
+            _e('Error: Reload the page and try again.', 'invoicing');
821 821
             exit;
822 822
         }
823 823
 
@@ -825,7 +825,7 @@  discard block
 block discarded – undo
825 825
         $submission = new GetPaid_Payment_Form_Submission();
826 826
 
827 827
         // Do we have an error?
828
-        if ( ! empty( $submission->last_error ) ) {
828
+        if (!empty($submission->last_error)) {
829 829
             wp_send_json_error(
830 830
                 array(
831 831
                     'code'  => $submission->last_error_code,
@@ -835,12 +835,12 @@  discard block
 block discarded – undo
835 835
         }
836 836
 
837 837
         // Prepare the response.
838
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
838
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
839 839
 
840 840
         // Filter the response.
841
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
841
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
842 842
 
843
-        wp_send_json_success( $response );
843
+        wp_send_json_success($response);
844 844
     }
845 845
 
846 846
 }
Please login to merge, or discard this patch.