Passed
Push — master ( e43dde...969080 )
by Brian
05:38
created
includes/payments/class-getpaid-form-item.php 2 patches
Indentation   +359 added lines, -359 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,67 +10,67 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Form_Item  extends WPInv_Item {
11 11
 
12 12
     /**
13
-	 * Stores a custom description for the item.
14
-	 *
15
-	 * @var string
16
-	 */
17
-	protected $custom_description = null;
18
-
19
-	/**
20
-	 * Stores the item quantity.
21
-	 *
22
-	 * @var float
23
-	 */
24
-	protected $quantity = 1;
25
-
26
-	/**
27
-	 * Stores the item meta.
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $meta = array();
32
-
33
-	/**
34
-	 * Is this item required?
35
-	 *
36
-	 * @var int
37
-	 */
38
-	protected $is_required = true;
39
-
40
-	/**
41
-	 * Are quantities allowed?
42
-	 *
43
-	 * @var int
44
-	 */
45
-	protected $allow_quantities = false;
46
-
47
-	/**
48
-	 * Associated invoice.
49
-	 *
50
-	 * @var int
51
-	 */
52
-	public $invoice_id = 0;
53
-
54
-	/**
55
-	 * Item discount.
56
-	 *
57
-	 * @var float
58
-	 */
59
-	public $item_discount = 0;
60
-
61
-	/**
62
-	 * Recurring item discount.
63
-	 *
64
-	 * @var float
65
-	 */
66
-	public $recurring_item_discount = 0;
67
-
68
-	/**
69
-	 * Item tax.
70
-	 *
71
-	 * @var float
72
-	 */
73
-	public $item_tax = 0;
13
+     * Stores a custom description for the item.
14
+     *
15
+     * @var string
16
+     */
17
+    protected $custom_description = null;
18
+
19
+    /**
20
+     * Stores the item quantity.
21
+     *
22
+     * @var float
23
+     */
24
+    protected $quantity = 1;
25
+
26
+    /**
27
+     * Stores the item meta.
28
+     *
29
+     * @var array
30
+     */
31
+    protected $meta = array();
32
+
33
+    /**
34
+     * Is this item required?
35
+     *
36
+     * @var int
37
+     */
38
+    protected $is_required = true;
39
+
40
+    /**
41
+     * Are quantities allowed?
42
+     *
43
+     * @var int
44
+     */
45
+    protected $allow_quantities = false;
46
+
47
+    /**
48
+     * Associated invoice.
49
+     *
50
+     * @var int
51
+     */
52
+    public $invoice_id = 0;
53
+
54
+    /**
55
+     * Item discount.
56
+     *
57
+     * @var float
58
+     */
59
+    public $item_discount = 0;
60
+
61
+    /**
62
+     * Recurring item discount.
63
+     *
64
+     * @var float
65
+     */
66
+    public $recurring_item_discount = 0;
67
+
68
+    /**
69
+     * Item tax.
70
+     *
71
+     * @var float
72
+     */
73
+    public $item_tax = 0;
74 74
 
75 75
     /*
76 76
 	|--------------------------------------------------------------------------
@@ -88,230 +88,230 @@  discard block
 block discarded – undo
88 88
     */
89 89
 
90 90
     /**
91
-	 * Get the item name.
92
-	 *
93
-	 * @since 1.0.19
94
-	 * @param  string $context View or edit context.
95
-	 * @return string
96
-	 */
97
-	public function get_name( $context = 'view' ) {
98
-		$name = parent::get_name( $context );
99
-		return $name . wpinv_get_item_suffix( $this );
100
-	}
101
-
102
-	/**
103
-	 * Get the item name without a suffix.
104
-	 *
105
-	 * @since 1.0.19
106
-	 * @param  string $context View or edit context.
107
-	 * @return string
108
-	 */
109
-	public function get_raw_name( $context = 'view' ) {
110
-		return parent::get_name( $context );
111
-	}
112
-
113
-	/**
114
-	 * Get the item description.
115
-	 *
116
-	 * @since 1.0.19
117
-	 * @param  string $context View or edit context.
118
-	 * @return string
119
-	 */
120
-	public function get_description( $context = 'view' ) {
121
-
122
-		if ( isset( $this->custom_description ) ) {
123
-			return $this->custom_description;
124
-		}
125
-
126
-		return parent::get_description( $context );
127
-	}
128
-
129
-	/**
130
-	 * Returns the sub total.
131
-	 *
132
-	 * @since 1.0.19
133
-	 * @param  string $context View or edit context.
134
-	 * @return float
135
-	 */
136
-	public function get_sub_total( $context = 'view' ) {
137
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context );
138
-	}
139
-
140
-	/**
141
-	 * Returns the recurring sub total.
142
-	 *
143
-	 * @since 1.0.19
144
-	 * @param  string $context View or edit context.
145
-	 * @return float
146
-	 */
147
-	public function get_recurring_sub_total( $context = 'view' ) {
148
-
149
-		if ( $this->is_recurring() ) {
150
-			return $this->get_quantity( $context ) * $this->get_price( $context );
151
-		}
152
-
153
-		return 0;
154
-	}
155
-
156
-	/**
157
-	 * @deprecated
158
-	 */
159
-	public function get_qantity( $context = 'view' ) {
160
-		return $this->get_quantity( $context );
161
-	}
162
-
163
-	/**
164
-	 * Get the item quantity.
165
-	 *
166
-	 * @since 1.0.19
167
-	 * @param  string $context View or edit context.
168
-	 * @return float
169
-	 */
170
-	public function get_quantity( $context = 'view' ) {
171
-		$quantity = (float) $this->quantity;
172
-
173
-		if ( 'view' == $context ) {
174
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
175
-		}
176
-
177
-		return $quantity;
178
-
179
-	}
180
-
181
-	/**
182
-	 * Get the item meta data.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return meta
187
-	 */
188
-	public function get_item_meta( $context = 'view' ) {
189
-		$meta = $this->meta;
190
-
191
-		if ( 'view' == $context ) {
192
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
193
-		}
194
-
195
-		return $meta;
196
-
197
-	}
198
-
199
-	/**
200
-	 * Returns whether or not customers can update the item quantity.
201
-	 *
202
-	 * @since 1.0.19
203
-	 * @param  string $context View or edit context.
204
-	 * @return bool
205
-	 */
206
-	public function get_allow_quantities( $context = 'view' ) {
207
-		$allow_quantities = (bool) $this->allow_quantities;
208
-
209
-		if ( 'view' == $context ) {
210
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
211
-		}
212
-
213
-		return $allow_quantities;
214
-
215
-	}
216
-
217
-	/**
218
-	 * Returns whether or not the item is required.
219
-	 *
220
-	 * @since 1.0.19
221
-	 * @param  string $context View or edit context.
222
-	 * @return bool
223
-	 */
224
-	public function get_is_required( $context = 'view' ) {
225
-		$is_required = (bool) $this->is_required;
226
-
227
-		if ( 'view' == $context ) {
228
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
229
-		}
230
-
231
-		return $is_required;
232
-
233
-	}
234
-
235
-	/**
236
-	 * Prepares form data for use.
237
-	 *
238
-	 * @since 1.0.19
239
-	 * @return array
240
-	 */
241
-	public function prepare_data_for_use( $required = null ) {
242
-
243
-		$required = is_null( $required ) ? $this->is_required() : $required;
244
-		return array(
245
-			'title'            => strip_tags( $this->get_name() ),
246
-			'id'               => $this->get_id(),
247
-			'price'            => $this->get_price(),
248
-			'recurring'        => $this->is_recurring(),
249
-			'description'      => $this->get_description(),
250
-			'allow_quantities' => $this->allows_quantities(),
251
-			'required'         => $required,
252
-		);
253
-
254
-	}
255
-
256
-	/**
257
-	 * Prepares form data for ajax use.
258
-	 *
259
-	 * @since 1.0.19
260
-	 * @return array
261
-	 */
262
-	public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
263
-
264
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
265
-
266
-		if ( $description ) {
267
-			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
268
-		}
269
-
270
-		$price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
271
-		$subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
272
-		return array(
273
-			'id'     => $this->get_id(),
274
-			'texts'  => array(
275
-				'item-name'        => sanitize_text_field( $this->get_name() ),
276
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
277
-				'item-quantity'    => floatval( $this->get_quantity() ),
278
-				'item-price'       => wpinv_price( $price, $currency ),
279
-				'item-total'       => wpinv_price( $subtotal, $currency ),
280
-			),
281
-			'inputs' => array(
282
-				'item-id'          => $this->get_id(),
283
-				'item-name'        => sanitize_text_field( $this->get_name() ),
284
-				'item-description' => wp_kses_post( $this->get_description() ),
285
-				'item-quantity'    => floatval( $this->get_quantity() ),
286
-				'item-price'       => $price,
287
-			)
288
-		);
289
-
290
-	}
291
-
292
-	/**
293
-	 * Prepares form data for saving (cart_details).
294
-	 *
295
-	 * @since 1.0.19
296
-	 * @return array
297
-	 */
298
-	public function prepare_data_for_saving() {
299
-
300
-		return array(
301
-			'post_id'           => $this->invoice_id,
302
-			'item_id'           => $this->get_id(),
303
-			'item_name'         => sanitize_text_field( $this->get_raw_name() ),
304
-			'item_description'  => $this->get_description(),
305
-			'tax'               => $this->item_tax,
306
-			'item_price'        => $this->get_price(),
307
-			'quantity'          => (float) $this->get_quantity(),
308
-			'discount'          => $this->item_discount,
309
-			'subtotal'          => $this->get_sub_total(),
310
-			'price'             => $this->get_sub_total() + $this->item_tax - $this->item_discount,
311
-			'meta'              => $this->get_item_meta(),
312
-		);
313
-
314
-	}
91
+     * Get the item name.
92
+     *
93
+     * @since 1.0.19
94
+     * @param  string $context View or edit context.
95
+     * @return string
96
+     */
97
+    public function get_name( $context = 'view' ) {
98
+        $name = parent::get_name( $context );
99
+        return $name . wpinv_get_item_suffix( $this );
100
+    }
101
+
102
+    /**
103
+     * Get the item name without a suffix.
104
+     *
105
+     * @since 1.0.19
106
+     * @param  string $context View or edit context.
107
+     * @return string
108
+     */
109
+    public function get_raw_name( $context = 'view' ) {
110
+        return parent::get_name( $context );
111
+    }
112
+
113
+    /**
114
+     * Get the item description.
115
+     *
116
+     * @since 1.0.19
117
+     * @param  string $context View or edit context.
118
+     * @return string
119
+     */
120
+    public function get_description( $context = 'view' ) {
121
+
122
+        if ( isset( $this->custom_description ) ) {
123
+            return $this->custom_description;
124
+        }
125
+
126
+        return parent::get_description( $context );
127
+    }
128
+
129
+    /**
130
+     * Returns the sub total.
131
+     *
132
+     * @since 1.0.19
133
+     * @param  string $context View or edit context.
134
+     * @return float
135
+     */
136
+    public function get_sub_total( $context = 'view' ) {
137
+        return $this->get_quantity( $context ) * $this->get_initial_price( $context );
138
+    }
139
+
140
+    /**
141
+     * Returns the recurring sub total.
142
+     *
143
+     * @since 1.0.19
144
+     * @param  string $context View or edit context.
145
+     * @return float
146
+     */
147
+    public function get_recurring_sub_total( $context = 'view' ) {
148
+
149
+        if ( $this->is_recurring() ) {
150
+            return $this->get_quantity( $context ) * $this->get_price( $context );
151
+        }
152
+
153
+        return 0;
154
+    }
155
+
156
+    /**
157
+     * @deprecated
158
+     */
159
+    public function get_qantity( $context = 'view' ) {
160
+        return $this->get_quantity( $context );
161
+    }
162
+
163
+    /**
164
+     * Get the item quantity.
165
+     *
166
+     * @since 1.0.19
167
+     * @param  string $context View or edit context.
168
+     * @return float
169
+     */
170
+    public function get_quantity( $context = 'view' ) {
171
+        $quantity = (float) $this->quantity;
172
+
173
+        if ( 'view' == $context ) {
174
+            return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
175
+        }
176
+
177
+        return $quantity;
178
+
179
+    }
180
+
181
+    /**
182
+     * Get the item meta data.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return meta
187
+     */
188
+    public function get_item_meta( $context = 'view' ) {
189
+        $meta = $this->meta;
190
+
191
+        if ( 'view' == $context ) {
192
+            return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
193
+        }
194
+
195
+        return $meta;
196
+
197
+    }
198
+
199
+    /**
200
+     * Returns whether or not customers can update the item quantity.
201
+     *
202
+     * @since 1.0.19
203
+     * @param  string $context View or edit context.
204
+     * @return bool
205
+     */
206
+    public function get_allow_quantities( $context = 'view' ) {
207
+        $allow_quantities = (bool) $this->allow_quantities;
208
+
209
+        if ( 'view' == $context ) {
210
+            return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
211
+        }
212
+
213
+        return $allow_quantities;
214
+
215
+    }
216
+
217
+    /**
218
+     * Returns whether or not the item is required.
219
+     *
220
+     * @since 1.0.19
221
+     * @param  string $context View or edit context.
222
+     * @return bool
223
+     */
224
+    public function get_is_required( $context = 'view' ) {
225
+        $is_required = (bool) $this->is_required;
226
+
227
+        if ( 'view' == $context ) {
228
+            return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
229
+        }
230
+
231
+        return $is_required;
232
+
233
+    }
234
+
235
+    /**
236
+     * Prepares form data for use.
237
+     *
238
+     * @since 1.0.19
239
+     * @return array
240
+     */
241
+    public function prepare_data_for_use( $required = null ) {
242
+
243
+        $required = is_null( $required ) ? $this->is_required() : $required;
244
+        return array(
245
+            'title'            => strip_tags( $this->get_name() ),
246
+            'id'               => $this->get_id(),
247
+            'price'            => $this->get_price(),
248
+            'recurring'        => $this->is_recurring(),
249
+            'description'      => $this->get_description(),
250
+            'allow_quantities' => $this->allows_quantities(),
251
+            'required'         => $required,
252
+        );
253
+
254
+    }
255
+
256
+    /**
257
+     * Prepares form data for ajax use.
258
+     *
259
+     * @since 1.0.19
260
+     * @return array
261
+     */
262
+    public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
263
+
264
+        $description = getpaid_item_recurring_price_help_text( $this, $currency );
265
+
266
+        if ( $description ) {
267
+            $description = "<div class='getpaid-subscription-help-text'>$description</div>";
268
+        }
269
+
270
+        $price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
271
+        $subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
272
+        return array(
273
+            'id'     => $this->get_id(),
274
+            'texts'  => array(
275
+                'item-name'        => sanitize_text_field( $this->get_name() ),
276
+                'item-description' => wp_kses_post( $this->get_description() ) . $description,
277
+                'item-quantity'    => floatval( $this->get_quantity() ),
278
+                'item-price'       => wpinv_price( $price, $currency ),
279
+                'item-total'       => wpinv_price( $subtotal, $currency ),
280
+            ),
281
+            'inputs' => array(
282
+                'item-id'          => $this->get_id(),
283
+                'item-name'        => sanitize_text_field( $this->get_name() ),
284
+                'item-description' => wp_kses_post( $this->get_description() ),
285
+                'item-quantity'    => floatval( $this->get_quantity() ),
286
+                'item-price'       => $price,
287
+            )
288
+        );
289
+
290
+    }
291
+
292
+    /**
293
+     * Prepares form data for saving (cart_details).
294
+     *
295
+     * @since 1.0.19
296
+     * @return array
297
+     */
298
+    public function prepare_data_for_saving() {
299
+
300
+        return array(
301
+            'post_id'           => $this->invoice_id,
302
+            'item_id'           => $this->get_id(),
303
+            'item_name'         => sanitize_text_field( $this->get_raw_name() ),
304
+            'item_description'  => $this->get_description(),
305
+            'tax'               => $this->item_tax,
306
+            'item_price'        => $this->get_price(),
307
+            'quantity'          => (float) $this->get_quantity(),
308
+            'discount'          => $this->item_discount,
309
+            'subtotal'          => $this->get_sub_total(),
310
+            'price'             => $this->get_sub_total() + $this->item_tax - $this->item_discount,
311
+            'meta'              => $this->get_item_meta(),
312
+        );
313
+
314
+    }
315 315
 
316 316
     /*
317 317
 	|--------------------------------------------------------------------------
@@ -323,70 +323,70 @@  discard block
 block discarded – undo
323 323
 	| object.
324 324
     */
325 325
 
326
-	/**
327
-	 * Set the item qantity.
328
-	 *
329
-	 * @since 1.0.19
330
-	 * @param  float $quantity The item quantity.
331
-	 */
332
-	public function set_quantity( $quantity ) {
333
-
334
-		if ( ! is_numeric( $quantity ) ) {
335
-			$quantity = 1;
336
-		}
337
-
338
-		$this->quantity = (float) $quantity;
339
-
340
-	}
341
-
342
-	/**
343
-	 * Set the item meta data.
344
-	 *
345
-	 * @since 1.0.19
346
-	 * @param  array $meta The item meta data.
347
-	 */
348
-	public function set_item_meta( $meta ) {
349
-		$this->meta = maybe_unserialize( $meta );
350
-	}
351
-
352
-	/**
353
-	 * Set whether or not the quantities are allowed.
354
-	 *
355
-	 * @since 1.0.19
356
-	 * @param  bool $allow_quantities
357
-	 */
358
-	public function set_allow_quantities( $allow_quantities ) {
359
-		$this->allow_quantities = (bool) $allow_quantities;
360
-	}
361
-
362
-	/**
363
-	 * Set whether or not the item is required.
364
-	 *
365
-	 * @since 1.0.19
366
-	 * @param  bool $is_required
367
-	 */
368
-	public function set_is_required( $is_required ) {
369
-		$this->is_required = (bool) $is_required;
370
-	}
371
-
372
-	/**
373
-	 * Sets the custom item description.
374
-	 *
375
-	 * @since 1.0.19
376
-	 * @param  string $description
377
-	 */
378
-	public function set_custom_description( $description ) {
379
-		$this->custom_description = $description;
380
-	}
326
+    /**
327
+     * Set the item qantity.
328
+     *
329
+     * @since 1.0.19
330
+     * @param  float $quantity The item quantity.
331
+     */
332
+    public function set_quantity( $quantity ) {
333
+
334
+        if ( ! is_numeric( $quantity ) ) {
335
+            $quantity = 1;
336
+        }
337
+
338
+        $this->quantity = (float) $quantity;
339
+
340
+    }
341
+
342
+    /**
343
+     * Set the item meta data.
344
+     *
345
+     * @since 1.0.19
346
+     * @param  array $meta The item meta data.
347
+     */
348
+    public function set_item_meta( $meta ) {
349
+        $this->meta = maybe_unserialize( $meta );
350
+    }
351
+
352
+    /**
353
+     * Set whether or not the quantities are allowed.
354
+     *
355
+     * @since 1.0.19
356
+     * @param  bool $allow_quantities
357
+     */
358
+    public function set_allow_quantities( $allow_quantities ) {
359
+        $this->allow_quantities = (bool) $allow_quantities;
360
+    }
361
+
362
+    /**
363
+     * Set whether or not the item is required.
364
+     *
365
+     * @since 1.0.19
366
+     * @param  bool $is_required
367
+     */
368
+    public function set_is_required( $is_required ) {
369
+        $this->is_required = (bool) $is_required;
370
+    }
371
+
372
+    /**
373
+     * Sets the custom item description.
374
+     *
375
+     * @since 1.0.19
376
+     * @param  string $description
377
+     */
378
+    public function set_custom_description( $description ) {
379
+        $this->custom_description = $description;
380
+    }
381 381
 
382 382
     /**
383 383
      * We do not want to save items to the database.
384 384
      * 
385
-	 * @return int item id
385
+     * @return int item id
386 386
      */
387 387
     public function save( $data = array() ) {
388 388
         return $this->get_id();
389
-	}
389
+    }
390 390
 
391 391
     /*
392 392
 	|--------------------------------------------------------------------------
@@ -398,23 +398,23 @@  discard block
 block discarded – undo
398 398
 	*/
399 399
 
400 400
     /**
401
-	 * Checks whether the item has enabled dynamic pricing.
402
-	 *
403
-	 * @since 1.0.19
404
-	 * @return bool
405
-	 */
406
-	public function is_required() {
401
+     * Checks whether the item has enabled dynamic pricing.
402
+     *
403
+     * @since 1.0.19
404
+     * @return bool
405
+     */
406
+    public function is_required() {
407 407
         return (bool) $this->get_is_required();
408
-	}
409
-
410
-	/**
411
-	 * Checks whether users can edit the quantities.
412
-	 *
413
-	 * @since 1.0.19
414
-	 * @return bool
415
-	 */
416
-	public function allows_quantities() {
408
+    }
409
+
410
+    /**
411
+     * Checks whether users can edit the quantities.
412
+     *
413
+     * @since 1.0.19
414
+     * @return bool
415
+     */
416
+    public function allows_quantities() {
417 417
         return (bool) $this->get_allow_quantities();
418
-	}
418
+    }
419 419
 
420 420
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 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
 
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
 	 * @param  string $context View or edit context.
95 95
 	 * @return string
96 96
 	 */
97
-	public function get_name( $context = 'view' ) {
98
-		$name = parent::get_name( $context );
99
-		return $name . wpinv_get_item_suffix( $this );
97
+	public function get_name($context = 'view') {
98
+		$name = parent::get_name($context);
99
+		return $name . wpinv_get_item_suffix($this);
100 100
 	}
101 101
 
102 102
 	/**
@@ -106,8 +106,8 @@  discard block
 block discarded – undo
106 106
 	 * @param  string $context View or edit context.
107 107
 	 * @return string
108 108
 	 */
109
-	public function get_raw_name( $context = 'view' ) {
110
-		return parent::get_name( $context );
109
+	public function get_raw_name($context = 'view') {
110
+		return parent::get_name($context);
111 111
 	}
112 112
 
113 113
 	/**
@@ -117,13 +117,13 @@  discard block
 block discarded – undo
117 117
 	 * @param  string $context View or edit context.
118 118
 	 * @return string
119 119
 	 */
120
-	public function get_description( $context = 'view' ) {
120
+	public function get_description($context = 'view') {
121 121
 
122
-		if ( isset( $this->custom_description ) ) {
122
+		if (isset($this->custom_description)) {
123 123
 			return $this->custom_description;
124 124
 		}
125 125
 
126
-		return parent::get_description( $context );
126
+		return parent::get_description($context);
127 127
 	}
128 128
 
129 129
 	/**
@@ -133,8 +133,8 @@  discard block
 block discarded – undo
133 133
 	 * @param  string $context View or edit context.
134 134
 	 * @return float
135 135
 	 */
136
-	public function get_sub_total( $context = 'view' ) {
137
-		return $this->get_quantity( $context ) * $this->get_initial_price( $context );
136
+	public function get_sub_total($context = 'view') {
137
+		return $this->get_quantity($context) * $this->get_initial_price($context);
138 138
 	}
139 139
 
140 140
 	/**
@@ -144,10 +144,10 @@  discard block
 block discarded – undo
144 144
 	 * @param  string $context View or edit context.
145 145
 	 * @return float
146 146
 	 */
147
-	public function get_recurring_sub_total( $context = 'view' ) {
147
+	public function get_recurring_sub_total($context = 'view') {
148 148
 
149
-		if ( $this->is_recurring() ) {
150
-			return $this->get_quantity( $context ) * $this->get_price( $context );
149
+		if ($this->is_recurring()) {
150
+			return $this->get_quantity($context) * $this->get_price($context);
151 151
 		}
152 152
 
153 153
 		return 0;
@@ -156,8 +156,8 @@  discard block
 block discarded – undo
156 156
 	/**
157 157
 	 * @deprecated
158 158
 	 */
159
-	public function get_qantity( $context = 'view' ) {
160
-		return $this->get_quantity( $context );
159
+	public function get_qantity($context = 'view') {
160
+		return $this->get_quantity($context);
161 161
 	}
162 162
 
163 163
 	/**
@@ -167,11 +167,11 @@  discard block
 block discarded – undo
167 167
 	 * @param  string $context View or edit context.
168 168
 	 * @return float
169 169
 	 */
170
-	public function get_quantity( $context = 'view' ) {
170
+	public function get_quantity($context = 'view') {
171 171
 		$quantity = (float) $this->quantity;
172 172
 
173
-		if ( 'view' == $context ) {
174
-			return apply_filters( 'getpaid_payment_form_item_quantity', $quantity, $this );
173
+		if ('view' == $context) {
174
+			return apply_filters('getpaid_payment_form_item_quantity', $quantity, $this);
175 175
 		}
176 176
 
177 177
 		return $quantity;
@@ -185,11 +185,11 @@  discard block
 block discarded – undo
185 185
 	 * @param  string $context View or edit context.
186 186
 	 * @return meta
187 187
 	 */
188
-	public function get_item_meta( $context = 'view' ) {
188
+	public function get_item_meta($context = 'view') {
189 189
 		$meta = $this->meta;
190 190
 
191
-		if ( 'view' == $context ) {
192
-			return apply_filters( 'getpaid_payment_form_item_meta', $meta, $this );
191
+		if ('view' == $context) {
192
+			return apply_filters('getpaid_payment_form_item_meta', $meta, $this);
193 193
 		}
194 194
 
195 195
 		return $meta;
@@ -203,11 +203,11 @@  discard block
 block discarded – undo
203 203
 	 * @param  string $context View or edit context.
204 204
 	 * @return bool
205 205
 	 */
206
-	public function get_allow_quantities( $context = 'view' ) {
206
+	public function get_allow_quantities($context = 'view') {
207 207
 		$allow_quantities = (bool) $this->allow_quantities;
208 208
 
209
-		if ( 'view' == $context ) {
210
-			return apply_filters( 'getpaid_payment_form_item_allow_quantities', $allow_quantities, $this );
209
+		if ('view' == $context) {
210
+			return apply_filters('getpaid_payment_form_item_allow_quantities', $allow_quantities, $this);
211 211
 		}
212 212
 
213 213
 		return $allow_quantities;
@@ -221,11 +221,11 @@  discard block
 block discarded – undo
221 221
 	 * @param  string $context View or edit context.
222 222
 	 * @return bool
223 223
 	 */
224
-	public function get_is_required( $context = 'view' ) {
224
+	public function get_is_required($context = 'view') {
225 225
 		$is_required = (bool) $this->is_required;
226 226
 
227
-		if ( 'view' == $context ) {
228
-			return apply_filters( 'getpaid_payment_form_item_is_required', $is_required, $this );
227
+		if ('view' == $context) {
228
+			return apply_filters('getpaid_payment_form_item_is_required', $is_required, $this);
229 229
 		}
230 230
 
231 231
 		return $is_required;
@@ -238,11 +238,11 @@  discard block
 block discarded – undo
238 238
 	 * @since 1.0.19
239 239
 	 * @return array
240 240
 	 */
241
-	public function prepare_data_for_use( $required = null ) {
241
+	public function prepare_data_for_use($required = null) {
242 242
 
243
-		$required = is_null( $required ) ? $this->is_required() : $required;
243
+		$required = is_null($required) ? $this->is_required() : $required;
244 244
 		return array(
245
-			'title'            => strip_tags( $this->get_name() ),
245
+			'title'            => strip_tags($this->get_name()),
246 246
 			'id'               => $this->get_id(),
247 247
 			'price'            => $this->get_price(),
248 248
 			'recurring'        => $this->is_recurring(),
@@ -259,30 +259,30 @@  discard block
 block discarded – undo
259 259
 	 * @since 1.0.19
260 260
 	 * @return array
261 261
 	 */
262
-	public function prepare_data_for_invoice_edit_ajax( $currency = '', $is_renewal = false ) {
262
+	public function prepare_data_for_invoice_edit_ajax($currency = '', $is_renewal = false) {
263 263
 
264
-		$description = getpaid_item_recurring_price_help_text( $this, $currency );
264
+		$description = getpaid_item_recurring_price_help_text($this, $currency);
265 265
 
266
-		if ( $description ) {
266
+		if ($description) {
267 267
 			$description = "<div class='getpaid-subscription-help-text'>$description</div>";
268 268
 		}
269 269
 
270
-		$price    = ! $is_renewal ? $this->get_price() : $this->get_recurring_price();
271
-		$subtotal = ! $is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
270
+		$price    = !$is_renewal ? $this->get_price() : $this->get_recurring_price();
271
+		$subtotal = !$is_renewal ? $this->get_sub_total() : $this->get_recurring_sub_total();
272 272
 		return array(
273 273
 			'id'     => $this->get_id(),
274 274
 			'texts'  => array(
275
-				'item-name'        => sanitize_text_field( $this->get_name() ),
276
-				'item-description' => wp_kses_post( $this->get_description() ) . $description,
277
-				'item-quantity'    => floatval( $this->get_quantity() ),
278
-				'item-price'       => wpinv_price( $price, $currency ),
279
-				'item-total'       => wpinv_price( $subtotal, $currency ),
275
+				'item-name'        => sanitize_text_field($this->get_name()),
276
+				'item-description' => wp_kses_post($this->get_description()) . $description,
277
+				'item-quantity'    => floatval($this->get_quantity()),
278
+				'item-price'       => wpinv_price($price, $currency),
279
+				'item-total'       => wpinv_price($subtotal, $currency),
280 280
 			),
281 281
 			'inputs' => array(
282 282
 				'item-id'          => $this->get_id(),
283
-				'item-name'        => sanitize_text_field( $this->get_name() ),
284
-				'item-description' => wp_kses_post( $this->get_description() ),
285
-				'item-quantity'    => floatval( $this->get_quantity() ),
283
+				'item-name'        => sanitize_text_field($this->get_name()),
284
+				'item-description' => wp_kses_post($this->get_description()),
285
+				'item-quantity'    => floatval($this->get_quantity()),
286 286
 				'item-price'       => $price,
287 287
 			)
288 288
 		);
@@ -300,7 +300,7 @@  discard block
 block discarded – undo
300 300
 		return array(
301 301
 			'post_id'           => $this->invoice_id,
302 302
 			'item_id'           => $this->get_id(),
303
-			'item_name'         => sanitize_text_field( $this->get_raw_name() ),
303
+			'item_name'         => sanitize_text_field($this->get_raw_name()),
304 304
 			'item_description'  => $this->get_description(),
305 305
 			'tax'               => $this->item_tax,
306 306
 			'item_price'        => $this->get_price(),
@@ -329,9 +329,9 @@  discard block
 block discarded – undo
329 329
 	 * @since 1.0.19
330 330
 	 * @param  float $quantity The item quantity.
331 331
 	 */
332
-	public function set_quantity( $quantity ) {
332
+	public function set_quantity($quantity) {
333 333
 
334
-		if ( ! is_numeric( $quantity ) ) {
334
+		if (!is_numeric($quantity)) {
335 335
 			$quantity = 1;
336 336
 		}
337 337
 
@@ -345,8 +345,8 @@  discard block
 block discarded – undo
345 345
 	 * @since 1.0.19
346 346
 	 * @param  array $meta The item meta data.
347 347
 	 */
348
-	public function set_item_meta( $meta ) {
349
-		$this->meta = maybe_unserialize( $meta );
348
+	public function set_item_meta($meta) {
349
+		$this->meta = maybe_unserialize($meta);
350 350
 	}
351 351
 
352 352
 	/**
@@ -355,7 +355,7 @@  discard block
 block discarded – undo
355 355
 	 * @since 1.0.19
356 356
 	 * @param  bool $allow_quantities
357 357
 	 */
358
-	public function set_allow_quantities( $allow_quantities ) {
358
+	public function set_allow_quantities($allow_quantities) {
359 359
 		$this->allow_quantities = (bool) $allow_quantities;
360 360
 	}
361 361
 
@@ -365,7 +365,7 @@  discard block
 block discarded – undo
365 365
 	 * @since 1.0.19
366 366
 	 * @param  bool $is_required
367 367
 	 */
368
-	public function set_is_required( $is_required ) {
368
+	public function set_is_required($is_required) {
369 369
 		$this->is_required = (bool) $is_required;
370 370
 	}
371 371
 
@@ -375,7 +375,7 @@  discard block
 block discarded – undo
375 375
 	 * @since 1.0.19
376 376
 	 * @param  string $description
377 377
 	 */
378
-	public function set_custom_description( $description ) {
378
+	public function set_custom_description($description) {
379 379
 		$this->custom_description = $description;
380 380
 	}
381 381
 
@@ -384,7 +384,7 @@  discard block
 block discarded – undo
384 384
      * 
385 385
 	 * @return int item id
386 386
      */
387
-    public function save( $data = array() ) {
387
+    public function save($data = array()) {
388 388
         return $this->get_id();
389 389
 	}
390 390
 
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission-items.php 2 patches
Indentation   +72 added lines, -72 removed lines patch added patch discarded remove patch
@@ -12,38 +12,38 @@  discard block
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Payment_Form_Submission_Items {
14 14
 
15
-	/**
16
-	 * Submission items.
17
-	 * @var GetPaid_Form_Item[]
18
-	 */
19
-	public $items = array();
15
+    /**
16
+     * Submission items.
17
+     * @var GetPaid_Form_Item[]
18
+     */
19
+    public $items = array();
20 20
 
21 21
     /**
22
-	 * Class constructor
23
-	 *
24
-	 * @param GetPaid_Payment_Form_Submission $submission
25
-	 */
26
-	public function __construct( $submission ) {
27
-
28
-		$data         = $submission->get_data();
29
-		$payment_form = $submission->get_payment_form();
30
-
31
-		// Prepare the selected items.
32
-		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
35
-		}
36
-
37
-		// (Maybe) set form items.
38
-		if ( isset( $data['getpaid-form-items'] ) ) {
39
-
40
-			// Confirm items key.
41
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
42
-			if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) {
43
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
44
-			}
45
-
46
-			$items    = array();
22
+     * Class constructor
23
+     *
24
+     * @param GetPaid_Payment_Form_Submission $submission
25
+     */
26
+    public function __construct( $submission ) {
27
+
28
+        $data         = $submission->get_data();
29
+        $payment_form = $submission->get_payment_form();
30
+
31
+        // Prepare the selected items.
32
+        $selected_items = array();
33
+        if ( ! empty( $data['getpaid-items'] ) ) {
34
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
35
+        }
36
+
37
+        // (Maybe) set form items.
38
+        if ( isset( $data['getpaid-form-items'] ) ) {
39
+
40
+            // Confirm items key.
41
+            $form_items = wpinv_clean( $data['getpaid-form-items'] );
42
+            if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) {
43
+                throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
44
+            }
45
+
46
+            $items    = array();
47 47
             $item_ids = array();
48 48
 
49 49
             foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
@@ -74,58 +74,58 @@  discard block
 block discarded – undo
74 74
 
75 75
             $payment_form->set_items( $items );
76 76
 
77
-		}
78
-
79
-		// Process each individual item.
80
-		foreach ( $payment_form->get_items() as $item ) {
81
-			$this->process_item( $item, $selected_items, $submission );
82
-		}
83
-
84
-	}
77
+        }
85 78
 
86
-	/**
87
-	 * Process a single item.
88
-	 *
89
-	 * @param GetPaid_Form_Item $item
90
-	 * @param array $selected_items
91
-	 * @param GetPaid_Payment_Form_Submission $submission
92
-	 */
93
-	public function process_item( $item, $selected_items, $submission ) {
79
+        // Process each individual item.
80
+        foreach ( $payment_form->get_items() as $item ) {
81
+            $this->process_item( $item, $selected_items, $submission );
82
+        }
94 83
 
95
-		// Abort if this is an optional item and it has not been selected.
96
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
97
-			return;
98
-		}
84
+    }
99 85
 
100
-		// (maybe) let customers change the quantities and prices.
101
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
102
-
103
-			// Maybe change the quantities.
104
-			if ( $item->allows_quantities() ) {
105
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
106
-			}
86
+    /**
87
+     * Process a single item.
88
+     *
89
+     * @param GetPaid_Form_Item $item
90
+     * @param array $selected_items
91
+     * @param GetPaid_Payment_Form_Submission $submission
92
+     */
93
+    public function process_item( $item, $selected_items, $submission ) {
94
+
95
+        // Abort if this is an optional item and it has not been selected.
96
+        if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
97
+            return;
98
+        }
99
+
100
+        // (maybe) let customers change the quantities and prices.
101
+        if ( isset( $selected_items[ $item->get_id() ] ) ) {
102
+
103
+            // Maybe change the quantities.
104
+            if ( $item->allows_quantities() ) {
105
+                $item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
106
+            }
107 107
 
108
-			// Maybe change the price.
109
-			if ( $item->user_can_set_their_price() ) {
110
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
108
+            // Maybe change the price.
109
+            if ( $item->user_can_set_their_price() ) {
110
+                $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
111 111
 
112
-				if ( $item->get_minimum_price() > $price ) {
113
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
114
-				}
112
+                if ( $item->get_minimum_price() > $price ) {
113
+                    throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
114
+                }
115 115
 
116
-				$item->set_price( $price );
116
+                $item->set_price( $price );
117 117
 
118
-			}
118
+            }
119 119
 
120
-		}
120
+        }
121 121
 
122
-		if ( 0 == $item->get_quantity() ) {
123
-			return;
124
-		}
122
+        if ( 0 == $item->get_quantity() ) {
123
+            return;
124
+        }
125 125
 
126
-		// Save the item.
127
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
126
+        // Save the item.
127
+        $this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
128 128
 
129
-	}
129
+    }
130 130
 
131 131
 }
Please login to merge, or discard this patch.
Spacing   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Payment form submission itemss class
@@ -23,37 +23,37 @@  discard block
 block discarded – undo
23 23
 	 *
24 24
 	 * @param GetPaid_Payment_Form_Submission $submission
25 25
 	 */
26
-	public function __construct( $submission ) {
26
+	public function __construct($submission) {
27 27
 
28 28
 		$data         = $submission->get_data();
29 29
 		$payment_form = $submission->get_payment_form();
30 30
 
31 31
 		// Prepare the selected items.
32 32
 		$selected_items = array();
33
-		if ( ! empty( $data['getpaid-items'] ) ) {
34
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
33
+		if (!empty($data['getpaid-items'])) {
34
+			$selected_items = wpinv_clean($data['getpaid-items']);
35 35
 		}
36 36
 
37 37
 		// (Maybe) set form items.
38
-		if ( isset( $data['getpaid-form-items'] ) ) {
38
+		if (isset($data['getpaid-form-items'])) {
39 39
 
40 40
 			// Confirm items key.
41
-			$form_items = wpinv_clean( $data['getpaid-form-items'] );
42
-			if ( ! isset( $data['getpaid-form-items-key'] ) || $data['getpaid-form-items-key'] !== md5( NONCE_KEY . AUTH_KEY . $form_items ) ) {
43
-				throw new Exception( __( 'We could not validate the form items. Please reload the page and try again.', 'invoicing' ) );
41
+			$form_items = wpinv_clean($data['getpaid-form-items']);
42
+			if (!isset($data['getpaid-form-items-key']) || $data['getpaid-form-items-key'] !== md5(NONCE_KEY . AUTH_KEY . $form_items)) {
43
+				throw new Exception(__('We could not validate the form items. Please reload the page and try again.', 'invoicing'));
44 44
 			}
45 45
 
46
-			$items    = array();
46
+			$items = array();
47 47
             $item_ids = array();
48 48
 
49
-            foreach ( getpaid_convert_items_to_array( $form_items ) as $item_id => $qty ) {
50
-                if ( ! in_array( $item_id, $item_ids ) ) {
51
-                    $item = new GetPaid_Form_Item( $item_id );
52
-                    $item->set_quantity( $qty );
49
+            foreach (getpaid_convert_items_to_array($form_items) as $item_id => $qty) {
50
+                if (!in_array($item_id, $item_ids)) {
51
+                    $item = new GetPaid_Form_Item($item_id);
52
+                    $item->set_quantity($qty);
53 53
 
54
-                    if ( 0 == $qty ) {
55
-                        $item->set_allow_quantities( true );
56
-                        $item->set_is_required( false );
54
+                    if (0 == $qty) {
55
+                        $item->set_allow_quantities(true);
56
+                        $item->set_is_required(false);
57 57
                     }
58 58
 
59 59
                     $item_ids[] = $item->get_id();
@@ -61,10 +61,10 @@  discard block
 block discarded – undo
61 61
                 }
62 62
             }
63 63
 
64
-            if ( ! $payment_form->is_default() ) {
64
+            if (!$payment_form->is_default()) {
65 65
 
66
-                foreach ( $payment_form->get_items() as $item ) {
67
-                    if ( ! in_array( $item->get_id(), $item_ids ) ) {
66
+                foreach ($payment_form->get_items() as $item) {
67
+                    if (!in_array($item->get_id(), $item_ids)) {
68 68
                         $item_ids[] = $item->get_id();
69 69
                         $items[]    = $item;
70 70
                     }
@@ -72,13 +72,13 @@  discard block
 block discarded – undo
72 72
 
73 73
             }
74 74
 
75
-            $payment_form->set_items( $items );
75
+            $payment_form->set_items($items);
76 76
 
77 77
 		}
78 78
 
79 79
 		// Process each individual item.
80
-		foreach ( $payment_form->get_items() as $item ) {
81
-			$this->process_item( $item, $selected_items, $submission );
80
+		foreach ($payment_form->get_items() as $item) {
81
+			$this->process_item($item, $selected_items, $submission);
82 82
 		}
83 83
 
84 84
 	}
@@ -90,41 +90,41 @@  discard block
 block discarded – undo
90 90
 	 * @param array $selected_items
91 91
 	 * @param GetPaid_Payment_Form_Submission $submission
92 92
 	 */
93
-	public function process_item( $item, $selected_items, $submission ) {
93
+	public function process_item($item, $selected_items, $submission) {
94 94
 
95 95
 		// Abort if this is an optional item and it has not been selected.
96
-		if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
96
+		if (!$item->is_required() && !isset($selected_items[$item->get_id()])) {
97 97
 			return;
98 98
 		}
99 99
 
100 100
 		// (maybe) let customers change the quantities and prices.
101
-		if ( isset( $selected_items[ $item->get_id() ] ) ) {
101
+		if (isset($selected_items[$item->get_id()])) {
102 102
 
103 103
 			// Maybe change the quantities.
104
-			if ( $item->allows_quantities() ) {
105
-				$item->set_quantity( (float) $selected_items[ $item->get_id() ]['quantity'] );
104
+			if ($item->allows_quantities()) {
105
+				$item->set_quantity((float) $selected_items[$item->get_id()]['quantity']);
106 106
 			}
107 107
 
108 108
 			// Maybe change the price.
109
-			if ( $item->user_can_set_their_price() ) {
110
-				$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
109
+			if ($item->user_can_set_their_price()) {
110
+				$price = (float) wpinv_sanitize_amount($selected_items[$item->get_id()]['price']);
111 111
 
112
-				if ( $item->get_minimum_price() > $price ) {
113
-					throw new Exception( sprintf( __( 'The minimum allowed amount is %s', 'invoicing' ), getpaid_unstandardize_amount( $item->get_minimum_price() ) ) );
112
+				if ($item->get_minimum_price() > $price) {
113
+					throw new Exception(sprintf(__('The minimum allowed amount is %s', 'invoicing'), getpaid_unstandardize_amount($item->get_minimum_price())));
114 114
 				}
115 115
 
116
-				$item->set_price( $price );
116
+				$item->set_price($price);
117 117
 
118 118
 			}
119 119
 
120 120
 		}
121 121
 
122
-		if ( 0 == $item->get_quantity() ) {
122
+		if (0 == $item->get_quantity()) {
123 123
 			return;
124 124
 		}
125 125
 
126 126
 		// Save the item.
127
-		$this->items[] = apply_filters( 'getpaid_payment_form_submission_processed_item' , $item, $submission );
127
+		$this->items[] = apply_filters('getpaid_payment_form_submission_processed_item', $item, $submission);
128 128
 
129 129
 	}
130 130
 
Please login to merge, or discard this patch.
includes/admin/meta-boxes/class-getpaid-meta-box-discount-details.php 2 patches
Indentation   +26 added lines, -26 removed lines patch added patch discarded remove patch
@@ -8,7 +8,7 @@  discard block
 block discarded – undo
8 8
  */
9 9
 
10 10
 if ( ! defined( 'ABSPATH' ) ) {
11
-	exit; // Exit if accessed directly
11
+    exit; // Exit if accessed directly
12 12
 }
13 13
 
14 14
 /**
@@ -17,10 +17,10 @@  discard block
 block discarded – undo
17 17
 class GetPaid_Meta_Box_Discount_Details {
18 18
 
19 19
     /**
20
-	 * Output the metabox.
21
-	 *
22
-	 * @param WP_Post $post
23
-	 */
20
+     * Output the metabox.
21
+     *
22
+     * @param WP_Post $post
23
+     */
24 24
     public static function output( $post ) {
25 25
 
26 26
         // Prepare the discount.
@@ -368,34 +368,34 @@  discard block
 block discarded – undo
368 368
     }
369 369
 
370 370
     /**
371
-	 * Save meta box data.
372
-	 *
373
-	 * @param int $post_id
374
-	 */
375
-	public static function save( $post_id ) {
371
+     * Save meta box data.
372
+     *
373
+     * @param int $post_id
374
+     */
375
+    public static function save( $post_id ) {
376 376
 
377 377
         // Prepare the discount.
378 378
         $discount = new WPInv_Discount( $post_id );
379 379
 
380 380
         // Load new data.
381 381
         $discount->set_props(
382
-			array(
383
-				'code'                 => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null,
384
-				'amount'               => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null,
385
-				'start'                => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
386
-				'expiration'           => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
387
-				'is_single_use'        => isset( $_POST['wpinv_discount_single_use'] ),
382
+            array(
383
+                'code'                 => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null,
384
+                'amount'               => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null,
385
+                'start'                => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
386
+                'expiration'           => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
387
+                'is_single_use'        => isset( $_POST['wpinv_discount_single_use'] ),
388 388
                 'type'                 => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null,
389
-				'is_recurring'         => isset( $_POST['wpinv_discount_recurring'] ),
390
-				'items'                => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(),
391
-				'excluded_items'       => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(),
392
-				'max_uses'             => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null,
393
-				'min_total'            => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null,
394
-				'max_total'            => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null,
395
-			)
389
+                'is_recurring'         => isset( $_POST['wpinv_discount_recurring'] ),
390
+                'items'                => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(),
391
+                'excluded_items'       => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(),
392
+                'max_uses'             => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null,
393
+                'min_total'            => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null,
394
+                'max_total'            => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null,
395
+            )
396 396
         );
397 397
 
398
-		$discount->save();
399
-		do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
400
-	}
398
+        $discount->save();
399
+        do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
400
+    }
401 401
 }
Please login to merge, or discard this patch.
Spacing   +96 added lines, -96 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  *
8 8
  */
9 9
 
10
-if ( ! defined( 'ABSPATH' ) ) {
10
+if (!defined('ABSPATH')) {
11 11
 	exit; // Exit if accessed directly
12 12
 }
13 13
 
@@ -21,24 +21,24 @@  discard block
 block discarded – undo
21 21
 	 *
22 22
 	 * @param WP_Post $post
23 23
 	 */
24
-    public static function output( $post ) {
24
+    public static function output($post) {
25 25
 
26 26
         // Prepare the discount.
27
-        $discount = new WPInv_Discount( $post );
27
+        $discount = new WPInv_Discount($post);
28 28
 
29 29
         // Nonce field.
30
-        wp_nonce_field( 'getpaid_meta_nonce', 'getpaid_meta_nonce' );
30
+        wp_nonce_field('getpaid_meta_nonce', 'getpaid_meta_nonce');
31 31
 
32
-        do_action( 'wpinv_discount_form_top', $discount );
32
+        do_action('wpinv_discount_form_top', $discount);
33 33
 
34 34
         // Set the currency position.
35 35
         $position = wpinv_currency_position();
36 36
 
37
-        if ( $position == 'left_space' ) {
37
+        if ($position == 'left_space') {
38 38
             $position = 'left';
39 39
         }
40 40
 
41
-        if ( $position == 'right_space' ) {
41
+        if ($position == 'right_space') {
42 42
             $position = 'right';
43 43
         }
44 44
 
@@ -52,66 +52,66 @@  discard block
 block discarded – undo
52 52
         </style>
53 53
         <div class='bsui' style='max-width: 600px;padding-top: 10px;'>
54 54
 
55
-            <?php do_action( 'wpinv_discount_form_first', $discount ); ?>
55
+            <?php do_action('wpinv_discount_form_first', $discount); ?>
56 56
 
57
-            <?php do_action( 'wpinv_discount_form_before_code', $discount ); ?>
57
+            <?php do_action('wpinv_discount_form_before_code', $discount); ?>
58 58
             <div class="form-group row">
59 59
                 <label for="wpinv_discount_code" class="col-sm-3 col-form-label">
60
-                    <?php _e( 'Discount Code', 'invoicing' );?>
60
+                    <?php _e('Discount Code', 'invoicing'); ?>
61 61
                 </label>
62 62
                 <div class="col-sm-8">
63 63
                     <div class="row">
64 64
                         <div class="col-sm-12 form-group">
65
-                            <input type="text" value="<?php echo esc_attr( $discount->get_code( 'edit' ) ); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" />
65
+                            <input type="text" value="<?php echo esc_attr($discount->get_code('edit')); ?>" placeholder="SUMMER_SALE" name="wpinv_discount_code" id="wpinv_discount_code" style="width: 100%;" />
66 66
                         </div>
67 67
                         <div class="col-sm-12">
68 68
                             <?php
69
-                                do_action( 'wpinv_discount_form_before_single_use', $discount );
69
+                                do_action('wpinv_discount_form_before_single_use', $discount);
70 70
 
71 71
                                 echo aui()->input(
72 72
                                     array(
73 73
                                         'id'          => 'wpinv_discount_single_use',
74 74
                                         'name'        => 'wpinv_discount_single_use',
75 75
                                         'type'        => 'checkbox',
76
-                                        'label'       => __( 'Each customer can only use this discount once', 'invoicing' ),
76
+                                        'label'       => __('Each customer can only use this discount once', 'invoicing'),
77 77
                                         'value'       => '1',
78 78
                                         'checked'     => $discount->is_single_use(),
79 79
                                     )
80 80
                                 );
81 81
 
82
-                                do_action( 'wpinv_discount_form_single_use', $discount );
82
+                                do_action('wpinv_discount_form_single_use', $discount);
83 83
                             ?>
84 84
                         </div>
85 85
                         <div class="col-sm-12">
86 86
                             <?php
87
-                                do_action( 'wpinv_discount_form_before_recurring', $discount );
87
+                                do_action('wpinv_discount_form_before_recurring', $discount);
88 88
 
89 89
                                 echo aui()->input(
90 90
                                     array(
91 91
                                         'id'          => 'wpinv_discount_recurring',
92 92
                                         'name'        => 'wpinv_discount_recurring',
93 93
                                         'type'        => 'checkbox',
94
-                                        'label'       => __( 'Apply this discount to all recurring payments for subscriptions', 'invoicing' ),
94
+                                        'label'       => __('Apply this discount to all recurring payments for subscriptions', 'invoicing'),
95 95
                                         'value'       => '1',
96 96
                                         'checked'     => $discount->is_recurring(),
97 97
                                     )
98 98
                                 );
99 99
 
100
-                                do_action( 'wpinv_discount_form_recurring', $discount );
100
+                                do_action('wpinv_discount_form_recurring', $discount);
101 101
                             ?>
102 102
                         </div>
103 103
                     </div>
104 104
                 </div>
105 105
                 <div class="col-sm-1 pt-2 pl-0">
106
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter a discount code such as 10OFF.', 'invoicing' ); ?>"></span>
106
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter a discount code such as 10OFF.', 'invoicing'); ?>"></span>
107 107
                 </div>
108 108
             </div>
109
-            <?php do_action( 'wpinv_discount_form_code', $discount ); ?>
109
+            <?php do_action('wpinv_discount_form_code', $discount); ?>
110 110
 
111
-            <?php do_action( 'wpinv_discount_form_before_type', $discount ); ?>
111
+            <?php do_action('wpinv_discount_form_before_type', $discount); ?>
112 112
             <div class="form-group row">
113 113
                 <label for="wpinv_discount_type" class="col-sm-3 col-form-label">
114
-                    <?php _e( 'Discount Type', 'invoicing' );?>
114
+                    <?php _e('Discount Type', 'invoicing'); ?>
115 115
                 </label>
116 116
                 <div class="col-sm-8">
117 117
                     <?php
@@ -119,9 +119,9 @@  discard block
 block discarded – undo
119 119
                             array(
120 120
                                 'id'               => 'wpinv_discount_type',
121 121
                                 'name'             => 'wpinv_discount_type',
122
-                                'label'            => __( 'Discount Type', 'invoicing' ),
123
-                                'placeholder'      => __( 'Select Discount Type', 'invoicing' ),
124
-                                'value'            => $discount->get_type( 'edit' ),
122
+                                'label'            => __('Discount Type', 'invoicing'),
123
+                                'placeholder'      => __('Select Discount Type', 'invoicing'),
124
+                                'value'            => $discount->get_type('edit'),
125 125
                                 'select2'          => true,
126 126
                                 'data-allow-clear' => 'false',
127 127
                                 'options'          => wpinv_get_discount_types()
@@ -130,19 +130,19 @@  discard block
 block discarded – undo
130 130
                     ?>
131 131
                 </div>
132 132
                 <div class="col-sm-1 pt-2 pl-0">
133
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Discount type.', 'invoicing' ); ?>"></span>
133
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Discount type.', 'invoicing'); ?>"></span>
134 134
                 </div>
135 135
             </div>
136
-            <?php do_action( 'wpinv_discount_form_type', $discount ); ?>
136
+            <?php do_action('wpinv_discount_form_type', $discount); ?>
137 137
 
138
-            <?php do_action( 'wpinv_discount_form_before_amount', $discount ); ?>
139
-            <div class="form-group row <?php echo esc_attr( $discount->get_type( 'edit' ) ); ?>" id="wpinv_discount_amount_wrap">
138
+            <?php do_action('wpinv_discount_form_before_amount', $discount); ?>
139
+            <div class="form-group row <?php echo esc_attr($discount->get_type('edit')); ?>" id="wpinv_discount_amount_wrap">
140 140
                 <label for="wpinv_discount_amount" class="col-sm-3 col-form-label">
141
-                    <?php _e( 'Discount Amount', 'invoicing' );?>
141
+                    <?php _e('Discount Amount', 'invoicing'); ?>
142 142
                 </label>
143 143
                 <div class="col-sm-8">
144 144
                     <div class="input-group input-group-sm">
145
-                        <?php if( 'left' == $position ) : ?>
145
+                        <?php if ('left' == $position) : ?>
146 146
                             <div class="input-group-prepend left wpinv-if-flat">
147 147
                                 <span class="input-group-text">
148 148
                                     <?php echo wpinv_currency_symbol(); ?>
@@ -150,9 +150,9 @@  discard block
 block discarded – undo
150 150
                             </div>
151 151
                         <?php endif; ?>
152 152
 
153
-                        <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr( $discount->get_amount( 'edit' ) ); ?>" placeholder="0" class="form-control">
153
+                        <input type="text" name="wpinv_discount_amount" id="wpinv_discount_amount" value="<?php echo esc_attr($discount->get_amount('edit')); ?>" placeholder="0" class="form-control">
154 154
 
155
-                        <?php if( 'right' == $position ) : ?>
155
+                        <?php if ('right' == $position) : ?>
156 156
                             <div class="input-group-prepend left wpinv-if-flat">
157 157
                                 <span class="input-group-text">
158 158
                                     <?php echo wpinv_currency_symbol(); ?>
@@ -165,15 +165,15 @@  discard block
 block discarded – undo
165 165
                     </div>
166 166
                 </div>
167 167
                 <div class="col-sm-1 pt-2 pl-0">
168
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Enter the discount value. Ex: 10', 'invoicing' ); ?>"></span>
168
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Enter the discount value. Ex: 10', 'invoicing'); ?>"></span>
169 169
                 </div>
170 170
             </div>
171
-            <?php do_action( 'wpinv_discount_form_amount', $discount ); ?>
171
+            <?php do_action('wpinv_discount_form_amount', $discount); ?>
172 172
 
173
-            <?php do_action( 'wpinv_discount_form_before_items', $discount ); ?>
173
+            <?php do_action('wpinv_discount_form_before_items', $discount); ?>
174 174
             <div class="form-group row">
175 175
                 <label for="wpinv_discount_items" class="col-sm-3 col-form-label">
176
-                    <?php _e( 'Items', 'invoicing' );?>
176
+                    <?php _e('Items', 'invoicing'); ?>
177 177
                 </label>
178 178
                 <div class="col-sm-8">
179 179
                     <?php
@@ -181,9 +181,9 @@  discard block
 block discarded – undo
181 181
                             array(
182 182
                                 'id'               => 'wpinv_discount_items',
183 183
                                 'name'             => 'wpinv_discount_items[]',
184
-                                'label'            => __( 'Items', 'invoicing' ),
185
-                                'placeholder'      => __( 'Select Items', 'invoicing' ),
186
-                                'value'            => $discount->get_items( 'edit' ),
184
+                                'label'            => __('Items', 'invoicing'),
185
+                                'placeholder'      => __('Select Items', 'invoicing'),
186
+                                'value'            => $discount->get_items('edit'),
187 187
                                 'select2'          => true,
188 188
                                 'multiple'         => true,
189 189
                                 'data-allow-clear' => 'false',
@@ -193,15 +193,15 @@  discard block
 block discarded – undo
193 193
                     ?>
194 194
                 </div>
195 195
                 <div class="col-sm-1 pt-2 pl-0">
196
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing' ); ?>"></span>
196
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select the items that are allowed to use this discount or leave blank to use this discount all items.', 'invoicing'); ?>"></span>
197 197
                 </div>
198 198
             </div>
199
-            <?php do_action( 'wpinv_discount_form_items', $discount ); ?>
199
+            <?php do_action('wpinv_discount_form_items', $discount); ?>
200 200
 
201
-            <?php do_action( 'wpinv_discount_form_before_excluded_items', $discount ); ?>
201
+            <?php do_action('wpinv_discount_form_before_excluded_items', $discount); ?>
202 202
             <div class="form-group row">
203 203
                 <label for="wpinv_discount_excluded_items" class="col-sm-3 col-form-label">
204
-                    <?php _e( 'Excluded Items', 'invoicing' );?>
204
+                    <?php _e('Excluded Items', 'invoicing'); ?>
205 205
                 </label>
206 206
                 <div class="col-sm-8">
207 207
                     <?php
@@ -209,9 +209,9 @@  discard block
 block discarded – undo
209 209
                             array(
210 210
                                 'id'               => 'wpinv_discount_excluded_items',
211 211
                                 'name'             => 'wpinv_discount_excluded_items[]',
212
-                                'label'            => __( 'Excluded Items', 'invoicing' ),
213
-                                'placeholder'      => __( 'Select Items', 'invoicing' ),
214
-                                'value'            => $discount->get_excluded_items( 'edit' ),
212
+                                'label'            => __('Excluded Items', 'invoicing'),
213
+                                'placeholder'      => __('Select Items', 'invoicing'),
214
+                                'value'            => $discount->get_excluded_items('edit'),
215 215
                                 'select2'          => true,
216 216
                                 'multiple'         => true,
217 217
                                 'data-allow-clear' => 'false',
@@ -221,15 +221,15 @@  discard block
 block discarded – undo
221 221
                     ?>
222 222
                 </div>
223 223
                 <div class="col-sm-1 pt-2 pl-0">
224
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Select all the items that are not allowed to use this discount.', 'invoicing' ); ?>"></span>
224
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Select all the items that are not allowed to use this discount.', 'invoicing'); ?>"></span>
225 225
                 </div>
226 226
             </div>
227
-            <?php do_action( 'wpinv_discount_form_excluded_items', $discount ); ?>
227
+            <?php do_action('wpinv_discount_form_excluded_items', $discount); ?>
228 228
 
229
-            <?php do_action( 'wpinv_discount_form_before_start', $discount ); ?>
229
+            <?php do_action('wpinv_discount_form_before_start', $discount); ?>
230 230
             <div class="form-group row">
231 231
                 <label for="wpinv_discount_start" class="col-sm-3 col-form-label">
232
-                    <?php _e( 'Start Date', 'invoicing' );?>
232
+                    <?php _e('Start Date', 'invoicing'); ?>
233 233
                 </label>
234 234
                 <div class="col-sm-8">
235 235
                     <?php
@@ -238,10 +238,10 @@  discard block
 block discarded – undo
238 238
                                 'type'        => 'datepicker',
239 239
                                 'id'          => 'wpinv_discount_start',
240 240
                                 'name'        => 'wpinv_discount_start',
241
-                                'label'       => __( 'Start Date', 'invoicing' ),
241
+                                'label'       => __('Start Date', 'invoicing'),
242 242
                                 'placeholder' => 'YYYY-MM-DD 00:00',
243 243
                                 'class'       => 'form-control-sm',
244
-                                'value'       => $discount->get_start_date( 'edit' ),
244
+                                'value'       => $discount->get_start_date('edit'),
245 245
                                 'extra_attributes' => array(
246 246
                                     'data-enable-time' => 'true',
247 247
                                     'data-time_24hr'   => 'true',
@@ -252,15 +252,15 @@  discard block
 block discarded – undo
252 252
                     ?>
253 253
                 </div>
254 254
                 <div class="col-sm-1 pt-2 pl-0">
255
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing' ); ?>"></span>
255
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('For no start date, leave blank. If entered, the discount can only be used after or on this date.', 'invoicing'); ?>"></span>
256 256
                 </div>
257 257
             </div>
258
-            <?php do_action( 'wpinv_discount_form_start', $discount ); ?>
258
+            <?php do_action('wpinv_discount_form_start', $discount); ?>
259 259
 
260
-            <?php do_action( 'wpinv_discount_form_before_expiration', $discount ); ?>
260
+            <?php do_action('wpinv_discount_form_before_expiration', $discount); ?>
261 261
             <div class="form-group row">
262 262
                 <label for="wpinv_discount_expiration" class="col-sm-3 col-form-label">
263
-                    <?php _e( 'Expiration Date', 'invoicing' );?>
263
+                    <?php _e('Expiration Date', 'invoicing'); ?>
264 264
                 </label>
265 265
                 <div class="col-sm-8">
266 266
                     <?php
@@ -269,10 +269,10 @@  discard block
 block discarded – undo
269 269
                                 'type'        => 'datepicker',
270 270
                                 'id'          => 'wpinv_discount_expiration',
271 271
                                 'name'        => 'wpinv_discount_expiration',
272
-                                'label'       => __( 'Expiration Date', 'invoicing' ),
272
+                                'label'       => __('Expiration Date', 'invoicing'),
273 273
                                 'placeholder' => 'YYYY-MM-DD 00:00',
274 274
                                 'class'       => 'form-control-sm',
275
-                                'value'       => $discount->get_end_date( 'edit' ),
275
+                                'value'       => $discount->get_end_date('edit'),
276 276
                                 'extra_attributes' => array(
277 277
                                     'data-enable-time' => 'true',
278 278
                                     'data-time_24hr'   => 'true',
@@ -285,27 +285,27 @@  discard block
 block discarded – undo
285 285
                     ?>
286 286
                 </div>
287 287
                 <div class="col-sm-1 pt-2 pl-0">
288
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the date after which the discount will expire.', 'invoicing' ); ?>"></span>
288
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the date after which the discount will expire.', 'invoicing'); ?>"></span>
289 289
                 </div>
290 290
             </div>
291
-            <?php do_action( 'wpinv_discount_form_expiration', $discount ); ?>
291
+            <?php do_action('wpinv_discount_form_expiration', $discount); ?>
292 292
 
293
-            <?php do_action( 'wpinv_discount_form_before_min_total', $discount ); ?>
293
+            <?php do_action('wpinv_discount_form_before_min_total', $discount); ?>
294 294
             <div class="form-group row">
295 295
                 <label for="wpinv_discount_min_total" class="col-sm-3 col-form-label">
296
-                    <?php _e( 'Minimum Amount', 'invoicing' );?>
296
+                    <?php _e('Minimum Amount', 'invoicing'); ?>
297 297
                 </label>
298 298
                 <div class="col-sm-8">
299 299
                     <div class="input-group input-group-sm">
300
-                        <?php if( 'left' == $position ) : ?>
300
+                        <?php if ('left' == $position) : ?>
301 301
                             <div class="input-group-prepend">
302 302
                                 <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span>
303 303
                             </div>
304 304
                         <?php endif; ?>
305 305
 
306
-                        <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr( $discount->get_minimum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No minimum', 'invoicing' ); ?>" class="form-control">
306
+                        <input type="text" name="wpinv_discount_min_total" id="wpinv_discount_min_total" value="<?php echo esc_attr($discount->get_minimum_total('edit')); ?>" placeholder="<?php esc_attr_e('No minimum', 'invoicing'); ?>" class="form-control">
307 307
 
308
-                        <?php if( 'left' != $position ) : ?>
308
+                        <?php if ('left' != $position) : ?>
309 309
                             <div class="input-group-append">
310 310
                                 <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span>
311 311
                             </div>
@@ -313,27 +313,27 @@  discard block
 block discarded – undo
313 313
                     </div>
314 314
                 </div>
315 315
                 <div class="col-sm-1 pt-2 pl-0">
316
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing' ); ?>"></span>
316
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the minimum amount (including taxes) required to use this discount.', 'invoicing'); ?>"></span>
317 317
                 </div>
318 318
             </div>
319
-            <?php do_action( 'wpinv_discount_form_min_total', $discount ); ?>
319
+            <?php do_action('wpinv_discount_form_min_total', $discount); ?>
320 320
 
321
-            <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?>
321
+            <?php do_action('wpinv_discount_form_before_max_total', $discount); ?>
322 322
             <div class="form-group row">
323 323
                 <label for="wpinv_discount_max_total" class="col-sm-3 col-form-label">
324
-                    <?php _e( 'Maximum Amount', 'invoicing' );?>
324
+                    <?php _e('Maximum Amount', 'invoicing'); ?>
325 325
                 </label>
326 326
                 <div class="col-sm-8">
327 327
                     <div class="input-group input-group-sm">
328
-                        <?php if( 'left' == $position ) : ?>
328
+                        <?php if ('left' == $position) : ?>
329 329
                             <div class="input-group-prepend">
330 330
                                 <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span>
331 331
                             </div>
332 332
                         <?php endif; ?>
333 333
 
334
-                        <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr( $discount->get_maximum_total( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'No maximum', 'invoicing' ); ?>" class="form-control">
334
+                        <input type="text" name="wpinv_discount_max_total" id="wpinv_discount_max_total" value="<?php echo esc_attr($discount->get_maximum_total('edit')); ?>" placeholder="<?php esc_attr_e('No maximum', 'invoicing'); ?>" class="form-control">
335 335
 
336
-                        <?php if( 'left' != $position ) : ?>
336
+                        <?php if ('left' != $position) : ?>
337 337
                             <div class="input-group-append">
338 338
                                 <span class="input-group-text"><?php echo wpinv_currency_symbol(); ?></span>
339 339
                             </div>
@@ -341,30 +341,30 @@  discard block
 block discarded – undo
341 341
                     </div>
342 342
                 </div>
343 343
                 <div class="col-sm-1 pt-2 pl-0">
344
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing' ); ?>"></span>
344
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum amount (including taxes) allowed when using this discount.', 'invoicing'); ?>"></span>
345 345
                 </div>
346 346
             </div>
347
-            <?php do_action( 'wpinv_discount_form_before_max_total', $discount ); ?>
347
+            <?php do_action('wpinv_discount_form_before_max_total', $discount); ?>
348 348
 
349
-            <?php do_action( 'wpinv_discount_form_before_max_uses', $discount ); ?>
349
+            <?php do_action('wpinv_discount_form_before_max_uses', $discount); ?>
350 350
             <div class="form-group row">
351 351
                 <label for="wpinv_discount_max_uses" class="col-sm-3 col-form-label">
352
-                    <?php _e( 'Maximum Uses', 'invoicing' );?>
352
+                    <?php _e('Maximum Uses', 'invoicing'); ?>
353 353
                 </label>
354 354
                 <div class="col-sm-8">
355
-                    <input type="text" value="<?php echo esc_attr( $discount->get_max_uses( 'edit' ) ); ?>" placeholder="<?php esc_attr_e( 'Unlimited', 'invoicing' ); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" />
355
+                    <input type="text" value="<?php echo esc_attr($discount->get_max_uses('edit')); ?>" placeholder="<?php esc_attr_e('Unlimited', 'invoicing'); ?>" name="wpinv_discount_max_uses" id="wpinv_discount_max_uses" style="width: 100%;" />
356 356
                 </div>
357 357
                 <div class="col-sm-1 pt-2 pl-0">
358
-                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e( 'Optionally set the maximum number of times that this discount code can be used.', 'invoicing' ); ?>"></span>
358
+                    <span class="wpi-help-tip dashicons dashicons-editor-help" title="<?php esc_attr_e('Optionally set the maximum number of times that this discount code can be used.', 'invoicing'); ?>"></span>
359 359
                 </div>
360 360
             </div>
361
-            <?php do_action( 'wpinv_discount_form_max_uses', $discount ); ?>
361
+            <?php do_action('wpinv_discount_form_max_uses', $discount); ?>
362 362
 
363
-            <?php do_action( 'wpinv_discount_form_last', $discount ); ?>
363
+            <?php do_action('wpinv_discount_form_last', $discount); ?>
364 364
 
365 365
         </div>
366 366
         <?php
367
-        do_action( 'wpinv_discount_form_bottom', $post );
367
+        do_action('wpinv_discount_form_bottom', $post);
368 368
     }
369 369
 
370 370
     /**
@@ -372,30 +372,30 @@  discard block
 block discarded – undo
372 372
 	 *
373 373
 	 * @param int $post_id
374 374
 	 */
375
-	public static function save( $post_id ) {
375
+	public static function save($post_id) {
376 376
 
377 377
         // Prepare the discount.
378
-        $discount = new WPInv_Discount( $post_id );
378
+        $discount = new WPInv_Discount($post_id);
379 379
 
380 380
         // Load new data.
381 381
         $discount->set_props(
382 382
 			array(
383
-				'code'                 => isset( $_POST['wpinv_discount_code'] ) ? wpinv_clean( $_POST['wpinv_discount_code'] ) : null,
384
-				'amount'               => isset( $_POST['wpinv_discount_amount'] ) ? floatval( $_POST['wpinv_discount_amount'] ) : null,
385
-				'start'                => isset( $_POST['wpinv_discount_start'] ) ? wpinv_clean( $_POST['wpinv_discount_start'] ) : null,
386
-				'expiration'           => isset( $_POST['wpinv_discount_expiration'] ) ? wpinv_clean( $_POST['wpinv_discount_expiration'] ) : null,
387
-				'is_single_use'        => isset( $_POST['wpinv_discount_single_use'] ),
388
-                'type'                 => isset( $_POST['wpinv_discount_type'] ) ? wpinv_clean( $_POST['wpinv_discount_type'] ) : null,
389
-				'is_recurring'         => isset( $_POST['wpinv_discount_recurring'] ),
390
-				'items'                => isset( $_POST['wpinv_discount_items'] ) ? wpinv_clean( $_POST['wpinv_discount_items'] ) : array(),
391
-				'excluded_items'       => isset( $_POST['wpinv_discount_excluded_items'] ) ? wpinv_clean( $_POST['wpinv_discount_excluded_items'] ) : array(),
392
-				'max_uses'             => isset( $_POST['wpinv_discount_max_uses'] ) ? intval( $_POST['wpinv_discount_max_uses'] ) : null,
393
-				'min_total'            => isset( $_POST['wpinv_discount_min_total'] ) ? floatval( $_POST['wpinv_discount_min_total'] ) : null,
394
-				'max_total'            => isset( $_POST['wpinv_discount_max_total'] ) ? floatval( $_POST['wpinv_discount_max_total'] ) : null,
383
+				'code'                 => isset($_POST['wpinv_discount_code']) ? wpinv_clean($_POST['wpinv_discount_code']) : null,
384
+				'amount'               => isset($_POST['wpinv_discount_amount']) ? floatval($_POST['wpinv_discount_amount']) : null,
385
+				'start'                => isset($_POST['wpinv_discount_start']) ? wpinv_clean($_POST['wpinv_discount_start']) : null,
386
+				'expiration'           => isset($_POST['wpinv_discount_expiration']) ? wpinv_clean($_POST['wpinv_discount_expiration']) : null,
387
+				'is_single_use'        => isset($_POST['wpinv_discount_single_use']),
388
+                'type'                 => isset($_POST['wpinv_discount_type']) ? wpinv_clean($_POST['wpinv_discount_type']) : null,
389
+				'is_recurring'         => isset($_POST['wpinv_discount_recurring']),
390
+				'items'                => isset($_POST['wpinv_discount_items']) ? wpinv_clean($_POST['wpinv_discount_items']) : array(),
391
+				'excluded_items'       => isset($_POST['wpinv_discount_excluded_items']) ? wpinv_clean($_POST['wpinv_discount_excluded_items']) : array(),
392
+				'max_uses'             => isset($_POST['wpinv_discount_max_uses']) ? intval($_POST['wpinv_discount_max_uses']) : null,
393
+				'min_total'            => isset($_POST['wpinv_discount_min_total']) ? floatval($_POST['wpinv_discount_min_total']) : null,
394
+				'max_total'            => isset($_POST['wpinv_discount_max_total']) ? floatval($_POST['wpinv_discount_max_total']) : null,
395 395
 			)
396 396
         );
397 397
 
398 398
 		$discount->save();
399
-		do_action( 'getpaid_discount_metabox_save', $post_id, $discount );
399
+		do_action('getpaid_discount_metabox_save', $post_id, $discount);
400 400
 	}
401 401
 }
Please login to merge, or discard this patch.
includes/payments/class-getpaid-payment-form-submission.php 2 patches
Indentation   +818 added lines, -818 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,198 +10,198 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
18
-
19
-	/**
20
-	 * The raw submission data.
21
-	 *
22
-	 * @var array
23
-	 */
24
-	protected $data = null;
25
-
26
-	/**
27
-	 * Submission totals
28
-	 *
29
-	 * @var array
30
-	 */
31
-	protected $totals = array(
32
-
33
-		'subtotal'      => array(
34
-			'initial'   => 0,
35
-			'recurring' => 0,
36
-		),
37
-
38
-		'discount'      => array(
39
-			'initial'   => 0,
40
-			'recurring' => 0,
41
-		),
42
-
43
-		'fees'          => array(
44
-			'initial'   => 0,
45
-			'recurring' => 0,
46
-		),
47
-
48
-		'taxes'         => array(
49
-			'initial'   => 0,
50
-			'recurring' => 0,
51
-		),
52
-
53
-	);
54
-
55
-	/**
56
-	 * Sets the associated payment form.
57
-	 *
58
-	 * @var GetPaid_Payment_Form
59
-	 */
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18
+
19
+    /**
20
+     * The raw submission data.
21
+     *
22
+     * @var array
23
+     */
24
+    protected $data = null;
25
+
26
+    /**
27
+     * Submission totals
28
+     *
29
+     * @var array
30
+     */
31
+    protected $totals = array(
32
+
33
+        'subtotal'      => array(
34
+            'initial'   => 0,
35
+            'recurring' => 0,
36
+        ),
37
+
38
+        'discount'      => array(
39
+            'initial'   => 0,
40
+            'recurring' => 0,
41
+        ),
42
+
43
+        'fees'          => array(
44
+            'initial'   => 0,
45
+            'recurring' => 0,
46
+        ),
47
+
48
+        'taxes'         => array(
49
+            'initial'   => 0,
50
+            'recurring' => 0,
51
+        ),
52
+
53
+    );
54
+
55
+    /**
56
+     * Sets the associated payment form.
57
+     *
58
+     * @var GetPaid_Payment_Form
59
+     */
60 60
     protected $payment_form = null;
61 61
 
62 62
     /**
63
-	 * The country for the submission.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	public $country = null;
68
-
69
-    /**
70
-	 * The state for the submission.
71
-	 *
72
-	 * @since 1.0.19
73
-	 * @var string
74
-	 */
75
-	public $state = null;
76
-
77
-	/**
78
-	 * The invoice associated with the submission.
79
-	 *
80
-	 * @var WPInv_Invoice
81
-	 */
82
-	protected $invoice = null;
83
-
84
-	/**
85
-	 * The recurring item for the submission.
86
-	 *
87
-	 * @var int
88
-	 */
89
-	public $has_recurring = 0;
90
-
91
-	/**
92
-	 * An array of fees for the submission.
93
-	 *
94
-	 * @var array
95
-	 */
96
-	protected $fees = array();
97
-
98
-	/**
99
-	 * An array of discounts for the submission.
100
-	 *
101
-	 * @var array
102
-	 */
103
-	protected $discounts = array();
104
-
105
-	/**
106
-	 * An array of taxes for the submission.
107
-	 *
108
-	 * @var array
109
-	 */
110
-	protected $taxes = array();
111
-
112
-	/**
113
-	 * An array of items for the submission.
114
-	 *
115
-	 * @var GetPaid_Form_Item[]
116
-	 */
117
-	protected $items = array();
118
-
119
-	/**
120
-	 * The last error.
121
-	 *
122
-	 * @var string
123
-	 */
124
-	public $last_error = null;
125
-
126
-	/**
127
-	 * The last error code.
128
-	 *
129
-	 * @var string
130
-	 */
131
-	public $last_error_code = null;
132
-
133
-    /**
134
-	 * Class constructor.
135
-	 *
136
-	 */
137
-	public function __construct() {
138
-
139
-		// Set the state and country to the default state and country.
140
-		$this->country = wpinv_default_billing_country();
141
-		$this->state   = wpinv_get_default_state();
142
-
143
-		// Do we have an actual submission?
144
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
145
-			$this->load_data( $_POST );
146
-		}
147
-
148
-	}
149
-
150
-	/**
151
-	 * Loads submission data.
152
-	 *
153
-	 * @param array $data
154
-	 */
155
-	public function load_data( $data ) {
156
-
157
-		// Remove slashes from the submitted data...
158
-		$data       = wp_kses_post_deep( 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_kses_post_deep( wp_unslash( $data ) );
159
+
160
+        // Allow plugins to filter the data.
161
+        $data       = apply_filters( 'getpaid_submission_data', $data, $this );
162
+
163
+        // Cache it...
164
+        $this->data = $data;
165
+
166
+        // Then generate a unique id from the data.
167
+        $this->id   = md5( wp_json_encode( $data ) );
168
+
169
+        // Finally, process the submission.
170
+        try {
171
+
172
+            // Each process is passed an instance of the class (with reference)
173
+            // and should throw an Exception whenever it encounters one.
174
+            $processors = apply_filters(
175
+                'getpaid_payment_form_submission_processors',
176
+                array(
177
+                    array( $this, 'process_payment_form' ),
178
+                    array( $this, 'process_invoice' ),
179
+                    array( $this, 'process_fees' ),
180
+                    array( $this, 'process_items' ),
181
+                    array( $this, 'process_discount' ),
182
+                    array( $this, 'process_taxes' ),
183
+                ),
184
+                $this		
185
+            );
186
+
187
+            foreach ( $processors as $processor ) {
188
+                call_user_func_array( $processor, array( &$this ) );
189
+            }
190
+
191
+        } catch( GetPaid_Payment_Exception $e ) {
192
+            $this->last_error      = $e->getMessage();
193
+            $this->last_error_code = $e->getErrorCode();
194
+        } catch ( Exception $e ) {
195
+            $this->last_error      = $e->getMessage();
196
+            $this->last_error_code = $e->getCode();
197
+        }
198
+
199
+        // Fired when we are done processing a submission.
200
+        do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
201
+
202
+    }
203
+
204
+    /*
205 205
 	|--------------------------------------------------------------------------
206 206
 	| Payment Forms.
207 207
 	|--------------------------------------------------------------------------
@@ -210,39 +210,39 @@  discard block
 block discarded – undo
210 210
 	| submission has an active payment form etc.
211 211
     */
212 212
 
213
-	/**
214
-	 * Prepares the submission's payment form.
215
-	 *
216
-	 * @since 1.0.19
217
-	 */
218
-	public function process_payment_form() {
213
+    /**
214
+     * Prepares the submission's payment form.
215
+     *
216
+     * @since 1.0.19
217
+     */
218
+    public function process_payment_form() {
219 219
 
220
-		// Every submission needs an active payment form.
221
-		if ( empty( $this->data['form_id'] ) ) {
222
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
223
-		}
220
+        // Every submission needs an active payment form.
221
+        if ( empty( $this->data['form_id'] ) ) {
222
+            throw new Exception( __( 'Missing payment form', 'invoicing' ) );
223
+        }
224 224
 
225
-		// Fetch the payment form.
226
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
225
+        // Fetch the payment form.
226
+        $this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
227 227
 
228
-		if ( ! $this->payment_form->is_active() ) {
229
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
230
-		}
228
+        if ( ! $this->payment_form->is_active() ) {
229
+            throw new Exception( __( 'Payment form not active', 'invoicing' ) );
230
+        }
231 231
 
232
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
233
-	}
232
+        do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
233
+    }
234 234
 
235 235
     /**
236
-	 * Returns the payment form.
237
-	 *
238
-	 * @since 1.0.19
239
-	 * @return GetPaid_Payment_Form
240
-	 */
241
-	public function get_payment_form() {
242
-		return $this->payment_form;
243
-	}
236
+     * Returns the payment form.
237
+     *
238
+     * @since 1.0.19
239
+     * @return GetPaid_Payment_Form
240
+     */
241
+    public function get_payment_form() {
242
+        return $this->payment_form;
243
+    }
244 244
 
245
-	/*
245
+    /*
246 246
 	|--------------------------------------------------------------------------
247 247
 	| Invoices.
248 248
 	|--------------------------------------------------------------------------
@@ -251,84 +251,84 @@  discard block
 block discarded – undo
251 251
 	| might be for an existing invoice.
252 252
 	*/
253 253
 
254
-	/**
255
-	 * Prepares the submission's invoice.
256
-	 *
257
-	 * @since 1.0.19
258
-	 */
259
-	public function process_invoice() {
254
+    /**
255
+     * Prepares the submission's invoice.
256
+     *
257
+     * @since 1.0.19
258
+     */
259
+    public function process_invoice() {
260 260
 
261
-		// Abort if there is no invoice.
262
-		if ( empty( $this->data['invoice_id'] ) ) {
263
-			return;
264
-		}
261
+        // Abort if there is no invoice.
262
+        if ( empty( $this->data['invoice_id'] ) ) {
263
+            return;
264
+        }
265 265
 
266
-		// If the submission is for an existing invoice, ensure that it exists
267
-		// and that it is not paid for.
268
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
266
+        // If the submission is for an existing invoice, ensure that it exists
267
+        // and that it is not paid for.
268
+        $invoice = wpinv_get_invoice( $this->data['invoice_id'] );
269 269
 
270 270
         if ( empty( $invoice ) ) {
271
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
272
-		}
271
+            throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
272
+        }
273 273
 
274
-		if ( $invoice->is_paid() ) {
275
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
276
-		}
274
+        if ( $invoice->is_paid() ) {
275
+            throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
276
+        }
277 277
 
278
-		$this->payment_form->invoice = $invoice;
279
-		if ( ! $this->payment_form->is_default() ) {
278
+        $this->payment_form->invoice = $invoice;
279
+        if ( ! $this->payment_form->is_default() ) {
280 280
 
281
-			$items    = array();
282
-			$item_ids = array();
281
+            $items    = array();
282
+            $item_ids = array();
283 283
 	
284
-			foreach ( $invoice->get_items() as $item ) {
285
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
286
-					$item_ids[] = $item->get_id();
287
-					$items[]    = $item;
288
-				}
289
-			}
284
+            foreach ( $invoice->get_items() as $item ) {
285
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
286
+                    $item_ids[] = $item->get_id();
287
+                    $items[]    = $item;
288
+                }
289
+            }
290 290
 	
291
-			foreach ( $this->payment_form->get_items() as $item ) {
292
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
293
-					$item_ids[] = $item->get_id();
294
-					$items[]    = $item;
295
-				}
296
-			}
291
+            foreach ( $this->payment_form->get_items() as $item ) {
292
+                if ( ! in_array( $item->get_id(), $item_ids ) ) {
293
+                    $item_ids[] = $item->get_id();
294
+                    $items[]    = $item;
295
+                }
296
+            }
297 297
 	
298
-			$this->payment_form->set_items( $items );
298
+            $this->payment_form->set_items( $items );
299 299
 	
300
-		} else {
301
-			$this->payment_form->set_items( $invoice->get_items() );
302
-		}
303
-
304
-		$this->country = $invoice->get_country();
305
-		$this->state   = $invoice->get_state();
306
-		$this->invoice = $invoice;
307
-
308
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
309
-	}
310
-
311
-	/**
312
-	 * Returns the associated invoice.
313
-	 *
314
-	 * @since 1.0.19
315
-	 * @return WPInv_Invoice
316
-	 */
317
-	public function get_invoice() {
318
-		return $this->invoice;
319
-	}
320
-
321
-	/**
322
-	 * Checks whether there is an invoice associated with this submission.
323
-	 *
324
-	 * @since 1.0.19
325
-	 * @return bool
326
-	 */
327
-	public function has_invoice() {
328
-		return ! empty( $this->invoice );
329
-	}
330
-
331
-	/*
300
+        } else {
301
+            $this->payment_form->set_items( $invoice->get_items() );
302
+        }
303
+
304
+        $this->country = $invoice->get_country();
305
+        $this->state   = $invoice->get_state();
306
+        $this->invoice = $invoice;
307
+
308
+        do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
309
+    }
310
+
311
+    /**
312
+     * Returns the associated invoice.
313
+     *
314
+     * @since 1.0.19
315
+     * @return WPInv_Invoice
316
+     */
317
+    public function get_invoice() {
318
+        return $this->invoice;
319
+    }
320
+
321
+    /**
322
+     * Checks whether there is an invoice associated with this submission.
323
+     *
324
+     * @since 1.0.19
325
+     * @return bool
326
+     */
327
+    public function has_invoice() {
328
+        return ! empty( $this->invoice );
329
+    }
330
+
331
+    /*
332 332
 	|--------------------------------------------------------------------------
333 333
 	| Items.
334 334
 	|--------------------------------------------------------------------------
@@ -337,129 +337,129 @@  discard block
 block discarded – undo
337 337
 	| recurring item. But can have an unlimited number of non-recurring items.
338 338
 	*/
339 339
 
340
-	/**
341
-	 * Prepares the submission's items.
342
-	 *
343
-	 * @since 1.0.19
344
-	 */
345
-	public function process_items() {
346
-
347
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
348
-
349
-		foreach ( $processor->items as $item ) {
350
-			$this->add_item( $item );
351
-		}
352
-
353
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
354
-	}
355
-
356
-	/**
357
-	 * Adds an item to the submission.
358
-	 *
359
-	 * @since 1.0.19
360
-	 * @param GetPaid_Form_Item $item
361
-	 */
362
-	public function add_item( $item ) {
363
-
364
-		// Make sure that it is available for purchase.
365
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
366
-			return;
367
-		}
368
-
369
-		// Each submission can only contain one recurring item.
370
-		if ( $item->is_recurring() ) {
371
-			$this->has_recurring = $item->get_id();
372
-		}
373
-
374
-		// Update the items and totals.
375
-		$this->items[ $item->get_id() ]         = $item;
376
-		$this->totals['subtotal']['initial']   += $item->get_sub_total();
377
-		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
378
-
379
-	}
380
-
381
-	/**
382
-	 * Removes a specific item.
383
-	 * 
384
-	 * You should not call this method after the discounts and taxes
385
-	 * have been calculated.
386
-	 *
387
-	 * @since 1.0.19
388
-	 */
389
-	public function remove_item( $item_id ) {
390
-
391
-		if ( isset( $this->items[ $item_id ] ) ) {
392
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
393
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
394
-
395
-			if ( $this->items[ $item_id ]->is_recurring() ) {
396
-				$this->has_recurring = 0;
397
-			}
398
-
399
-			unset( $this->items[ $item_id ] );
400
-		}
401
-
402
-	}
403
-
404
-	/**
405
-	 * Returns the subtotal.
406
-	 *
407
-	 * @since 1.0.19
408
-	 */
409
-	public function get_subtotal() {
410
-
411
-		if ( wpinv_prices_include_tax() ) {
412
-			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
413
-		}
414
-
415
-		return $this->totals['subtotal']['initial'];
416
-	}
417
-
418
-	/**
419
-	 * Returns the recurring subtotal.
420
-	 *
421
-	 * @since 1.0.19
422
-	 */
423
-	public function get_recurring_subtotal() {
424
-
425
-		if ( wpinv_prices_include_tax() ) {
426
-			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
427
-		}
428
-
429
-		return $this->totals['subtotal']['recurring'];
430
-	}
431
-
432
-	/**
433
-	 * Returns all items.
434
-	 *
435
-	 * @since 1.0.19
436
-	 * @return GetPaid_Form_Item[]
437
-	 */
438
-	public function get_items() {
439
-		return $this->items;
440
-	}
441
-
442
-	/**
443
-	 * Checks if there's a single subscription group in the submission.
444
-	 *
445
-	 * @since 2.3.0
446
-	 * @return bool
447
-	 */
448
-	public function has_subscription_group() {
449
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
450
-	}
451
-
452
-	/**
453
-	 * Checks if there are multipe subscription groups in the submission.
454
-	 *
455
-	 * @since 2.3.0
456
-	 * @return bool
457
-	 */
458
-	public function has_multiple_subscription_groups() {
459
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
460
-	}
461
-
462
-	/*
340
+    /**
341
+     * Prepares the submission's items.
342
+     *
343
+     * @since 1.0.19
344
+     */
345
+    public function process_items() {
346
+
347
+        $processor = new GetPaid_Payment_Form_Submission_Items( $this );
348
+
349
+        foreach ( $processor->items as $item ) {
350
+            $this->add_item( $item );
351
+        }
352
+
353
+        do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
354
+    }
355
+
356
+    /**
357
+     * Adds an item to the submission.
358
+     *
359
+     * @since 1.0.19
360
+     * @param GetPaid_Form_Item $item
361
+     */
362
+    public function add_item( $item ) {
363
+
364
+        // Make sure that it is available for purchase.
365
+        if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
366
+            return;
367
+        }
368
+
369
+        // Each submission can only contain one recurring item.
370
+        if ( $item->is_recurring() ) {
371
+            $this->has_recurring = $item->get_id();
372
+        }
373
+
374
+        // Update the items and totals.
375
+        $this->items[ $item->get_id() ]         = $item;
376
+        $this->totals['subtotal']['initial']   += $item->get_sub_total();
377
+        $this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
378
+
379
+    }
380
+
381
+    /**
382
+     * Removes a specific item.
383
+     * 
384
+     * You should not call this method after the discounts and taxes
385
+     * have been calculated.
386
+     *
387
+     * @since 1.0.19
388
+     */
389
+    public function remove_item( $item_id ) {
390
+
391
+        if ( isset( $this->items[ $item_id ] ) ) {
392
+            $this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
393
+            $this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
394
+
395
+            if ( $this->items[ $item_id ]->is_recurring() ) {
396
+                $this->has_recurring = 0;
397
+            }
398
+
399
+            unset( $this->items[ $item_id ] );
400
+        }
401
+
402
+    }
403
+
404
+    /**
405
+     * Returns the subtotal.
406
+     *
407
+     * @since 1.0.19
408
+     */
409
+    public function get_subtotal() {
410
+
411
+        if ( wpinv_prices_include_tax() ) {
412
+            return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
413
+        }
414
+
415
+        return $this->totals['subtotal']['initial'];
416
+    }
417
+
418
+    /**
419
+     * Returns the recurring subtotal.
420
+     *
421
+     * @since 1.0.19
422
+     */
423
+    public function get_recurring_subtotal() {
424
+
425
+        if ( wpinv_prices_include_tax() ) {
426
+            return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
427
+        }
428
+
429
+        return $this->totals['subtotal']['recurring'];
430
+    }
431
+
432
+    /**
433
+     * Returns all items.
434
+     *
435
+     * @since 1.0.19
436
+     * @return GetPaid_Form_Item[]
437
+     */
438
+    public function get_items() {
439
+        return $this->items;
440
+    }
441
+
442
+    /**
443
+     * Checks if there's a single subscription group in the submission.
444
+     *
445
+     * @since 2.3.0
446
+     * @return bool
447
+     */
448
+    public function has_subscription_group() {
449
+        return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
450
+    }
451
+
452
+    /**
453
+     * Checks if there are multipe subscription groups in the submission.
454
+     *
455
+     * @since 2.3.0
456
+     * @return bool
457
+     */
458
+    public function has_multiple_subscription_groups() {
459
+        return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
460
+    }
461
+
462
+    /*
463 463
 	|--------------------------------------------------------------------------
464 464
 	| Taxes
465 465
 	|--------------------------------------------------------------------------
@@ -468,128 +468,128 @@  discard block
 block discarded – undo
468 468
 	| or only one-time.
469 469
     */
470 470
 
471
-	/**
472
-	 * Prepares the submission's taxes.
473
-	 *
474
-	 * @since 1.0.19
475
-	 */
476
-	public function process_taxes() {
477
-
478
-		// Abort if we're not using taxes.
479
-		if ( ! $this->use_taxes() ) {
480
-			return;
481
-		}
482
-
483
-		// If a custom country && state has been passed in, use it to calculate taxes.
484
-		$country = $this->get_field( 'wpinv_country', 'billing' );
485
-		if ( ! empty( $country ) ) {
486
-			$this->country = $country;
487
-		}
488
-
489
-		$state = $this->get_field( 'wpinv_state', 'billing' );
490
-		if ( ! empty( $state ) ) {
491
-			$this->state = $state;
492
-		}
493
-
494
-		// Confirm if the provided country and the ip country are similar.
495
-		$address_confirmed = $this->get_field( 'confirm-address' );
496
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
497
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
498
-		}
499
-
500
-		// Abort if the country is not taxable.
501
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
502
-			return;
503
-		}
504
-
505
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
506
-
507
-		foreach ( $processor->taxes as $tax ) {
508
-			$this->add_tax( $tax );
509
-		}
510
-
511
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
512
-	}
513
-
514
-	/**
515
-	 * Adds a tax to the submission.
516
-	 *
517
-	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
518
-	 * @since 1.0.19
519
-	 */
520
-	public function add_tax( $tax ) {
521
-
522
-		if ( wpinv_round_tax_per_tax_rate() ) {
523
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
524
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
525
-		}
526
-
527
-		$this->taxes[ $tax['name'] ]         = $tax;
528
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
529
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
530
-
531
-	}
532
-
533
-	/**
534
-	 * Removes a specific tax.
535
-	 *
536
-	 * @since 1.0.19
537
-	 */
538
-	public function remove_tax( $tax_name ) {
539
-
540
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
541
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
542
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
543
-			unset( $this->taxes[ $tax_name ] );
544
-		}
545
-
546
-	}
547
-
548
-	/**
549
-	 * Whether or not we'll use taxes for the submission.
550
-	 *
551
-	 * @since 1.0.19
552
-	 */
553
-	public function use_taxes() {
554
-
555
-		$use_taxes = wpinv_use_taxes();
556
-
557
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
558
-			$use_taxes = false;
559
-		}
560
-
561
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
562
-
563
-	}
564
-
565
-	/**
566
-	 * Returns the tax.
567
-	 *
568
-	 * @since 1.0.19
569
-	 */
570
-	public function get_tax() {
571
-		return $this->totals['taxes']['initial'];
572
-	}
573
-
574
-	/**
575
-	 * Returns the recurring tax.
576
-	 *
577
-	 * @since 1.0.19
578
-	 */
579
-	public function get_recurring_tax() {
580
-		return $this->totals['taxes']['recurring'];
581
-	}
582
-
583
-	/**
584
-	 * Returns all taxes.
585
-	 *
586
-	 * @since 1.0.19
587
-	 */
588
-	public function get_taxes() {
589
-		return $this->taxes;
590
-	}
591
-
592
-	/*
471
+    /**
472
+     * Prepares the submission's taxes.
473
+     *
474
+     * @since 1.0.19
475
+     */
476
+    public function process_taxes() {
477
+
478
+        // Abort if we're not using taxes.
479
+        if ( ! $this->use_taxes() ) {
480
+            return;
481
+        }
482
+
483
+        // If a custom country && state has been passed in, use it to calculate taxes.
484
+        $country = $this->get_field( 'wpinv_country', 'billing' );
485
+        if ( ! empty( $country ) ) {
486
+            $this->country = $country;
487
+        }
488
+
489
+        $state = $this->get_field( 'wpinv_state', 'billing' );
490
+        if ( ! empty( $state ) ) {
491
+            $this->state = $state;
492
+        }
493
+
494
+        // Confirm if the provided country and the ip country are similar.
495
+        $address_confirmed = $this->get_field( 'confirm-address' );
496
+        if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
497
+            throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
498
+        }
499
+
500
+        // Abort if the country is not taxable.
501
+        if ( ! wpinv_is_country_taxable( $this->country ) ) {
502
+            return;
503
+        }
504
+
505
+        $processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
506
+
507
+        foreach ( $processor->taxes as $tax ) {
508
+            $this->add_tax( $tax );
509
+        }
510
+
511
+        do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
512
+    }
513
+
514
+    /**
515
+     * Adds a tax to the submission.
516
+     *
517
+     * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
518
+     * @since 1.0.19
519
+     */
520
+    public function add_tax( $tax ) {
521
+
522
+        if ( wpinv_round_tax_per_tax_rate() ) {
523
+            $tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
524
+            $tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
525
+        }
526
+
527
+        $this->taxes[ $tax['name'] ]         = $tax;
528
+        $this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
529
+        $this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
530
+
531
+    }
532
+
533
+    /**
534
+     * Removes a specific tax.
535
+     *
536
+     * @since 1.0.19
537
+     */
538
+    public function remove_tax( $tax_name ) {
539
+
540
+        if ( isset( $this->taxes[ $tax_name ] ) ) {
541
+            $this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
542
+            $this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
543
+            unset( $this->taxes[ $tax_name ] );
544
+        }
545
+
546
+    }
547
+
548
+    /**
549
+     * Whether or not we'll use taxes for the submission.
550
+     *
551
+     * @since 1.0.19
552
+     */
553
+    public function use_taxes() {
554
+
555
+        $use_taxes = wpinv_use_taxes();
556
+
557
+        if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
558
+            $use_taxes = false;
559
+        }
560
+
561
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
562
+
563
+    }
564
+
565
+    /**
566
+     * Returns the tax.
567
+     *
568
+     * @since 1.0.19
569
+     */
570
+    public function get_tax() {
571
+        return $this->totals['taxes']['initial'];
572
+    }
573
+
574
+    /**
575
+     * Returns the recurring tax.
576
+     *
577
+     * @since 1.0.19
578
+     */
579
+    public function get_recurring_tax() {
580
+        return $this->totals['taxes']['recurring'];
581
+    }
582
+
583
+    /**
584
+     * Returns all taxes.
585
+     *
586
+     * @since 1.0.19
587
+     */
588
+    public function get_taxes() {
589
+        return $this->taxes;
590
+    }
591
+
592
+    /*
593 593
 	|--------------------------------------------------------------------------
594 594
 	| Discounts
595 595
 	|--------------------------------------------------------------------------
@@ -598,99 +598,99 @@  discard block
 block discarded – undo
598 598
 	| or only one-time. They also do not have to come from a discount code.
599 599
     */
600 600
 
601
-	/**
602
-	 * Prepares the submission's discount.
603
-	 *
604
-	 * @since 1.0.19
605
-	 */
606
-	public function process_discount() {
607
-
608
-		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
609
-		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
610
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
611
-
612
-		foreach ( $processor->discounts as $discount ) {
613
-			$this->add_discount( $discount );
614
-		}
615
-
616
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
617
-	}
618
-
619
-	/**
620
-	 * Adds a discount to the submission.
621
-	 *
622
-	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
623
-	 * @since 1.0.19
624
-	 */
625
-	public function add_discount( $discount ) {
626
-		$this->discounts[ $discount['name'] ]   = $discount;
627
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
628
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
629
-	}
630
-
631
-	/**
632
-	 * Removes a discount from the submission.
633
-	 *
634
-	 * @since 1.0.19
635
-	 */
636
-	public function remove_discount( $name ) {
637
-
638
-		if ( isset( $this->discounts[ $name ] ) ) {
639
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
640
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
641
-			unset( $this->discounts[ $name ] );
642
-		}
643
-
644
-	}
645
-
646
-	/**
647
-	 * Checks whether there is a discount code associated with this submission.
648
-	 *
649
-	 * @since 1.0.19
650
-	 * @return bool
651
-	 */
652
-	public function has_discount_code() {
653
-		return ! empty( $this->discounts['discount_code'] );
654
-	}
655
-
656
-	/**
657
-	 * Returns the discount code.
658
-	 *
659
-	 * @since 1.0.19
660
-	 * @return string
661
-	 */
662
-	public function get_discount_code() {
663
-		return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
664
-	}
665
-
666
-	/**
667
-	 * Returns the discount.
668
-	 *
669
-	 * @since 1.0.19
670
-	 */
671
-	public function get_discount() {
672
-		return $this->totals['discount']['initial'];
673
-	}
674
-
675
-	/**
676
-	 * Returns the recurring discount.
677
-	 *
678
-	 * @since 1.0.19
679
-	 */
680
-	public function get_recurring_discount() {
681
-		return $this->totals['discount']['recurring'];
682
-	}
683
-
684
-	/**
685
-	 * Returns all discounts.
686
-	 *
687
-	 * @since 1.0.19
688
-	 */
689
-	public function get_discounts() {
690
-		return $this->discounts;
691
-	}
692
-
693
-	/*
601
+    /**
602
+     * Prepares the submission's discount.
603
+     *
604
+     * @since 1.0.19
605
+     */
606
+    public function process_discount() {
607
+
608
+        $initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
609
+        $recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
610
+        $processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
611
+
612
+        foreach ( $processor->discounts as $discount ) {
613
+            $this->add_discount( $discount );
614
+        }
615
+
616
+        do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
617
+    }
618
+
619
+    /**
620
+     * Adds a discount to the submission.
621
+     *
622
+     * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
623
+     * @since 1.0.19
624
+     */
625
+    public function add_discount( $discount ) {
626
+        $this->discounts[ $discount['name'] ]   = $discount;
627
+        $this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
628
+        $this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
629
+    }
630
+
631
+    /**
632
+     * Removes a discount from the submission.
633
+     *
634
+     * @since 1.0.19
635
+     */
636
+    public function remove_discount( $name ) {
637
+
638
+        if ( isset( $this->discounts[ $name ] ) ) {
639
+            $this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
640
+            $this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
641
+            unset( $this->discounts[ $name ] );
642
+        }
643
+
644
+    }
645
+
646
+    /**
647
+     * Checks whether there is a discount code associated with this submission.
648
+     *
649
+     * @since 1.0.19
650
+     * @return bool
651
+     */
652
+    public function has_discount_code() {
653
+        return ! empty( $this->discounts['discount_code'] );
654
+    }
655
+
656
+    /**
657
+     * Returns the discount code.
658
+     *
659
+     * @since 1.0.19
660
+     * @return string
661
+     */
662
+    public function get_discount_code() {
663
+        return $this->has_discount_code() ? $this->discounts['discount_code']['discount_code'] : '';
664
+    }
665
+
666
+    /**
667
+     * Returns the discount.
668
+     *
669
+     * @since 1.0.19
670
+     */
671
+    public function get_discount() {
672
+        return $this->totals['discount']['initial'];
673
+    }
674
+
675
+    /**
676
+     * Returns the recurring discount.
677
+     *
678
+     * @since 1.0.19
679
+     */
680
+    public function get_recurring_discount() {
681
+        return $this->totals['discount']['recurring'];
682
+    }
683
+
684
+    /**
685
+     * Returns all discounts.
686
+     *
687
+     * @since 1.0.19
688
+     */
689
+    public function get_discounts() {
690
+        return $this->discounts;
691
+    }
692
+
693
+    /*
694 694
 	|--------------------------------------------------------------------------
695 695
 	| Fees
696 696
 	|--------------------------------------------------------------------------
@@ -700,89 +700,89 @@  discard block
 block discarded – undo
700 700
 	| fees.
701 701
     */
702 702
 
703
-	/**
704
-	 * Prepares the submission's fees.
705
-	 *
706
-	 * @since 1.0.19
707
-	 */
708
-	public function process_fees() {
709
-
710
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
711
-
712
-		foreach ( $fees_processor->fees as $fee ) {
713
-			$this->add_fee( $fee );
714
-		}
715
-
716
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
717
-	}
718
-
719
-	/**
720
-	 * Adds a fee to the submission.
721
-	 *
722
-	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
723
-	 * @since 1.0.19
724
-	 */
725
-	public function add_fee( $fee ) {
726
-
727
-		$this->fees[ $fee['name'] ]         = $fee;
728
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
729
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
730
-
731
-	}
732
-
733
-	/**
734
-	 * Removes a fee from the submission.
735
-	 *
736
-	 * @since 1.0.19
737
-	 */
738
-	public function remove_fee( $name ) {
739
-
740
-		if ( isset( $this->fees[ $name ] ) ) {
741
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
742
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
743
-			unset( $this->fees[ $name ] );
744
-		}
745
-
746
-	}
747
-
748
-	/**
749
-	 * Returns the fees.
750
-	 *
751
-	 * @since 1.0.19
752
-	 */
753
-	public function get_fee() {
754
-		return $this->totals['fees']['initial'];
755
-	}
756
-
757
-	/**
758
-	 * Returns the recurring fees.
759
-	 *
760
-	 * @since 1.0.19
761
-	 */
762
-	public function get_recurring_fee() {
763
-		return $this->totals['fees']['recurring'];
764
-	}
765
-
766
-	/**
767
-	 * Returns all fees.
768
-	 *
769
-	 * @since 1.0.19
770
-	 */
771
-	public function get_fees() {
772
-		return $this->fees;
773
-	}
774
-
775
-	/**
776
-	 * Checks if there are any fees for the form.
777
-	 *
778
-	 * @return bool
779
-	 * @since 1.0.19
780
-	 */
781
-	public function has_fees() {
782
-		return count( $this->fees ) !== 0;
783
-	}
784
-
785
-	/*
703
+    /**
704
+     * Prepares the submission's fees.
705
+     *
706
+     * @since 1.0.19
707
+     */
708
+    public function process_fees() {
709
+
710
+        $fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
711
+
712
+        foreach ( $fees_processor->fees as $fee ) {
713
+            $this->add_fee( $fee );
714
+        }
715
+
716
+        do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
717
+    }
718
+
719
+    /**
720
+     * Adds a fee to the submission.
721
+     *
722
+     * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
723
+     * @since 1.0.19
724
+     */
725
+    public function add_fee( $fee ) {
726
+
727
+        $this->fees[ $fee['name'] ]         = $fee;
728
+        $this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
729
+        $this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
730
+
731
+    }
732
+
733
+    /**
734
+     * Removes a fee from the submission.
735
+     *
736
+     * @since 1.0.19
737
+     */
738
+    public function remove_fee( $name ) {
739
+
740
+        if ( isset( $this->fees[ $name ] ) ) {
741
+            $this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
742
+            $this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
743
+            unset( $this->fees[ $name ] );
744
+        }
745
+
746
+    }
747
+
748
+    /**
749
+     * Returns the fees.
750
+     *
751
+     * @since 1.0.19
752
+     */
753
+    public function get_fee() {
754
+        return $this->totals['fees']['initial'];
755
+    }
756
+
757
+    /**
758
+     * Returns the recurring fees.
759
+     *
760
+     * @since 1.0.19
761
+     */
762
+    public function get_recurring_fee() {
763
+        return $this->totals['fees']['recurring'];
764
+    }
765
+
766
+    /**
767
+     * Returns all fees.
768
+     *
769
+     * @since 1.0.19
770
+     */
771
+    public function get_fees() {
772
+        return $this->fees;
773
+    }
774
+
775
+    /**
776
+     * Checks if there are any fees for the form.
777
+     *
778
+     * @return bool
779
+     * @since 1.0.19
780
+     */
781
+    public function has_fees() {
782
+        return count( $this->fees ) !== 0;
783
+    }
784
+
785
+    /*
786 786
 	|--------------------------------------------------------------------------
787 787
 	| MISC
788 788
 	|--------------------------------------------------------------------------
@@ -790,119 +790,119 @@  discard block
 block discarded – undo
790 790
 	| Extra submission functions.
791 791
     */
792 792
 
793
-	/**
794
-	 * Checks if this is the initial fetch.
795
-	 *
796
-	 * @return bool
797
-	 * @since 1.0.19
798
-	 */
799
-	public function is_initial_fetch() {
800
-		return empty( $this->data['initial_state'] );
801
-	}
802
-
803
-	/**
804
-	 * Returns the total amount to collect for this submission.
805
-	 *
806
-	 * @since 1.0.19
807
-	 */
808
-	public function get_total() {
809
-		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
810
-		return max( $total, 0 );
811
-	}
812
-
813
-	/**
814
-	 * Returns the recurring total amount to collect for this submission.
815
-	 *
816
-	 * @since 1.0.19
817
-	 */
818
-	public function get_recurring_total() {
819
-		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
820
-		return max( $total, 0 );
821
-	}
822
-
823
-	/**
824
-	 * Whether payment details should be collected for this submission.
825
-	 *
826
-	 * @since 1.0.19
827
-	 */
828
-	public function should_collect_payment_details() {
829
-		$initial   = $this->get_total();
830
-		$recurring = $this->get_recurring_total();
831
-
832
-		if ( $this->has_recurring == 0 ) {
833
-			$recurring = 0;
834
-		}
835
-
836
-		$collect = $initial > 0 || $recurring > 0;
837
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
838
-	}
839
-
840
-	/**
841
-	 * Returns the billing email of the user.
842
-	 *
843
-	 * @since 1.0.19
844
-	 */
845
-	public function get_billing_email() {
846
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
847
-	}
848
-
849
-	/**
850
-	 * Checks if the submitter has a billing email.
851
-	 *
852
-	 * @since 1.0.19
853
-	 */
854
-	public function has_billing_email() {
855
-		$billing_email = $this->get_billing_email();
856
-		return ! empty( $billing_email ) && is_email( $billing_email );
857
-	}
858
-
859
-	/**
860
-	 * Returns the appropriate currency for the submission.
861
-	 *
862
-	 * @since 1.0.19
863
-	 * @return string
864
-	 */
865
-	public function get_currency() {
866
-		return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
867
-    }
868
-
869
-    /**
870
-	 * Returns the raw submission data.
871
-	 *
872
-	 * @since 1.0.19
873
-	 * @return array
874
-	 */
875
-	public function get_data() {
876
-		return $this->data;
877
-	}
878
-
879
-	/**
880
-	 * Returns a field from the submission data
881
-	 *
882
-	 * @param string $field
883
-	 * @since 1.0.19
884
-	 * @return mixed|null
885
-	 */
886
-	public function get_field( $field, $sub_array_key = null ) {
887
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
888
-	}
889
-
890
-	/**
891
-	 * Checks if a required field is set.
892
-	 *
893
-	 * @since 1.0.19
894
-	 */
895
-	public function is_required_field_set( $field ) {
896
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
897
-	}
898
-
899
-	/**
900
-	 * Formats an amount
901
-	 *
902
-	 * @since 1.0.19
903
-	 */
904
-	public function format_amount( $amount ) {
905
-		return wpinv_price( $amount, $this->get_currency() );
906
-	}
793
+    /**
794
+     * Checks if this is the initial fetch.
795
+     *
796
+     * @return bool
797
+     * @since 1.0.19
798
+     */
799
+    public function is_initial_fetch() {
800
+        return empty( $this->data['initial_state'] );
801
+    }
802
+
803
+    /**
804
+     * Returns the total amount to collect for this submission.
805
+     *
806
+     * @since 1.0.19
807
+     */
808
+    public function get_total() {
809
+        $total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
810
+        return max( $total, 0 );
811
+    }
812
+
813
+    /**
814
+     * Returns the recurring total amount to collect for this submission.
815
+     *
816
+     * @since 1.0.19
817
+     */
818
+    public function get_recurring_total() {
819
+        $total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
820
+        return max( $total, 0 );
821
+    }
822
+
823
+    /**
824
+     * Whether payment details should be collected for this submission.
825
+     *
826
+     * @since 1.0.19
827
+     */
828
+    public function should_collect_payment_details() {
829
+        $initial   = $this->get_total();
830
+        $recurring = $this->get_recurring_total();
831
+
832
+        if ( $this->has_recurring == 0 ) {
833
+            $recurring = 0;
834
+        }
835
+
836
+        $collect = $initial > 0 || $recurring > 0;
837
+        return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
838
+    }
839
+
840
+    /**
841
+     * Returns the billing email of the user.
842
+     *
843
+     * @since 1.0.19
844
+     */
845
+    public function get_billing_email() {
846
+        return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
847
+    }
848
+
849
+    /**
850
+     * Checks if the submitter has a billing email.
851
+     *
852
+     * @since 1.0.19
853
+     */
854
+    public function has_billing_email() {
855
+        $billing_email = $this->get_billing_email();
856
+        return ! empty( $billing_email ) && is_email( $billing_email );
857
+    }
858
+
859
+    /**
860
+     * Returns the appropriate currency for the submission.
861
+     *
862
+     * @since 1.0.19
863
+     * @return string
864
+     */
865
+    public function get_currency() {
866
+        return $this->has_invoice() ? $this->invoice->get_currency() : wpinv_get_currency();
867
+    }
868
+
869
+    /**
870
+     * Returns the raw submission data.
871
+     *
872
+     * @since 1.0.19
873
+     * @return array
874
+     */
875
+    public function get_data() {
876
+        return $this->data;
877
+    }
878
+
879
+    /**
880
+     * Returns a field from the submission data
881
+     *
882
+     * @param string $field
883
+     * @since 1.0.19
884
+     * @return mixed|null
885
+     */
886
+    public function get_field( $field, $sub_array_key = null ) {
887
+        return getpaid_get_array_field( $this->data, $field, $sub_array_key );
888
+    }
889
+
890
+    /**
891
+     * Checks if a required field is set.
892
+     *
893
+     * @since 1.0.19
894
+     */
895
+    public function is_required_field_set( $field ) {
896
+        return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
897
+    }
898
+
899
+    /**
900
+     * Formats an amount
901
+     *
902
+     * @since 1.0.19
903
+     */
904
+    public function format_amount( $amount ) {
905
+        return wpinv_price( $amount, $this->get_currency() );
906
+    }
907 907
 
908 908
 }
Please login to merge, or discard this patch.
Spacing   +125 added lines, -125 removed lines patch added patch discarded remove patch
@@ -1,5 +1,5 @@  discard block
 block discarded – undo
1 1
 <?php
2
-if ( ! defined( 'ABSPATH' ) ) {
2
+if (!defined('ABSPATH')) {
3 3
 	exit;
4 4
 }
5 5
 
@@ -141,8 +141,8 @@  discard block
 block discarded – undo
141 141
 		$this->state   = wpinv_get_default_state();
142 142
 
143 143
 		// Do we have an actual submission?
144
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
145
-			$this->load_data( $_POST );
144
+		if (isset($_POST['getpaid_payment_form_submission'])) {
145
+			$this->load_data($_POST);
146 146
 		}
147 147
 
148 148
 	}
@@ -152,19 +152,19 @@  discard block
 block discarded – undo
152 152
 	 *
153 153
 	 * @param array $data
154 154
 	 */
155
-	public function load_data( $data ) {
155
+	public function load_data($data) {
156 156
 
157 157
 		// Remove slashes from the submitted data...
158
-		$data       = wp_kses_post_deep( wp_unslash( $data ) );
158
+		$data       = wp_kses_post_deep(wp_unslash($data));
159 159
 
160 160
 		// Allow plugins to filter the data.
161
-		$data       = apply_filters( 'getpaid_submission_data', $data, $this );
161
+		$data       = apply_filters('getpaid_submission_data', $data, $this);
162 162
 
163 163
 		// Cache it...
164 164
 		$this->data = $data;
165 165
 
166 166
 		// Then generate a unique id from the data.
167
-		$this->id   = md5( wp_json_encode( $data ) );
167
+		$this->id   = md5(wp_json_encode($data));
168 168
 
169 169
 		// Finally, process the submission.
170 170
 		try {
@@ -174,30 +174,30 @@  discard block
 block discarded – undo
174 174
 			$processors = apply_filters(
175 175
 				'getpaid_payment_form_submission_processors',
176 176
 				array(
177
-					array( $this, 'process_payment_form' ),
178
-					array( $this, 'process_invoice' ),
179
-					array( $this, 'process_fees' ),
180
-					array( $this, 'process_items' ),
181
-					array( $this, 'process_discount' ),
182
-					array( $this, 'process_taxes' ),
177
+					array($this, 'process_payment_form'),
178
+					array($this, 'process_invoice'),
179
+					array($this, 'process_fees'),
180
+					array($this, 'process_items'),
181
+					array($this, 'process_discount'),
182
+					array($this, 'process_taxes'),
183 183
 				),
184 184
 				$this		
185 185
 			);
186 186
 
187
-			foreach ( $processors as $processor ) {
188
-				call_user_func_array( $processor, array( &$this ) );
187
+			foreach ($processors as $processor) {
188
+				call_user_func_array($processor, array(&$this));
189 189
 			}
190 190
 
191
-		} catch( GetPaid_Payment_Exception $e ) {
191
+		} catch (GetPaid_Payment_Exception $e) {
192 192
 			$this->last_error      = $e->getMessage();
193 193
 			$this->last_error_code = $e->getErrorCode();
194
-		} catch ( Exception $e ) {
194
+		} catch (Exception $e) {
195 195
 			$this->last_error      = $e->getMessage();
196 196
 			$this->last_error_code = $e->getCode();
197 197
 		}
198 198
 
199 199
 		// Fired when we are done processing a submission.
200
-		do_action_ref_array( 'getpaid_process_submission', array( &$this ) );
200
+		do_action_ref_array('getpaid_process_submission', array(&$this));
201 201
 
202 202
 	}
203 203
 
@@ -218,18 +218,18 @@  discard block
 block discarded – undo
218 218
 	public function process_payment_form() {
219 219
 
220 220
 		// Every submission needs an active payment form.
221
-		if ( empty( $this->data['form_id'] ) ) {
222
-			throw new Exception( __( 'Missing payment form', 'invoicing' ) );
221
+		if (empty($this->data['form_id'])) {
222
+			throw new Exception(__('Missing payment form', 'invoicing'));
223 223
 		}
224 224
 
225 225
 		// Fetch the payment form.
226
-		$this->payment_form = new GetPaid_Payment_Form( $this->data['form_id'] );
226
+		$this->payment_form = new GetPaid_Payment_Form($this->data['form_id']);
227 227
 
228
-		if ( ! $this->payment_form->is_active() ) {
229
-			throw new Exception( __( 'Payment form not active', 'invoicing' ) );
228
+		if (!$this->payment_form->is_active()) {
229
+			throw new Exception(__('Payment form not active', 'invoicing'));
230 230
 		}
231 231
 
232
-		do_action_ref_array( 'getpaid_submissions_process_payment_form', array( &$this ) );
232
+		do_action_ref_array('getpaid_submissions_process_payment_form', array(&$this));
233 233
 	}
234 234
 
235 235
     /**
@@ -259,53 +259,53 @@  discard block
 block discarded – undo
259 259
 	public function process_invoice() {
260 260
 
261 261
 		// Abort if there is no invoice.
262
-		if ( empty( $this->data['invoice_id'] ) ) {
262
+		if (empty($this->data['invoice_id'])) {
263 263
 			return;
264 264
 		}
265 265
 
266 266
 		// If the submission is for an existing invoice, ensure that it exists
267 267
 		// and that it is not paid for.
268
-		$invoice = wpinv_get_invoice( $this->data['invoice_id'] );
268
+		$invoice = wpinv_get_invoice($this->data['invoice_id']);
269 269
 
270
-        if ( empty( $invoice ) ) {
271
-			throw new Exception( __( 'Invalid invoice', 'invoicing' ) );
270
+        if (empty($invoice)) {
271
+			throw new Exception(__('Invalid invoice', 'invoicing'));
272 272
 		}
273 273
 
274
-		if ( $invoice->is_paid() ) {
275
-			throw new Exception( __( 'This invoice is already paid for.', 'invoicing' ) );
274
+		if ($invoice->is_paid()) {
275
+			throw new Exception(__('This invoice is already paid for.', 'invoicing'));
276 276
 		}
277 277
 
278 278
 		$this->payment_form->invoice = $invoice;
279
-		if ( ! $this->payment_form->is_default() ) {
279
+		if (!$this->payment_form->is_default()) {
280 280
 
281 281
 			$items    = array();
282 282
 			$item_ids = array();
283 283
 	
284
-			foreach ( $invoice->get_items() as $item ) {
285
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
284
+			foreach ($invoice->get_items() as $item) {
285
+				if (!in_array($item->get_id(), $item_ids)) {
286 286
 					$item_ids[] = $item->get_id();
287 287
 					$items[]    = $item;
288 288
 				}
289 289
 			}
290 290
 	
291
-			foreach ( $this->payment_form->get_items() as $item ) {
292
-				if ( ! in_array( $item->get_id(), $item_ids ) ) {
291
+			foreach ($this->payment_form->get_items() as $item) {
292
+				if (!in_array($item->get_id(), $item_ids)) {
293 293
 					$item_ids[] = $item->get_id();
294 294
 					$items[]    = $item;
295 295
 				}
296 296
 			}
297 297
 	
298
-			$this->payment_form->set_items( $items );
298
+			$this->payment_form->set_items($items);
299 299
 	
300 300
 		} else {
301
-			$this->payment_form->set_items( $invoice->get_items() );
301
+			$this->payment_form->set_items($invoice->get_items());
302 302
 		}
303 303
 
304 304
 		$this->country = $invoice->get_country();
305 305
 		$this->state   = $invoice->get_state();
306 306
 		$this->invoice = $invoice;
307 307
 
308
-		do_action_ref_array( 'getpaid_submissions_process_invoice', array( &$this ) );
308
+		do_action_ref_array('getpaid_submissions_process_invoice', array(&$this));
309 309
 	}
310 310
 
311 311
 	/**
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 	 * @return bool
326 326
 	 */
327 327
 	public function has_invoice() {
328
-		return ! empty( $this->invoice );
328
+		return !empty($this->invoice);
329 329
 	}
330 330
 
331 331
 	/*
@@ -344,13 +344,13 @@  discard block
 block discarded – undo
344 344
 	 */
345 345
 	public function process_items() {
346 346
 
347
-		$processor = new GetPaid_Payment_Form_Submission_Items( $this );
347
+		$processor = new GetPaid_Payment_Form_Submission_Items($this);
348 348
 
349
-		foreach ( $processor->items as $item ) {
350
-			$this->add_item( $item );
349
+		foreach ($processor->items as $item) {
350
+			$this->add_item($item);
351 351
 		}
352 352
 
353
-		do_action_ref_array( 'getpaid_submissions_process_items', array( &$this ) );
353
+		do_action_ref_array('getpaid_submissions_process_items', array(&$this));
354 354
 	}
355 355
 
356 356
 	/**
@@ -359,20 +359,20 @@  discard block
 block discarded – undo
359 359
 	 * @since 1.0.19
360 360
 	 * @param GetPaid_Form_Item $item
361 361
 	 */
362
-	public function add_item( $item ) {
362
+	public function add_item($item) {
363 363
 
364 364
 		// Make sure that it is available for purchase.
365
-		if ( ! $item->can_purchase() || isset( $this->items[ $item->get_id() ] ) ) {
365
+		if (!$item->can_purchase() || isset($this->items[$item->get_id()])) {
366 366
 			return;
367 367
 		}
368 368
 
369 369
 		// Each submission can only contain one recurring item.
370
-		if ( $item->is_recurring() ) {
370
+		if ($item->is_recurring()) {
371 371
 			$this->has_recurring = $item->get_id();
372 372
 		}
373 373
 
374 374
 		// Update the items and totals.
375
-		$this->items[ $item->get_id() ]         = $item;
375
+		$this->items[$item->get_id()]         = $item;
376 376
 		$this->totals['subtotal']['initial']   += $item->get_sub_total();
377 377
 		$this->totals['subtotal']['recurring'] += $item->get_recurring_sub_total();
378 378
 
@@ -386,17 +386,17 @@  discard block
 block discarded – undo
386 386
 	 *
387 387
 	 * @since 1.0.19
388 388
 	 */
389
-	public function remove_item( $item_id ) {
389
+	public function remove_item($item_id) {
390 390
 
391
-		if ( isset( $this->items[ $item_id ] ) ) {
392
-			$this->totals['subtotal']['initial']   -= $this->items[ $item_id ]->get_sub_total();
393
-			$this->totals['subtotal']['recurring'] -= $this->items[ $item_id ]->get_recurring_sub_total();
391
+		if (isset($this->items[$item_id])) {
392
+			$this->totals['subtotal']['initial']   -= $this->items[$item_id]->get_sub_total();
393
+			$this->totals['subtotal']['recurring'] -= $this->items[$item_id]->get_recurring_sub_total();
394 394
 
395
-			if ( $this->items[ $item_id ]->is_recurring() ) {
395
+			if ($this->items[$item_id]->is_recurring()) {
396 396
 				$this->has_recurring = 0;
397 397
 			}
398 398
 
399
-			unset( $this->items[ $item_id ] );
399
+			unset($this->items[$item_id]);
400 400
 		}
401 401
 
402 402
 	}
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
 	 */
409 409
 	public function get_subtotal() {
410 410
 
411
-		if ( wpinv_prices_include_tax() ) {
411
+		if (wpinv_prices_include_tax()) {
412 412
 			return $this->totals['subtotal']['initial'] - $this->totals['taxes']['initial'];
413 413
 		}
414 414
 
@@ -422,7 +422,7 @@  discard block
 block discarded – undo
422 422
 	 */
423 423
 	public function get_recurring_subtotal() {
424 424
 
425
-		if ( wpinv_prices_include_tax() ) {
425
+		if (wpinv_prices_include_tax()) {
426 426
 			return $this->totals['subtotal']['recurring'] - $this->totals['taxes']['recurring'];
427 427
 		}
428 428
 
@@ -446,7 +446,7 @@  discard block
 block discarded – undo
446 446
 	 * @return bool
447 447
 	 */
448 448
 	public function has_subscription_group() {
449
-		return $this->has_recurring && getpaid_should_group_subscriptions( $this ) && 1 == count( getpaid_get_subscription_groups( $this ) );
449
+		return $this->has_recurring && getpaid_should_group_subscriptions($this) && 1 == count(getpaid_get_subscription_groups($this));
450 450
 	}
451 451
 
452 452
 	/**
@@ -456,7 +456,7 @@  discard block
 block discarded – undo
456 456
 	 * @return bool
457 457
 	 */
458 458
 	public function has_multiple_subscription_groups() {
459
-		return $this->has_recurring && 1 < count( getpaid_get_subscription_groups( $this ) );
459
+		return $this->has_recurring && 1 < count(getpaid_get_subscription_groups($this));
460 460
 	}
461 461
 
462 462
 	/*
@@ -476,39 +476,39 @@  discard block
 block discarded – undo
476 476
 	public function process_taxes() {
477 477
 
478 478
 		// Abort if we're not using taxes.
479
-		if ( ! $this->use_taxes() ) {
479
+		if (!$this->use_taxes()) {
480 480
 			return;
481 481
 		}
482 482
 
483 483
 		// If a custom country && state has been passed in, use it to calculate taxes.
484
-		$country = $this->get_field( 'wpinv_country', 'billing' );
485
-		if ( ! empty( $country ) ) {
484
+		$country = $this->get_field('wpinv_country', 'billing');
485
+		if (!empty($country)) {
486 486
 			$this->country = $country;
487 487
 		}
488 488
 
489
-		$state = $this->get_field( 'wpinv_state', 'billing' );
490
-		if ( ! empty( $state ) ) {
489
+		$state = $this->get_field('wpinv_state', 'billing');
490
+		if (!empty($state)) {
491 491
 			$this->state = $state;
492 492
 		}
493 493
 
494 494
 		// Confirm if the provided country and the ip country are similar.
495
-		$address_confirmed = $this->get_field( 'confirm-address' );
496
-		if ( isset( $_POST['billing']['country'] ) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty( $address_confirmed ) ) {
497
-			throw new Exception( __( 'The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing' ) );
495
+		$address_confirmed = $this->get_field('confirm-address');
496
+		if (isset($_POST['billing']['country']) && wpinv_should_validate_vat_number() && getpaid_get_ip_country() != $this->country && empty($address_confirmed)) {
497
+			throw new Exception(__('The country of your current location must be the same as the country of your billing location or you must confirm the billing address is your home country.', 'invoicing'));
498 498
 		}
499 499
 
500 500
 		// Abort if the country is not taxable.
501
-		if ( ! wpinv_is_country_taxable( $this->country ) ) {
501
+		if (!wpinv_is_country_taxable($this->country)) {
502 502
 			return;
503 503
 		}
504 504
 
505
-		$processor = new GetPaid_Payment_Form_Submission_Taxes( $this );
505
+		$processor = new GetPaid_Payment_Form_Submission_Taxes($this);
506 506
 
507
-		foreach ( $processor->taxes as $tax ) {
508
-			$this->add_tax( $tax );
507
+		foreach ($processor->taxes as $tax) {
508
+			$this->add_tax($tax);
509 509
 		}
510 510
 
511
-		do_action_ref_array( 'getpaid_submissions_process_taxes', array( &$this ) );
511
+		do_action_ref_array('getpaid_submissions_process_taxes', array(&$this));
512 512
 	}
513 513
 
514 514
 	/**
@@ -517,16 +517,16 @@  discard block
 block discarded – undo
517 517
 	 * @param array $tax An array of tax details. name, initial_tax, and recurring_tax are required.
518 518
 	 * @since 1.0.19
519 519
 	 */
520
-	public function add_tax( $tax ) {
520
+	public function add_tax($tax) {
521 521
 
522
-		if ( wpinv_round_tax_per_tax_rate() ) {
523
-			$tax['initial_tax']   = wpinv_round_amount( $tax['initial_tax'] );
524
-			$tax['recurring_tax'] = wpinv_round_amount( $tax['recurring_tax'] );
522
+		if (wpinv_round_tax_per_tax_rate()) {
523
+			$tax['initial_tax']   = wpinv_round_amount($tax['initial_tax']);
524
+			$tax['recurring_tax'] = wpinv_round_amount($tax['recurring_tax']);
525 525
 		}
526 526
 
527
-		$this->taxes[ $tax['name'] ]         = $tax;
528
-		$this->totals['taxes']['initial']   += wpinv_sanitize_amount( $tax['initial_tax'] );
529
-		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount( $tax['recurring_tax'] );
527
+		$this->taxes[$tax['name']]         = $tax;
528
+		$this->totals['taxes']['initial']   += wpinv_sanitize_amount($tax['initial_tax']);
529
+		$this->totals['taxes']['recurring'] += wpinv_sanitize_amount($tax['recurring_tax']);
530 530
 
531 531
 	}
532 532
 
@@ -535,12 +535,12 @@  discard block
 block discarded – undo
535 535
 	 *
536 536
 	 * @since 1.0.19
537 537
 	 */
538
-	public function remove_tax( $tax_name ) {
538
+	public function remove_tax($tax_name) {
539 539
 
540
-		if ( isset( $this->taxes[ $tax_name ] ) ) {
541
-			$this->totals['taxes']['initial']   -= $this->taxes[ $tax_name ]['initial_tax'];
542
-			$this->totals['taxes']['recurring'] -= $this->taxes[ $tax_name ]['recurring_tax'];
543
-			unset( $this->taxes[ $tax_name ] );
540
+		if (isset($this->taxes[$tax_name])) {
541
+			$this->totals['taxes']['initial']   -= $this->taxes[$tax_name]['initial_tax'];
542
+			$this->totals['taxes']['recurring'] -= $this->taxes[$tax_name]['recurring_tax'];
543
+			unset($this->taxes[$tax_name]);
544 544
 		}
545 545
 
546 546
 	}
@@ -554,11 +554,11 @@  discard block
 block discarded – undo
554 554
 
555 555
 		$use_taxes = wpinv_use_taxes();
556 556
 
557
-		if ( $this->has_invoice() && ! $this->invoice->is_taxable() ) {
557
+		if ($this->has_invoice() && !$this->invoice->is_taxable()) {
558 558
 			$use_taxes = false;
559 559
 		}
560 560
 
561
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
561
+		return apply_filters('getpaid_submission_use_taxes', $use_taxes, $this);
562 562
 
563 563
 	}
564 564
 
@@ -607,13 +607,13 @@  discard block
 block discarded – undo
607 607
 
608 608
 		$initial_total    = $this->get_subtotal() + $this->get_fee() + $this->get_tax();
609 609
 		$recurring_total  = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax();
610
-		$processor        = new GetPaid_Payment_Form_Submission_Discount( $this, $initial_total, $recurring_total );
610
+		$processor        = new GetPaid_Payment_Form_Submission_Discount($this, $initial_total, $recurring_total);
611 611
 
612
-		foreach ( $processor->discounts as $discount ) {
613
-			$this->add_discount( $discount );
612
+		foreach ($processor->discounts as $discount) {
613
+			$this->add_discount($discount);
614 614
 		}
615 615
 
616
-		do_action_ref_array( 'getpaid_submissions_process_discounts', array( &$this ) );
616
+		do_action_ref_array('getpaid_submissions_process_discounts', array(&$this));
617 617
 	}
618 618
 
619 619
 	/**
@@ -622,10 +622,10 @@  discard block
 block discarded – undo
622 622
 	 * @param array $discount An array of discount details. name, initial_discount, and recurring_discount are required. Include discount_code if the discount is from a discount code.
623 623
 	 * @since 1.0.19
624 624
 	 */
625
-	public function add_discount( $discount ) {
626
-		$this->discounts[ $discount['name'] ]   = $discount;
627
-		$this->totals['discount']['initial']   += wpinv_sanitize_amount( $discount['initial_discount'] );
628
-		$this->totals['discount']['recurring'] += wpinv_sanitize_amount( $discount['recurring_discount'] );
625
+	public function add_discount($discount) {
626
+		$this->discounts[$discount['name']]   = $discount;
627
+		$this->totals['discount']['initial']   += wpinv_sanitize_amount($discount['initial_discount']);
628
+		$this->totals['discount']['recurring'] += wpinv_sanitize_amount($discount['recurring_discount']);
629 629
 	}
630 630
 
631 631
 	/**
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
 	 *
634 634
 	 * @since 1.0.19
635 635
 	 */
636
-	public function remove_discount( $name ) {
636
+	public function remove_discount($name) {
637 637
 
638
-		if ( isset( $this->discounts[ $name ] ) ) {
639
-			$this->totals['discount']['initial']   -= $this->discounts[ $name ]['initial_discount'];
640
-			$this->totals['discount']['recurring'] -= $this->discounts[ $name ]['recurring_discount'];
641
-			unset( $this->discounts[ $name ] );
638
+		if (isset($this->discounts[$name])) {
639
+			$this->totals['discount']['initial']   -= $this->discounts[$name]['initial_discount'];
640
+			$this->totals['discount']['recurring'] -= $this->discounts[$name]['recurring_discount'];
641
+			unset($this->discounts[$name]);
642 642
 		}
643 643
 
644 644
 	}
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
 	 * @return bool
651 651
 	 */
652 652
 	public function has_discount_code() {
653
-		return ! empty( $this->discounts['discount_code'] );
653
+		return !empty($this->discounts['discount_code']);
654 654
 	}
655 655
 
656 656
 	/**
@@ -707,13 +707,13 @@  discard block
 block discarded – undo
707 707
 	 */
708 708
 	public function process_fees() {
709 709
 
710
-		$fees_processor = new GetPaid_Payment_Form_Submission_Fees( $this );
710
+		$fees_processor = new GetPaid_Payment_Form_Submission_Fees($this);
711 711
 
712
-		foreach ( $fees_processor->fees as $fee ) {
713
-			$this->add_fee( $fee );
712
+		foreach ($fees_processor->fees as $fee) {
713
+			$this->add_fee($fee);
714 714
 		}
715 715
 
716
-		do_action_ref_array( 'getpaid_submissions_process_fees', array( &$this ) );
716
+		do_action_ref_array('getpaid_submissions_process_fees', array(&$this));
717 717
 	}
718 718
 
719 719
 	/**
@@ -722,11 +722,11 @@  discard block
 block discarded – undo
722 722
 	 * @param array $fee An array of fee details. name, initial_fee, and recurring_fee are required.
723 723
 	 * @since 1.0.19
724 724
 	 */
725
-	public function add_fee( $fee ) {
725
+	public function add_fee($fee) {
726 726
 
727
-		$this->fees[ $fee['name'] ]         = $fee;
728
-		$this->totals['fees']['initial']   += wpinv_sanitize_amount( $fee['initial_fee'] );
729
-		$this->totals['fees']['recurring'] += wpinv_sanitize_amount( $fee['recurring_fee'] );
727
+		$this->fees[$fee['name']]         = $fee;
728
+		$this->totals['fees']['initial']   += wpinv_sanitize_amount($fee['initial_fee']);
729
+		$this->totals['fees']['recurring'] += wpinv_sanitize_amount($fee['recurring_fee']);
730 730
 
731 731
 	}
732 732
 
@@ -735,12 +735,12 @@  discard block
 block discarded – undo
735 735
 	 *
736 736
 	 * @since 1.0.19
737 737
 	 */
738
-	public function remove_fee( $name ) {
738
+	public function remove_fee($name) {
739 739
 
740
-		if ( isset( $this->fees[ $name ] ) ) {
741
-			$this->totals['fees']['initial']   -= $this->fees[ $name ]['initial_fee'];
742
-			$this->totals['fees']['recurring'] -= $this->fees[ $name ]['recurring_fee'];
743
-			unset( $this->fees[ $name ] );
740
+		if (isset($this->fees[$name])) {
741
+			$this->totals['fees']['initial']   -= $this->fees[$name]['initial_fee'];
742
+			$this->totals['fees']['recurring'] -= $this->fees[$name]['recurring_fee'];
743
+			unset($this->fees[$name]);
744 744
 		}
745 745
 
746 746
 	}
@@ -779,7 +779,7 @@  discard block
 block discarded – undo
779 779
 	 * @since 1.0.19
780 780
 	 */
781 781
 	public function has_fees() {
782
-		return count( $this->fees ) !== 0;
782
+		return count($this->fees) !== 0;
783 783
 	}
784 784
 
785 785
 	/*
@@ -797,7 +797,7 @@  discard block
 block discarded – undo
797 797
 	 * @since 1.0.19
798 798
 	 */
799 799
 	public function is_initial_fetch() {
800
-		return empty( $this->data['initial_state'] );
800
+		return empty($this->data['initial_state']);
801 801
 	}
802 802
 
803 803
 	/**
@@ -807,7 +807,7 @@  discard block
 block discarded – undo
807 807
 	 */
808 808
 	public function get_total() {
809 809
 		$total = $this->get_subtotal() + $this->get_fee() + $this->get_tax() - $this->get_discount();
810
-		return max( $total, 0 );
810
+		return max($total, 0);
811 811
 	}
812 812
 
813 813
 	/**
@@ -817,7 +817,7 @@  discard block
 block discarded – undo
817 817
 	 */
818 818
 	public function get_recurring_total() {
819 819
 		$total = $this->get_recurring_subtotal() + $this->get_recurring_fee() + $this->get_recurring_tax() - $this->get_recurring_discount();
820
-		return max( $total, 0 );
820
+		return max($total, 0);
821 821
 	}
822 822
 
823 823
 	/**
@@ -829,12 +829,12 @@  discard block
 block discarded – undo
829 829
 		$initial   = $this->get_total();
830 830
 		$recurring = $this->get_recurring_total();
831 831
 
832
-		if ( $this->has_recurring == 0 ) {
832
+		if ($this->has_recurring == 0) {
833 833
 			$recurring = 0;
834 834
 		}
835 835
 
836 836
 		$collect = $initial > 0 || $recurring > 0;
837
-		return apply_filters( 'getpaid_submission_should_collect_payment_details', $collect, $this  );
837
+		return apply_filters('getpaid_submission_should_collect_payment_details', $collect, $this);
838 838
 	}
839 839
 
840 840
 	/**
@@ -843,7 +843,7 @@  discard block
 block discarded – undo
843 843
 	 * @since 1.0.19
844 844
 	 */
845 845
 	public function get_billing_email() {
846
-		return apply_filters( 'getpaid_get_submission_billing_email', $this->get_field( 'billing_email' ), $this  );
846
+		return apply_filters('getpaid_get_submission_billing_email', $this->get_field('billing_email'), $this);
847 847
 	}
848 848
 
849 849
 	/**
@@ -853,7 +853,7 @@  discard block
 block discarded – undo
853 853
 	 */
854 854
 	public function has_billing_email() {
855 855
 		$billing_email = $this->get_billing_email();
856
-		return ! empty( $billing_email ) && is_email( $billing_email );
856
+		return !empty($billing_email) && is_email($billing_email);
857 857
 	}
858 858
 
859 859
 	/**
@@ -883,8 +883,8 @@  discard block
 block discarded – undo
883 883
 	 * @since 1.0.19
884 884
 	 * @return mixed|null
885 885
 	 */
886
-	public function get_field( $field, $sub_array_key = null ) {
887
-		return getpaid_get_array_field( $this->data, $field, $sub_array_key );
886
+	public function get_field($field, $sub_array_key = null) {
887
+		return getpaid_get_array_field($this->data, $field, $sub_array_key);
888 888
 	}
889 889
 
890 890
 	/**
@@ -892,8 +892,8 @@  discard block
 block discarded – undo
892 892
 	 *
893 893
 	 * @since 1.0.19
894 894
 	 */
895
-	public function is_required_field_set( $field ) {
896
-		return empty( $field['required'] ) || ! empty( $this->data[ $field['id'] ] );
895
+	public function is_required_field_set($field) {
896
+		return empty($field['required']) || !empty($this->data[$field['id']]);
897 897
 	}
898 898
 
899 899
 	/**
@@ -901,8 +901,8 @@  discard block
 block discarded – undo
901 901
 	 *
902 902
 	 * @since 1.0.19
903 903
 	 */
904
-	public function format_amount( $amount ) {
905
-		return wpinv_price( $amount, $this->get_currency() );
904
+	public function format_amount($amount) {
905
+		return wpinv_price($amount, $this->get_currency());
906 906
 	}
907 907
 
908 908
 }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-worldpay-gateway.php 2 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -13,65 +13,65 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Worldpay_Gateway extends GetPaid_Payment_Gateway {
14 14
 
15 15
     /**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20 20
     public $id = 'worldpay';
21 21
 
22 22
     /**
23
-	 * Payment method order.
24
-	 *
25
-	 * @var int
26
-	 */
23
+     * Payment method order.
24
+     *
25
+     * @var int
26
+     */
27 27
     public $order = 5;
28 28
 
29 29
     /**
30
-	 * Endpoint for requests from Worldpay.
31
-	 *
32
-	 * @var string
33
-	 */
34
-	protected $notify_url;
35
-
36
-	/**
37
-	 * Endpoint for requests to Worldpay.
38
-	 *
39
-	 * @var string
40
-	 */
30
+     * Endpoint for requests from Worldpay.
31
+     *
32
+     * @var string
33
+     */
34
+    protected $notify_url;
35
+
36
+    /**
37
+     * Endpoint for requests to Worldpay.
38
+     *
39
+     * @var string
40
+     */
41 41
     protected $endpoint;
42 42
 
43 43
     /**
44
-	 * An array of features that this gateway supports.
45
-	 *
46
-	 * @var array
47
-	 */
44
+     * An array of features that this gateway supports.
45
+     *
46
+     * @var array
47
+     */
48 48
     protected $supports = array( 'sandbox' );
49 49
     
50 50
     /**
51
-	 * Currencies this gateway is allowed for.
52
-	 *
53
-	 * @var array
54
-	 */
55
-	public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' );
51
+     * Currencies this gateway is allowed for.
52
+     *
53
+     * @var array
54
+     */
55
+    public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' );
56 56
 
57 57
     /**
58
-	 * URL to view a transaction.
59
-	 *
60
-	 * @var string
61
-	 */
58
+     * URL to view a transaction.
59
+     *
60
+     * @var string
61
+     */
62 62
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
63 63
 
64 64
     /**
65
-	 * URL to view a subscription.
66
-	 *
67
-	 * @var string
68
-	 */
69
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
65
+     * URL to view a subscription.
66
+     *
67
+     * @var string
68
+     */
69
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
70 70
 
71 71
     /**
72
-	 * Class constructor.
73
-	 */
74
-	public function __construct() {
72
+     * Class constructor.
73
+     */
74
+    public function __construct() {
75 75
 
76 76
         $this->method_title         = __( 'Worldpay', 'invoicing' );
77 77
         $this->title                = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' );
@@ -85,15 +85,15 @@  discard block
 block discarded – undo
85 85
     }
86 86
 
87 87
     /**
88
-	 * Process Payment.
89
-	 *
90
-	 *
91
-	 * @param WPInv_Invoice $invoice Invoice.
92
-	 * @param array $submission_data Posted checkout fields.
93
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
94
-	 * @return array
95
-	 */
96
-	public function process_payment( $invoice, $submission_data, $submission ) {
88
+     * Process Payment.
89
+     *
90
+     *
91
+     * @param WPInv_Invoice $invoice Invoice.
92
+     * @param array $submission_data Posted checkout fields.
93
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
94
+     * @return array
95
+     */
96
+    public function process_payment( $invoice, $submission_data, $submission ) {
97 97
 
98 98
         // Get redirect url.
99 99
         $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) );
@@ -128,31 +128,31 @@  discard block
 block discarded – undo
128 128
     }
129 129
 
130 130
     /**
131
-	 * Get the Worldpay request URL for an invoice.
132
-	 *
133
-	 * @param  WPInv_Invoice $invoice Invoice object.
134
-	 * @return string
135
-	 */
136
-	public function get_request_url( $invoice ) {
131
+     * Get the Worldpay request URL for an invoice.
132
+     *
133
+     * @param  WPInv_Invoice $invoice Invoice object.
134
+     * @return string
135
+     */
136
+    public function get_request_url( $invoice ) {
137 137
 
138 138
         // Endpoint for this request
139
-		$this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
139
+        $this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
140 140
 
141 141
         return $this->endpoint;
142 142
 
143
-	}
143
+    }
144 144
 
145 145
     /**
146
-	 * Get Worldpay Args for passing to Worldpay.
147
-	 *
148
-	 * @param  WPInv_Invoice $invoice Invoice object.
149
-	 * @return array
150
-	 */
151
-	protected function get_worldpay_args( $invoice ) {
152
-
153
-		return apply_filters(
154
-			'getpaid_worldpay_args',
155
-			array(
146
+     * Get Worldpay Args for passing to Worldpay.
147
+     *
148
+     * @param  WPInv_Invoice $invoice Invoice object.
149
+     * @return array
150
+     */
151
+    protected function get_worldpay_args( $invoice ) {
152
+
153
+        return apply_filters(
154
+            'getpaid_worldpay_args',
155
+            array(
156 156
                 'amount'         => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory
157 157
                 'cartId'         => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased
158 158
                 'currency'       => wpinv_clean( $invoice->get_currency() ), // mandatory
@@ -177,18 +177,18 @@  discard block
 block discarded – undo
177 177
                 'countryString'  => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ),
178 178
                 'compName'       => wpinv_clean( $invoice->get_company() ),
179 179
             ),
180
-			$invoice
181
-		);
180
+            $invoice
181
+        );
182 182
 
183 183
     }
184 184
 
185 185
     /**
186
-	 * Secures worldpay args with an md5 hash.
187
-	 *
188
-	 * @param  array $args Gateway args.
189
-	 * @return array
190
-	 */
191
-	public function hash_args( $args ) {
186
+     * Secures worldpay args with an md5 hash.
187
+     *
188
+     * @param  array $args Gateway args.
189
+     * @return array
190
+     */
191
+    public function hash_args( $args ) {
192 192
 
193 193
         $md5_secret = $this->get_option( 'md5_secret' );
194 194
 
@@ -204,16 +204,16 @@  discard block
 block discarded – undo
204 204
     }
205 205
 
206 206
     /**
207
-	 * Processes ipns and marks payments as complete.
208
-	 *
209
-	 * @return void
210
-	 */
211
-	public function verify_ipn() {
207
+     * Processes ipns and marks payments as complete.
208
+     *
209
+     * @return void
210
+     */
211
+    public function verify_ipn() {
212 212
 
213 213
         // Validate the IPN.
214 214
         if ( empty( $_POST ) || ! $this->validate_ipn() ) {
215
-		    wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) );
216
-		}
215
+            wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) );
216
+        }
217 217
 
218 218
         // Process the IPN.
219 219
         $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
@@ -229,8 +229,8 @@  discard block
 block discarded – undo
229 229
                 $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) );
230 230
             }
231 231
 
232
-             // Update the ip address.
233
-             if ( ! empty( $posted['ipAddress'] ) ) {
232
+                // Update the ip address.
233
+                if ( ! empty( $posted['ipAddress'] ) ) {
234 234
                 $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) );
235 235
             }
236 236
 
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
     }
258 258
 
259 259
     /**
260
-	 * Check Worldpay IPN validity.
261
-	 */
262
-	public function validate_ipn() {
260
+     * Check Worldpay IPN validity.
261
+     */
262
+    public function validate_ipn() {
263 263
 
264 264
         wpinv_error_log( 'Validating Worldpay IPN response' );
265 265
 
@@ -305,11 +305,11 @@  discard block
 block discarded – undo
305 305
     }
306 306
 
307 307
     /**
308
-	 * Filters the gateway settings.
309
-	 * 
310
-	 * @param array $admin_settings
311
-	 */
312
-	public function admin_settings( $admin_settings ) {
308
+     * Filters the gateway settings.
309
+     * 
310
+     * @param array $admin_settings
311
+     */
312
+    public function admin_settings( $admin_settings ) {
313 313
 
314 314
         $currencies = sprintf(
315 315
             __( 'Supported Currencies: %s', 'invoicing' ),
@@ -350,7 +350,7 @@  discard block
 block discarded – undo
350 350
             'readonly' => true
351 351
         );
352 352
 
353
-		return $admin_settings;
354
-	}
353
+        return $admin_settings;
354
+    }
355 355
 
356 356
 }
Please login to merge, or discard this patch.
Spacing   +86 added lines, -86 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
  * Worldpay Payment Gateway class.
@@ -45,14 +45,14 @@  discard block
 block discarded – undo
45 45
 	 *
46 46
 	 * @var array
47 47
 	 */
48
-    protected $supports = array( 'sandbox' );
48
+    protected $supports = array('sandbox');
49 49
     
50 50
     /**
51 51
 	 * Currencies this gateway is allowed for.
52 52
 	 *
53 53
 	 * @var array
54 54
 	 */
55
-	public $currencies = array( 'AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR' );
55
+	public $currencies = array('AUD', 'ARS', 'CAD', 'CHF', 'DKK', 'EUR', 'HKD', 'MYR', 'GBP', 'NZD', 'NOK', 'SGD', 'LKR', 'SEK', 'TRY', 'USD', 'ZAR');
56 56
 
57 57
     /**
58 58
 	 * URL to view a transaction.
@@ -73,13 +73,13 @@  discard block
 block discarded – undo
73 73
 	 */
74 74
 	public function __construct() {
75 75
 
76
-        $this->method_title         = __( 'Worldpay', 'invoicing' );
77
-        $this->title                = __( 'Worldpay - Credit Card / Debit Card', 'invoicing' );
78
-        $this->checkout_button_text = __( 'Proceed to Worldpay', 'invoicing' );
79
-        $this->notify_url           = wpinv_get_ipn_url( $this->id );
76
+        $this->method_title         = __('Worldpay', 'invoicing');
77
+        $this->title                = __('Worldpay - Credit Card / Debit Card', 'invoicing');
78
+        $this->checkout_button_text = __('Proceed to Worldpay', 'invoicing');
79
+        $this->notify_url           = wpinv_get_ipn_url($this->id);
80 80
 
81
-        add_filter( 'wpinv_gateway_description', array( $this, 'sandbox_notice' ), 10, 2 );
82
-        add_filter( 'getpaid_worldpay_args', array( $this, 'hash_args' ) );
81
+        add_filter('wpinv_gateway_description', array($this, 'sandbox_notice'), 10, 2);
82
+        add_filter('getpaid_worldpay_args', array($this, 'hash_args'));
83 83
 
84 84
         parent::__construct();
85 85
     }
@@ -93,24 +93,24 @@  discard block
 block discarded – undo
93 93
 	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
94 94
 	 * @return array
95 95
 	 */
96
-	public function process_payment( $invoice, $submission_data, $submission ) {
96
+	public function process_payment($invoice, $submission_data, $submission) {
97 97
 
98 98
         // Get redirect url.
99
-        $worldpay_redirect = esc_url( $this->get_request_url( $invoice ) );
99
+        $worldpay_redirect = esc_url($this->get_request_url($invoice));
100 100
 
101 101
         // Get submission args.
102
-        $worldpay_args     = $this->get_worldpay_args( $invoice );
102
+        $worldpay_args     = $this->get_worldpay_args($invoice);
103 103
 
104 104
         $form = "<form action='$worldpay_redirect' name='wpi_worldpay_form' method='POST'>";
105 105
 
106
-        foreach ( $worldpay_args as $key => $value ) {
106
+        foreach ($worldpay_args as $key => $value) {
107 107
 
108
-            if ( false === $value || '' === trim( $value ) ) {
108
+            if (false === $value || '' === trim($value)) {
109 109
                 continue;
110 110
             }
111 111
 
112
-            $value = esc_attr( $value );
113
-            $key   = wpinv_clean( $key );
112
+            $value = esc_attr($value);
113
+            $key   = wpinv_clean($key);
114 114
             $form .= "<input type='hidden' name='$key' value='$value'>";
115 115
         }
116 116
 
@@ -133,10 +133,10 @@  discard block
 block discarded – undo
133 133
 	 * @param  WPInv_Invoice $invoice Invoice object.
134 134
 	 * @return string
135 135
 	 */
136
-	public function get_request_url( $invoice ) {
136
+	public function get_request_url($invoice) {
137 137
 
138 138
         // Endpoint for this request
139
-		$this->endpoint = $this->is_sandbox( $invoice ) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
139
+		$this->endpoint = $this->is_sandbox($invoice) ? 'https://secure-test.worldpay.com/wcc/purchase' : 'https://secure.worldpay.com/wcc/purchase';
140 140
 
141 141
         return $this->endpoint;
142 142
 
@@ -148,34 +148,34 @@  discard block
 block discarded – undo
148 148
 	 * @param  WPInv_Invoice $invoice Invoice object.
149 149
 	 * @return array
150 150
 	 */
151
-	protected function get_worldpay_args( $invoice ) {
151
+	protected function get_worldpay_args($invoice) {
152 152
 
153 153
 		return apply_filters(
154 154
 			'getpaid_worldpay_args',
155 155
 			array(
156
-                'amount'         => wpinv_sanitize_amount( $invoice->get_total() ), // mandatory
157
-                'cartId'         => wpinv_clean( $invoice->get_number() ), // mandatory reference for the item purchased
158
-                'currency'       => wpinv_clean( $invoice->get_currency() ), // mandatory
159
-                'instId'         => wpinv_clean( $this->get_option( 'instId', '' ) ), // mandatory
160
-                'testMode'       => $this->is_sandbox( $invoice ) ? 100 : 0, // mandatory
161
-                'name'           => wpinv_clean( $invoice->get_full_name() ),
162
-                'address'        => wpinv_clean( $invoice->get_address() ),
163
-                'postcode'       => wpinv_clean( $invoice->get_zip() ),
164
-                'tel'            => wpinv_clean( $invoice->get_phone() ),
165
-                'email'          => sanitize_email( $invoice->get_email() ),
166
-                'country'        => wpinv_clean( $invoice->get_country() ),
167
-                'desc'           => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ),
168
-                'MC_description' => sprintf( __( 'Payment for invoice %s.', 'invoicing' ), wpinv_clean( $invoice->get_number() ) ),
169
-                'MC_callback'    => esc_url_raw( $this->notify_url ),
170
-                'resultfile'     => esc_url_raw( $this->get_return_url( $invoice ) ),
171
-                'MC_key'         => wpinv_clean( $invoice->get_key() ),
156
+                'amount'         => wpinv_sanitize_amount($invoice->get_total()), // mandatory
157
+                'cartId'         => wpinv_clean($invoice->get_number()), // mandatory reference for the item purchased
158
+                'currency'       => wpinv_clean($invoice->get_currency()), // mandatory
159
+                'instId'         => wpinv_clean($this->get_option('instId', '')), // mandatory
160
+                'testMode'       => $this->is_sandbox($invoice) ? 100 : 0, // mandatory
161
+                'name'           => wpinv_clean($invoice->get_full_name()),
162
+                'address'        => wpinv_clean($invoice->get_address()),
163
+                'postcode'       => wpinv_clean($invoice->get_zip()),
164
+                'tel'            => wpinv_clean($invoice->get_phone()),
165
+                'email'          => sanitize_email($invoice->get_email()),
166
+                'country'        => wpinv_clean($invoice->get_country()),
167
+                'desc'           => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())),
168
+                'MC_description' => sprintf(__('Payment for invoice %s.', 'invoicing'), wpinv_clean($invoice->get_number())),
169
+                'MC_callback'    => esc_url_raw($this->notify_url),
170
+                'resultfile'     => esc_url_raw($this->get_return_url($invoice)),
171
+                'MC_key'         => wpinv_clean($invoice->get_key()),
172 172
                 'MC_invoice_id'  => $invoice->get_id(),
173
-                'address1'       => wpinv_clean( $invoice->get_address() ),
174
-                'town'           => wpinv_clean( $invoice->get_city() ),
175
-                'region'         => wpinv_clean( $invoice->get_state() ),
176
-                'amountString'   => wpinv_price( $invoice->get_total(), $invoice->get_currency() ),
177
-                'countryString'  => wpinv_clean( wpinv_country_name( $invoice->get_country() ) ),
178
-                'compName'       => wpinv_clean( $invoice->get_company() ),
173
+                'address1'       => wpinv_clean($invoice->get_address()),
174
+                'town'           => wpinv_clean($invoice->get_city()),
175
+                'region'         => wpinv_clean($invoice->get_state()),
176
+                'amountString'   => wpinv_price($invoice->get_total(), $invoice->get_currency()),
177
+                'countryString'  => wpinv_clean(wpinv_country_name($invoice->get_country())),
178
+                'compName'       => wpinv_clean($invoice->get_company()),
179 179
             ),
180 180
 			$invoice
181 181
 		);
@@ -188,17 +188,17 @@  discard block
 block discarded – undo
188 188
 	 * @param  array $args Gateway args.
189 189
 	 * @return array
190 190
 	 */
191
-	public function hash_args( $args ) {
191
+	public function hash_args($args) {
192 192
 
193
-        $md5_secret = $this->get_option( 'md5_secret' );
193
+        $md5_secret = $this->get_option('md5_secret');
194 194
 
195 195
         // Abort if there is no secret.
196
-        if ( empty( $md5_secret ) ) {
196
+        if (empty($md5_secret)) {
197 197
             return $args;
198 198
         }
199 199
 
200 200
         // Hash the args.
201
-        $args['signature'] = md5( "$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}" );
201
+        $args['signature'] = md5("$md5_secret:{$args['instId']}:{$args['amount']}:{$args['currency']}:{$args['cartId']}");
202 202
 
203 203
         return $args;
204 204
     }
@@ -211,43 +211,43 @@  discard block
 block discarded – undo
211 211
 	public function verify_ipn() {
212 212
 
213 213
         // Validate the IPN.
214
-        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
215
-		    wp_die( 'Worldpay IPN Request Failure', 'Worldpay IPN', array( 'response' => 500 ) );
214
+        if (empty($_POST) || !$this->validate_ipn()) {
215
+		    wp_die('Worldpay IPN Request Failure', 'Worldpay IPN', array('response' => 500));
216 216
 		}
217 217
 
218 218
         // Process the IPN.
219
-        $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
220
-        $invoice = wpinv_get_invoice( $posted['MC_invoice_id'] );
219
+        $posted  = wp_kses_post_deep(wp_unslash($_POST));
220
+        $invoice = wpinv_get_invoice($posted['MC_invoice_id']);
221 221
 
222
-        if ( $invoice && $this->id == $invoice->get_gateway() ) {
222
+        if ($invoice && $this->id == $invoice->get_gateway()) {
223 223
 
224
-            wpinv_error_log( 'Found invoice #' . $invoice->get_number() );
225
-            wpinv_error_log( 'Payment status:' . $posted['transStatus'] );
224
+            wpinv_error_log('Found invoice #' . $invoice->get_number());
225
+            wpinv_error_log('Payment status:' . $posted['transStatus']);
226 226
 
227 227
             // Update the transaction id.
228
-            if ( ! empty( $posted['transId'] ) ) {
229
-                $invoice->set_transaction_id( wpinv_clean( $posted['transId'] ) );
228
+            if (!empty($posted['transId'])) {
229
+                $invoice->set_transaction_id(wpinv_clean($posted['transId']));
230 230
             }
231 231
 
232 232
              // Update the ip address.
233
-             if ( ! empty( $posted['ipAddress'] ) ) {
234
-                $invoice->set_ip( wpinv_clean( $posted['ipAddress'] ) );
233
+             if (!empty($posted['ipAddress'])) {
234
+                $invoice->set_ip(wpinv_clean($posted['ipAddress']));
235 235
             }
236 236
 
237
-            if ( $posted['transStatus'] == 'Y' ) {
238
-                $invoice->set_completed_date( date( 'Y-m-d H:i:s', $posted['transTime'] ) );
237
+            if ($posted['transStatus'] == 'Y') {
238
+                $invoice->set_completed_date(date('Y-m-d H:i:s', $posted['transTime']));
239 239
                 $invoice->mark_paid();
240 240
                 return;
241 241
             }
242 242
 
243
-            if ( $posted['transStatus'] == 'C' ) {
244
-                $invoice->set_status( 'wpi-failed' );
245
-                $invoice->add_note( __( 'Payment transaction failed while processing Worldpay payment.', 'invoicing' ), false, false, true );
243
+            if ($posted['transStatus'] == 'C') {
244
+                $invoice->set_status('wpi-failed');
245
+                $invoice->add_note(__('Payment transaction failed while processing Worldpay payment.', 'invoicing'), false, false, true);
246 246
                 $invoice->save();
247 247
                 return;
248 248
             }
249 249
 
250
-            wpinv_error_log( 'Aborting, Invalid transaction status:' . $posted['transStatus'] );
250
+            wpinv_error_log('Aborting, Invalid transaction status:' . $posted['transStatus']);
251 251
             $invoice->save();
252 252
 
253 253
         }
@@ -261,27 +261,27 @@  discard block
 block discarded – undo
261 261
 	 */
262 262
 	public function validate_ipn() {
263 263
 
264
-        wpinv_error_log( 'Validating Worldpay IPN response' );
264
+        wpinv_error_log('Validating Worldpay IPN response');
265 265
 
266
-        $data = wp_kses_post_deep( wp_unslash( $_POST ) );
266
+        $data = wp_kses_post_deep(wp_unslash($_POST));
267 267
 
268 268
         // Verify installation.
269
-        if ( empty( $data['instId'] ) || $data['instId'] != wpinv_clean( $this->get_option( 'instId', '' ) ) ) {
270
-            wpinv_error_log( 'Received invalid installation ID from Worldpay IPN' );
269
+        if (empty($data['instId']) || $data['instId'] != wpinv_clean($this->get_option('instId', ''))) {
270
+            wpinv_error_log('Received invalid installation ID from Worldpay IPN');
271 271
             return false;
272 272
         }
273 273
 
274 274
         // Verify invoice.
275
-        if ( empty( $data['cartId'] ) || !  wpinv_get_id_by_invoice_number( $data['cartId'] ) ) {
276
-            wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' );
275
+        if (empty($data['cartId']) || !wpinv_get_id_by_invoice_number($data['cartId'])) {
276
+            wpinv_error_log('Received invalid invoice number from Worldpay IPN');
277 277
             return false;
278 278
         }
279 279
         
280 280
         // (maybe) verify password.
281
-        $password = $this->get_option( 'callback_password' );
281
+        $password = $this->get_option('callback_password');
282 282
 
283
-        if ( ! empty( $password ) && ( empty( $data['callbackPW'] ) || $password != $data['callbackPW'] ) ) {
284
-            wpinv_error_log( 'Received invalid invoice number from Worldpay IPN' );
283
+        if (!empty($password) && (empty($data['callbackPW']) || $password != $data['callbackPW'])) {
284
+            wpinv_error_log('Received invalid invoice number from Worldpay IPN');
285 285
             return false;
286 286
         }
287 287
 
@@ -292,10 +292,10 @@  discard block
 block discarded – undo
292 292
     /**
293 293
      * Displays a notice on the checkout page if sandbox is enabled.
294 294
      */
295
-    public function sandbox_notice( $description, $gateway ) {
296
-        if ( 'worldpay' == $gateway && wpinv_is_test_mode( 'worldpay' ) ) {
295
+    public function sandbox_notice($description, $gateway) {
296
+        if ('worldpay' == $gateway && wpinv_is_test_mode('worldpay')) {
297 297
             $description .= '<br>' . sprintf(
298
-                __( 'SANDBOX ENABLED. See the %sWorldpay Sandbox Testing Guide%s for more details.', 'invoicing' ),
298
+                __('SANDBOX ENABLED. See the %sWorldpay Sandbox Testing Guide%s for more details.', 'invoicing'),
299 299
                 '<a href="https://developer.worldpay.com/docs/wpg/directintegration/abouttesting">',
300 300
                 '</a>'
301 301
             );
@@ -309,43 +309,43 @@  discard block
 block discarded – undo
309 309
 	 * 
310 310
 	 * @param array $admin_settings
311 311
 	 */
312
-	public function admin_settings( $admin_settings ) {
312
+	public function admin_settings($admin_settings) {
313 313
 
314 314
         $currencies = sprintf(
315
-            __( 'Supported Currencies: %s', 'invoicing' ),
316
-            implode( ', ', $this->currencies )
315
+            __('Supported Currencies: %s', 'invoicing'),
316
+            implode(', ', $this->currencies)
317 317
         );
318 318
 
319 319
         $admin_settings['worldpay_active']['desc'] = $admin_settings['worldpay_active']['desc'] . " ($currencies)";
320
-        $admin_settings['worldpay_desc']['std']    = __( 'Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing' );
320
+        $admin_settings['worldpay_desc']['std']    = __('Pay securely via Worldpay using your PayPal account, credit or debit card.', 'invoicing');
321 321
 
322 322
         $admin_settings['worldpay_instId'] = array(
323 323
             'type' => 'text',
324 324
             'id'   => 'worldpay_instId',
325
-            'name' => __( 'Installation Id', 'invoicing' ),
326
-            'desc' => __( 'Your installation id. Ex: 211616', 'invoicing' ),
325
+            'name' => __('Installation Id', 'invoicing'),
326
+            'desc' => __('Your installation id. Ex: 211616', 'invoicing'),
327 327
         );
328 328
 
329 329
         $admin_settings['worldpay_md5_secret'] = array(
330 330
             'type' => 'text',
331 331
             'id'   => 'worldpay_md5_secret',
332
-            'name' => __( 'MD5 secret', 'invoicing' ),
333
-            'desc' => __( 'Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing' ) . '<code>instId:amount:currency:cartId</code>',
332
+            'name' => __('MD5 secret', 'invoicing'),
333
+            'desc' => __('Optionally enter your MD5 secret here. Next, open your installation settings and ensure that your SignatureFields parameter is set to ', 'invoicing') . '<code>instId:amount:currency:cartId</code>',
334 334
         );
335 335
 
336 336
         $admin_settings['worldpay_callbackPW'] = array(
337 337
             'type' => 'text',
338 338
             'id'   => 'worldpay_callbackPW',
339
-            'name' => __( 'Payment Response password', 'invoicing' ),
340
-            'desc' => __( 'Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing' ),
339
+            'name' => __('Payment Response password', 'invoicing'),
340
+            'desc' => __('Recommended. Enter your WorldPay response password to validate payment notifications.', 'invoicing'),
341 341
         );
342 342
 
343 343
         $admin_settings['worldpay_ipn_url'] = array(
344 344
             'type'     => 'ipn_url',
345 345
             'id'       => 'worldpay_ipn_url',
346
-            'name'     => __( 'Payment Response URL', 'invoicing' ),
346
+            'name'     => __('Payment Response URL', 'invoicing'),
347 347
             'std'      => $this->notify_url,
348
-            'desc'     => __( 'Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing' ),
348
+            'desc'     => __('Login to your Worldpay Merchant Interface then enable Payment Response & Shopper Response. Next, go to the Payment Response URL field and enter the above URL.', 'invoicing'),
349 349
             'custom'   => 'worldpay',
350 350
             'readonly' => true
351 351
         );
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-authorize-net-legacy-gateway.php 2 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -15,31 +15,31 @@  discard block
 block discarded – undo
15 15
 abstract class GetPaid_Authorize_Net_Legacy_Gateway extends GetPaid_Payment_Gateway {
16 16
 
17 17
     /**
18
-	 * Class constructor.
19
-	 */
20
-	public function __construct() {
18
+     * Class constructor.
19
+     */
20
+    public function __construct() {
21 21
         parent::__construct();
22 22
     }
23 23
 
24 24
     /**
25
-	 * Returns the API URL.
26
-	 *
27
-	 *
28
-	 * @param WPInv_Invoice $invoice Invoice.
29
-	 * @return string
30
-	 */
31
-	public function get_api_url( $invoice ) {
25
+     * Returns the API URL.
26
+     *
27
+     *
28
+     * @param WPInv_Invoice $invoice Invoice.
29
+     * @return string
30
+     */
31
+    public function get_api_url( $invoice ) {
32 32
         return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
33 33
     }
34 34
 
35 35
     /**
36
-	 * Communicates with authorize.net
37
-	 *
38
-	 *
39
-	 * @param array $post Data to post.
36
+     * Communicates with authorize.net
37
+     *
38
+     *
39
+     * @param array $post Data to post.
40 40
      * @param WPInv_Invoice $invoice Invoice.
41
-	 * @return stdClass|WP_Error
42
-	 */
41
+     * @return stdClass|WP_Error
42
+     */
43 43
     public function post( $post, $invoice ){
44 44
 
45 45
         $url      = $this->get_api_url( $invoice );
@@ -89,12 +89,12 @@  discard block
 block discarded – undo
89 89
     }
90 90
 
91 91
     /**
92
-	 * Returns the API authentication params.
93
-	 *
94
-	 *
95
-	 * @return array
96
-	 */
97
-	public function get_auth_params() {
92
+     * Returns the API authentication params.
93
+     *
94
+     *
95
+     * @return array
96
+     */
97
+    public function get_auth_params() {
98 98
 
99 99
         return array(
100 100
             'name'           => $this->get_option( 'login_id' ),
@@ -104,13 +104,13 @@  discard block
 block discarded – undo
104 104
     }
105 105
 
106 106
     /**
107
-	 * Cancels a subscription remotely
108
-	 *
109
-	 *
110
-	 * @param WPInv_Subscription $subscription Subscription.
107
+     * Cancels a subscription remotely
108
+     *
109
+     *
110
+     * @param WPInv_Subscription $subscription Subscription.
111 111
      * @param WPInv_Invoice $invoice Invoice.
112
-	 */
113
-	public function cancel_subscription( $subscription, $invoice ) {
112
+     */
113
+    public function cancel_subscription( $subscription, $invoice ) {
114 114
 
115 115
         // Backwards compatibility. New version do not use authorize.net subscriptions.
116 116
         $this->post(
@@ -126,17 +126,17 @@  discard block
 block discarded – undo
126 126
     }
127 127
 
128 128
     /**
129
-	 * Processes ipns.
130
-	 *
131
-	 * @return void
132
-	 */
133
-	public function verify_ipn() {
129
+     * Processes ipns.
130
+     *
131
+     * @return void
132
+     */
133
+    public function verify_ipn() {
134 134
 
135 135
         $this->maybe_process_old_ipn();
136 136
 
137 137
         // Validate the IPN.
138 138
         if ( empty( $_POST ) || ! $this->validate_ipn() ) {
139
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) );
139
+            wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) );
140 140
         }
141 141
 
142 142
         // Event type.
@@ -175,24 +175,24 @@  discard block
 block discarded – undo
175 175
     }
176 176
 
177 177
     /**
178
-	 * Validates IPN invoices.
179
-	 *
178
+     * Validates IPN invoices.
179
+     *
180 180
      * @param WPInv_Invoice $invoice
181 181
      * @param object $payload
182
-	 * @return void
183
-	 */
184
-	public function validate_ipn_invoice( $invoice, $payload ) {
182
+     * @return void
183
+     */
184
+    public function validate_ipn_invoice( $invoice, $payload ) {
185 185
         if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) {
186 186
             exit;
187 187
         }
188 188
     }
189 189
 
190 190
     /**
191
-	 * Process subscriptio IPNS.
192
-	 *
193
-	 * @return void
194
-	 */
195
-	public function maybe_process_old_ipn() {
191
+     * Process subscriptio IPNS.
192
+     *
193
+     * @return void
194
+     */
195
+    public function maybe_process_old_ipn() {
196 196
 
197 197
         $data = wp_kses_post_deep( wp_unslash( $_POST ) );
198 198
 
@@ -234,11 +234,11 @@  discard block
 block discarded – undo
234 234
     }
235 235
 
236 236
     /**
237
-	 * Validates the old IPN signature.
237
+     * Validates the old IPN signature.
238 238
      *
239 239
      * @param array $posted
240
-	 */
241
-	public function validate_old_ipn_signature( $posted ) {
240
+     */
241
+    public function validate_old_ipn_signature( $posted ) {
242 242
 
243 243
         $signature = $this->get_option( 'signature_key' );
244 244
         if ( ! empty( $signature ) ) {
@@ -257,9 +257,9 @@  discard block
 block discarded – undo
257 257
     }
258 258
 
259 259
     /**
260
-	 * Check Authorize.NET IPN validity.
261
-	 */
262
-	public function validate_ipn() {
260
+     * Check Authorize.NET IPN validity.
261
+     */
262
+    public function validate_ipn() {
263 263
 
264 264
         wpinv_error_log( 'Validating Authorize.NET IPN response' );
265 265
 
Please login to merge, or discard this patch.
Spacing   +68 added lines, -68 removed lines patch added patch discarded remove patch
@@ -4,7 +4,7 @@  discard block
 block discarded – undo
4 4
  *
5 5
  */
6 6
 
7
-defined( 'ABSPATH' ) || exit;
7
+defined('ABSPATH') || exit;
8 8
 
9 9
 /**
10 10
  * Authorize.net Legacy Payment Gateway class.
@@ -28,8 +28,8 @@  discard block
 block discarded – undo
28 28
 	 * @param WPInv_Invoice $invoice Invoice.
29 29
 	 * @return string
30 30
 	 */
31
-	public function get_api_url( $invoice ) {
32
-        return $this->is_sandbox( $invoice ) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
31
+	public function get_api_url($invoice) {
32
+        return $this->is_sandbox($invoice) ? 'https://apitest.authorize.net/xml/v1/request.api' : 'https://api.authorize.net/xml/v1/request.api';
33 33
     }
34 34
 
35 35
     /**
@@ -40,48 +40,48 @@  discard block
 block discarded – undo
40 40
      * @param WPInv_Invoice $invoice Invoice.
41 41
 	 * @return stdClass|WP_Error
42 42
 	 */
43
-    public function post( $post, $invoice ){
43
+    public function post($post, $invoice) {
44 44
 
45
-        $url      = $this->get_api_url( $invoice );
45
+        $url      = $this->get_api_url($invoice);
46 46
         $response = wp_remote_post(
47 47
             $url,
48 48
             array(
49 49
                 'headers'          => array(
50 50
                     'Content-Type' => 'application/json; charset=utf-8'
51 51
                 ),
52
-                'body'             => json_encode( $post ),
52
+                'body'             => json_encode($post),
53 53
                 'method'           => 'POST'
54 54
             )
55 55
         );
56 56
 
57
-        if ( is_wp_error( $response ) ) {
57
+        if (is_wp_error($response)) {
58 58
             return $response;
59 59
         }
60 60
 
61
-        $response = wp_unslash( wp_remote_retrieve_body( $response ) );
61
+        $response = wp_unslash(wp_remote_retrieve_body($response));
62 62
         $response = preg_replace('/\xEF\xBB\xBF/', '', $response); // https://community.developer.authorize.net/t5/Integration-and-Testing/JSON-issues/td-p/48851
63
-        $response = json_decode( $response );
63
+        $response = json_decode($response);
64 64
 
65
-        if ( empty( $response ) ) {
66
-            return new WP_Error( 'invalid_reponse', __( 'Invalid gateway response', 'invoicing' ) );
65
+        if (empty($response)) {
66
+            return new WP_Error('invalid_reponse', __('Invalid gateway response', 'invoicing'));
67 67
         }
68 68
 
69
-        if ( $response->messages->resultCode == 'Error' ) {
69
+        if ($response->messages->resultCode == 'Error') {
70 70
 
71
-            if ( $this->is_sandbox( $invoice ) ) {
72
-                wpinv_error_log( $response );
71
+            if ($this->is_sandbox($invoice)) {
72
+                wpinv_error_log($response);
73 73
             }
74 74
 
75
-            if ( $response->messages->message[0]->code == 'E00039' && ! empty( $response->customerProfileId )  && ! empty( $response->customerPaymentProfileId ) ) {
76
-                return new WP_Error( 'dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId );
75
+            if ($response->messages->message[0]->code == 'E00039' && !empty($response->customerProfileId) && !empty($response->customerPaymentProfileId)) {
76
+                return new WP_Error('dup_payment_profile', $response->customerProfileId . '.' . $response->customerPaymentProfileId);
77 77
             }
78 78
 
79
-            if ( ! empty( $response->transactionResponse ) && ! empty( $response->transactionResponse->errors ) ) {
79
+            if (!empty($response->transactionResponse) && !empty($response->transactionResponse->errors)) {
80 80
                 $error = $response->transactionResponse->errors[0];
81
-                return new WP_Error( $error->errorCode, $error->errorText );
81
+                return new WP_Error($error->errorCode, $error->errorText);
82 82
             }
83 83
 
84
-            return new WP_Error( $response->messages->message[0]->code, $response->messages->message[0]->text );
84
+            return new WP_Error($response->messages->message[0]->code, $response->messages->message[0]->text);
85 85
         }
86 86
 
87 87
         return $response;
@@ -97,8 +97,8 @@  discard block
 block discarded – undo
97 97
 	public function get_auth_params() {
98 98
 
99 99
         return array(
100
-            'name'           => $this->get_option( 'login_id' ),
101
-            'transactionKey' => $this->get_option( 'transaction_key' ),
100
+            'name'           => $this->get_option('login_id'),
101
+            'transactionKey' => $this->get_option('transaction_key'),
102 102
         );
103 103
 
104 104
     }
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @param WPInv_Subscription $subscription Subscription.
111 111
      * @param WPInv_Invoice $invoice Invoice.
112 112
 	 */
113
-	public function cancel_subscription( $subscription, $invoice ) {
113
+	public function cancel_subscription($subscription, $invoice) {
114 114
 
115 115
         // Backwards compatibility. New version do not use authorize.net subscriptions.
116 116
         $this->post(
@@ -135,38 +135,38 @@  discard block
 block discarded – undo
135 135
         $this->maybe_process_old_ipn();
136 136
 
137 137
         // Validate the IPN.
138
-        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
139
-		    wp_die( 'Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array( 'response' => 500 ) );
138
+        if (empty($_POST) || !$this->validate_ipn()) {
139
+		    wp_die('Authorize.NET IPN Request Failure', 'Authorize.NET IPN', array('response' => 500));
140 140
         }
141 141
 
142 142
         // Event type.
143
-        $posted = json_decode( file_get_contents( 'php://input' ) );
144
-        if ( empty( $posted ) ) {
145
-            wp_die( 'Invalid JSON', 'Authorize.NET IPN', array( 'response' => 500 ) );
143
+        $posted = json_decode(file_get_contents('php://input'));
144
+        if (empty($posted)) {
145
+            wp_die('Invalid JSON', 'Authorize.NET IPN', array('response' => 500));
146 146
         }
147 147
 
148 148
         // Process the IPN.
149
-        $posted = (object) wp_unslash( $posted );
149
+        $posted = (object) wp_unslash($posted);
150 150
 
151 151
         // Process refunds.
152
-        if ( 'net.authorize.payment.refund.created' == $posted->eventType ) {
153
-            $invoice = new WPInv_Invoice( $posted->payload->merchantReferenceId );
154
-            $this->validate_ipn_invoice( $invoice, $posted->payload );
152
+        if ('net.authorize.payment.refund.created' == $posted->eventType) {
153
+            $invoice = new WPInv_Invoice($posted->payload->merchantReferenceId);
154
+            $this->validate_ipn_invoice($invoice, $posted->payload);
155 155
             $invoice->refund();
156 156
         }
157 157
 
158 158
         // Held funds approved.
159
-        if ( 'net.authorize.payment.fraud.approved' == $posted->eventType ) {
160
-            $invoice = new WPInv_Invoice( $posted->payload->id );
161
-            $this->validate_ipn_invoice( $invoice, $posted->payload );
162
-            $invoice->mark_paid( false, __( 'Payment released', 'invoicing' ) );
159
+        if ('net.authorize.payment.fraud.approved' == $posted->eventType) {
160
+            $invoice = new WPInv_Invoice($posted->payload->id);
161
+            $this->validate_ipn_invoice($invoice, $posted->payload);
162
+            $invoice->mark_paid(false, __('Payment released', 'invoicing'));
163 163
         }
164 164
 
165 165
         // Held funds declined.
166
-        if ( 'net.authorize.payment.fraud.declined' == $posted->eventType ) {
167
-            $invoice = new WPInv_Invoice( $posted->payload->id );
168
-            $this->validate_ipn_invoice( $invoice, $posted->payload );
169
-            $invoice->set_status( 'wpi-failed', __( 'Payment declined', 'invoicing' ) );
166
+        if ('net.authorize.payment.fraud.declined' == $posted->eventType) {
167
+            $invoice = new WPInv_Invoice($posted->payload->id);
168
+            $this->validate_ipn_invoice($invoice, $posted->payload);
169
+            $invoice->set_status('wpi-failed', __('Payment declined', 'invoicing'));
170 170
             $invoice->save();
171 171
         }
172 172
 
@@ -181,8 +181,8 @@  discard block
 block discarded – undo
181 181
      * @param object $payload
182 182
 	 * @return void
183 183
 	 */
184
-	public function validate_ipn_invoice( $invoice, $payload ) {
185
-        if ( ! $invoice->exists() || $payload->id != $invoice->get_transaction_id() ) {
184
+	public function validate_ipn_invoice($invoice, $payload) {
185
+        if (!$invoice->exists() || $payload->id != $invoice->get_transaction_id()) {
186 186
             exit;
187 187
         }
188 188
     }
@@ -194,32 +194,32 @@  discard block
 block discarded – undo
194 194
 	 */
195 195
 	public function maybe_process_old_ipn() {
196 196
 
197
-        $data = wp_kses_post_deep( wp_unslash( $_POST ) );
197
+        $data = wp_kses_post_deep(wp_unslash($_POST));
198 198
 
199 199
         // Only process subscriptions subscriptions.
200
-        if ( empty( $data['x_subscription_id'] ) ) {
200
+        if (empty($data['x_subscription_id'])) {
201 201
             return;
202 202
         }
203 203
 
204 204
         // Check validity.
205
-        $this->validate_old_ipn_signature( $data );
205
+        $this->validate_old_ipn_signature($data);
206 206
 
207 207
         // Fetch the associated subscription.
208
-        $subscription_id = WPInv_Subscription::get_subscription_id_by_field( $data['x_subscription_id'] );
209
-        $subscription    = new WPInv_Subscription( $subscription_id );
208
+        $subscription_id = WPInv_Subscription::get_subscription_id_by_field($data['x_subscription_id']);
209
+        $subscription    = new WPInv_Subscription($subscription_id);
210 210
 
211 211
         // Abort if it is missing or completed.
212
-        if ( ! $subscription->get_id() || $subscription->has_status( 'completed' ) ) {
212
+        if (!$subscription->get_id() || $subscription->has_status('completed')) {
213 213
             return;
214 214
         }
215 215
 
216 216
         // Payment status.
217
-        if ( 1 == $data['x_response_code'] ) {
217
+        if (1 == $data['x_response_code']) {
218 218
 
219 219
             // Renew the subscription.
220 220
             $subscription->add_payment(
221 221
                 array(
222
-                    'transaction_id' => sanitize_text_field( $data['x_trans_id'] ),
222
+                    'transaction_id' => sanitize_text_field($data['x_trans_id']),
223 223
                     'gateway'        => $this->id
224 224
                 )
225 225
             );
@@ -238,17 +238,17 @@  discard block
 block discarded – undo
238 238
      *
239 239
      * @param array $posted
240 240
 	 */
241
-	public function validate_old_ipn_signature( $posted ) {
241
+	public function validate_old_ipn_signature($posted) {
242 242
 
243
-        $signature = $this->get_option( 'signature_key' );
244
-        if ( ! empty( $signature ) ) {
245
-            $login_id  = $this->get_option( 'login_id' );
246
-            $trans_id  = wpinv_clean( $_POST['x_trans_id'] );
247
-            $amount    = wpinv_clean( $_POST['x_amount'] );
248
-            $hash      = hash_hmac ( 'sha512', "^$login_id^$trans_id^$amount^", hex2bin( $signature ) );
243
+        $signature = $this->get_option('signature_key');
244
+        if (!empty($signature)) {
245
+            $login_id  = $this->get_option('login_id');
246
+            $trans_id  = wpinv_clean($_POST['x_trans_id']);
247
+            $amount    = wpinv_clean($_POST['x_amount']);
248
+            $hash      = hash_hmac('sha512', "^$login_id^$trans_id^$amount^", hex2bin($signature));
249 249
 
250
-            if ( ! hash_equals( $hash, $posted['x_SHA2_Hash'] ) ) {
251
-                wpinv_error_log( $posted['x_SHA2_Hash'], "Invalid signature. Expected $hash" );
250
+            if (!hash_equals($hash, $posted['x_SHA2_Hash'])) {
251
+                wpinv_error_log($posted['x_SHA2_Hash'], "Invalid signature. Expected $hash");
252 252
                 exit;
253 253
             }
254 254
 
@@ -261,28 +261,28 @@  discard block
 block discarded – undo
261 261
 	 */
262 262
 	public function validate_ipn() {
263 263
 
264
-        wpinv_error_log( 'Validating Authorize.NET IPN response' );
264
+        wpinv_error_log('Validating Authorize.NET IPN response');
265 265
 
266
-        if ( empty( $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
266
+        if (empty($_SERVER['HTTP_X_ANET_SIGNATURE'])) {
267 267
             return false;
268 268
         }
269 269
 
270
-        $signature = $this->get_option( 'signature_key' );
270
+        $signature = $this->get_option('signature_key');
271 271
 
272
-        if ( empty( $signature ) ) {
273
-            wpinv_error_log( 'Error: You have not set a signature key' );
272
+        if (empty($signature)) {
273
+            wpinv_error_log('Error: You have not set a signature key');
274 274
             return false;
275 275
         }
276 276
 
277
-        $hash  = hash_hmac ( 'sha512', file_get_contents( 'php://input' ), hex2bin( $signature ) );
277
+        $hash = hash_hmac('sha512', file_get_contents('php://input'), hex2bin($signature));
278 278
 
279
-        if ( hash_equals( $hash, $_SERVER['HTTP_X_ANET_SIGNATURE'] ) ) {
280
-            wpinv_error_log( 'Successfully validated the IPN' );
279
+        if (hash_equals($hash, $_SERVER['HTTP_X_ANET_SIGNATURE'])) {
280
+            wpinv_error_log('Successfully validated the IPN');
281 281
             return true;
282 282
         }
283 283
 
284
-        wpinv_error_log( 'IPN hash is not valid' );
285
-        wpinv_error_log(  $_SERVER['HTTP_X_ANET_SIGNATURE']  );
284
+        wpinv_error_log('IPN hash is not valid');
285
+        wpinv_error_log($_SERVER['HTTP_X_ANET_SIGNATURE']);
286 286
         return false;
287 287
 
288 288
     }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway-ipn-handler.php 2 patches
Indentation   +390 added lines, -390 removed lines patch added patch discarded remove patch
@@ -12,474 +12,474 @@
 block discarded – undo
12 12
  */
13 13
 class GetPaid_Paypal_Gateway_IPN_Handler {
14 14
 
15
-	/**
16
-	 * Payment method id.
17
-	 *
18
-	 * @var string
19
-	 */
20
-	protected $id = 'paypal';
21
-
22
-	/**
23
-	 * Payment method object.
24
-	 *
25
-	 * @var GetPaid_Paypal_Gateway
26
-	 */
27
-	protected $gateway;
28
-
29
-	/**
30
-	 * Class constructor.
31
-	 *
32
-	 * @param GetPaid_Paypal_Gateway $gateway
33
-	 */
34
-	public function __construct( $gateway ) {
35
-		$this->gateway = $gateway;
36
-		$this->verify_ipn();
37
-	}
38
-
39
-	/**
40
-	 * Processes ipns and marks payments as complete.
41
-	 *
42
-	 * @return void
43
-	 */
44
-	public function verify_ipn() {
45
-
46
-		wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
-
48
-		// Validate the IPN.
49
-		if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
-			wp_die( 'PayPal IPN Request Failure', 500 );
51
-		}
52
-
53
-		// Process the IPN.
54
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
55
-		$invoice = $this->get_ipn_invoice( $posted );
56
-
57
-		// Abort if it was not paid by our gateway.
58
-		if ( $this->id != $invoice->get_gateway() ) {
59
-			wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
-			wp_die( 'Invoice not paid via PayPal', 200 );
61
-		}
62
-
63
-		$posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
-		$posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
65
-
66
-		wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
-		wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
68
-
69
-		if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
-			call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
-			wpinv_error_log( 'Done processing IPN', false );
72
-			wp_die( 'Processed', 200 );
73
-		}
74
-
75
-		wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
-		wp_die( 'Unsupported IPN type', 200 );
77
-
78
-	}
79
-
80
-	/**
81
-	 * Retrieves IPN Invoice.
82
-	 *
83
-	 * @param array $posted
84
-	 * @return WPInv_Invoice
85
-	 */
86
-	protected function get_ipn_invoice( $posted ) {
87
-
88
-		wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
-
90
-		if ( ! empty( $posted['custom'] ) ) {
91
-			$invoice = new WPInv_Invoice( $posted['custom'] );
92
-
93
-			if ( $invoice->exists() ) {
94
-				wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
-				return $invoice;
96
-			}
97
-
98
-		}
99
-
100
-		wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
-		wp_die( 'Could not retrieve the associated invoice.', 200 );
102
-	}
103
-
104
-	/**
105
-	 * Check PayPal IPN validity.
106
-	 */
107
-	protected function validate_ipn() {
108
-
109
-		wpinv_error_log( 'Validating PayPal IPN response', false );
110
-
111
-		// Retrieve the associated invoice.
112
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
113
-		$invoice = $this->get_ipn_invoice( $posted );
114
-
115
-		if ( $this->gateway->is_sandbox( $invoice ) ) {
116
-			wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
117
-		}
118
-
119
-		// Validate the IPN.
120
-		$posted['cmd'] = '_notify-validate';
121
-
122
-		// Send back post vars to paypal.
123
-		$params = array(
124
-			'body'        => $posted,
125
-			'timeout'     => 60,
126
-			'httpversion' => '1.1',
127
-			'compress'    => false,
128
-			'decompress'  => false,
129
-			'user-agent'  => 'GetPaid/' . WPINV_VERSION,
130
-		);
131
-
132
-		// Post back to get a response.
133
-		$response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
134
-
135
-		// Check to see if the request was valid.
136
-		if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
137
-			wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
138
-			return true;
139
-		}
140
-
141
-		if ( is_wp_error( $response ) ) {
142
-			wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
143
-			return false;
144
-		}
15
+    /**
16
+     * Payment method id.
17
+     *
18
+     * @var string
19
+     */
20
+    protected $id = 'paypal';
21
+
22
+    /**
23
+     * Payment method object.
24
+     *
25
+     * @var GetPaid_Paypal_Gateway
26
+     */
27
+    protected $gateway;
28
+
29
+    /**
30
+     * Class constructor.
31
+     *
32
+     * @param GetPaid_Paypal_Gateway $gateway
33
+     */
34
+    public function __construct( $gateway ) {
35
+        $this->gateway = $gateway;
36
+        $this->verify_ipn();
37
+    }
38
+
39
+    /**
40
+     * Processes ipns and marks payments as complete.
41
+     *
42
+     * @return void
43
+     */
44
+    public function verify_ipn() {
45
+
46
+        wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
47
+
48
+        // Validate the IPN.
49
+        if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
+            wp_die( 'PayPal IPN Request Failure', 500 );
51
+        }
52
+
53
+        // Process the IPN.
54
+        $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
55
+        $invoice = $this->get_ipn_invoice( $posted );
56
+
57
+        // Abort if it was not paid by our gateway.
58
+        if ( $this->id != $invoice->get_gateway() ) {
59
+            wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
+            wp_die( 'Invoice not paid via PayPal', 200 );
61
+        }
62
+
63
+        $posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
+        $posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
65
+
66
+        wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
+        wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
68
+
69
+        if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
+            call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
+            wpinv_error_log( 'Done processing IPN', false );
72
+            wp_die( 'Processed', 200 );
73
+        }
74
+
75
+        wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
+        wp_die( 'Unsupported IPN type', 200 );
77
+
78
+    }
79
+
80
+    /**
81
+     * Retrieves IPN Invoice.
82
+     *
83
+     * @param array $posted
84
+     * @return WPInv_Invoice
85
+     */
86
+    protected function get_ipn_invoice( $posted ) {
87
+
88
+        wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
89
+
90
+        if ( ! empty( $posted['custom'] ) ) {
91
+            $invoice = new WPInv_Invoice( $posted['custom'] );
92
+
93
+            if ( $invoice->exists() ) {
94
+                wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
95
+                return $invoice;
96
+            }
97
+
98
+        }
99
+
100
+        wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
+        wp_die( 'Could not retrieve the associated invoice.', 200 );
102
+    }
103
+
104
+    /**
105
+     * Check PayPal IPN validity.
106
+     */
107
+    protected function validate_ipn() {
108
+
109
+        wpinv_error_log( 'Validating PayPal IPN response', false );
110
+
111
+        // Retrieve the associated invoice.
112
+        $posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
113
+        $invoice = $this->get_ipn_invoice( $posted );
114
+
115
+        if ( $this->gateway->is_sandbox( $invoice ) ) {
116
+            wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
117
+        }
118
+
119
+        // Validate the IPN.
120
+        $posted['cmd'] = '_notify-validate';
121
+
122
+        // Send back post vars to paypal.
123
+        $params = array(
124
+            'body'        => $posted,
125
+            'timeout'     => 60,
126
+            'httpversion' => '1.1',
127
+            'compress'    => false,
128
+            'decompress'  => false,
129
+            'user-agent'  => 'GetPaid/' . WPINV_VERSION,
130
+        );
131
+
132
+        // Post back to get a response.
133
+        $response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
134
+
135
+        // Check to see if the request was valid.
136
+        if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
137
+            wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
138
+            return true;
139
+        }
140
+
141
+        if ( is_wp_error( $response ) ) {
142
+            wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
143
+            return false;
144
+        }
145 145
 
146
-		wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
147
-		return false;
148
-
149
-	}
146
+        wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
147
+        return false;
148
+
149
+    }
150 150
 
151
-	/**
152
-	 * Check currency from IPN matches the invoice.
153
-	 *
154
-	 * @param WPInv_Invoice $invoice          Invoice object.
155
-	 * @param string   $currency currency to validate.
156
-	 */
157
-	protected function validate_ipn_currency( $invoice, $currency ) {
151
+    /**
152
+     * Check currency from IPN matches the invoice.
153
+     *
154
+     * @param WPInv_Invoice $invoice          Invoice object.
155
+     * @param string   $currency currency to validate.
156
+     */
157
+    protected function validate_ipn_currency( $invoice, $currency ) {
158 158
 
159
-		if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
159
+        if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
160 160
 
161
-			/* translators: %s: currency code. */
162
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
161
+            /* translators: %s: currency code. */
162
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
163 163
 
164
-			wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
165
-		}
164
+            wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
165
+        }
166 166
 
167
-		wpinv_error_log( $currency, 'Validated IPN Currency', false );
168
-	}
167
+        wpinv_error_log( $currency, 'Validated IPN Currency', false );
168
+    }
169 169
 
170
-	/**
171
-	 * Check payment amount from IPN matches the invoice.
172
-	 *
173
-	 * @param WPInv_Invoice $invoice          Invoice object.
174
-	 * @param float   $amount amount to validate.
175
-	 */
176
-	protected function validate_ipn_amount( $invoice, $amount ) {
177
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
170
+    /**
171
+     * Check payment amount from IPN matches the invoice.
172
+     *
173
+     * @param WPInv_Invoice $invoice          Invoice object.
174
+     * @param float   $amount amount to validate.
175
+     */
176
+    protected function validate_ipn_amount( $invoice, $amount ) {
177
+        if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
178 178
 
179
-			/* translators: %s: Amount. */
180
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
179
+            /* translators: %s: Amount. */
180
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
181 181
 
182
-			wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
183
-		}
182
+            wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
183
+        }
184 184
 
185
-		wpinv_error_log( $amount, 'Validated IPN Amount', false );
186
-	}
185
+        wpinv_error_log( $amount, 'Validated IPN Amount', false );
186
+    }
187 187
 
188
-	/**
189
-	 * Verify receiver email from PayPal.
190
-	 *
191
-	 * @param WPInv_Invoice $invoice          Invoice object.
192
-	 * @param string   $receiver_email Email to validate.
193
-	 */
194
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
195
-		$paypal_email = wpinv_get_option( 'paypal_email' );
188
+    /**
189
+     * Verify receiver email from PayPal.
190
+     *
191
+     * @param WPInv_Invoice $invoice          Invoice object.
192
+     * @param string   $receiver_email Email to validate.
193
+     */
194
+    protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
195
+        $paypal_email = wpinv_get_option( 'paypal_email' );
196 196
 
197
-		if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
198
-			wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
197
+        if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
198
+            wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
199 199
 
200
-			/* translators: %s: email address . */
201
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
200
+            /* translators: %s: email address . */
201
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
202 202
 
203
-			return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
204
-		}
203
+            return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
204
+        }
205 205
 
206
-		wpinv_error_log( 'Validated PayPal Email', false );
207
-	}
206
+        wpinv_error_log( 'Validated PayPal Email', false );
207
+    }
208 208
 
209
-	/**
210
-	 * Handles one time payments.
211
-	 *
212
-	 * @param WPInv_Invoice $invoice  Invoice object.
213
-	 * @param array    $posted Posted data.
214
-	 */
215
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
209
+    /**
210
+     * Handles one time payments.
211
+     *
212
+     * @param WPInv_Invoice $invoice  Invoice object.
213
+     * @param array    $posted Posted data.
214
+     */
215
+    protected function ipn_txn_web_accept( $invoice, $posted ) {
216 216
 
217
-		// Collect payment details
218
-		$payment_status = strtolower( $posted['payment_status'] );
219
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
217
+        // Collect payment details
218
+        $payment_status = strtolower( $posted['payment_status'] );
219
+        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
220 220
 
221
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
222
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
221
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
222
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
223 223
 
224
-		// Update the transaction id.
225
-		if ( ! empty( $posted['txn_id'] ) ) {
226
-			$invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
227
-			$invoice->save();
228
-		}
224
+        // Update the transaction id.
225
+        if ( ! empty( $posted['txn_id'] ) ) {
226
+            $invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
227
+            $invoice->save();
228
+        }
229 229
 
230
-		$invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) );
230
+        $invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) );
231 231
 
232
-		// Process a refund.
233
-		if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
232
+        // Process a refund.
233
+        if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
234 234
 
235
-			update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
235
+            update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
236 236
 
237
-			if ( ! $invoice->is_refunded() ) {
238
-				$invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
239
-			}
237
+            if ( ! $invoice->is_refunded() ) {
238
+                $invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
239
+            }
240 240
 
241
-			return wpinv_error_log( $posted['reason_code'], false );
242
-		}
241
+            return wpinv_error_log( $posted['reason_code'], false );
242
+        }
243 243
 
244
-		// Process payments.
245
-		if ( $payment_status == 'completed' ) {
244
+        // Process payments.
245
+        if ( $payment_status == 'completed' ) {
246 246
 
247
-			if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
248
-				return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
249
-			}
247
+            if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
248
+                return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
249
+            }
250 250
 
251
-			$this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
251
+            $this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
252 252
 
253
-			$note = '';
253
+            $note = '';
254 254
 
255
-			if ( ! empty( $posted['mc_fee'] ) ) {
256
-				$note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
257
-			}
255
+            if ( ! empty( $posted['mc_fee'] ) ) {
256
+                $note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
257
+            }
258 258
 
259
-			if ( ! empty( $posted['payer_status'] ) ) {
260
-				$note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
261
-			}
259
+            if ( ! empty( $posted['payer_status'] ) ) {
260
+                $note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
261
+            }
262 262
 
263
-			$invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
264
-			return wpinv_error_log( 'Invoice marked as paid.', false );
263
+            $invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
264
+            return wpinv_error_log( 'Invoice marked as paid.', false );
265 265
 
266
-		}
266
+        }
267 267
 
268
-		// Pending payments.
269
-		if ( $payment_status == 'pending' ) {
268
+        // Pending payments.
269
+        if ( $payment_status == 'pending' ) {
270 270
 
271
-			/* translators: %s: pending reason. */
272
-			$invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
271
+            /* translators: %s: pending reason. */
272
+            $invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
273 273
 
274
-			return wpinv_error_log( 'Invoice marked as "payment held".', false );
275
-		}
274
+            return wpinv_error_log( 'Invoice marked as "payment held".', false );
275
+        }
276 276
 
277
-		/* translators: %s: payment status. */
278
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
277
+        /* translators: %s: payment status. */
278
+        $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
279 279
 
280
-	}
280
+    }
281 281
 
282
-	/**
283
-	 * Handles one time payments.
284
-	 *
285
-	 * @param WPInv_Invoice $invoice  Invoice object.
286
-	 * @param array    $posted Posted data.
287
-	 */
288
-	protected function ipn_txn_cart( $invoice, $posted ) {
289
-		$this->ipn_txn_web_accept( $invoice, $posted );
290
-	}
282
+    /**
283
+     * Handles one time payments.
284
+     *
285
+     * @param WPInv_Invoice $invoice  Invoice object.
286
+     * @param array    $posted Posted data.
287
+     */
288
+    protected function ipn_txn_cart( $invoice, $posted ) {
289
+        $this->ipn_txn_web_accept( $invoice, $posted );
290
+    }
291 291
 
292
-	/**
293
-	 * Handles subscription sign ups.
294
-	 *
295
-	 * @param WPInv_Invoice $invoice  Invoice object.
296
-	 * @param array    $posted Posted data.
297
-	 */
298
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
292
+    /**
293
+     * Handles subscription sign ups.
294
+     *
295
+     * @param WPInv_Invoice $invoice  Invoice object.
296
+     * @param array    $posted Posted data.
297
+     */
298
+    protected function ipn_txn_subscr_signup( $invoice, $posted ) {
299 299
 
300
-		wpinv_error_log( 'Processing subscription signup', false );
300
+        wpinv_error_log( 'Processing subscription signup', false );
301 301
 
302
-		// Make sure the invoice has a subscription.
303
-		$subscription = getpaid_get_invoice_subscription( $invoice );
302
+        // Make sure the invoice has a subscription.
303
+        $subscription = getpaid_get_invoice_subscription( $invoice );
304 304
 
305
-		if ( empty( $subscription ) ) {
306
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
307
-		}
305
+        if ( empty( $subscription ) ) {
306
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
307
+        }
308 308
 
309
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
309
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
310 310
 
311
-		// Validate the IPN.
312
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
313
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
314
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
311
+        // Validate the IPN.
312
+        $business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
313
+        $this->validate_ipn_receiver_email( $invoice, $business_email );
314
+        $this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
315 315
 
316
-		// Activate the subscription.
317
-		$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
318
-		$subscription->set_date_created( current_time( 'mysql' ) );
319
-		$subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
320
-		$subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
321
-		$subscription->activate();
316
+        // Activate the subscription.
317
+        $duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
318
+        $subscription->set_date_created( current_time( 'mysql' ) );
319
+        $subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
320
+        $subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
321
+        $subscription->activate();
322 322
 
323
-		// Set the transaction id.
324
-		if ( ! empty( $posted['txn_id'] ) ) {
325
-			$invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
326
-			$invoice->set_transaction_id( $posted['txn_id'] );
327
-		}
323
+        // Set the transaction id.
324
+        if ( ! empty( $posted['txn_id'] ) ) {
325
+            $invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
326
+            $invoice->set_transaction_id( $posted['txn_id'] );
327
+        }
328 328
 
329
-		// Update the payment status.
330
-		$invoice->mark_paid();
329
+        // Update the payment status.
330
+        $invoice->mark_paid();
331 331
 
332
-		$invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
332
+        $invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
333 333
 
334
-		wpinv_error_log( 'Subscription started.', false );
335
-	}
334
+        wpinv_error_log( 'Subscription started.', false );
335
+    }
336 336
 
337
-	/**
338
-	 * Handles subscription renewals.
339
-	 *
340
-	 * @param WPInv_Invoice $invoice  Invoice object.
341
-	 * @param array    $posted Posted data.
342
-	 */
343
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
337
+    /**
338
+     * Handles subscription renewals.
339
+     *
340
+     * @param WPInv_Invoice $invoice  Invoice object.
341
+     * @param array    $posted Posted data.
342
+     */
343
+    protected function ipn_txn_subscr_payment( $invoice, $posted ) {
344 344
 
345
-		// Make sure the invoice has a subscription.
346
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
345
+        // Make sure the invoice has a subscription.
346
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
347 347
 
348
-		if ( empty( $subscription ) ) {
349
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
350
-		}
348
+        if ( empty( $subscription ) ) {
349
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
350
+        }
351 351
 
352
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
352
+        wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
353 353
 
354
-		// PayPal sends a subscr_payment for the first payment too.
355
-		$date_completed = getpaid_format_date( $invoice->get_date_completed() );
356
-		$date_created   = getpaid_format_date( $invoice->get_date_created() );
357
-		$today_date     = getpaid_format_date( current_time( 'mysql' ) );
358
-		$payment_date   = getpaid_format_date( $posted['payment_date'] );
359
-		$subscribe_date = getpaid_format_date( $subscription->get_date_created() );
360
-		$dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
354
+        // PayPal sends a subscr_payment for the first payment too.
355
+        $date_completed = getpaid_format_date( $invoice->get_date_completed() );
356
+        $date_created   = getpaid_format_date( $invoice->get_date_created() );
357
+        $today_date     = getpaid_format_date( current_time( 'mysql' ) );
358
+        $payment_date   = getpaid_format_date( $posted['payment_date'] );
359
+        $subscribe_date = getpaid_format_date( $subscription->get_date_created() );
360
+        $dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
361 361
 
362
-		foreach( $dates as $date ) {
362
+        foreach( $dates as $date ) {
363 363
 
364
-			if ( $date !== $today_date && $date !== $payment_date ) {
365
-				continue;
366
-			}
364
+            if ( $date !== $today_date && $date !== $payment_date ) {
365
+                continue;
366
+            }
367 367
 
368
-			if ( ! empty( $posted['txn_id'] ) ) {
369
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
370
-				$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
371
-			}
368
+            if ( ! empty( $posted['txn_id'] ) ) {
369
+                $invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
370
+                $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
371
+            }
372 372
 
373
-			return $invoice->mark_paid();
374
-
375
-		}
373
+            return $invoice->mark_paid();
374
+
375
+        }
376 376
 
377
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
378
-
379
-		// Abort if the payment is already recorded.
380
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
381
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
382
-		}
383
-
384
-		$args = array(
385
-			'transaction_id' => $posted['txn_id'],
386
-			'gateway'        => $this->id,
387
-		);
388
-
389
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
377
+        wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
378
+
379
+        // Abort if the payment is already recorded.
380
+        if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
381
+            return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
382
+        }
383
+
384
+        $args = array(
385
+            'transaction_id' => $posted['txn_id'],
386
+            'gateway'        => $this->id,
387
+        );
388
+
389
+        $invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
390 390
 
391
-		if ( empty( $invoice ) ) {
392
-			return;
393
-		}
391
+        if ( empty( $invoice ) ) {
392
+            return;
393
+        }
394 394
 
395
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
396
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
395
+        $invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
396
+        $invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
397 397
 
398
-		$subscription->renew();
399
-		wpinv_error_log( 'Subscription renewed.', false );
398
+        $subscription->renew();
399
+        wpinv_error_log( 'Subscription renewed.', false );
400 400
 
401
-	}
401
+    }
402 402
 
403
-	/**
404
-	 * Handles subscription cancelations.
405
-	 *
406
-	 * @param WPInv_Invoice $invoice  Invoice object.
407
-	 */
408
-	protected function ipn_txn_subscr_cancel( $invoice ) {
403
+    /**
404
+     * Handles subscription cancelations.
405
+     *
406
+     * @param WPInv_Invoice $invoice  Invoice object.
407
+     */
408
+    protected function ipn_txn_subscr_cancel( $invoice ) {
409 409
 
410
-		// Make sure the invoice has a subscription.
411
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
412
-
413
-		if ( empty( $subscription ) ) {
414
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
415
-		}
416
-
417
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
418
-		$subscription->cancel();
419
-		wpinv_error_log( 'Subscription cancelled.', false );
410
+        // Make sure the invoice has a subscription.
411
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
412
+
413
+        if ( empty( $subscription ) ) {
414
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
415
+        }
416
+
417
+        wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
418
+        $subscription->cancel();
419
+        wpinv_error_log( 'Subscription cancelled.', false );
420 420
 
421
-	}
421
+    }
422 422
 
423
-	/**
424
-	 * Handles subscription completions.
425
-	 *
426
-	 * @param WPInv_Invoice $invoice  Invoice object.
427
-	 * @param array    $posted Posted data.
428
-	 */
429
-	protected function ipn_txn_subscr_eot( $invoice ) {
423
+    /**
424
+     * Handles subscription completions.
425
+     *
426
+     * @param WPInv_Invoice $invoice  Invoice object.
427
+     * @param array    $posted Posted data.
428
+     */
429
+    protected function ipn_txn_subscr_eot( $invoice ) {
430 430
 
431
-		// Make sure the invoice has a subscription.
432
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
431
+        // Make sure the invoice has a subscription.
432
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
433 433
 
434
-		if ( empty( $subscription ) ) {
435
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
436
-		}
434
+        if ( empty( $subscription ) ) {
435
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
436
+        }
437 437
 
438
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
439
-		$subscription->complete();
440
-		wpinv_error_log( 'Subscription completed.', false );
438
+        wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
439
+        $subscription->complete();
440
+        wpinv_error_log( 'Subscription completed.', false );
441 441
 
442
-	}
442
+    }
443 443
 
444
-	/**
445
-	 * Handles subscription fails.
446
-	 *
447
-	 * @param WPInv_Invoice $invoice  Invoice object.
448
-	 * @param array    $posted Posted data.
449
-	 */
450
-	protected function ipn_txn_subscr_failed( $invoice ) {
444
+    /**
445
+     * Handles subscription fails.
446
+     *
447
+     * @param WPInv_Invoice $invoice  Invoice object.
448
+     * @param array    $posted Posted data.
449
+     */
450
+    protected function ipn_txn_subscr_failed( $invoice ) {
451 451
 
452
-		// Make sure the invoice has a subscription.
453
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
452
+        // Make sure the invoice has a subscription.
453
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
454 454
 
455
-		if ( empty( $subscription ) ) {
456
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
457
-		}
455
+        if ( empty( $subscription ) ) {
456
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
457
+        }
458 458
 
459
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
460
-		$subscription->failing();
461
-		wpinv_error_log( 'Subscription marked as failing.', false );
459
+        wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
460
+        $subscription->failing();
461
+        wpinv_error_log( 'Subscription marked as failing.', false );
462 462
 
463
-	}
463
+    }
464 464
 
465
-	/**
466
-	 * Handles subscription suspensions.
467
-	 *
468
-	 * @param WPInv_Invoice $invoice  Invoice object.
469
-	 * @param array    $posted Posted data.
470
-	 */
471
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
465
+    /**
466
+     * Handles subscription suspensions.
467
+     *
468
+     * @param WPInv_Invoice $invoice  Invoice object.
469
+     * @param array    $posted Posted data.
470
+     */
471
+    protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
472 472
 
473
-		// Make sure the invoice has a subscription.
474
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
473
+        // Make sure the invoice has a subscription.
474
+        $subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
475 475
 
476
-		if ( empty( $subscription ) ) {
477
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
478
-		}
479
-
480
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
481
-		$subscription->cancel();
482
-		wpinv_error_log( 'Subscription cancelled.', false );
483
-	}
476
+        if ( empty( $subscription ) ) {
477
+            return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
478
+        }
479
+
480
+        wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
481
+        $subscription->cancel();
482
+        wpinv_error_log( 'Subscription cancelled.', false );
483
+    }
484 484
 
485 485
 }
Please login to merge, or discard this patch.
Spacing   +151 added lines, -151 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
  * Paypal Payment Gateway IPN handler class.
@@ -31,7 +31,7 @@  discard block
 block discarded – undo
31 31
 	 *
32 32
 	 * @param GetPaid_Paypal_Gateway $gateway
33 33
 	 */
34
-	public function __construct( $gateway ) {
34
+	public function __construct($gateway) {
35 35
 		$this->gateway = $gateway;
36 36
 		$this->verify_ipn();
37 37
 	}
@@ -43,37 +43,37 @@  discard block
 block discarded – undo
43 43
 	 */
44 44
 	public function verify_ipn() {
45 45
 
46
-		wpinv_error_log( 'GetPaid PayPal IPN Handler', false );
46
+		wpinv_error_log('GetPaid PayPal IPN Handler', false);
47 47
 
48 48
 		// Validate the IPN.
49
-		if ( empty( $_POST ) || ! $this->validate_ipn() ) {
50
-			wp_die( 'PayPal IPN Request Failure', 500 );
49
+		if (empty($_POST) || !$this->validate_ipn()) {
50
+			wp_die('PayPal IPN Request Failure', 500);
51 51
 		}
52 52
 
53 53
 		// Process the IPN.
54
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
55
-		$invoice = $this->get_ipn_invoice( $posted );
54
+		$posted  = wp_kses_post_deep(wp_unslash($_POST));
55
+		$invoice = $this->get_ipn_invoice($posted);
56 56
 
57 57
 		// Abort if it was not paid by our gateway.
58
-		if ( $this->id != $invoice->get_gateway() ) {
59
-			wpinv_error_log( 'Aborting, Invoice was not paid via PayPal', false );
60
-			wp_die( 'Invoice not paid via PayPal', 200 );
58
+		if ($this->id != $invoice->get_gateway()) {
59
+			wpinv_error_log('Aborting, Invoice was not paid via PayPal', false);
60
+			wp_die('Invoice not paid via PayPal', 200);
61 61
 		}
62 62
 
63
-		$posted['payment_status'] = isset( $posted['payment_status'] ) ? sanitize_key( strtolower( $posted['payment_status'] ) ) : '';
64
-		$posted['txn_type']       = sanitize_key( strtolower( $posted['txn_type'] ) );
63
+		$posted['payment_status'] = isset($posted['payment_status']) ? sanitize_key(strtolower($posted['payment_status'])) : '';
64
+		$posted['txn_type']       = sanitize_key(strtolower($posted['txn_type']));
65 65
 
66
-		wpinv_error_log( 'Payment status:' . $posted['payment_status'], false );
67
-		wpinv_error_log( 'IPN Type:' . $posted['txn_type'], false );
66
+		wpinv_error_log('Payment status:' . $posted['payment_status'], false);
67
+		wpinv_error_log('IPN Type:' . $posted['txn_type'], false);
68 68
 
69
-		if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
70
-			call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
71
-			wpinv_error_log( 'Done processing IPN', false );
72
-			wp_die( 'Processed', 200 );
69
+		if (method_exists($this, 'ipn_txn_' . $posted['txn_type'])) {
70
+			call_user_func(array($this, 'ipn_txn_' . $posted['txn_type']), $invoice, $posted);
71
+			wpinv_error_log('Done processing IPN', false);
72
+			wp_die('Processed', 200);
73 73
 		}
74 74
 
75
-		wpinv_error_log( 'Aborting, Unsupported IPN type:' . $posted['txn_type'], false );
76
-		wp_die( 'Unsupported IPN type', 200 );
75
+		wpinv_error_log('Aborting, Unsupported IPN type:' . $posted['txn_type'], false);
76
+		wp_die('Unsupported IPN type', 200);
77 77
 
78 78
 	}
79 79
 
@@ -83,22 +83,22 @@  discard block
 block discarded – undo
83 83
 	 * @param array $posted
84 84
 	 * @return WPInv_Invoice
85 85
 	 */
86
-	protected function get_ipn_invoice( $posted ) {
86
+	protected function get_ipn_invoice($posted) {
87 87
 
88
-		wpinv_error_log( 'Retrieving PayPal IPN Response Invoice', false );
88
+		wpinv_error_log('Retrieving PayPal IPN Response Invoice', false);
89 89
 
90
-		if ( ! empty( $posted['custom'] ) ) {
91
-			$invoice = new WPInv_Invoice( $posted['custom'] );
90
+		if (!empty($posted['custom'])) {
91
+			$invoice = new WPInv_Invoice($posted['custom']);
92 92
 
93
-			if ( $invoice->exists() ) {
94
-				wpinv_error_log( 'Found invoice #' . $invoice->get_number(), false );
93
+			if ($invoice->exists()) {
94
+				wpinv_error_log('Found invoice #' . $invoice->get_number(), false);
95 95
 				return $invoice;
96 96
 			}
97 97
 
98 98
 		}
99 99
 
100
-		wpinv_error_log( 'Could not retrieve the associated invoice.', false );
101
-		wp_die( 'Could not retrieve the associated invoice.', 200 );
100
+		wpinv_error_log('Could not retrieve the associated invoice.', false);
101
+		wp_die('Could not retrieve the associated invoice.', 200);
102 102
 	}
103 103
 
104 104
 	/**
@@ -106,14 +106,14 @@  discard block
 block discarded – undo
106 106
 	 */
107 107
 	protected function validate_ipn() {
108 108
 
109
-		wpinv_error_log( 'Validating PayPal IPN response', false );
109
+		wpinv_error_log('Validating PayPal IPN response', false);
110 110
 
111 111
 		// Retrieve the associated invoice.
112
-		$posted  = wp_kses_post_deep( wp_unslash( $_POST ) );
113
-		$invoice = $this->get_ipn_invoice( $posted );
112
+		$posted  = wp_kses_post_deep(wp_unslash($_POST));
113
+		$invoice = $this->get_ipn_invoice($posted);
114 114
 
115
-		if ( $this->gateway->is_sandbox( $invoice ) ) {
116
-			wpinv_error_log( $posted, 'Invoice was processed in sandbox hence logging the posted data', false );
115
+		if ($this->gateway->is_sandbox($invoice)) {
116
+			wpinv_error_log($posted, 'Invoice was processed in sandbox hence logging the posted data', false);
117 117
 		}
118 118
 
119 119
 		// Validate the IPN.
@@ -130,20 +130,20 @@  discard block
 block discarded – undo
130 130
 		);
131 131
 
132 132
 		// Post back to get a response.
133
-		$response = wp_safe_remote_post( $this->gateway->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
133
+		$response = wp_safe_remote_post($this->gateway->is_sandbox($invoice) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params);
134 134
 
135 135
 		// Check to see if the request was valid.
136
-		if ( ! is_wp_error( $response ) && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
137
-			wpinv_error_log( 'Received valid response from PayPal IPN: ' . $response['body'], false );
136
+		if (!is_wp_error($response) && $response['response']['code'] < 300 && strstr($response['body'], 'VERIFIED')) {
137
+			wpinv_error_log('Received valid response from PayPal IPN: ' . $response['body'], false);
138 138
 			return true;
139 139
 		}
140 140
 
141
-		if ( is_wp_error( $response ) ) {
142
-			wpinv_error_log( $response->get_error_message(), 'Received invalid response from PayPal IPN' );
141
+		if (is_wp_error($response)) {
142
+			wpinv_error_log($response->get_error_message(), 'Received invalid response from PayPal IPN');
143 143
 			return false;
144 144
 		}
145 145
 
146
-		wpinv_error_log( $response['body'], 'Received invalid response from PayPal IPN' );
146
+		wpinv_error_log($response['body'], 'Received invalid response from PayPal IPN');
147 147
 		return false;
148 148
 
149 149
 	}
@@ -154,17 +154,17 @@  discard block
 block discarded – undo
154 154
 	 * @param WPInv_Invoice $invoice          Invoice object.
155 155
 	 * @param string   $currency currency to validate.
156 156
 	 */
157
-	protected function validate_ipn_currency( $invoice, $currency ) {
157
+	protected function validate_ipn_currency($invoice, $currency) {
158 158
 
159
-		if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
159
+		if (strtolower($invoice->get_currency()) !== strtolower($currency)) {
160 160
 
161 161
 			/* translators: %s: currency code. */
162
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
162
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal currencies do not match (code %s).', 'invoicing'), $currency));
163 163
 
164
-			wpinv_error_log( "Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true );
164
+			wpinv_error_log("Currencies do not match: {$currency} instead of {$invoice->get_currency()}", 'IPN Error', __FILE__, __LINE__, true);
165 165
 		}
166 166
 
167
-		wpinv_error_log( $currency, 'Validated IPN Currency', false );
167
+		wpinv_error_log($currency, 'Validated IPN Currency', false);
168 168
 	}
169 169
 
170 170
 	/**
@@ -173,16 +173,16 @@  discard block
 block discarded – undo
173 173
 	 * @param WPInv_Invoice $invoice          Invoice object.
174 174
 	 * @param float   $amount amount to validate.
175 175
 	 */
176
-	protected function validate_ipn_amount( $invoice, $amount ) {
177
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
176
+	protected function validate_ipn_amount($invoice, $amount) {
177
+		if (number_format($invoice->get_total(), 2, '.', '') !== number_format($amount, 2, '.', '')) {
178 178
 
179 179
 			/* translators: %s: Amount. */
180
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
180
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal amounts do not match (gross %s).', 'invoicing'), $amount));
181 181
 
182
-			wpinv_error_log( "Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true );
182
+			wpinv_error_log("Amounts do not match: {$amount} instead of {$invoice->get_total()}", 'IPN Error', __FILE__, __LINE__, true);
183 183
 		}
184 184
 
185
-		wpinv_error_log( $amount, 'Validated IPN Amount', false );
185
+		wpinv_error_log($amount, 'Validated IPN Amount', false);
186 186
 	}
187 187
 
188 188
 	/**
@@ -191,19 +191,19 @@  discard block
 block discarded – undo
191 191
 	 * @param WPInv_Invoice $invoice          Invoice object.
192 192
 	 * @param string   $receiver_email Email to validate.
193 193
 	 */
194
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
195
-		$paypal_email = wpinv_get_option( 'paypal_email' );
194
+	protected function validate_ipn_receiver_email($invoice, $receiver_email) {
195
+		$paypal_email = wpinv_get_option('paypal_email');
196 196
 
197
-		if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
198
-			wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
197
+		if (strcasecmp(trim($receiver_email), trim($paypal_email)) !== 0) {
198
+			wpinv_record_gateway_error('IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}");
199 199
 
200 200
 			/* translators: %s: email address . */
201
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
201
+			$invoice->update_status('wpi-processing', sprintf(__('Validation error: PayPal IPN response from a different email address (%s).', 'invoicing'), $receiver_email));
202 202
 
203
-			return wpinv_error_log( "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true );
203
+			return wpinv_error_log("IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}", 'IPN Error', __FILE__, __LINE__, true);
204 204
 		}
205 205
 
206
-		wpinv_error_log( 'Validated PayPal Email', false );
206
+		wpinv_error_log('Validated PayPal Email', false);
207 207
 	}
208 208
 
209 209
 	/**
@@ -212,70 +212,70 @@  discard block
 block discarded – undo
212 212
 	 * @param WPInv_Invoice $invoice  Invoice object.
213 213
 	 * @param array    $posted Posted data.
214 214
 	 */
215
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
215
+	protected function ipn_txn_web_accept($invoice, $posted) {
216 216
 
217 217
 		// Collect payment details
218
-		$payment_status = strtolower( $posted['payment_status'] );
219
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
218
+		$payment_status = strtolower($posted['payment_status']);
219
+		$business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']);
220 220
 
221
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
222
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
221
+		$this->validate_ipn_receiver_email($invoice, $business_email);
222
+		$this->validate_ipn_currency($invoice, $posted['mc_currency']);
223 223
 
224 224
 		// Update the transaction id.
225
-		if ( ! empty( $posted['txn_id'] ) ) {
226
-			$invoice->set_transaction_id( wpinv_clean( $posted['txn_id'] ) );
225
+		if (!empty($posted['txn_id'])) {
226
+			$invoice->set_transaction_id(wpinv_clean($posted['txn_id']));
227 227
 			$invoice->save();
228 228
 		}
229 229
 
230
-		$invoice->add_system_note( __( 'Processing invoice IPN', 'invoicing' ) );
230
+		$invoice->add_system_note(__('Processing invoice IPN', 'invoicing'));
231 231
 
232 232
 		// Process a refund.
233
-		if ( $payment_status == 'refunded' || $payment_status == 'reversed' ) {
233
+		if ($payment_status == 'refunded' || $payment_status == 'reversed') {
234 234
 
235
-			update_post_meta( $invoice->get_id(), 'refunded_remotely', 1 );
235
+			update_post_meta($invoice->get_id(), 'refunded_remotely', 1);
236 236
 
237
-			if ( ! $invoice->is_refunded() ) {
238
-				$invoice->update_status( 'wpi-refunded', $posted['reason_code'] );
237
+			if (!$invoice->is_refunded()) {
238
+				$invoice->update_status('wpi-refunded', $posted['reason_code']);
239 239
 			}
240 240
 
241
-			return wpinv_error_log( $posted['reason_code'], false );
241
+			return wpinv_error_log($posted['reason_code'], false);
242 242
 		}
243 243
 
244 244
 		// Process payments.
245
-		if ( $payment_status == 'completed' ) {
245
+		if ($payment_status == 'completed') {
246 246
 
247
-			if ( $invoice->is_paid() && 'wpi_processing' != $invoice->get_status() ) {
248
-				return wpinv_error_log( 'Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false );
247
+			if ($invoice->is_paid() && 'wpi_processing' != $invoice->get_status()) {
248
+				return wpinv_error_log('Aborting, Invoice #' . $invoice->get_number() . ' is already paid.', false);
249 249
 			}
250 250
 
251
-			$this->validate_ipn_amount( $invoice, $posted['mc_gross'] );
251
+			$this->validate_ipn_amount($invoice, $posted['mc_gross']);
252 252
 
253 253
 			$note = '';
254 254
 
255
-			if ( ! empty( $posted['mc_fee'] ) ) {
256
-				$note = sprintf( __( 'PayPal Transaction Fee %.', 'invoicing' ), sanitize_text_field( $posted['mc_fee'] ) );
255
+			if (!empty($posted['mc_fee'])) {
256
+				$note = sprintf(__('PayPal Transaction Fee %.', 'invoicing'), sanitize_text_field($posted['mc_fee']));
257 257
 			}
258 258
 
259
-			if ( ! empty( $posted['payer_status'] ) ) {
260
-				$note = ' ' . sprintf( __( 'Buyer status %.', 'invoicing' ), sanitize_text_field( $posted['payer_status'] ) );
259
+			if (!empty($posted['payer_status'])) {
260
+				$note = ' ' . sprintf(__('Buyer status %.', 'invoicing'), sanitize_text_field($posted['payer_status']));
261 261
 			}
262 262
 
263
-			$invoice->mark_paid( ( ! empty( $posted['txn_id'] ) ? sanitize_text_field( $posted['txn_id'] ) : '' ), trim( $note ) );
264
-			return wpinv_error_log( 'Invoice marked as paid.', false );
263
+			$invoice->mark_paid((!empty($posted['txn_id']) ? sanitize_text_field($posted['txn_id']) : ''), trim($note));
264
+			return wpinv_error_log('Invoice marked as paid.', false);
265 265
 
266 266
 		}
267 267
 
268 268
 		// Pending payments.
269
-		if ( $payment_status == 'pending' ) {
269
+		if ($payment_status == 'pending') {
270 270
 
271 271
 			/* translators: %s: pending reason. */
272
-			$invoice->update_status( 'wpi-onhold', sprintf( __( 'Payment pending (%s).', 'invoicing' ), $posted['pending_reason'] ) );
272
+			$invoice->update_status('wpi-onhold', sprintf(__('Payment pending (%s).', 'invoicing'), $posted['pending_reason']));
273 273
 
274
-			return wpinv_error_log( 'Invoice marked as "payment held".', false );
274
+			return wpinv_error_log('Invoice marked as "payment held".', false);
275 275
 		}
276 276
 
277 277
 		/* translators: %s: payment status. */
278
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), sanitize_text_field( $posted['payment_status'] ) ) );
278
+		$invoice->update_status('wpi-failed', sprintf(__('Payment %s via IPN.', 'invoicing'), sanitize_text_field($posted['payment_status'])));
279 279
 
280 280
 	}
281 281
 
@@ -285,8 +285,8 @@  discard block
 block discarded – undo
285 285
 	 * @param WPInv_Invoice $invoice  Invoice object.
286 286
 	 * @param array    $posted Posted data.
287 287
 	 */
288
-	protected function ipn_txn_cart( $invoice, $posted ) {
289
-		$this->ipn_txn_web_accept( $invoice, $posted );
288
+	protected function ipn_txn_cart($invoice, $posted) {
289
+		$this->ipn_txn_web_accept($invoice, $posted);
290 290
 	}
291 291
 
292 292
 	/**
@@ -295,43 +295,43 @@  discard block
 block discarded – undo
295 295
 	 * @param WPInv_Invoice $invoice  Invoice object.
296 296
 	 * @param array    $posted Posted data.
297 297
 	 */
298
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
298
+	protected function ipn_txn_subscr_signup($invoice, $posted) {
299 299
 
300
-		wpinv_error_log( 'Processing subscription signup', false );
300
+		wpinv_error_log('Processing subscription signup', false);
301 301
 
302 302
 		// Make sure the invoice has a subscription.
303
-		$subscription = getpaid_get_invoice_subscription( $invoice );
303
+		$subscription = getpaid_get_invoice_subscription($invoice);
304 304
 
305
-		if ( empty( $subscription ) ) {
306
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
305
+		if (empty($subscription)) {
306
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
307 307
 		}
308 308
 
309
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
309
+		wpinv_error_log('Found subscription #' . $subscription->get_id(), false);
310 310
 
311 311
 		// Validate the IPN.
312
-		$business_email = isset( $posted['business'] ) && is_email( $posted['business'] ) ? trim( $posted['business'] ) : trim( $posted['receiver_email'] );
313
-		$this->validate_ipn_receiver_email( $invoice, $business_email );
314
-		$this->validate_ipn_currency( $invoice, $posted['mc_currency'] );
312
+		$business_email = isset($posted['business']) && is_email($posted['business']) ? trim($posted['business']) : trim($posted['receiver_email']);
313
+		$this->validate_ipn_receiver_email($invoice, $business_email);
314
+		$this->validate_ipn_currency($invoice, $posted['mc_currency']);
315 315
 
316 316
 		// Activate the subscription.
317
-		$duration = strtotime( $subscription->get_expiration() ) - strtotime( $subscription->get_date_created() );
318
-		$subscription->set_date_created( current_time( 'mysql' ) );
319
-		$subscription->set_expiration( date( 'Y-m-d H:i:s', ( current_time( 'timestamp' ) + $duration ) ) );
320
-		$subscription->set_profile_id( sanitize_text_field( $posted['subscr_id'] ) );
317
+		$duration = strtotime($subscription->get_expiration()) - strtotime($subscription->get_date_created());
318
+		$subscription->set_date_created(current_time('mysql'));
319
+		$subscription->set_expiration(date('Y-m-d H:i:s', (current_time('timestamp') + $duration)));
320
+		$subscription->set_profile_id(sanitize_text_field($posted['subscr_id']));
321 321
 		$subscription->activate();
322 322
 
323 323
 		// Set the transaction id.
324
-		if ( ! empty( $posted['txn_id'] ) ) {
325
-			$invoice->add_note( sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
326
-			$invoice->set_transaction_id( $posted['txn_id'] );
324
+		if (!empty($posted['txn_id'])) {
325
+			$invoice->add_note(sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
326
+			$invoice->set_transaction_id($posted['txn_id']);
327 327
 		}
328 328
 
329 329
 		// Update the payment status.
330 330
 		$invoice->mark_paid();
331 331
 
332
-		$invoice->add_note( sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
332
+		$invoice->add_note(sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
333 333
 
334
-		wpinv_error_log( 'Subscription started.', false );
334
+		wpinv_error_log('Subscription started.', false);
335 335
 	}
336 336
 
337 337
 	/**
@@ -340,45 +340,45 @@  discard block
 block discarded – undo
340 340
 	 * @param WPInv_Invoice $invoice  Invoice object.
341 341
 	 * @param array    $posted Posted data.
342 342
 	 */
343
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
343
+	protected function ipn_txn_subscr_payment($invoice, $posted) {
344 344
 
345 345
 		// Make sure the invoice has a subscription.
346
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
346
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
347 347
 
348
-		if ( empty( $subscription ) ) {
349
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
348
+		if (empty($subscription)) {
349
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
350 350
 		}
351 351
 
352
-		wpinv_error_log( 'Found subscription #' . $subscription->get_id(), false );
352
+		wpinv_error_log('Found subscription #' . $subscription->get_id(), false);
353 353
 
354 354
 		// PayPal sends a subscr_payment for the first payment too.
355
-		$date_completed = getpaid_format_date( $invoice->get_date_completed() );
356
-		$date_created   = getpaid_format_date( $invoice->get_date_created() );
357
-		$today_date     = getpaid_format_date( current_time( 'mysql' ) );
358
-		$payment_date   = getpaid_format_date( $posted['payment_date'] );
359
-		$subscribe_date = getpaid_format_date( $subscription->get_date_created() );
360
-		$dates          = array_filter( compact( 'date_completed', 'date_created', 'subscribe_date' ) );
355
+		$date_completed = getpaid_format_date($invoice->get_date_completed());
356
+		$date_created   = getpaid_format_date($invoice->get_date_created());
357
+		$today_date     = getpaid_format_date(current_time('mysql'));
358
+		$payment_date   = getpaid_format_date($posted['payment_date']);
359
+		$subscribe_date = getpaid_format_date($subscription->get_date_created());
360
+		$dates          = array_filter(compact('date_completed', 'date_created', 'subscribe_date'));
361 361
 
362
-		foreach( $dates as $date ) {
362
+		foreach ($dates as $date) {
363 363
 
364
-			if ( $date !== $today_date && $date !== $payment_date ) {
364
+			if ($date !== $today_date && $date !== $payment_date) {
365 365
 				continue;
366 366
 			}
367 367
 
368
-			if ( ! empty( $posted['txn_id'] ) ) {
369
-				$invoice->set_transaction_id( sanitize_text_field( $posted['txn_id'] ) );	
370
-				$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , sanitize_text_field( $posted['txn_id'] ) ), false, false, true );
368
+			if (!empty($posted['txn_id'])) {
369
+				$invoice->set_transaction_id(sanitize_text_field($posted['txn_id']));	
370
+				$invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), sanitize_text_field($posted['txn_id'])), false, false, true);
371 371
 			}
372 372
 
373 373
 			return $invoice->mark_paid();
374 374
 
375 375
 		}
376 376
 
377
-		wpinv_error_log( 'Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false );
377
+		wpinv_error_log('Processing subscription renewal payment for the invoice ' . $invoice->get_id(), false);
378 378
 
379 379
 		// Abort if the payment is already recorded.
380
-		if ( wpinv_get_id_by_transaction_id( $posted['txn_id'] ) ) {
381
-			return wpinv_error_log( 'Aborting, Transaction ' . $posted['txn_id'] .' has already been processed', false );
380
+		if (wpinv_get_id_by_transaction_id($posted['txn_id'])) {
381
+			return wpinv_error_log('Aborting, Transaction ' . $posted['txn_id'] . ' has already been processed', false);
382 382
 		}
383 383
 
384 384
 		$args = array(
@@ -386,17 +386,17 @@  discard block
 block discarded – undo
386 386
 			'gateway'        => $this->id,
387 387
 		);
388 388
 
389
-		$invoice = wpinv_get_invoice( $subscription->add_payment( $args ) );
389
+		$invoice = wpinv_get_invoice($subscription->add_payment($args));
390 390
 
391
-		if ( empty( $invoice ) ) {
391
+		if (empty($invoice)) {
392 392
 			return;
393 393
 		}
394 394
 
395
-		$invoice->add_note( wp_sprintf( __( 'PayPal Transaction ID: %s', 'invoicing' ) , $posted['txn_id'] ), false, false, true );
396
-		$invoice->add_note( wp_sprintf( __( 'PayPal Subscription ID: %s', 'invoicing' ) , $posted['subscr_id'] ), false, false, true );
395
+		$invoice->add_note(wp_sprintf(__('PayPal Transaction ID: %s', 'invoicing'), $posted['txn_id']), false, false, true);
396
+		$invoice->add_note(wp_sprintf(__('PayPal Subscription ID: %s', 'invoicing'), $posted['subscr_id']), false, false, true);
397 397
 
398 398
 		$subscription->renew();
399
-		wpinv_error_log( 'Subscription renewed.', false );
399
+		wpinv_error_log('Subscription renewed.', false);
400 400
 
401 401
 	}
402 402
 
@@ -405,18 +405,18 @@  discard block
 block discarded – undo
405 405
 	 *
406 406
 	 * @param WPInv_Invoice $invoice  Invoice object.
407 407
 	 */
408
-	protected function ipn_txn_subscr_cancel( $invoice ) {
408
+	protected function ipn_txn_subscr_cancel($invoice) {
409 409
 
410 410
 		// Make sure the invoice has a subscription.
411
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
411
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
412 412
 
413
-		if ( empty( $subscription ) ) {
414
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
413
+		if (empty($subscription)) {
414
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
415 415
 		}
416 416
 
417
-		wpinv_error_log( 'Processing subscription cancellation for the invoice ' . $invoice->get_id(), false );
417
+		wpinv_error_log('Processing subscription cancellation for the invoice ' . $invoice->get_id(), false);
418 418
 		$subscription->cancel();
419
-		wpinv_error_log( 'Subscription cancelled.', false );
419
+		wpinv_error_log('Subscription cancelled.', false);
420 420
 
421 421
 	}
422 422
 
@@ -426,18 +426,18 @@  discard block
 block discarded – undo
426 426
 	 * @param WPInv_Invoice $invoice  Invoice object.
427 427
 	 * @param array    $posted Posted data.
428 428
 	 */
429
-	protected function ipn_txn_subscr_eot( $invoice ) {
429
+	protected function ipn_txn_subscr_eot($invoice) {
430 430
 
431 431
 		// Make sure the invoice has a subscription.
432
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
432
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
433 433
 
434
-		if ( empty( $subscription ) ) {
435
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
434
+		if (empty($subscription)) {
435
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
436 436
 		}
437 437
 
438
-		wpinv_error_log( 'Processing subscription end of life for the invoice ' . $invoice->get_id(), false );
438
+		wpinv_error_log('Processing subscription end of life for the invoice ' . $invoice->get_id(), false);
439 439
 		$subscription->complete();
440
-		wpinv_error_log( 'Subscription completed.', false );
440
+		wpinv_error_log('Subscription completed.', false);
441 441
 
442 442
 	}
443 443
 
@@ -447,18 +447,18 @@  discard block
 block discarded – undo
447 447
 	 * @param WPInv_Invoice $invoice  Invoice object.
448 448
 	 * @param array    $posted Posted data.
449 449
 	 */
450
-	protected function ipn_txn_subscr_failed( $invoice ) {
450
+	protected function ipn_txn_subscr_failed($invoice) {
451 451
 
452 452
 		// Make sure the invoice has a subscription.
453
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
453
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
454 454
 
455
-		if ( empty( $subscription ) ) {
456
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
455
+		if (empty($subscription)) {
456
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
457 457
 		}
458 458
 
459
-		wpinv_error_log( 'Processing subscription payment failure for the invoice ' . $invoice->get_id(), false );
459
+		wpinv_error_log('Processing subscription payment failure for the invoice ' . $invoice->get_id(), false);
460 460
 		$subscription->failing();
461
-		wpinv_error_log( 'Subscription marked as failing.', false );
461
+		wpinv_error_log('Subscription marked as failing.', false);
462 462
 
463 463
 	}
464 464
 
@@ -468,18 +468,18 @@  discard block
 block discarded – undo
468 468
 	 * @param WPInv_Invoice $invoice  Invoice object.
469 469
 	 * @param array    $posted Posted data.
470 470
 	 */
471
-	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment( $invoice ) {
471
+	protected function ipn_txn_recurring_payment_suspended_due_to_max_failed_payment($invoice) {
472 472
 
473 473
 		// Make sure the invoice has a subscription.
474
-		$subscription = getpaid_subscriptions()->get_invoice_subscription( $invoice );
474
+		$subscription = getpaid_subscriptions()->get_invoice_subscription($invoice);
475 475
 
476
-		if ( empty( $subscription ) ) {
477
-			return wpinv_error_log( 'Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false );
476
+		if (empty($subscription)) {
477
+			return wpinv_error_log('Aborting, Subscription for the invoice ' . $invoice->get_id() . ' not found', false);
478 478
 		}
479 479
 
480
-		wpinv_error_log( 'Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false );
480
+		wpinv_error_log('Processing subscription cancellation due to max failed payment for the invoice ' . $invoice->get_id(), false);
481 481
 		$subscription->cancel();
482
-		wpinv_error_log( 'Subscription cancelled.', false );
482
+		wpinv_error_log('Subscription cancelled.', false);
483 483
 	}
484 484
 
485 485
 }
Please login to merge, or discard this patch.
includes/class-wpinv-ajax.php 2 patches
Indentation   +59 added lines, -59 removed lines patch added patch discarded remove patch
@@ -14,70 +14,70 @@  discard block
 block discarded – undo
14 14
 class WPInv_Ajax {
15 15
 
16 16
     /**
17
-	 * Hook in ajax handlers.
18
-	 */
19
-	public static function init() {
20
-		add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
-		add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
-		self::add_ajax_events();
17
+     * Hook in ajax handlers.
18
+     */
19
+    public static function init() {
20
+        add_action( 'init', array( __CLASS__, 'define_ajax' ), 0 );
21
+        add_action( 'template_redirect', array( __CLASS__, 'do_wpinv_ajax' ), 0 );
22
+        self::add_ajax_events();
23 23
     }
24 24
 
25 25
     /**
26
-	 * Set GetPaid AJAX constant and headers.
27
-	 */
28
-	public static function define_ajax() {
29
-
30
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
-			getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
-			getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
-			if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
-				/** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
-			}
36
-			$GLOBALS['wpdb']->hide_errors();
37
-		}
26
+     * Set GetPaid AJAX constant and headers.
27
+     */
28
+    public static function define_ajax() {
29
+
30
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
31
+            getpaid_maybe_define_constant( 'DOING_AJAX', true );
32
+            getpaid_maybe_define_constant( 'WPInv_DOING_AJAX', true );
33
+            if ( ! WP_DEBUG || ( WP_DEBUG && ! WP_DEBUG_DISPLAY ) ) {
34
+                /** @scrutinizer ignore-unhandled */ @ini_set( 'display_errors', 0 );
35
+            }
36
+            $GLOBALS['wpdb']->hide_errors();
37
+        }
38 38
 
39 39
     }
40 40
     
41 41
     /**
42
-	 * Send headers for GetPaid Ajax Requests.
43
-	 *
44
-	 * @since 1.0.18
45
-	 */
46
-	private static function wpinv_ajax_headers() {
47
-		if ( ! headers_sent() ) {
48
-			send_origin_headers();
49
-			send_nosniff_header();
50
-			nocache_headers();
51
-			header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
-			header( 'X-Robots-Tag: noindex' );
53
-			status_header( 200 );
54
-		}
42
+     * Send headers for GetPaid Ajax Requests.
43
+     *
44
+     * @since 1.0.18
45
+     */
46
+    private static function wpinv_ajax_headers() {
47
+        if ( ! headers_sent() ) {
48
+            send_origin_headers();
49
+            send_nosniff_header();
50
+            nocache_headers();
51
+            header( 'Content-Type: text/html; charset=' . get_option( 'blog_charset' ) );
52
+            header( 'X-Robots-Tag: noindex' );
53
+            status_header( 200 );
54
+        }
55 55
     }
56 56
     
57 57
     /**
58
-	 * Check for GetPaid Ajax request and fire action.
59
-	 */
60
-	public static function do_wpinv_ajax() {
61
-		global $wp_query;
58
+     * Check for GetPaid Ajax request and fire action.
59
+     */
60
+    public static function do_wpinv_ajax() {
61
+        global $wp_query;
62 62
 
63
-		if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
-			$wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
-		}
63
+        if ( ! empty( $_GET['wpinv-ajax'] ) ) {
64
+            $wp_query->set( 'wpinv-ajax', sanitize_text_field( wp_unslash( $_GET['wpinv-ajax'] ) ) );
65
+        }
66 66
 
67
-		$action = $wp_query->get( 'wpinv-ajax' );
67
+        $action = $wp_query->get( 'wpinv-ajax' );
68 68
 
69
-		if ( $action ) {
70
-			self::wpinv_ajax_headers();
71
-			$action = sanitize_text_field( $action );
72
-			do_action( 'wpinv_ajax_' . $action );
73
-			wp_die();
74
-		}
69
+        if ( $action ) {
70
+            self::wpinv_ajax_headers();
71
+            $action = sanitize_text_field( $action );
72
+            do_action( 'wpinv_ajax_' . $action );
73
+            wp_die();
74
+        }
75 75
 
76 76
     }
77 77
 
78 78
     /**
79
-	 * Hook in ajax methods.
80
-	 */
79
+     * Hook in ajax methods.
80
+     */
81 81
     public static function add_ajax_events() {
82 82
 
83 83
         // array( 'event' => is_frontend )
@@ -260,18 +260,18 @@  discard block
 block discarded – undo
260 260
         check_ajax_referer( 'getpaid_form_nonce' );
261 261
 
262 262
         // Is the request set up correctly?
263
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
264
-			echo aui()->alert(
265
-				array(
266
-					'type'    => 'warning',
267
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
268
-				)
263
+        if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
264
+            echo aui()->alert(
265
+                array(
266
+                    'type'    => 'warning',
267
+                    'content' => __( 'No payment form or item provided', 'invoicing' ),
268
+                )
269 269
             );
270 270
             exit;
271 271
         }
272 272
 
273 273
         // Payment form or button?
274
-		if ( ! empty( $_GET['form'] ) ) {
274
+        if ( ! empty( $_GET['form'] ) ) {
275 275
             $form = urldecode( $_GET['form'] );
276 276
 
277 277
             if ( false !== strpos( $form, '|' ) ) {
@@ -325,11 +325,11 @@  discard block
 block discarded – undo
325 325
                 getpaid_display_payment_form( $form );
326 326
             }
327 327
 
328
-		} else if( ! empty( $_GET['invoice'] ) ) {
329
-		    getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
328
+        } else if( ! empty( $_GET['invoice'] ) ) {
329
+            getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
330 330
         } else {
331
-			$items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
332
-		    getpaid_display_item_payment_form( $items );
331
+            $items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
332
+            getpaid_display_item_payment_form( $items );
333 333
         }
334 334
 
335 335
         exit;
@@ -650,7 +650,7 @@  discard block
 block discarded – undo
650 650
         if ( is_wp_error( $error ) ) {
651 651
             $alert = $error->get_error_message();
652 652
             wp_send_json_success( compact( 'alert' ) );
653
-         }
653
+            }
654 654
 
655 655
         // Update totals.
656 656
         $invoice->recalculate_total();
Please login to merge, or discard this patch.
Spacing   +300 added lines, -300 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
 
@@ -105,36 +105,36 @@  discard block
 block discarded – undo
105 105
             'payment_form_refresh_prices' => true,
106 106
         );
107 107
 
108
-        foreach ( $ajax_events as $ajax_event => $nopriv ) {
109
-            add_action( 'wp_ajax_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
110
-            add_action( 'wp_ajax_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
108
+        foreach ($ajax_events as $ajax_event => $nopriv) {
109
+            add_action('wp_ajax_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
110
+            add_action('wp_ajax_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
111 111
 
112
-            if ( $nopriv ) {
113
-                add_action( 'wp_ajax_nopriv_wpinv_' . $ajax_event, array( __CLASS__, $ajax_event ) );
114
-                add_action( 'wp_ajax_nopriv_getpaid_' . $ajax_event, array( __CLASS__, $ajax_event ) );
115
-                add_action( 'wpinv_ajax_' . $ajax_event, array( __CLASS__, $ajax_event ) );
112
+            if ($nopriv) {
113
+                add_action('wp_ajax_nopriv_wpinv_' . $ajax_event, array(__CLASS__, $ajax_event));
114
+                add_action('wp_ajax_nopriv_getpaid_' . $ajax_event, array(__CLASS__, $ajax_event));
115
+                add_action('wpinv_ajax_' . $ajax_event, array(__CLASS__, $ajax_event));
116 116
             }
117 117
         }
118 118
     }
119 119
     
120 120
     public static function add_note() {
121
-        check_ajax_referer( 'add-invoice-note', '_nonce' );
121
+        check_ajax_referer('add-invoice-note', '_nonce');
122 122
 
123
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
123
+        if (!wpinv_current_user_can_manage_invoicing()) {
124 124
             die(-1);
125 125
         }
126 126
 
127
-        $post_id   = absint( $_POST['post_id'] );
128
-        $note      = wp_kses_post( trim( stripslashes( $_POST['note'] ) ) );
129
-        $note_type = sanitize_text_field( $_POST['note_type'] );
127
+        $post_id   = absint($_POST['post_id']);
128
+        $note      = wp_kses_post(trim(stripslashes($_POST['note'])));
129
+        $note_type = sanitize_text_field($_POST['note_type']);
130 130
 
131 131
         $is_customer_note = $note_type == 'customer' ? 1 : 0;
132 132
 
133
-        if ( $post_id > 0 ) {
134
-            $note_id = wpinv_insert_payment_note( $post_id, $note, $is_customer_note );
133
+        if ($post_id > 0) {
134
+            $note_id = wpinv_insert_payment_note($post_id, $note, $is_customer_note);
135 135
 
136
-            if ( $note_id > 0 && !is_wp_error( $note_id ) ) {
137
-                wpinv_get_invoice_note_line_item( $note_id );
136
+            if ($note_id > 0 && !is_wp_error($note_id)) {
137
+                wpinv_get_invoice_note_line_item($note_id);
138 138
             }
139 139
         }
140 140
 
@@ -142,16 +142,16 @@  discard block
 block discarded – undo
142 142
     }
143 143
 
144 144
     public static function delete_note() {
145
-        check_ajax_referer( 'delete-invoice-note', '_nonce' );
145
+        check_ajax_referer('delete-invoice-note', '_nonce');
146 146
 
147
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
147
+        if (!wpinv_current_user_can_manage_invoicing()) {
148 148
             die(-1);
149 149
         }
150 150
 
151
-        $note_id = (int)$_POST['note_id'];
151
+        $note_id = (int) $_POST['note_id'];
152 152
 
153
-        if ( $note_id > 0 ) {
154
-            wp_delete_comment( $note_id, true );
153
+        if ($note_id > 0) {
154
+            wp_delete_comment($note_id, true);
155 155
         }
156 156
 
157 157
         die();
@@ -169,34 +169,34 @@  discard block
 block discarded – undo
169 169
     public static function get_billing_details() {
170 170
 
171 171
         // Verify nonce.
172
-        check_ajax_referer( 'wpinv-nonce' );
172
+        check_ajax_referer('wpinv-nonce');
173 173
 
174 174
         // Can the user manage the plugin?
175
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
175
+        if (!wpinv_current_user_can_manage_invoicing()) {
176 176
             die(-1);
177 177
         }
178 178
 
179 179
         // Do we have a user id?
180 180
         $user_id = $_GET['user_id'];
181 181
 
182
-        if ( empty( $user_id ) || ! is_numeric( $user_id ) ) {
182
+        if (empty($user_id) || !is_numeric($user_id)) {
183 183
             die(-1);
184 184
         }
185 185
 
186 186
         // Fetch the billing details.
187
-        $billing_details    = wpinv_get_user_address( $user_id );
188
-        $billing_details    = apply_filters( 'wpinv_ajax_billing_details', $billing_details, $user_id );
187
+        $billing_details    = wpinv_get_user_address($user_id);
188
+        $billing_details    = apply_filters('wpinv_ajax_billing_details', $billing_details, $user_id);
189 189
 
190 190
         // unset the user id and email.
191
-        $to_ignore = array( 'user_id', 'email' );
191
+        $to_ignore = array('user_id', 'email');
192 192
 
193
-        foreach ( $to_ignore as $key ) {
194
-            if ( isset( $billing_details[ $key ] ) ) {
195
-                unset( $billing_details[ $key ] );
193
+        foreach ($to_ignore as $key) {
194
+            if (isset($billing_details[$key])) {
195
+                unset($billing_details[$key]);
196 196
             }
197 197
         }
198 198
 
199
-        wp_send_json_success( $billing_details );
199
+        wp_send_json_success($billing_details);
200 200
 
201 201
     }
202 202
 
@@ -206,47 +206,47 @@  discard block
 block discarded – undo
206 206
     public static function check_new_user_email() {
207 207
 
208 208
         // Verify nonce.
209
-        check_ajax_referer( 'wpinv-nonce' );
209
+        check_ajax_referer('wpinv-nonce');
210 210
 
211 211
         // Can the user manage the plugin?
212
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
212
+        if (!wpinv_current_user_can_manage_invoicing()) {
213 213
             die(-1);
214 214
         }
215 215
 
216 216
         // We need an email address.
217
-        if ( empty( $_GET['email'] ) ) {
218
-            _e( "Provide the new user's email address", 'invoicing' );
217
+        if (empty($_GET['email'])) {
218
+            _e("Provide the new user's email address", 'invoicing');
219 219
             exit;
220 220
         }
221 221
 
222 222
         // Ensure the email is valid.
223
-        $email = sanitize_text_field( $_GET['email'] );
224
-        if ( ! is_email( $email ) ) {
225
-            _e( 'Invalid email address', 'invoicing' );
223
+        $email = sanitize_text_field($_GET['email']);
224
+        if (!is_email($email)) {
225
+            _e('Invalid email address', 'invoicing');
226 226
             exit;
227 227
         }
228 228
 
229 229
         // And it does not exist.
230
-        $id = email_exists( $email );
231
-        if ( $id ) {
232
-            wp_send_json_success( compact( 'id' ) );
230
+        $id = email_exists($email);
231
+        if ($id) {
232
+            wp_send_json_success(compact('id'));
233 233
         }
234 234
 
235
-        wp_send_json_success( true );
235
+        wp_send_json_success(true);
236 236
     }
237 237
     
238 238
     public static function run_tool() {
239
-        check_ajax_referer( 'wpinv-nonce', '_nonce' );
240
-        if ( !wpinv_current_user_can_manage_invoicing() ) {
239
+        check_ajax_referer('wpinv-nonce', '_nonce');
240
+        if (!wpinv_current_user_can_manage_invoicing()) {
241 241
             die(-1);
242 242
         }
243 243
         
244
-        $tool = sanitize_text_field( $_POST['tool'] );
244
+        $tool = sanitize_text_field($_POST['tool']);
245 245
         
246
-        do_action( 'wpinv_run_tool' );
246
+        do_action('wpinv_run_tool');
247 247
         
248
-        if ( !empty( $tool ) ) {
249
-            do_action( 'wpinv_tool_' . $tool );
248
+        if (!empty($tool)) {
249
+            do_action('wpinv_tool_' . $tool);
250 250
         }
251 251
     }
252 252
 
@@ -257,43 +257,43 @@  discard block
 block discarded – undo
257 257
         global $getpaid_force_checkbox;
258 258
 
259 259
         // Check nonce.
260
-        check_ajax_referer( 'getpaid_form_nonce' );
260
+        check_ajax_referer('getpaid_form_nonce');
261 261
 
262 262
         // Is the request set up correctly?
263
-		if ( empty( $_GET['form'] ) && empty( $_GET['item'] ) && empty( $_GET['invoice'] ) ) {
263
+		if (empty($_GET['form']) && empty($_GET['item']) && empty($_GET['invoice'])) {
264 264
 			echo aui()->alert(
265 265
 				array(
266 266
 					'type'    => 'warning',
267
-					'content' => __( 'No payment form or item provided', 'invoicing' ),
267
+					'content' => __('No payment form or item provided', 'invoicing'),
268 268
 				)
269 269
             );
270 270
             exit;
271 271
         }
272 272
 
273 273
         // Payment form or button?
274
-		if ( ! empty( $_GET['form'] ) ) {
275
-            $form = urldecode( $_GET['form'] );
274
+		if (!empty($_GET['form'])) {
275
+            $form = urldecode($_GET['form']);
276 276
 
277
-            if ( false !== strpos( $form, '|' ) ) {
278
-                $form_pos = strpos( $form, '|' );
279
-                $_items   = getpaid_convert_items_to_array( substr( $form, $form_pos + 1 ) );
280
-                $form     = substr( $form, 0, $form_pos );
277
+            if (false !== strpos($form, '|')) {
278
+                $form_pos = strpos($form, '|');
279
+                $_items   = getpaid_convert_items_to_array(substr($form, $form_pos + 1));
280
+                $form     = substr($form, 0, $form_pos);
281 281
 
282 282
                 // Retrieve appropriate payment form.
283
-                $payment_form = new GetPaid_Payment_Form( $form );
284
-                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form( wpinv_get_default_payment_form() );
283
+                $payment_form = new GetPaid_Payment_Form($form);
284
+                $payment_form = $payment_form->exists() ? $payment_form : new GetPaid_Payment_Form(wpinv_get_default_payment_form());
285 285
 
286 286
                 $items    = array();
287 287
                 $item_ids = array();
288 288
 
289
-                foreach ( $_items as $item_id => $qty ) {
290
-                    if ( ! in_array( $item_id, $item_ids ) ) {
291
-                        $item = new GetPaid_Form_Item( $item_id );
292
-                        $item->set_quantity( $qty );
289
+                foreach ($_items as $item_id => $qty) {
290
+                    if (!in_array($item_id, $item_ids)) {
291
+                        $item = new GetPaid_Form_Item($item_id);
292
+                        $item->set_quantity($qty);
293 293
 
294
-                        if ( 0 == $qty ) {
295
-                            $item->set_allow_quantities( true );
296
-                            $item->set_is_required( false );
294
+                        if (0 == $qty) {
295
+                            $item->set_allow_quantities(true);
296
+                            $item->set_is_required(false);
297 297
                             $getpaid_force_checkbox = true;
298 298
                         }
299 299
 
@@ -302,10 +302,10 @@  discard block
 block discarded – undo
302 302
                     }
303 303
                 }
304 304
 
305
-                if ( ! $payment_form->is_default() ) {
305
+                if (!$payment_form->is_default()) {
306 306
 
307
-                    foreach ( $payment_form->get_items() as $item ) {
308
-                        if ( ! in_array( $item->get_id(), $item_ids ) ) {
307
+                    foreach ($payment_form->get_items() as $item) {
308
+                        if (!in_array($item->get_id(), $item_ids)) {
309 309
                             $item_ids[] = $item->get_id();
310 310
                             $items[]    = $item;
311 311
                         }
@@ -313,23 +313,23 @@  discard block
 block discarded – undo
313 313
 
314 314
                 }
315 315
 
316
-                $payment_form->set_items( $items );
317
-                $extra_items     = esc_attr( getpaid_convert_items_to_string( $_items ) );
318
-                $extra_items_key = md5( NONCE_KEY . AUTH_KEY . $extra_items );
316
+                $payment_form->set_items($items);
317
+                $extra_items     = esc_attr(getpaid_convert_items_to_string($_items));
318
+                $extra_items_key = md5(NONCE_KEY . AUTH_KEY . $extra_items);
319 319
                 $extra_items     = "<input type='hidden' name='getpaid-form-items' value='$extra_items' />";
320 320
                 $extra_items    .= "<input type='hidden' name='getpaid-form-items-key' value='$extra_items_key' />";
321
-                $payment_form->display( $extra_items );
321
+                $payment_form->display($extra_items);
322 322
                 $getpaid_force_checkbox = false;
323 323
 
324 324
             } else {
325
-                getpaid_display_payment_form( $form );
325
+                getpaid_display_payment_form($form);
326 326
             }
327 327
 
328
-		} else if( ! empty( $_GET['invoice'] ) ) {
329
-		    getpaid_display_invoice_payment_form( urldecode( $_GET['invoice'] ) );
328
+		} else if (!empty($_GET['invoice'])) {
329
+		    getpaid_display_invoice_payment_form(urldecode($_GET['invoice']));
330 330
         } else {
331
-			$items = getpaid_convert_items_to_array( urldecode( $_GET['item'] ) );
332
-		    getpaid_display_item_payment_form( $items );
331
+			$items = getpaid_convert_items_to_array(urldecode($_GET['item']));
332
+		    getpaid_display_item_payment_form($items);
333 333
         }
334 334
 
335 335
         exit;
@@ -344,17 +344,17 @@  discard block
 block discarded – undo
344 344
     public static function payment_form() {
345 345
 
346 346
         // Check nonce.
347
-        check_ajax_referer( 'getpaid_form_nonce' );
347
+        check_ajax_referer('getpaid_form_nonce');
348 348
 
349 349
         // ... form fields...
350
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
351
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
350
+        if (empty($_POST['getpaid_payment_form_submission'])) {
351
+            _e('Error: Reload the page and try again.', 'invoicing');
352 352
             exit;
353 353
         }
354 354
 
355 355
         // Process the payment form.
356
-        $checkout_class = apply_filters( 'getpaid_checkout_class', 'GetPaid_Checkout' );
357
-        $checkout       = new $checkout_class( new GetPaid_Payment_Form_Submission() );
356
+        $checkout_class = apply_filters('getpaid_checkout_class', 'GetPaid_Checkout');
357
+        $checkout       = new $checkout_class(new GetPaid_Payment_Form_Submission());
358 358
         $checkout->process_checkout();
359 359
 
360 360
         exit;
@@ -367,55 +367,55 @@  discard block
 block discarded – undo
367 367
      */
368 368
     public static function get_payment_form_states_field() {
369 369
 
370
-        if ( empty( $_GET['country'] ) || empty( $_GET['form'] ) ) {
370
+        if (empty($_GET['country']) || empty($_GET['form'])) {
371 371
             exit;
372 372
         }
373 373
 
374
-        $elements = getpaid_get_payment_form_elements( $_GET['form'] );
374
+        $elements = getpaid_get_payment_form_elements($_GET['form']);
375 375
 
376
-        if ( empty( $elements ) ) {
376
+        if (empty($elements)) {
377 377
             exit;
378 378
         }
379 379
 
380 380
         $address_fields = array();
381
-        foreach ( $elements as $element ) {
382
-            if ( 'address' === $element['type'] ) {
381
+        foreach ($elements as $element) {
382
+            if ('address' === $element['type']) {
383 383
                 $address_fields = $element;
384 384
                 break;
385 385
             }
386 386
         }
387 387
 
388
-        if ( empty( $address_fields ) ) {
388
+        if (empty($address_fields)) {
389 389
             exit;
390 390
         }
391 391
 
392
-        foreach ( $address_fields['fields'] as $address_field ) {
392
+        foreach ($address_fields['fields'] as $address_field) {
393 393
 
394
-            if ( 'wpinv_state' == $address_field['name'] ) {
394
+            if ('wpinv_state' == $address_field['name']) {
395 395
 
396
-                $wrap_class  = getpaid_get_form_element_grid_class( $address_field );
397
-                $wrap_class  = esc_attr( "$wrap_class getpaid-address-field-wrapper" );
398
-                $placeholder = empty( $address_field['placeholder'] ) ? '' : esc_attr( $address_field['placeholder'] );
399
-                $description = empty( $address_field['description'] ) ? '' : wp_kses_post( $address_field['description'] );
400
-                $value       = is_user_logged_in() ? get_user_meta( get_current_user_id(), '_wpinv_state', true ) : '';
401
-                $label       = empty( $address_field['label'] ) ? '' : wp_kses_post( $address_field['label'] );
396
+                $wrap_class  = getpaid_get_form_element_grid_class($address_field);
397
+                $wrap_class  = esc_attr("$wrap_class getpaid-address-field-wrapper");
398
+                $placeholder = empty($address_field['placeholder']) ? '' : esc_attr($address_field['placeholder']);
399
+                $description = empty($address_field['description']) ? '' : wp_kses_post($address_field['description']);
400
+                $value       = is_user_logged_in() ? get_user_meta(get_current_user_id(), '_wpinv_state', true) : '';
401
+                $label       = empty($address_field['label']) ? '' : wp_kses_post($address_field['label']);
402 402
 
403
-                if ( ! empty( $address_field['required'] ) ) {
403
+                if (!empty($address_field['required'])) {
404 404
                     $label .= "<span class='text-danger'> *</span>";
405 405
                 }
406 406
 
407
-                $html = getpaid_get_states_select_markup (
408
-                    sanitize_text_field( $_GET['country'] ),
407
+                $html = getpaid_get_states_select_markup(
408
+                    sanitize_text_field($_GET['country']),
409 409
                     $value,
410 410
                     $placeholder,
411 411
                     $label,
412 412
                     $description,
413
-                    ! empty( $address_field['required'] ),
413
+                    !empty($address_field['required']),
414 414
                     $wrap_class,
415
-                    wpinv_clean( $_GET['name'] )
415
+                    wpinv_clean($_GET['name'])
416 416
                 );
417 417
 
418
-                wp_send_json_success( $html );
418
+                wp_send_json_success($html);
419 419
                 exit;
420 420
 
421 421
             }
@@ -431,66 +431,66 @@  discard block
 block discarded – undo
431 431
     public static function recalculate_invoice_totals() {
432 432
 
433 433
         // Verify nonce.
434
-        check_ajax_referer( 'wpinv-nonce' );
434
+        check_ajax_referer('wpinv-nonce');
435 435
 
436
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
436
+        if (!wpinv_current_user_can_manage_invoicing()) {
437 437
             exit;
438 438
         }
439 439
 
440 440
         // We need an invoice.
441
-        if ( empty( $_POST['post_id'] ) ) {
441
+        if (empty($_POST['post_id'])) {
442 442
             exit;
443 443
         }
444 444
 
445 445
         // Fetch the invoice.
446
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
446
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
447 447
 
448 448
         // Ensure it exists.
449
-        if ( ! $invoice->get_id() ) {
449
+        if (!$invoice->get_id()) {
450 450
             exit;
451 451
         }
452 452
 
453 453
         // Maybe set the country, state, currency.
454
-        foreach ( array( 'country', 'state', 'currency', 'vat_number', 'discount_code' ) as $key ) {
455
-            if ( isset( $_POST[ $key ] ) ) {
454
+        foreach (array('country', 'state', 'currency', 'vat_number', 'discount_code') as $key) {
455
+            if (isset($_POST[$key])) {
456 456
                 $method = "set_$key";
457
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
457
+                $invoice->$method(sanitize_text_field($_POST[$key]));
458 458
             }
459 459
         }
460 460
 
461 461
         // Maybe disable taxes.
462
-        $invoice->set_disable_taxes( ! empty( $_POST['taxes'] ) );
462
+        $invoice->set_disable_taxes(!empty($_POST['taxes']));
463 463
 
464 464
         // Discount code.
465
-        if ( ! $invoice->is_paid() && ! $invoice->is_refunded() ) {
466
-            $discount = new WPInv_Discount( $invoice->get_discount_code() );
467
-            if ( $discount->exists() ) {
468
-                $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
465
+        if (!$invoice->is_paid() && !$invoice->is_refunded()) {
466
+            $discount = new WPInv_Discount($invoice->get_discount_code());
467
+            if ($discount->exists()) {
468
+                $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
469 469
             } else {
470
-                $invoice->remove_discount( 'discount_code' );
470
+                $invoice->remove_discount('discount_code');
471 471
             }
472 472
         }
473 473
 
474 474
         // Recalculate totals.
475 475
         $invoice->recalculate_total();
476 476
 
477
-        $total        = wpinv_price( $invoice->get_total(), $invoice->get_currency() );
478
-        $suscriptions = getpaid_get_invoice_subscriptions( $invoice );
479
-        if ( is_a( $suscriptions, 'WPInv_Subscription' ) && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total() ) {
480
-            $recurring_total = wpinv_price( $invoice->get_recurring_total(), $invoice->get_currency() );
481
-            $total          .= '<small class="form-text text-muted">' . sprintf( __( 'Recurring Price: %s', 'invoicing' ), $recurring_total ) . '</small>';
477
+        $total        = wpinv_price($invoice->get_total(), $invoice->get_currency());
478
+        $suscriptions = getpaid_get_invoice_subscriptions($invoice);
479
+        if (is_a($suscriptions, 'WPInv_Subscription') && $invoice->is_recurring() && $invoice->is_parent() && $invoice->get_total() != $invoice->get_recurring_total()) {
480
+            $recurring_total = wpinv_price($invoice->get_recurring_total(), $invoice->get_currency());
481
+            $total          .= '<small class="form-text text-muted">' . sprintf(__('Recurring Price: %s', 'invoicing'), $recurring_total) . '</small>';
482 482
         }
483 483
 
484 484
         $totals = array(
485
-            'subtotal' => wpinv_price( $invoice->get_subtotal(), $invoice->get_currency() ),
486
-            'discount' => wpinv_price( $invoice->get_total_discount(), $invoice->get_currency() ),
487
-            'tax'      => wpinv_price( $invoice->get_total_tax(), $invoice->get_currency() ),
485
+            'subtotal' => wpinv_price($invoice->get_subtotal(), $invoice->get_currency()),
486
+            'discount' => wpinv_price($invoice->get_total_discount(), $invoice->get_currency()),
487
+            'tax'      => wpinv_price($invoice->get_total_tax(), $invoice->get_currency()),
488 488
             'total'    => $total,
489 489
         );
490 490
 
491
-        $totals = apply_filters( 'getpaid_invoice_totals', $totals, $invoice );
491
+        $totals = apply_filters('getpaid_invoice_totals', $totals, $invoice);
492 492
 
493
-        wp_send_json_success( compact( 'totals' ) );
493
+        wp_send_json_success(compact('totals'));
494 494
     }
495 495
 
496 496
     /**
@@ -499,33 +499,33 @@  discard block
 block discarded – undo
499 499
     public static function get_invoice_items() {
500 500
 
501 501
         // Verify nonce.
502
-        check_ajax_referer( 'wpinv-nonce' );
502
+        check_ajax_referer('wpinv-nonce');
503 503
 
504
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
504
+        if (!wpinv_current_user_can_manage_invoicing()) {
505 505
             exit;
506 506
         }
507 507
 
508 508
         // We need an invoice and items.
509
-        if ( empty( $_POST['post_id'] ) ) {
509
+        if (empty($_POST['post_id'])) {
510 510
             exit;
511 511
         }
512 512
 
513 513
         // Fetch the invoice.
514
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
514
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
515 515
 
516 516
         // Ensure it exists.
517
-        if ( ! $invoice->get_id() ) {
517
+        if (!$invoice->get_id()) {
518 518
             exit;
519 519
         }
520 520
 
521 521
         // Return an array of invoice items.
522 522
         $items = array();
523 523
 
524
-        foreach ( $invoice->get_items() as $item ) {
525
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency(), $invoice->is_renewal()  );
524
+        foreach ($invoice->get_items() as $item) {
525
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency(), $invoice->is_renewal());
526 526
         }
527 527
 
528
-        wp_send_json_success( compact( 'items' ) );
528
+        wp_send_json_success(compact('items'));
529 529
     }
530 530
 
531 531
     /**
@@ -534,50 +534,50 @@  discard block
 block discarded – undo
534 534
     public static function edit_invoice_item() {
535 535
 
536 536
         // Verify nonce.
537
-        check_ajax_referer( 'wpinv-nonce' );
537
+        check_ajax_referer('wpinv-nonce');
538 538
 
539
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
539
+        if (!wpinv_current_user_can_manage_invoicing()) {
540 540
             exit;
541 541
         }
542 542
 
543 543
         // We need an invoice and item details.
544
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['data'] ) ) {
544
+        if (empty($_POST['post_id']) || empty($_POST['data'])) {
545 545
             exit;
546 546
         }
547 547
 
548 548
         // Fetch the invoice.
549
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
549
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
550 550
 
551 551
         // Ensure it exists and its not been paid for.
552
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
552
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
553 553
             exit;
554 554
         }
555 555
 
556 556
         // Format the data.
557
-        $data = wp_kses_post_deep( wp_unslash( wp_list_pluck( $_POST['data'], 'value', 'field' ) ) );
557
+        $data = wp_kses_post_deep(wp_unslash(wp_list_pluck($_POST['data'], 'value', 'field')));
558 558
 
559 559
         // Ensure that we have an item id.
560
-        if ( empty( $data['id'] ) ) {
560
+        if (empty($data['id'])) {
561 561
             exit;
562 562
         }
563 563
 
564 564
         // Abort if the invoice does not have the specified item.
565
-        $item = $invoice->get_item( (int) $data['id'] );
565
+        $item = $invoice->get_item((int) $data['id']);
566 566
 
567
-        if ( empty( $item ) ) {
567
+        if (empty($item)) {
568 568
             exit;
569 569
         }
570 570
 
571 571
         // Update the item.
572
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
573
-        $item->set_name( sanitize_text_field( $data['name'] ) );
574
-        $item->set_description( wp_kses_post( $data['description'] ) );
575
-        $item->set_quantity( floatval( $data['quantity'] ) );
572
+        $item->set_price(getpaid_standardize_amount($data['price']));
573
+        $item->set_name(sanitize_text_field($data['name']));
574
+        $item->set_description(wp_kses_post($data['description']));
575
+        $item->set_quantity(floatval($data['quantity']));
576 576
 
577 577
         // Add it to the invoice.
578
-        $error = $invoice->add_item( $item );
578
+        $error = $invoice->add_item($item);
579 579
         $alert = false;
580
-        if ( is_wp_error( $error ) ) {
580
+        if (is_wp_error($error)) {
581 581
             $alert = $error->get_error_message();
582 582
         }
583 583
 
@@ -590,11 +590,11 @@  discard block
 block discarded – undo
590 590
         // Return an array of invoice items.
591 591
         $items = array();
592 592
 
593
-        foreach ( $invoice->get_items() as $item ) {
594
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
593
+        foreach ($invoice->get_items() as $item) {
594
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
595 595
         }
596 596
 
597
-        wp_send_json_success( compact( 'items', 'alert' ) );
597
+        wp_send_json_success(compact('items', 'alert'));
598 598
     }
599 599
 
600 600
     /**
@@ -603,53 +603,53 @@  discard block
 block discarded – undo
603 603
     public static function create_invoice_item() {
604 604
 
605 605
         // Verify nonce.
606
-        check_ajax_referer( 'wpinv-nonce' );
606
+        check_ajax_referer('wpinv-nonce');
607 607
 
608
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
608
+        if (!wpinv_current_user_can_manage_invoicing()) {
609 609
             exit;
610 610
         }
611 611
 
612 612
         // We need an invoice and item details.
613
-        if ( empty( $_POST['invoice_id'] ) || empty( $_POST['_wpinv_quick'] ) ) {
613
+        if (empty($_POST['invoice_id']) || empty($_POST['_wpinv_quick'])) {
614 614
             exit;
615 615
         }
616 616
 
617 617
         // Fetch the invoice.
618
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['invoice_id'] ) );
618
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['invoice_id']));
619 619
 
620 620
         // Ensure it exists and its not been paid for.
621
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
621
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
622 622
             exit;
623 623
         }
624 624
 
625 625
         // Format the data.
626
-        $data = wp_unslash( $_POST['_wpinv_quick'] );
626
+        $data = wp_unslash($_POST['_wpinv_quick']);
627 627
 
628 628
         $item = new WPInv_Item();
629
-        $item->set_price( getpaid_standardize_amount( $data['price'] ) );
630
-        $item->set_name( sanitize_text_field( $data['name'] ) );
631
-        $item->set_description( wp_kses_post( $data['description'] ) );
632
-        $item->set_type( sanitize_text_field( $data['type'] ) );
633
-        $item->set_vat_rule( sanitize_text_field( $data['vat_rule'] ) );
634
-        $item->set_vat_class( sanitize_text_field( $data['vat_class'] ) );
635
-        $item->set_status( 'publish' );
629
+        $item->set_price(getpaid_standardize_amount($data['price']));
630
+        $item->set_name(sanitize_text_field($data['name']));
631
+        $item->set_description(wp_kses_post($data['description']));
632
+        $item->set_type(sanitize_text_field($data['type']));
633
+        $item->set_vat_rule(sanitize_text_field($data['vat_rule']));
634
+        $item->set_vat_class(sanitize_text_field($data['vat_class']));
635
+        $item->set_status('publish');
636 636
         $item->save();
637 637
 
638
-        if ( ! $item->exists() ) {
639
-            $alert = __( 'Could not create invoice item. Please try again.', 'invoicing' );
640
-            wp_send_json_success( compact( 'alert' ) );
638
+        if (!$item->exists()) {
639
+            $alert = __('Could not create invoice item. Please try again.', 'invoicing');
640
+            wp_send_json_success(compact('alert'));
641 641
         }
642 642
 
643
-        $item = new GetPaid_Form_Item( $item->get_id() );
644
-        $item->set_quantity( floatval( $data['qty'] ) );
643
+        $item = new GetPaid_Form_Item($item->get_id());
644
+        $item->set_quantity(floatval($data['qty']));
645 645
 
646 646
         // Add it to the invoice.
647
-        $error = $invoice->add_item( $item );
647
+        $error = $invoice->add_item($item);
648 648
         $alert = false;
649 649
 
650
-        if ( is_wp_error( $error ) ) {
650
+        if (is_wp_error($error)) {
651 651
             $alert = $error->get_error_message();
652
-            wp_send_json_success( compact( 'alert' ) );
652
+            wp_send_json_success(compact('alert'));
653 653
          }
654 654
 
655 655
         // Update totals.
@@ -662,9 +662,9 @@  discard block
 block discarded – undo
662 662
         $invoice->recalculate_total();
663 663
         $invoice->save();
664 664
         ob_start();
665
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
665
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
666 666
         $row = ob_get_clean();
667
-        wp_send_json_success( compact( 'row' ) );
667
+        wp_send_json_success(compact('row'));
668 668
     }
669 669
 
670 670
     /**
@@ -673,33 +673,33 @@  discard block
 block discarded – undo
673 673
     public static function remove_invoice_item() {
674 674
 
675 675
         // Verify nonce.
676
-        check_ajax_referer( 'wpinv-nonce' );
676
+        check_ajax_referer('wpinv-nonce');
677 677
 
678
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
678
+        if (!wpinv_current_user_can_manage_invoicing()) {
679 679
             exit;
680 680
         }
681 681
 
682 682
         // We need an invoice and an item.
683
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
683
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
684 684
             exit;
685 685
         }
686 686
 
687 687
         // Fetch the invoice.
688
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
688
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
689 689
 
690 690
         // Ensure it exists and its not been paid for.
691
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
691
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
692 692
             exit;
693 693
         }
694 694
 
695 695
         // Abort if the invoice does not have the specified item.
696
-        $item = $invoice->get_item( (int) $_POST['item_id'] );
696
+        $item = $invoice->get_item((int) $_POST['item_id']);
697 697
 
698
-        if ( empty( $item ) ) {
698
+        if (empty($item)) {
699 699
             exit;
700 700
         }
701 701
 
702
-        $invoice->remove_item( (int) $_POST['item_id'] );
702
+        $invoice->remove_item((int) $_POST['item_id']);
703 703
 
704 704
         // Update totals.
705 705
         $invoice->recalculate_total();
@@ -710,11 +710,11 @@  discard block
 block discarded – undo
710 710
         // Return an array of invoice items.
711 711
         $items = array();
712 712
 
713
-        foreach ( $invoice->get_items() as $item ) {
714
-            $items[] = $item->prepare_data_for_invoice_edit_ajax(  $invoice->get_currency()  );
713
+        foreach ($invoice->get_items() as $item) {
714
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
715 715
         }
716 716
 
717
-        wp_send_json_success( compact( 'items' ) );
717
+        wp_send_json_success(compact('items'));
718 718
     }
719 719
 
720 720
     /**
@@ -723,69 +723,69 @@  discard block
 block discarded – undo
723 723
     public static function recalculate_full_prices() {
724 724
 
725 725
         // Verify nonce.
726
-        check_ajax_referer( 'wpinv-nonce' );
726
+        check_ajax_referer('wpinv-nonce');
727 727
 
728
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
728
+        if (!wpinv_current_user_can_manage_invoicing()) {
729 729
             exit;
730 730
         }
731 731
 
732 732
         // We need an invoice and item.
733
-        if ( empty( $_POST['post_id'] ) ) {
733
+        if (empty($_POST['post_id'])) {
734 734
             exit;
735 735
         }
736 736
 
737 737
         // Fetch the invoice.
738
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
738
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
739 739
         $alert   = false;
740 740
 
741 741
         // Ensure it exists and its not been paid for.
742
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
742
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
743 743
             exit;
744 744
         }
745 745
 
746
-        $invoice->set_items( array() );
746
+        $invoice->set_items(array());
747 747
 
748
-        if ( ! empty( $_POST['getpaid_items'] ) ) {
748
+        if (!empty($_POST['getpaid_items'])) {
749 749
 
750
-            foreach ( $_POST['getpaid_items'] as $item_id => $args ) {
751
-                $item = new GetPaid_Form_Item( $item_id );
750
+            foreach ($_POST['getpaid_items'] as $item_id => $args) {
751
+                $item = new GetPaid_Form_Item($item_id);
752 752
 
753
-                if ( $item->exists() ) {
754
-                    $item->set_price( getpaid_standardize_amount( $args['price'] ) );
755
-                    $item->set_quantity( floatval( $args['quantity'] ) );
756
-                    $item->set_name( sanitize_text_field( $args['name'] ) );
757
-                    $item->set_description( wp_kses_post( $args['description'] ) );
758
-                    $invoice->add_item( $item );
753
+                if ($item->exists()) {
754
+                    $item->set_price(getpaid_standardize_amount($args['price']));
755
+                    $item->set_quantity(floatval($args['quantity']));
756
+                    $item->set_name(sanitize_text_field($args['name']));
757
+                    $item->set_description(wp_kses_post($args['description']));
758
+                    $invoice->add_item($item);
759 759
                 }
760 760
             }
761 761
 
762 762
         }
763 763
 
764
-        $invoice->set_disable_taxes( ! empty( $_POST['disable_taxes'] ) );
764
+        $invoice->set_disable_taxes(!empty($_POST['disable_taxes']));
765 765
 
766 766
         // Maybe set the country, state, currency.
767
-        foreach ( array( 'wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code' ) as $key ) {
768
-            if ( isset( $_POST[ $key ] ) ) {
769
-                $_key   = str_replace( 'wpinv_', '', $key );
767
+        foreach (array('wpinv_country', 'wpinv_state', 'wpinv_currency', 'wpinv_vat_number', 'wpinv_discount_code') as $key) {
768
+            if (isset($_POST[$key])) {
769
+                $_key   = str_replace('wpinv_', '', $key);
770 770
                 $method = "set_$_key";
771
-                $invoice->$method( sanitize_text_field( $_POST[ $key ] ) );
771
+                $invoice->$method(sanitize_text_field($_POST[$key]));
772 772
             }
773 773
         }
774 774
 
775
-        $discount = new WPInv_Discount( $invoice->get_discount_code() );
776
-        if ( $discount->exists() ) {
777
-            $invoice->add_discount( getpaid_calculate_invoice_discount( $invoice, $discount ) );
775
+        $discount = new WPInv_Discount($invoice->get_discount_code());
776
+        if ($discount->exists()) {
777
+            $invoice->add_discount(getpaid_calculate_invoice_discount($invoice, $discount));
778 778
         } else {
779
-            $invoice->remove_discount( 'discount_code' );
779
+            $invoice->remove_discount('discount_code');
780 780
         }
781 781
 
782 782
         // Save the invoice.
783 783
         $invoice->recalculate_total();
784 784
         $invoice->save();
785 785
         ob_start();
786
-        GetPaid_Meta_Box_Invoice_Items::output( get_post( $invoice->get_id() ), $invoice );
786
+        GetPaid_Meta_Box_Invoice_Items::output(get_post($invoice->get_id()), $invoice);
787 787
         $table = ob_get_clean();
788
-        wp_send_json_success( compact( 'table' ) );
788
+        wp_send_json_success(compact('table'));
789 789
     }
790 790
 
791 791
     /**
@@ -794,42 +794,42 @@  discard block
 block discarded – undo
794 794
     public static function admin_add_invoice_item() {
795 795
 
796 796
         // Verify nonce.
797
-        check_ajax_referer( 'wpinv-nonce' );
797
+        check_ajax_referer('wpinv-nonce');
798 798
 
799
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
799
+        if (!wpinv_current_user_can_manage_invoicing()) {
800 800
             exit;
801 801
         }
802 802
 
803 803
         // We need an invoice and item.
804
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['item_id'] ) ) {
804
+        if (empty($_POST['post_id']) || empty($_POST['item_id'])) {
805 805
             exit;
806 806
         }
807 807
 
808 808
         // Fetch the invoice.
809
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
809
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
810 810
         $alert   = false;
811 811
 
812 812
         // Ensure it exists and its not been paid for.
813
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
813
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
814 814
             exit;
815 815
         }
816 816
 
817 817
         // Add the item.
818
-        $item  = new GetPaid_Form_Item( (int) $_POST['item_id'] );
819
-        $error = $invoice->add_item( $item );
818
+        $item  = new GetPaid_Form_Item((int) $_POST['item_id']);
819
+        $error = $invoice->add_item($item);
820 820
 
821
-        if ( is_wp_error( $error ) ) {
821
+        if (is_wp_error($error)) {
822 822
             $alert = $error->get_error_message();
823
-            wp_send_json_success( compact( 'alert' ) );
823
+            wp_send_json_success(compact('alert'));
824 824
         }
825 825
 
826 826
         // Save the invoice.
827 827
         $invoice->recalculate_total();
828 828
         $invoice->save();
829 829
         ob_start();
830
-        GetPaid_Meta_Box_Invoice_Items::output_row( GetPaid_Meta_Box_Invoice_Items::get_columns( $invoice ), $item, $invoice );
830
+        GetPaid_Meta_Box_Invoice_Items::output_row(GetPaid_Meta_Box_Invoice_Items::get_columns($invoice), $item, $invoice);
831 831
         $row = ob_get_clean();
832
-        wp_send_json_success( compact( 'row' ) );
832
+        wp_send_json_success(compact('row'));
833 833
     }
834 834
 
835 835
     /**
@@ -838,39 +838,39 @@  discard block
 block discarded – undo
838 838
     public static function add_invoice_items() {
839 839
 
840 840
         // Verify nonce.
841
-        check_ajax_referer( 'wpinv-nonce' );
841
+        check_ajax_referer('wpinv-nonce');
842 842
 
843
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
843
+        if (!wpinv_current_user_can_manage_invoicing()) {
844 844
             exit;
845 845
         }
846 846
 
847 847
         // We need an invoice and items.
848
-        if ( empty( $_POST['post_id'] ) || empty( $_POST['items'] ) ) {
848
+        if (empty($_POST['post_id']) || empty($_POST['items'])) {
849 849
             exit;
850 850
         }
851 851
 
852 852
         // Fetch the invoice.
853
-        $invoice = new WPInv_Invoice( wpinv_clean( $_POST['post_id'] ) );
853
+        $invoice = new WPInv_Invoice(wpinv_clean($_POST['post_id']));
854 854
         $alert   = false;
855 855
 
856 856
         // Ensure it exists and its not been paid for.
857
-        if ( ! $invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded() ) {
857
+        if (!$invoice->get_id() || $invoice->is_paid() || $invoice->is_refunded()) {
858 858
             exit;
859 859
         }
860 860
 
861 861
         // Add the items.
862
-        foreach ( $_POST['items'] as $data ) {
862
+        foreach ($_POST['items'] as $data) {
863 863
 
864
-            $item = new GetPaid_Form_Item( (int) $data[ 'id' ] );
864
+            $item = new GetPaid_Form_Item((int) $data['id']);
865 865
 
866
-            if ( is_numeric( $data[ 'qty' ] ) && (float) $data[ 'qty' ] > 0 ) {
867
-                $item->set_quantity( floatval( $data[ 'qty' ] ) );
866
+            if (is_numeric($data['qty']) && (float) $data['qty'] > 0) {
867
+                $item->set_quantity(floatval($data['qty']));
868 868
             }
869 869
 
870
-            if ( $item->get_id() > 0 ) {
871
-                $error = $invoice->add_item( $item );
870
+            if ($item->get_id() > 0) {
871
+                $error = $invoice->add_item($item);
872 872
 
873
-                if ( is_wp_error( $error ) ) {
873
+                if (is_wp_error($error)) {
874 874
                     $alert = $error->get_error_message();
875 875
                 }
876 876
 
@@ -885,11 +885,11 @@  discard block
 block discarded – undo
885 885
         // Return an array of invoice items.
886 886
         $items = array();
887 887
 
888
-        foreach ( $invoice->get_items() as $item ) {
889
-            $items[] = $item->prepare_data_for_invoice_edit_ajax( $invoice->get_currency() );
888
+        foreach ($invoice->get_items() as $item) {
889
+            $items[] = $item->prepare_data_for_invoice_edit_ajax($invoice->get_currency());
890 890
         }
891 891
 
892
-        wp_send_json_success( compact( 'items', 'alert' ) );
892
+        wp_send_json_success(compact('items', 'alert'));
893 893
     }
894 894
 
895 895
     /**
@@ -898,15 +898,15 @@  discard block
 block discarded – undo
898 898
     public static function get_invoicing_items() {
899 899
 
900 900
         // Verify nonce.
901
-        check_ajax_referer( 'wpinv-nonce' );
901
+        check_ajax_referer('wpinv-nonce');
902 902
 
903
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
903
+        if (!wpinv_current_user_can_manage_invoicing()) {
904 904
             exit;
905 905
         }
906 906
 
907 907
         // We need a search term.
908
-        if ( empty( $_GET['search'] ) ) {
909
-            wp_send_json_success( array() );
908
+        if (empty($_GET['search'])) {
909
+            wp_send_json_success(array());
910 910
         }
911 911
 
912 912
         // Retrieve items.
@@ -915,8 +915,8 @@  discard block
 block discarded – undo
915 915
             'orderby'        => 'title',
916 916
             'order'          => 'ASC',
917 917
             'posts_per_page' => -1,
918
-            'post_status'    => array( 'publish' ),
919
-            's'              => trim( $_GET['search'] ),
918
+            'post_status'    => array('publish'),
919
+            's'              => trim($_GET['search']),
920 920
             'meta_query'     => array(
921 921
                 array(
922 922
                     'key'       => '_wpinv_type',
@@ -926,21 +926,21 @@  discard block
 block discarded – undo
926 926
             )
927 927
         );
928 928
 
929
-        $items = get_posts( apply_filters( 'getpaid_ajax_invoice_items_query_args', $item_args ) );
929
+        $items = get_posts(apply_filters('getpaid_ajax_invoice_items_query_args', $item_args));
930 930
         $data  = array();
931 931
 
932
-        $is_payment_form = ( ! empty( $_GET['post_id'] ) && 'wpi_payment_form' == get_post_type( $_GET['post_id'] ) );
932
+        $is_payment_form = (!empty($_GET['post_id']) && 'wpi_payment_form' == get_post_type($_GET['post_id']));
933 933
 
934
-        foreach ( $items as $item ) {
935
-            $item      = new GetPaid_Form_Item( $item );
934
+        foreach ($items as $item) {
935
+            $item = new GetPaid_Form_Item($item);
936 936
             $data[] = array(
937 937
                 'id'        => (int) $item->get_id(),
938
-                'text'      => strip_tags( $item->get_name() ),
939
-                'form_data' => $is_payment_form ? $item->prepare_data_for_use( false ) : '',
938
+                'text'      => strip_tags($item->get_name()),
939
+                'form_data' => $is_payment_form ? $item->prepare_data_for_use(false) : '',
940 940
             );
941 941
         }
942 942
 
943
-        wp_send_json_success( $data );
943
+        wp_send_json_success($data);
944 944
 
945 945
     }
946 946
 
@@ -950,37 +950,37 @@  discard block
 block discarded – undo
950 950
     public static function get_customers() {
951 951
 
952 952
         // Verify nonce.
953
-        check_ajax_referer( 'wpinv-nonce' );
953
+        check_ajax_referer('wpinv-nonce');
954 954
 
955
-        if ( ! wpinv_current_user_can_manage_invoicing() ) {
955
+        if (!wpinv_current_user_can_manage_invoicing()) {
956 956
             exit;
957 957
         }
958 958
 
959 959
         // We need a search term.
960
-        if ( empty( $_GET['search'] ) ) {
961
-            wp_send_json_success( array() );
960
+        if (empty($_GET['search'])) {
961
+            wp_send_json_success(array());
962 962
         }
963 963
 
964 964
         // Retrieve customers.
965 965
     
966 966
         $customer_args = array(
967
-            'fields'         => array( 'ID', 'user_email', 'display_name' ),
967
+            'fields'         => array('ID', 'user_email', 'display_name'),
968 968
             'orderby'        => 'display_name',
969
-            'search'         => '*' . sanitize_text_field( $_GET['search'] ) . '*',
970
-            'search_columns' => array( 'user_login', 'user_email', 'display_name' ),
969
+            'search'         => '*' . sanitize_text_field($_GET['search']) . '*',
970
+            'search_columns' => array('user_login', 'user_email', 'display_name'),
971 971
         );
972 972
 
973
-        $customers = get_users( apply_filters( 'getpaid_ajax_invoice_customers_query_args', $customer_args ) );
973
+        $customers = get_users(apply_filters('getpaid_ajax_invoice_customers_query_args', $customer_args));
974 974
         $data      = array();
975 975
 
976
-        foreach ( $customers as $customer ) {
976
+        foreach ($customers as $customer) {
977 977
             $data[] = array(
978 978
                 'id'        => (int) $customer->ID,
979
-                'text'      => strip_tags( sprintf( _x( '%1$s (%2$s)', 'user dropdown', 'invoicing' ), $customer->display_name, $customer->user_email ) ),
979
+                'text'      => strip_tags(sprintf(_x('%1$s (%2$s)', 'user dropdown', 'invoicing'), $customer->display_name, $customer->user_email)),
980 980
             );
981 981
         }
982 982
 
983
-        wp_send_json_success( $data );
983
+        wp_send_json_success($data);
984 984
 
985 985
     }
986 986
 
@@ -990,28 +990,28 @@  discard block
 block discarded – undo
990 990
     public static function get_aui_states_field() {
991 991
 
992 992
         // Verify nonce.
993
-        check_ajax_referer( 'wpinv-nonce' );
993
+        check_ajax_referer('wpinv-nonce');
994 994
 
995 995
         // We need a country.
996
-        if ( empty( $_GET['country'] ) ) {
996
+        if (empty($_GET['country'])) {
997 997
             exit;
998 998
         }
999 999
 
1000
-        $states = wpinv_get_country_states( sanitize_text_field( $_GET['country'] ) );
1001
-        $state  = isset( $_GET['state'] ) ? sanitize_text_field( $_GET['state'] ) : wpinv_get_default_state();
1002
-        $name   = isset( $_GET['name'] ) ? sanitize_text_field( $_GET['name'] ) : 'wpinv_state';
1003
-        $class  = isset( $_GET['class'] ) ? sanitize_text_field( $_GET['class'] ) : 'form-control-sm';
1000
+        $states = wpinv_get_country_states(sanitize_text_field($_GET['country']));
1001
+        $state  = isset($_GET['state']) ? sanitize_text_field($_GET['state']) : wpinv_get_default_state();
1002
+        $name   = isset($_GET['name']) ? sanitize_text_field($_GET['name']) : 'wpinv_state';
1003
+        $class  = isset($_GET['class']) ? sanitize_text_field($_GET['class']) : 'form-control-sm';
1004 1004
 
1005
-        if ( empty( $states ) ) {
1005
+        if (empty($states)) {
1006 1006
 
1007 1007
             $html = aui()->input(
1008 1008
                 array(
1009 1009
                     'type'        => 'text',
1010 1010
                     'id'          => 'wpinv_state',
1011 1011
                     'name'        => $name,
1012
-                    'label'       => __( 'State', 'invoicing' ),
1012
+                    'label'       => __('State', 'invoicing'),
1013 1013
                     'label_type'  => 'vertical',
1014
-                    'placeholder' => __( 'State', 'invoicing' ),
1014
+                    'placeholder' => __('State', 'invoicing'),
1015 1015
                     'class'       => $class,
1016 1016
                     'value'       => $state,
1017 1017
                 )
@@ -1023,9 +1023,9 @@  discard block
 block discarded – undo
1023 1023
                 array(
1024 1024
                     'id'          => 'wpinv_state',
1025 1025
                     'name'        => $name,
1026
-                    'label'       => __( 'State', 'invoicing' ),
1026
+                    'label'       => __('State', 'invoicing'),
1027 1027
                     'label_type'  => 'vertical',
1028
-                    'placeholder' => __( 'Select a state', 'invoicing' ),
1028
+                    'placeholder' => __('Select a state', 'invoicing'),
1029 1029
                     'class'       => $class,
1030 1030
                     'value'       => $state,
1031 1031
                     'options'     => $states,
@@ -1039,7 +1039,7 @@  discard block
 block discarded – undo
1039 1039
         wp_send_json_success(
1040 1040
             array(
1041 1041
                 'html'   => $html,
1042
-                'select' => ! empty ( $states )
1042
+                'select' => !empty ($states)
1043 1043
             )
1044 1044
         );
1045 1045
 
@@ -1053,11 +1053,11 @@  discard block
 block discarded – undo
1053 1053
     public static function payment_form_refresh_prices() {
1054 1054
 
1055 1055
         // Check nonce.
1056
-        check_ajax_referer( 'getpaid_form_nonce' );
1056
+        check_ajax_referer('getpaid_form_nonce');
1057 1057
 
1058 1058
         // ... form fields...
1059
-        if ( empty( $_POST['getpaid_payment_form_submission'] ) ) {
1060
-            _e( 'Error: Reload the page and try again.', 'invoicing' );
1059
+        if (empty($_POST['getpaid_payment_form_submission'])) {
1060
+            _e('Error: Reload the page and try again.', 'invoicing');
1061 1061
             exit;
1062 1062
         }
1063 1063
 
@@ -1065,7 +1065,7 @@  discard block
 block discarded – undo
1065 1065
         $submission = new GetPaid_Payment_Form_Submission();
1066 1066
 
1067 1067
         // Do we have an error?
1068
-        if ( ! empty( $submission->last_error ) ) {
1068
+        if (!empty($submission->last_error)) {
1069 1069
             wp_send_json_error(
1070 1070
                 array(
1071 1071
                     'code'  => $submission->last_error_code,
@@ -1075,12 +1075,12 @@  discard block
 block discarded – undo
1075 1075
         }
1076 1076
 
1077 1077
         // Prepare the response.
1078
-        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices( $submission );
1078
+        $response = new GetPaid_Payment_Form_Submission_Refresh_Prices($submission);
1079 1079
 
1080 1080
         // Filter the response.
1081
-        $response = apply_filters( 'getpaid_payment_form_ajax_refresh_prices', $response->response, $submission );
1081
+        $response = apply_filters('getpaid_payment_form_ajax_refresh_prices', $response->response, $submission);
1082 1082
 
1083
-        wp_send_json_success( $response );
1083
+        wp_send_json_success($response);
1084 1084
     }
1085 1085
 
1086 1086
 }
Please login to merge, or discard this patch.
admin/meta-boxes/class-getpaid-meta-box-invoice-shipping-address.php 2 patches
Indentation   +34 added lines, -34 removed lines patch added patch discarded remove patch
@@ -7,7 +7,7 @@  discard block
 block discarded – undo
7 7
  */
8 8
 
9 9
 if ( ! defined( 'ABSPATH' ) ) {
10
-	exit; // Exit if accessed directly
10
+    exit; // Exit if accessed directly
11 11
 }
12 12
 
13 13
 /**
@@ -15,22 +15,22 @@  discard block
 block discarded – undo
15 15
  */
16 16
 class GetPaid_Meta_Box_Invoice_Shipping_Address {
17 17
 
18
-	/**
19
-	 * Output the metabox.
20
-	 *
21
-	 * @param WP_Post $post
22
-	 */
23
-	public static function output( $post ) {
18
+    /**
19
+     * Output the metabox.
20
+     *
21
+     * @param WP_Post $post
22
+     */
23
+    public static function output( $post ) {
24 24
 
25
-		// Retrieve shipping address.
26
-		$shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
25
+        // Retrieve shipping address.
26
+        $shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
27 27
 
28
-		// Abort if it is invalid.
29
-		if ( ! is_array( $shipping_address ) ) {
30
-			return;
31
-		}
28
+        // Abort if it is invalid.
29
+        if ( ! is_array( $shipping_address ) ) {
30
+            return;
31
+        }
32 32
 
33
-		?>
33
+        ?>
34 34
 
35 35
 		<div class="bsui">
36 36
 
@@ -55,31 +55,31 @@  discard block
 block discarded – undo
55 55
 
56 56
 		<?php
57 57
 
58
-	}
58
+    }
59 59
 
60
-	/**
61
-	 * Prepares a value.
62
-	 *
63
-	 * @param array $address
64
-	 * @param string $key
65
-	 * @return string
66
-	 */
67
-	public static function prepare_for_display( $address, $key ) {
60
+    /**
61
+     * Prepares a value.
62
+     *
63
+     * @param array $address
64
+     * @param string $key
65
+     * @return string
66
+     */
67
+    public static function prepare_for_display( $address, $key ) {
68 68
 
69
-		// Prepare the value.
70
-		$value = $address[ $key ];
69
+        // Prepare the value.
70
+        $value = $address[ $key ];
71 71
 
72
-		if ( $key == 'country' ) {
73
-			$value = wpinv_country_name( $value );
74
-		}
72
+        if ( $key == 'country' ) {
73
+            $value = wpinv_country_name( $value );
74
+        }
75 75
 
76
-		if ( $key == 'state' ) {
77
-			$country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country();
78
-			$value = wpinv_state_name( $value, $country );
79
-		}
76
+        if ( $key == 'state' ) {
77
+            $country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country();
78
+            $value = wpinv_state_name( $value, $country );
79
+        }
80 80
 
81
-		return esc_html( $value );
81
+        return esc_html( $value );
82 82
 
83
-	}
83
+    }
84 84
 
85 85
 }
Please login to merge, or discard this patch.
Spacing   +16 added lines, -16 removed lines patch added patch discarded remove patch
@@ -6,7 +6,7 @@  discard block
 block discarded – undo
6 6
  *
7 7
  */
8 8
 
9
-if ( ! defined( 'ABSPATH' ) ) {
9
+if (!defined('ABSPATH')) {
10 10
 	exit; // Exit if accessed directly
11 11
 }
12 12
 
@@ -20,13 +20,13 @@  discard block
 block discarded – undo
20 20
 	 *
21 21
 	 * @param WP_Post $post
22 22
 	 */
23
-	public static function output( $post ) {
23
+	public static function output($post) {
24 24
 
25 25
 		// Retrieve shipping address.
26
-		$shipping_address = get_post_meta( $post->ID, 'shipping_address', true );
26
+		$shipping_address = get_post_meta($post->ID, 'shipping_address', true);
27 27
 
28 28
 		// Abort if it is invalid.
29
-		if ( ! is_array( $shipping_address ) ) {
29
+		if (!is_array($shipping_address)) {
30 30
 			return;
31 31
 		}
32 32
 
@@ -34,16 +34,16 @@  discard block
 block discarded – undo
34 34
 
35 35
 		<div class="bsui">
36 36
 
37
-			<?php foreach ( getpaid_user_address_fields() as $key => $label ) : ?>
37
+			<?php foreach (getpaid_user_address_fields() as $key => $label) : ?>
38 38
 
39
-					<?php if ( ! empty( $shipping_address[ $key ] ) ) : ?>
39
+					<?php if (!empty($shipping_address[$key])) : ?>
40 40
 
41 41
 						<div class="form-group form-row">
42 42
 							<div class="col">
43
-								<span style="font-weight: 600"><?php echo esc_html( $label ); ?>:</span>
43
+								<span style="font-weight: 600"><?php echo esc_html($label); ?>:</span>
44 44
 							</div>
45 45
 							<div class="col">
46
-								<?php echo self::prepare_for_display( $shipping_address, $key ); ?>
46
+								<?php echo self::prepare_for_display($shipping_address, $key); ?>
47 47
 							</div>
48 48
 						</div>
49 49
 
@@ -64,21 +64,21 @@  discard block
 block discarded – undo
64 64
 	 * @param string $key
65 65
 	 * @return string
66 66
 	 */
67
-	public static function prepare_for_display( $address, $key ) {
67
+	public static function prepare_for_display($address, $key) {
68 68
 
69 69
 		// Prepare the value.
70
-		$value = $address[ $key ];
70
+		$value = $address[$key];
71 71
 
72
-		if ( $key == 'country' ) {
73
-			$value = wpinv_country_name( $value );
72
+		if ($key == 'country') {
73
+			$value = wpinv_country_name($value);
74 74
 		}
75 75
 
76
-		if ( $key == 'state' ) {
77
-			$country = isset( $address[ 'country' ] ) ? $address[ 'country' ] : wpinv_get_default_country();
78
-			$value = wpinv_state_name( $value, $country );
76
+		if ($key == 'state') {
77
+			$country = isset($address['country']) ? $address['country'] : wpinv_get_default_country();
78
+			$value = wpinv_state_name($value, $country);
79 79
 		}
80 80
 
81
-		return esc_html( $value );
81
+		return esc_html($value);
82 82
 
83 83
 	}
84 84
 
Please login to merge, or discard this patch.