Passed
Pull Request — master (#388)
by Brian
05:00
created
includes/class-wpinv-item.php 1 patch
Indentation   +622 added lines, -622 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,30 +10,30 @@  discard block
 block discarded – undo
10 10
 class WPInv_Item  extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'item';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'item';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'item';
25 25
 
26 26
     /**
27
-	 * Item Data array. This is the core item data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'parent_id'            => 0,
34
-		'status'               => 'draft',
35
-		'version'              => '',
36
-		'date_created'         => null,
27
+     * Item Data array. This is the core item data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'parent_id'            => 0,
34
+        'status'               => 'draft',
35
+        'version'              => '',
36
+        'date_created'         => null,
37 37
         'date_modified'        => null,
38 38
         'name'                 => '',
39 39
         'description'          => '',
@@ -58,13 +58,13 @@  discard block
 block discarded – undo
58 58
     );
59 59
 
60 60
     /**
61
-	 * Stores meta in cache for future reads.
62
-	 *
63
-	 * A group must be set to to enable caching.
64
-	 *
65
-	 * @var string
66
-	 */
67
-	protected $cache_group = 'getpaid_items';
61
+     * Stores meta in cache for future reads.
62
+     *
63
+     * A group must be set to to enable caching.
64
+     *
65
+     * @var string
66
+     */
67
+    protected $cache_group = 'getpaid_items';
68 68
 
69 69
     /**
70 70
      * Stores a reference to the original WP_Post object
@@ -74,33 +74,33 @@  discard block
 block discarded – undo
74 74
     protected $post = null;
75 75
 
76 76
     /**
77
-	 * Get the item if ID is passed, otherwise the item is new and empty.
78
-	 *
79
-	 * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
-	 */
81
-	public function __construct( $item = 0 ) {
82
-		parent::__construct( $item );
83
-
84
-		if ( is_numeric( $item ) && $item > 0 ) {
85
-			$this->set_id( $item );
86
-		} elseif ( $item instanceof self ) {
87
-			$this->set_id( $item->get_id() );
88
-		} elseif ( ! empty( $item->ID ) ) {
89
-			$this->set_id( $item->ID );
90
-		} else {
91
-			$this->set_object_read( true );
92
-		}
77
+     * Get the item if ID is passed, otherwise the item is new and empty.
78
+     *
79
+     * @param  int|object|WPInv_Item|WP_Post $item Item to read.
80
+     */
81
+    public function __construct( $item = 0 ) {
82
+        parent::__construct( $item );
83
+
84
+        if ( is_numeric( $item ) && $item > 0 ) {
85
+            $this->set_id( $item );
86
+        } elseif ( $item instanceof self ) {
87
+            $this->set_id( $item->get_id() );
88
+        } elseif ( ! empty( $item->ID ) ) {
89
+            $this->set_id( $item->ID );
90
+        } else {
91
+            $this->set_object_read( true );
92
+        }
93 93
 
94 94
         // Load the datastore.
95
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
95
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
96 96
 
97
-		if ( $this->get_id() > 0 ) {
97
+        if ( $this->get_id() > 0 ) {
98 98
             $this->post = get_post( $this->get_id() );
99 99
             $this->ID   = $this->get_id();
100
-			$this->data_store->read( $this );
100
+            $this->data_store->read( $this );
101 101
         }
102 102
 
103
-	}
103
+    }
104 104
 
105 105
     /*
106 106
 	|--------------------------------------------------------------------------
@@ -118,379 +118,379 @@  discard block
 block discarded – undo
118 118
     */
119 119
 
120 120
     /**
121
-	 * Get parent item ID.
122
-	 *
123
-	 * @since 1.0.19
124
-	 * @param  string $context View or edit context.
125
-	 * @return int
126
-	 */
127
-	public function get_parent_id( $context = 'view' ) {
128
-		return (int) $this->get_prop( 'parent_id', $context );
121
+     * Get parent item ID.
122
+     *
123
+     * @since 1.0.19
124
+     * @param  string $context View or edit context.
125
+     * @return int
126
+     */
127
+    public function get_parent_id( $context = 'view' ) {
128
+        return (int) $this->get_prop( 'parent_id', $context );
129 129
     }
130 130
 
131 131
     /**
132
-	 * Get item status.
133
-	 *
134
-	 * @since 1.0.19
135
-	 * @param  string $context View or edit context.
136
-	 * @return string
137
-	 */
138
-	public function get_status( $context = 'view' ) {
139
-		return $this->get_prop( 'status', $context );
132
+     * Get item status.
133
+     *
134
+     * @since 1.0.19
135
+     * @param  string $context View or edit context.
136
+     * @return string
137
+     */
138
+    public function get_status( $context = 'view' ) {
139
+        return $this->get_prop( 'status', $context );
140 140
     }
141 141
 
142 142
     /**
143
-	 * Get plugin version when the item was created.
144
-	 *
145
-	 * @since 1.0.19
146
-	 * @param  string $context View or edit context.
147
-	 * @return string
148
-	 */
149
-	public function get_version( $context = 'view' ) {
150
-		return $this->get_prop( 'version', $context );
143
+     * Get plugin version when the item was created.
144
+     *
145
+     * @since 1.0.19
146
+     * @param  string $context View or edit context.
147
+     * @return string
148
+     */
149
+    public function get_version( $context = 'view' ) {
150
+        return $this->get_prop( 'version', $context );
151 151
     }
152 152
 
153 153
     /**
154
-	 * Get date when the item was created.
155
-	 *
156
-	 * @since 1.0.19
157
-	 * @param  string $context View or edit context.
158
-	 * @return string
159
-	 */
160
-	public function get_date_created( $context = 'view' ) {
161
-		return $this->get_prop( 'date_created', $context );
154
+     * Get date when the item was created.
155
+     *
156
+     * @since 1.0.19
157
+     * @param  string $context View or edit context.
158
+     * @return string
159
+     */
160
+    public function get_date_created( $context = 'view' ) {
161
+        return $this->get_prop( 'date_created', $context );
162 162
     }
163 163
 
164 164
     /**
165
-	 * Get GMT date when the item was created.
166
-	 *
167
-	 * @since 1.0.19
168
-	 * @param  string $context View or edit context.
169
-	 * @return string
170
-	 */
171
-	public function get_date_created_gmt( $context = 'view' ) {
165
+     * Get GMT date when the item was created.
166
+     *
167
+     * @since 1.0.19
168
+     * @param  string $context View or edit context.
169
+     * @return string
170
+     */
171
+    public function get_date_created_gmt( $context = 'view' ) {
172 172
         $date = $this->get_date_created( $context );
173 173
 
174 174
         if ( $date ) {
175 175
             $date = get_gmt_from_date( $date );
176 176
         }
177
-		return $date;
177
+        return $date;
178 178
     }
179 179
 
180 180
     /**
181
-	 * Get date when the item was last modified.
182
-	 *
183
-	 * @since 1.0.19
184
-	 * @param  string $context View or edit context.
185
-	 * @return string
186
-	 */
187
-	public function get_date_modified( $context = 'view' ) {
188
-		return $this->get_prop( 'date_modified', $context );
181
+     * Get date when the item was last modified.
182
+     *
183
+     * @since 1.0.19
184
+     * @param  string $context View or edit context.
185
+     * @return string
186
+     */
187
+    public function get_date_modified( $context = 'view' ) {
188
+        return $this->get_prop( 'date_modified', $context );
189 189
     }
190 190
 
191 191
     /**
192
-	 * Get GMT date when the item was last modified.
193
-	 *
194
-	 * @since 1.0.19
195
-	 * @param  string $context View or edit context.
196
-	 * @return string
197
-	 */
198
-	public function get_date_modified_gmt( $context = 'view' ) {
192
+     * Get GMT date when the item was last modified.
193
+     *
194
+     * @since 1.0.19
195
+     * @param  string $context View or edit context.
196
+     * @return string
197
+     */
198
+    public function get_date_modified_gmt( $context = 'view' ) {
199 199
         $date = $this->get_date_modified( $context );
200 200
 
201 201
         if ( $date ) {
202 202
             $date = get_gmt_from_date( $date );
203 203
         }
204
-		return $date;
204
+        return $date;
205 205
     }
206 206
 
207 207
     /**
208
-	 * Get the item name.
209
-	 *
210
-	 * @since 1.0.19
211
-	 * @param  string $context View or edit context.
212
-	 * @return string
213
-	 */
214
-	public function get_name( $context = 'view' ) {
215
-		return $this->get_prop( 'name', $context );
208
+     * Get the item name.
209
+     *
210
+     * @since 1.0.19
211
+     * @param  string $context View or edit context.
212
+     * @return string
213
+     */
214
+    public function get_name( $context = 'view' ) {
215
+        return $this->get_prop( 'name', $context );
216 216
     }
217 217
 
218 218
     /**
219
-	 * Alias of self::get_name().
220
-	 *
221
-	 * @since 1.0.19
222
-	 * @param  string $context View or edit context.
223
-	 * @return string
224
-	 */
225
-	public function get_title( $context = 'view' ) {
226
-		return $this->get_name( $context );
219
+     * Alias of self::get_name().
220
+     *
221
+     * @since 1.0.19
222
+     * @param  string $context View or edit context.
223
+     * @return string
224
+     */
225
+    public function get_title( $context = 'view' ) {
226
+        return $this->get_name( $context );
227 227
     }
228 228
 
229 229
     /**
230
-	 * Get the item description.
231
-	 *
232
-	 * @since 1.0.19
233
-	 * @param  string $context View or edit context.
234
-	 * @return string
235
-	 */
236
-	public function get_description( $context = 'view' ) {
237
-		return $this->get_prop( 'description', $context );
230
+     * Get the item description.
231
+     *
232
+     * @since 1.0.19
233
+     * @param  string $context View or edit context.
234
+     * @return string
235
+     */
236
+    public function get_description( $context = 'view' ) {
237
+        return $this->get_prop( 'description', $context );
238 238
     }
239 239
 
240 240
     /**
241
-	 * Alias of self::get_description().
242
-	 *
243
-	 * @since 1.0.19
244
-	 * @param  string $context View or edit context.
245
-	 * @return string
246
-	 */
247
-	public function get_excerpt( $context = 'view' ) {
248
-		return $this->get_description( $context );
241
+     * Alias of self::get_description().
242
+     *
243
+     * @since 1.0.19
244
+     * @param  string $context View or edit context.
245
+     * @return string
246
+     */
247
+    public function get_excerpt( $context = 'view' ) {
248
+        return $this->get_description( $context );
249 249
     }
250 250
 
251 251
     /**
252
-	 * Alias of self::get_description().
253
-	 *
254
-	 * @since 1.0.19
255
-	 * @param  string $context View or edit context.
256
-	 * @return string
257
-	 */
258
-	public function get_summary( $context = 'view' ) {
259
-		return $this->get_description( $context );
252
+     * Alias of self::get_description().
253
+     *
254
+     * @since 1.0.19
255
+     * @param  string $context View or edit context.
256
+     * @return string
257
+     */
258
+    public function get_summary( $context = 'view' ) {
259
+        return $this->get_description( $context );
260 260
     }
261 261
 
262 262
     /**
263
-	 * Get the owner of the item.
264
-	 *
265
-	 * @since 1.0.19
266
-	 * @param  string $context View or edit context.
267
-	 * @return string
268
-	 */
269
-	public function get_author( $context = 'view' ) {
270
-		return (int) $this->get_prop( 'author', $context );
263
+     * Get the owner of the item.
264
+     *
265
+     * @since 1.0.19
266
+     * @param  string $context View or edit context.
267
+     * @return string
268
+     */
269
+    public function get_author( $context = 'view' ) {
270
+        return (int) $this->get_prop( 'author', $context );
271 271
     }
272 272
 
273 273
     /**
274
-	 * Get the price of the item.
275
-	 *
276
-	 * @since 1.0.19
277
-	 * @param  string $context View or edit context.
278
-	 * @return float
279
-	 */
280
-	public function get_price( $context = 'view' ) {
274
+     * Get the price of the item.
275
+     *
276
+     * @since 1.0.19
277
+     * @param  string $context View or edit context.
278
+     * @return float
279
+     */
280
+    public function get_price( $context = 'view' ) {
281 281
         return wpinv_sanitize_amount( $this->get_prop( 'price', $context ) );
282
-	}
282
+    }
283 283
 	
284
-	/**
285
-	 * Get the inital price of the item.
286
-	 *
287
-	 * @since 1.0.19
288
-	 * @param  string $context View or edit context.
289
-	 * @return float
290
-	 */
291
-	public function get_initial_price( $context = 'view' ) {
284
+    /**
285
+     * Get the inital price of the item.
286
+     *
287
+     * @since 1.0.19
288
+     * @param  string $context View or edit context.
289
+     * @return float
290
+     */
291
+    public function get_initial_price( $context = 'view' ) {
292 292
 
293
-		$price = (float) $this->get_price( $context );
293
+        $price = (float) $this->get_price( $context );
294 294
 
295
-		if ( $this->has_free_trial() ) {
296
-			$price = 0;
297
-		}
295
+        if ( $this->has_free_trial() ) {
296
+            $price = 0;
297
+        }
298 298
 
299 299
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_initial_item_price', $price, $this ) );
300 300
     }
301 301
 
302 302
     /**
303
-	 * Returns a formated price.
304
-	 *
305
-	 * @since 1.0.19
306
-	 * @param  string $context View or edit context.
307
-	 * @return string
308
-	 */
303
+     * Returns a formated price.
304
+     *
305
+     * @since 1.0.19
306
+     * @param  string $context View or edit context.
307
+     * @return string
308
+     */
309 309
     public function get_the_price() {
310 310
         return wpinv_price( wpinv_format_amount( $this->get_price() ) );
311
-	}
312
-
313
-	/**
314
-	 * Returns the formated initial price.
315
-	 *
316
-	 * @since 1.0.19
317
-	 * @param  string $context View or edit context.
318
-	 * @return string
319
-	 */
311
+    }
312
+
313
+    /**
314
+     * Returns the formated initial price.
315
+     *
316
+     * @since 1.0.19
317
+     * @param  string $context View or edit context.
318
+     * @return string
319
+     */
320 320
     public function get_the_initial_price() {
321 321
         return wpinv_price( wpinv_format_amount( $this->get_initial_price() ) );
322 322
     }
323 323
 
324 324
     /**
325
-	 * Get the VAT rule of the item.
326
-	 *
327
-	 * @since 1.0.19
328
-	 * @param  string $context View or edit context.
329
-	 * @return string
330
-	 */
331
-	public function get_vat_rule( $context = 'view' ) {
325
+     * Get the VAT rule of the item.
326
+     *
327
+     * @since 1.0.19
328
+     * @param  string $context View or edit context.
329
+     * @return string
330
+     */
331
+    public function get_vat_rule( $context = 'view' ) {
332 332
         return $this->get_prop( 'vat_rule', $context );
333 333
     }
334 334
 
335 335
     /**
336
-	 * Get the VAT class of the item.
337
-	 *
338
-	 * @since 1.0.19
339
-	 * @param  string $context View or edit context.
340
-	 * @return string
341
-	 */
342
-	public function get_vat_class( $context = 'view' ) {
336
+     * Get the VAT class of the item.
337
+     *
338
+     * @since 1.0.19
339
+     * @param  string $context View or edit context.
340
+     * @return string
341
+     */
342
+    public function get_vat_class( $context = 'view' ) {
343 343
         return $this->get_prop( 'vat_class', $context );
344 344
     }
345 345
 
346 346
     /**
347
-	 * Get the type of the item.
348
-	 *
349
-	 * @since 1.0.19
350
-	 * @param  string $context View or edit context.
351
-	 * @return string
352
-	 */
353
-	public function get_type( $context = 'view' ) {
347
+     * Get the type of the item.
348
+     *
349
+     * @since 1.0.19
350
+     * @param  string $context View or edit context.
351
+     * @return string
352
+     */
353
+    public function get_type( $context = 'view' ) {
354 354
         return $this->get_prop( 'type', $context );
355 355
     }
356 356
 
357 357
     /**
358
-	 * Get the custom id of the item.
359
-	 *
360
-	 * @since 1.0.19
361
-	 * @param  string $context View or edit context.
362
-	 * @return string
363
-	 */
364
-	public function get_custom_id( $context = 'view' ) {
358
+     * Get the custom id of the item.
359
+     *
360
+     * @since 1.0.19
361
+     * @param  string $context View or edit context.
362
+     * @return string
363
+     */
364
+    public function get_custom_id( $context = 'view' ) {
365 365
         return $this->get_prop( 'custom_id', $context );
366 366
     }
367 367
 
368 368
     /**
369
-	 * Get the custom name of the item.
370
-	 *
371
-	 * @since 1.0.19
372
-	 * @param  string $context View or edit context.
373
-	 * @return string
374
-	 */
375
-	public function get_custom_name( $context = 'view' ) {
369
+     * Get the custom name of the item.
370
+     *
371
+     * @since 1.0.19
372
+     * @param  string $context View or edit context.
373
+     * @return string
374
+     */
375
+    public function get_custom_name( $context = 'view' ) {
376 376
         return $this->get_prop( 'custom_name', $context );
377 377
     }
378 378
 
379 379
     /**
380
-	 * Get the custom singular name of the item.
381
-	 *
382
-	 * @since 1.0.19
383
-	 * @param  string $context View or edit context.
384
-	 * @return string
385
-	 */
386
-	public function get_custom_singular_name( $context = 'view' ) {
380
+     * Get the custom singular name of the item.
381
+     *
382
+     * @since 1.0.19
383
+     * @param  string $context View or edit context.
384
+     * @return string
385
+     */
386
+    public function get_custom_singular_name( $context = 'view' ) {
387 387
         return $this->get_prop( 'custom_singular_name', $context );
388 388
     }
389 389
 
390 390
     /**
391
-	 * Checks if an item is editable..
392
-	 *
393
-	 * @since 1.0.19
394
-	 * @param  string $context View or edit context.
395
-	 * @return int
396
-	 */
397
-	public function get_is_editable( $context = 'view' ) {
391
+     * Checks if an item is editable..
392
+     *
393
+     * @since 1.0.19
394
+     * @param  string $context View or edit context.
395
+     * @return int
396
+     */
397
+    public function get_is_editable( $context = 'view' ) {
398 398
         return (int) $this->get_prop( 'is_editable', $context );
399 399
     }
400 400
 
401 401
     /**
402
-	 * Alias of self::get_is_editable().
403
-	 *
404
-	 * @since 1.0.19
405
-	 * @param  string $context View or edit context.
406
-	 * @return int
407
-	 */
408
-	public function get_editable( $context = 'view' ) {
409
-		return $this->get_is_editable( $context );
402
+     * Alias of self::get_is_editable().
403
+     *
404
+     * @since 1.0.19
405
+     * @param  string $context View or edit context.
406
+     * @return int
407
+     */
408
+    public function get_editable( $context = 'view' ) {
409
+        return $this->get_is_editable( $context );
410 410
     }
411 411
 
412 412
     /**
413
-	 * Checks if dynamic pricing is enabled.
414
-	 *
415
-	 * @since 1.0.19
416
-	 * @param  string $context View or edit context.
417
-	 * @return int
418
-	 */
419
-	public function get_is_dynamic_pricing( $context = 'view' ) {
413
+     * Checks if dynamic pricing is enabled.
414
+     *
415
+     * @since 1.0.19
416
+     * @param  string $context View or edit context.
417
+     * @return int
418
+     */
419
+    public function get_is_dynamic_pricing( $context = 'view' ) {
420 420
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
421 421
     }
422 422
 
423 423
     /**
424
-	 * Returns the minimum price if dynamic pricing is enabled.
425
-	 *
426
-	 * @since 1.0.19
427
-	 * @param  string $context View or edit context.
428
-	 * @return float
429
-	 */
430
-	public function get_minimum_price( $context = 'view' ) {
424
+     * Returns the minimum price if dynamic pricing is enabled.
425
+     *
426
+     * @since 1.0.19
427
+     * @param  string $context View or edit context.
428
+     * @return float
429
+     */
430
+    public function get_minimum_price( $context = 'view' ) {
431 431
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
432 432
     }
433 433
 
434 434
     /**
435
-	 * Checks if this is a recurring item.
436
-	 *
437
-	 * @since 1.0.19
438
-	 * @param  string $context View or edit context.
439
-	 * @return int
440
-	 */
441
-	public function get_is_recurring( $context = 'view' ) {
435
+     * Checks if this is a recurring item.
436
+     *
437
+     * @since 1.0.19
438
+     * @param  string $context View or edit context.
439
+     * @return int
440
+     */
441
+    public function get_is_recurring( $context = 'view' ) {
442 442
         return (int) $this->get_prop( 'is_recurring', $context );
443
-	}
443
+    }
444 444
 	
445
-	/**
446
-	 * Get the recurring price of the item.
447
-	 *
448
-	 * @since 1.0.19
449
-	 * @param  string $context View or edit context.
450
-	 * @return float
451
-	 */
452
-	public function get_recurring_price( $context = 'view' ) {
453
-		$price = $this->get_price( $context );
445
+    /**
446
+     * Get the recurring price of the item.
447
+     *
448
+     * @since 1.0.19
449
+     * @param  string $context View or edit context.
450
+     * @return float
451
+     */
452
+    public function get_recurring_price( $context = 'view' ) {
453
+        $price = $this->get_price( $context );
454 454
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
455
-	}
456
-
457
-	/**
458
-	 * Get the first renewal date (in timestamps) of the item.
459
-	 *
460
-	 * @since 1.0.19
461
-	 * @return int
462
-	 */
463
-	public function get_first_renewal_date() {
464
-
465
-		$periods = array(
466
-			'D' => 'days',
467
-			'W' => 'weeks',
468
-			'M' => 'months',
469
-			'Y' => 'years',
470
-		);
471
-
472
-		$period   = $this->get_recurring_period();
473
-		$interval = $this->get_recurring_interval();
474
-
475
-		if ( $this->has_free_trial() ) {
476
-			$period   = $this->get_trial_period();
477
-			$interval = $this->get_trial_interval();
478
-		}
479
-
480
-		$period       = $periods[ $period ];
481
-		$interval     = empty( $interval ) ? 1 : $interval;
482
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
455
+    }
456
+
457
+    /**
458
+     * Get the first renewal date (in timestamps) of the item.
459
+     *
460
+     * @since 1.0.19
461
+     * @return int
462
+     */
463
+    public function get_first_renewal_date() {
464
+
465
+        $periods = array(
466
+            'D' => 'days',
467
+            'W' => 'weeks',
468
+            'M' => 'months',
469
+            'Y' => 'years',
470
+        );
471
+
472
+        $period   = $this->get_recurring_period();
473
+        $interval = $this->get_recurring_interval();
474
+
475
+        if ( $this->has_free_trial() ) {
476
+            $period   = $this->get_trial_period();
477
+            $interval = $this->get_trial_interval();
478
+        }
479
+
480
+        $period       = $periods[ $period ];
481
+        $interval     = empty( $interval ) ? 1 : $interval;
482
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
483 483
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
484 484
     }
485 485
 
486 486
     /**
487
-	 * Get the recurring period.
488
-	 *
489
-	 * @since 1.0.19
490
-	 * @param  bool $full Return abbreviation or in full.
491
-	 * @return string
492
-	 */
493
-	public function get_recurring_period( $full = false ) {
487
+     * Get the recurring period.
488
+     *
489
+     * @since 1.0.19
490
+     * @param  bool $full Return abbreviation or in full.
491
+     * @return string
492
+     */
493
+    public function get_recurring_period( $full = false ) {
494 494
         $period = $this->get_prop( 'recurring_period', 'view' );
495 495
 
496 496
         if ( $full && ! is_bool( $full ) ) {
@@ -501,63 +501,63 @@  discard block
 block discarded – undo
501 501
     }
502 502
 
503 503
     /**
504
-	 * Get the recurring interval.
505
-	 *
506
-	 * @since 1.0.19
507
-	 * @param  string $context View or edit context.
508
-	 * @return int
509
-	 */
510
-	public function get_recurring_interval( $context = 'view' ) {
511
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
504
+     * Get the recurring interval.
505
+     *
506
+     * @since 1.0.19
507
+     * @param  string $context View or edit context.
508
+     * @return int
509
+     */
510
+    public function get_recurring_interval( $context = 'view' ) {
511
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
512 512
 
513
-		if ( $interval < 1 ) {
514
-			$interval = 1;
515
-		}
513
+        if ( $interval < 1 ) {
514
+            $interval = 1;
515
+        }
516 516
 
517 517
         return $interval;
518 518
     }
519 519
 
520 520
     /**
521
-	 * Get the recurring limit.
522
-	 *
523
-	 * @since 1.0.19
524
-	 * @param  string $context View or edit context.
525
-	 * @return int
526
-	 */
527
-	public function get_recurring_limit( $context = 'view' ) {
521
+     * Get the recurring limit.
522
+     *
523
+     * @since 1.0.19
524
+     * @param  string $context View or edit context.
525
+     * @return int
526
+     */
527
+    public function get_recurring_limit( $context = 'view' ) {
528 528
         return (int) $this->get_prop( 'recurring_limit', $context );
529 529
     }
530 530
 
531 531
     /**
532
-	 * Checks if we have a free trial.
533
-	 *
534
-	 * @since 1.0.19
535
-	 * @param  string $context View or edit context.
536
-	 * @return int
537
-	 */
538
-	public function get_is_free_trial( $context = 'view' ) {
532
+     * Checks if we have a free trial.
533
+     *
534
+     * @since 1.0.19
535
+     * @param  string $context View or edit context.
536
+     * @return int
537
+     */
538
+    public function get_is_free_trial( $context = 'view' ) {
539 539
         return (int) $this->get_prop( 'is_free_trial', $context );
540 540
     }
541 541
 
542 542
     /**
543
-	 * Alias for self::get_is_free_trial().
544
-	 *
545
-	 * @since 1.0.19
546
-	 * @param  string $context View or edit context.
547
-	 * @return int
548
-	 */
549
-	public function get_free_trial( $context = 'view' ) {
543
+     * Alias for self::get_is_free_trial().
544
+     *
545
+     * @since 1.0.19
546
+     * @param  string $context View or edit context.
547
+     * @return int
548
+     */
549
+    public function get_free_trial( $context = 'view' ) {
550 550
         return $this->get_is_free_trial( $context );
551 551
     }
552 552
 
553 553
     /**
554
-	 * Get the trial period.
555
-	 *
556
-	 * @since 1.0.19
557
-	 * @param  bool $full Return abbreviation or in full.
558
-	 * @return string
559
-	 */
560
-	public function get_trial_period( $full = false ) {
554
+     * Get the trial period.
555
+     *
556
+     * @since 1.0.19
557
+     * @param  bool $full Return abbreviation or in full.
558
+     * @return string
559
+     */
560
+    public function get_trial_period( $full = false ) {
561 561
         $period = $this->get_prop( 'trial_period', 'view' );
562 562
 
563 563
         if ( $full && ! is_bool( $full ) ) {
@@ -568,25 +568,25 @@  discard block
 block discarded – undo
568 568
     }
569 569
 
570 570
     /**
571
-	 * Get the trial interval.
572
-	 *
573
-	 * @since 1.0.19
574
-	 * @param  string $context View or edit context.
575
-	 * @return int
576
-	 */
577
-	public function get_trial_interval( $context = 'view' ) {
571
+     * Get the trial interval.
572
+     *
573
+     * @since 1.0.19
574
+     * @param  string $context View or edit context.
575
+     * @return int
576
+     */
577
+    public function get_trial_interval( $context = 'view' ) {
578 578
         return (int) $this->get_prop( 'trial_interval', $context );
579
-	}
579
+    }
580 580
 	
581
-	/**
582
-	 * Get the item's edit url.
583
-	 *
584
-	 * @since 1.0.19
585
-	 * @return string
586
-	 */
587
-	public function get_edit_url() {
581
+    /**
582
+     * Get the item's edit url.
583
+     *
584
+     * @since 1.0.19
585
+     * @return string
586
+     */
587
+    public function get_edit_url() {
588 588
         return get_edit_post_link( $this->get_id() );
589
-	}
589
+    }
590 590
 
591 591
     /**
592 592
      * Margic method for retrieving a property.
@@ -618,52 +618,52 @@  discard block
 block discarded – undo
618 618
     */
619 619
 
620 620
     /**
621
-	 * Set parent order ID.
622
-	 *
623
-	 * @since 1.0.19
624
-	 */
625
-	public function set_parent_id( $value ) {
626
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
627
-			return;
628
-		}
629
-		$this->set_prop( 'parent_id', absint( $value ) );
630
-	}
631
-
632
-    /**
633
-	 * Sets item status.
634
-	 *
635
-	 * @since 1.0.19
636
-	 * @param  string $status New status.
637
-	 * @return array details of change.
638
-	 */
639
-	public function set_status( $status ) {
621
+     * Set parent order ID.
622
+     *
623
+     * @since 1.0.19
624
+     */
625
+    public function set_parent_id( $value ) {
626
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
627
+            return;
628
+        }
629
+        $this->set_prop( 'parent_id', absint( $value ) );
630
+    }
631
+
632
+    /**
633
+     * Sets item status.
634
+     *
635
+     * @since 1.0.19
636
+     * @param  string $status New status.
637
+     * @return array details of change.
638
+     */
639
+    public function set_status( $status ) {
640 640
         $old_status = $this->get_status();
641 641
 
642 642
         $this->set_prop( 'status', $status );
643 643
 
644
-		return array(
645
-			'from' => $old_status,
646
-			'to'   => $status,
647
-		);
644
+        return array(
645
+            'from' => $old_status,
646
+            'to'   => $status,
647
+        );
648 648
     }
649 649
 
650 650
     /**
651
-	 * Set plugin version when the item was created.
652
-	 *
653
-	 * @since 1.0.19
654
-	 */
655
-	public function set_version( $value ) {
656
-		$this->set_prop( 'version', $value );
651
+     * Set plugin version when the item was created.
652
+     *
653
+     * @since 1.0.19
654
+     */
655
+    public function set_version( $value ) {
656
+        $this->set_prop( 'version', $value );
657 657
     }
658 658
 
659 659
     /**
660
-	 * Set date when the item was created.
661
-	 *
662
-	 * @since 1.0.19
663
-	 * @param string $value Value to set.
660
+     * Set date when the item was created.
661
+     *
662
+     * @since 1.0.19
663
+     * @param string $value Value to set.
664 664
      * @return bool Whether or not the date was set.
665
-	 */
666
-	public function set_date_created( $value ) {
665
+     */
666
+    public function set_date_created( $value ) {
667 667
         $date = strtotime( $value );
668 668
 
669 669
         if ( $date ) {
@@ -676,13 +676,13 @@  discard block
 block discarded – undo
676 676
     }
677 677
 
678 678
     /**
679
-	 * Set date when the item was last modified.
680
-	 *
681
-	 * @since 1.0.19
682
-	 * @param string $value Value to set.
679
+     * Set date when the item was last modified.
680
+     *
681
+     * @since 1.0.19
682
+     * @param string $value Value to set.
683 683
      * @return bool Whether or not the date was set.
684
-	 */
685
-	public function set_date_modified( $value ) {
684
+     */
685
+    public function set_date_modified( $value ) {
686 686
         $date = strtotime( $value );
687 687
 
688 688
         if ( $date ) {
@@ -695,105 +695,105 @@  discard block
 block discarded – undo
695 695
     }
696 696
 
697 697
     /**
698
-	 * Set the item name.
699
-	 *
700
-	 * @since 1.0.19
701
-	 * @param  string $value New name.
702
-	 */
703
-	public function set_name( $value ) {
698
+     * Set the item name.
699
+     *
700
+     * @since 1.0.19
701
+     * @param  string $value New name.
702
+     */
703
+    public function set_name( $value ) {
704 704
         $name = sanitize_text_field( $value );
705
-		$this->set_prop( 'name', $name );
705
+        $this->set_prop( 'name', $name );
706 706
     }
707 707
 
708 708
     /**
709
-	 * Alias of self::set_name().
710
-	 *
711
-	 * @since 1.0.19
712
-	 * @param  string $value New name.
713
-	 */
714
-	public function set_title( $value ) {
715
-		$this->set_name( $value );
709
+     * Alias of self::set_name().
710
+     *
711
+     * @since 1.0.19
712
+     * @param  string $value New name.
713
+     */
714
+    public function set_title( $value ) {
715
+        $this->set_name( $value );
716 716
     }
717 717
 
718 718
     /**
719
-	 * Set the item description.
720
-	 *
721
-	 * @since 1.0.19
722
-	 * @param  string $value New description.
723
-	 */
724
-	public function set_description( $value ) {
719
+     * Set the item description.
720
+     *
721
+     * @since 1.0.19
722
+     * @param  string $value New description.
723
+     */
724
+    public function set_description( $value ) {
725 725
         $description = wp_kses_post( $value );
726
-		return $this->set_prop( 'description', $description );
726
+        return $this->set_prop( 'description', $description );
727 727
     }
728 728
 
729 729
     /**
730
-	 * Alias of self::set_description().
731
-	 *
732
-	 * @since 1.0.19
733
-	 * @param  string $value New description.
734
-	 */
735
-	public function set_excerpt( $value ) {
736
-		$this->set_description( $value );
730
+     * Alias of self::set_description().
731
+     *
732
+     * @since 1.0.19
733
+     * @param  string $value New description.
734
+     */
735
+    public function set_excerpt( $value ) {
736
+        $this->set_description( $value );
737 737
     }
738 738
 
739 739
     /**
740
-	 * Alias of self::set_description().
741
-	 *
742
-	 * @since 1.0.19
743
-	 * @param  string $value New description.
744
-	 */
745
-	public function set_summary( $value ) {
746
-		$this->set_description( $value );
740
+     * Alias of self::set_description().
741
+     *
742
+     * @since 1.0.19
743
+     * @param  string $value New description.
744
+     */
745
+    public function set_summary( $value ) {
746
+        $this->set_description( $value );
747 747
     }
748 748
 
749 749
     /**
750
-	 * Set the owner of the item.
751
-	 *
752
-	 * @since 1.0.19
753
-	 * @param  int $value New author.
754
-	 */
755
-	public function set_author( $value ) {
756
-		$this->set_prop( 'author', (int) $value );
750
+     * Set the owner of the item.
751
+     *
752
+     * @since 1.0.19
753
+     * @param  int $value New author.
754
+     */
755
+    public function set_author( $value ) {
756
+        $this->set_prop( 'author', (int) $value );
757 757
     }
758 758
 
759 759
     /**
760
-	 * Set the price of the item.
761
-	 *
762
-	 * @since 1.0.19
763
-	 * @param  float $value New price.
764
-	 */
765
-	public function set_price( $value ) {
760
+     * Set the price of the item.
761
+     *
762
+     * @since 1.0.19
763
+     * @param  float $value New price.
764
+     */
765
+    public function set_price( $value ) {
766 766
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
767 767
     }
768 768
 
769 769
     /**
770
-	 * Set the VAT rule of the item.
771
-	 *
772
-	 * @since 1.0.19
773
-	 * @param  string $value new rule.
774
-	 */
775
-	public function set_vat_rule( $value ) {
770
+     * Set the VAT rule of the item.
771
+     *
772
+     * @since 1.0.19
773
+     * @param  string $value new rule.
774
+     */
775
+    public function set_vat_rule( $value ) {
776 776
         $this->set_prop( 'vat_rule', $value );
777 777
     }
778 778
 
779 779
     /**
780
-	 * Set the VAT class of the item.
781
-	 *
782
-	 * @since 1.0.19
783
-	 * @param  string $value new class.
784
-	 */
785
-	public function set_vat_class( $value ) {
780
+     * Set the VAT class of the item.
781
+     *
782
+     * @since 1.0.19
783
+     * @param  string $value new class.
784
+     */
785
+    public function set_vat_class( $value ) {
786 786
         $this->set_prop( 'vat_class', $value );
787 787
     }
788 788
 
789 789
     /**
790
-	 * Set the type of the item.
791
-	 *
792
-	 * @since 1.0.19
793
-	 * @param  string $value new item type.
794
-	 * @return string
795
-	 */
796
-	public function set_type( $value ) {
790
+     * Set the type of the item.
791
+     *
792
+     * @since 1.0.19
793
+     * @param  string $value new item type.
794
+     * @return string
795
+     */
796
+    public function set_type( $value ) {
797 797
 
798 798
         if ( empty( $value ) ) {
799 799
             $value = 'custom';
@@ -803,134 +803,134 @@  discard block
 block discarded – undo
803 803
     }
804 804
 
805 805
     /**
806
-	 * Set the custom id of the item.
807
-	 *
808
-	 * @since 1.0.19
809
-	 * @param  string $value new custom id.
810
-	 */
811
-	public function set_custom_id( $value ) {
806
+     * Set the custom id of the item.
807
+     *
808
+     * @since 1.0.19
809
+     * @param  string $value new custom id.
810
+     */
811
+    public function set_custom_id( $value ) {
812 812
         $this->set_prop( 'custom_id', $value );
813 813
     }
814 814
 
815 815
     /**
816
-	 * Set the custom name of the item.
817
-	 *
818
-	 * @since 1.0.19
819
-	 * @param  string $value new custom name.
820
-	 */
821
-	public function set_custom_name( $value ) {
816
+     * Set the custom name of the item.
817
+     *
818
+     * @since 1.0.19
819
+     * @param  string $value new custom name.
820
+     */
821
+    public function set_custom_name( $value ) {
822 822
         $this->set_prop( 'custom_name', $value );
823 823
     }
824 824
 
825 825
     /**
826
-	 * Set the custom singular name of the item.
827
-	 *
828
-	 * @since 1.0.19
829
-	 * @param  string $value new custom singular name.
830
-	 */
831
-	public function set_custom_singular_name( $value ) {
826
+     * Set the custom singular name of the item.
827
+     *
828
+     * @since 1.0.19
829
+     * @param  string $value new custom singular name.
830
+     */
831
+    public function set_custom_singular_name( $value ) {
832 832
         $this->set_prop( 'custom_singular_name', $value );
833 833
     }
834 834
 
835 835
     /**
836
-	 * Sets if an item is editable..
837
-	 *
838
-	 * @since 1.0.19
839
-	 * @param  int|bool $value whether or not the item is editable.
840
-	 */
841
-	public function set_is_editable( $value ) {
842
-		if ( is_numeric( $value ) ) {
843
-			$this->set_prop( 'is_editable', (int) $value );
844
-		}
836
+     * Sets if an item is editable..
837
+     *
838
+     * @since 1.0.19
839
+     * @param  int|bool $value whether or not the item is editable.
840
+     */
841
+    public function set_is_editable( $value ) {
842
+        if ( is_numeric( $value ) ) {
843
+            $this->set_prop( 'is_editable', (int) $value );
844
+        }
845 845
     }
846 846
 
847 847
     /**
848
-	 * Sets if dynamic pricing is enabled.
849
-	 *
850
-	 * @since 1.0.19
851
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
852
-	 */
853
-	public function set_is_dynamic_pricing( $value ) {
848
+     * Sets if dynamic pricing is enabled.
849
+     *
850
+     * @since 1.0.19
851
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
852
+     */
853
+    public function set_is_dynamic_pricing( $value ) {
854 854
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
855 855
     }
856 856
 
857 857
     /**
858
-	 * Sets the minimum price if dynamic pricing is enabled.
859
-	 *
860
-	 * @since 1.0.19
861
-	 * @param  float $value minimum price.
862
-	 */
863
-	public function set_minimum_price( $value ) {
858
+     * Sets the minimum price if dynamic pricing is enabled.
859
+     *
860
+     * @since 1.0.19
861
+     * @param  float $value minimum price.
862
+     */
863
+    public function set_minimum_price( $value ) {
864 864
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
865 865
     }
866 866
 
867 867
     /**
868
-	 * Sets if this is a recurring item.
869
-	 *
870
-	 * @since 1.0.19
871
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
872
-	 */
873
-	public function set_is_recurring( $value ) {
868
+     * Sets if this is a recurring item.
869
+     *
870
+     * @since 1.0.19
871
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
872
+     */
873
+    public function set_is_recurring( $value ) {
874 874
         $this->set_prop( 'is_recurring', (int) $value );
875 875
     }
876 876
 
877 877
     /**
878
-	 * Set the recurring period.
879
-	 *
880
-	 * @since 1.0.19
881
-	 * @param  string $value new period.
882
-	 */
883
-	public function set_recurring_period( $value ) {
878
+     * Set the recurring period.
879
+     *
880
+     * @since 1.0.19
881
+     * @param  string $value new period.
882
+     */
883
+    public function set_recurring_period( $value ) {
884 884
         $this->set_prop( 'recurring_period', $value );
885 885
     }
886 886
 
887 887
     /**
888
-	 * Set the recurring interval.
889
-	 *
890
-	 * @since 1.0.19
891
-	 * @param  int $value recurring interval.
892
-	 */
893
-	public function set_recurring_interval( $value ) {
888
+     * Set the recurring interval.
889
+     *
890
+     * @since 1.0.19
891
+     * @param  int $value recurring interval.
892
+     */
893
+    public function set_recurring_interval( $value ) {
894 894
         return $this->set_prop( 'recurring_interval', (int) $value );
895 895
     }
896 896
 
897 897
     /**
898
-	 * Get the recurring limit.
899
-	 * @since 1.0.19
900
-	 * @param  int $value The recurring limit.
901
-	 * @return int
902
-	 */
903
-	public function set_recurring_limit( $value ) {
898
+     * Get the recurring limit.
899
+     * @since 1.0.19
900
+     * @param  int $value The recurring limit.
901
+     * @return int
902
+     */
903
+    public function set_recurring_limit( $value ) {
904 904
         $this->set_prop( 'recurring_limit', (int) $value );
905 905
     }
906 906
 
907 907
     /**
908
-	 * Checks if we have a free trial.
909
-	 *
910
-	 * @since 1.0.19
911
-	 * @param  int|bool $value whether or not it has a free trial.
912
-	 */
913
-	public function set_is_free_trial( $value ) {
908
+     * Checks if we have a free trial.
909
+     *
910
+     * @since 1.0.19
911
+     * @param  int|bool $value whether or not it has a free trial.
912
+     */
913
+    public function set_is_free_trial( $value ) {
914 914
         $this->set_prop( 'is_free_trial', (int) $value );
915 915
     }
916 916
 
917 917
     /**
918
-	 * Set the trial period.
919
-	 *
920
-	 * @since 1.0.19
921
-	 * @param  string $value trial period.
922
-	 */
923
-	public function set_trial_period( $value ) {
918
+     * Set the trial period.
919
+     *
920
+     * @since 1.0.19
921
+     * @param  string $value trial period.
922
+     */
923
+    public function set_trial_period( $value ) {
924 924
         $this->set_prop( 'trial_period', $value );
925 925
     }
926 926
 
927 927
     /**
928
-	 * Set the trial interval.
929
-	 *
930
-	 * @since 1.0.19
931
-	 * @param  int $value trial interval.
932
-	 */
933
-	public function set_trial_interval( $value ) {
928
+     * Set the trial interval.
929
+     *
930
+     * @since 1.0.19
931
+     * @param  int $value trial interval.
932
+     */
933
+    public function set_trial_interval( $value ) {
934 934
         $this->set_prop( 'trial_interval', $value );
935 935
     }
936 936
 
@@ -938,17 +938,17 @@  discard block
 block discarded – undo
938 938
      * Create an item. For backwards compatibilty.
939 939
      * 
940 940
      * @deprecated
941
-	 * @return int item id
941
+     * @return int item id
942 942
      */
943 943
     public function create( $data = array() ) {
944 944
 
945
-		// Set the properties.
946
-		if ( is_array( $data ) ) {
947
-			$this->set_props( $data );
948
-		}
945
+        // Set the properties.
946
+        if ( is_array( $data ) ) {
947
+            $this->set_props( $data );
948
+        }
949 949
 
950
-		// Save the item.
951
-		return $this->save();
950
+        // Save the item.
951
+        return $this->save();
952 952
 
953 953
     }
954 954
 
@@ -956,7 +956,7 @@  discard block
 block discarded – undo
956 956
      * Updates an item. For backwards compatibilty.
957 957
      * 
958 958
      * @deprecated
959
-	 * @return int item id
959
+     * @return int item id
960 960
      */
961 961
     public function update( $data = array() ) {
962 962
         return $this->create( $data );
@@ -972,84 +972,84 @@  discard block
 block discarded – undo
972 972
 	*/
973 973
 
974 974
     /**
975
-	 * Checks whether the item has enabled dynamic pricing.
976
-	 *
977
-	 * @since 1.0.19
978
-	 * @return bool
979
-	 */
980
-	public function user_can_set_their_price() {
975
+     * Checks whether the item has enabled dynamic pricing.
976
+     *
977
+     * @since 1.0.19
978
+     * @return bool
979
+     */
980
+    public function user_can_set_their_price() {
981 981
         return (bool) $this->get_is_dynamic_pricing();
982
-	}
982
+    }
983 983
 	
984
-	/**
985
-	 * Checks whether the item is recurring.
986
-	 *
987
-	 * @since 1.0.19
988
-	 * @return bool
989
-	 */
990
-	public function is_recurring() {
984
+    /**
985
+     * Checks whether the item is recurring.
986
+     *
987
+     * @since 1.0.19
988
+     * @return bool
989
+     */
990
+    public function is_recurring() {
991 991
         return (bool) $this->get_is_recurring();
992 992
     }
993 993
 
994 994
     /**
995
-	 * Checks whether the item has a free trial.
996
-	 *
997
-	 * @since 1.0.19
998
-	 * @return bool
999
-	 */
995
+     * Checks whether the item has a free trial.
996
+     *
997
+     * @since 1.0.19
998
+     * @return bool
999
+     */
1000 1000
     public function has_free_trial() {
1001 1001
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
1002 1002
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
1003 1003
     }
1004 1004
 
1005 1005
     /**
1006
-	 * Checks whether the item is free.
1007
-	 *
1008
-	 * @since 1.0.19
1009
-	 * @return bool
1010
-	 */
1006
+     * Checks whether the item is free.
1007
+     *
1008
+     * @since 1.0.19
1009
+     * @return bool
1010
+     */
1011 1011
     public function is_free() {
1012 1012
         $is_free   = $this->get_price() == 0;
1013 1013
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
1014 1014
     }
1015 1015
 
1016 1016
     /**
1017
-	 * Checks the item status against a passed in status.
1018
-	 *
1019
-	 * @param array|string $status Status to check.
1020
-	 * @return bool
1021
-	 */
1022
-	public function has_status( $status ) {
1023
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1024
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1017
+     * Checks the item status against a passed in status.
1018
+     *
1019
+     * @param array|string $status Status to check.
1020
+     * @return bool
1021
+     */
1022
+    public function has_status( $status ) {
1023
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1024
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1025 1025
     }
1026 1026
 
1027 1027
     /**
1028
-	 * Checks the item type against a passed in types.
1029
-	 *
1030
-	 * @param array|string $type Type to check.
1031
-	 * @return bool
1032
-	 */
1033
-	public function is_type( $type ) {
1034
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1035
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1036
-	}
1028
+     * Checks the item type against a passed in types.
1029
+     *
1030
+     * @param array|string $type Type to check.
1031
+     * @return bool
1032
+     */
1033
+    public function is_type( $type ) {
1034
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1035
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1036
+    }
1037 1037
 
1038 1038
     /**
1039
-	 * Checks whether the item is editable.
1040
-	 *
1041
-	 * @since 1.0.19
1042
-	 * @return bool
1043
-	 */
1039
+     * Checks whether the item is editable.
1040
+     *
1041
+     * @since 1.0.19
1042
+     * @return bool
1043
+     */
1044 1044
     public function is_editable() {
1045 1045
         $is_editable = $this->get_is_editable();
1046 1046
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1047
-	}
1047
+    }
1048 1048
 
1049
-	/**
1050
-	 * Returns an array of cart fees.
1051
-	 */
1052
-	public function get_fees( $type = 'fee', $item_id = 0 ) {
1049
+    /**
1050
+     * Returns an array of cart fees.
1051
+     */
1052
+    public function get_fees( $type = 'fee', $item_id = 0 ) {
1053 1053
         global $wpi_session;
1054 1054
         
1055 1055
         $fees = $wpi_session->get( 'wpi_cart_fees' );
@@ -1093,11 +1093,11 @@  discard block
 block discarded – undo
1093 1093
     }
1094 1094
 
1095 1095
     /**
1096
-	 * Checks whether the item is purchasable.
1097
-	 *
1098
-	 * @since 1.0.19
1099
-	 * @return bool
1100
-	 */
1096
+     * Checks whether the item is purchasable.
1097
+     *
1098
+     * @since 1.0.19
1099
+     * @return bool
1100
+     */
1101 1101
     public function can_purchase() {
1102 1102
         $can_purchase = null !== $this->get_id();
1103 1103
 
@@ -1109,11 +1109,11 @@  discard block
 block discarded – undo
1109 1109
     }
1110 1110
 
1111 1111
     /**
1112
-	 * Checks whether the item supports dynamic pricing.
1113
-	 *
1114
-	 * @since 1.0.19
1115
-	 * @return bool
1116
-	 */
1112
+     * Checks whether the item supports dynamic pricing.
1113
+     *
1114
+     * @since 1.0.19
1115
+     * @return bool
1116
+     */
1117 1117
     public function supports_dynamic_pricing() {
1118 1118
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1119 1119
     }
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-paypal-gateway.php 1 patch
Indentation   +331 added lines, -331 removed lines patch added patch discarded remove patch
@@ -13,72 +13,72 @@  discard block
 block discarded – undo
13 13
 class GetPaid_Paypal_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 = 'paypal';
21 21
 
22 22
     /**
23
-	 * An array of features that this gateway supports.
24
-	 *
25
-	 * @var array
26
-	 */
23
+     * An array of features that this gateway supports.
24
+     *
25
+     * @var array
26
+     */
27 27
     protected $supports = array( 'subscription', 'sandbox' );
28 28
 
29 29
     /**
30
-	 * Payment method order.
31
-	 *
32
-	 * @var int
33
-	 */
30
+     * Payment method order.
31
+     *
32
+     * @var int
33
+     */
34 34
     public $order = 1;
35 35
 
36 36
     /**
37
-	 * Stores line items to send to PayPal.
38
-	 *
39
-	 * @var array
40
-	 */
37
+     * Stores line items to send to PayPal.
38
+     *
39
+     * @var array
40
+     */
41 41
     protected $line_items = array();
42 42
 
43 43
     /**
44
-	 * Endpoint for requests from PayPal.
45
-	 *
46
-	 * @var string
47
-	 */
48
-	protected $notify_url;
44
+     * Endpoint for requests from PayPal.
45
+     *
46
+     * @var string
47
+     */
48
+    protected $notify_url;
49 49
 
50
-	/**
51
-	 * Endpoint for requests to PayPal.
52
-	 *
53
-	 * @var string
54
-	 */
50
+    /**
51
+     * Endpoint for requests to PayPal.
52
+     *
53
+     * @var string
54
+     */
55 55
     protected $endpoint;
56 56
     
57 57
     /**
58
-	 * Currencies this gateway is allowed for.
59
-	 *
60
-	 * @var array
61
-	 */
62
-	public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
58
+     * Currencies this gateway is allowed for.
59
+     *
60
+     * @var array
61
+     */
62
+    public $currencies = array( 'AUD', 'BRL', 'CAD', 'MXN', 'NZD', 'HKD', 'SGD', 'USD', 'EUR', 'JPY', 'TRY', 'NOK', 'CZK', 'DKK', 'HUF', 'ILS', 'MYR', 'PHP', 'PLN', 'SEK', 'CHF', 'TWD', 'THB', 'GBP', 'RMB', 'RUB', 'INR' );
63 63
 
64 64
     /**
65
-	 * URL to view a transaction.
66
-	 *
67
-	 * @var string
68
-	 */
65
+     * URL to view a transaction.
66
+     *
67
+     * @var string
68
+     */
69 69
     public $view_transaction_url = 'https://www.{sandbox}paypal.com/activity/payment/%s';
70 70
 
71 71
     /**
72
-	 * URL to view a subscription.
73
-	 *
74
-	 * @var string
75
-	 */
76
-	public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
72
+     * URL to view a subscription.
73
+     *
74
+     * @var string
75
+     */
76
+    public $view_subscription_url = 'https://www.{sandbox}paypal.com/cgi-bin/webscr?cmd=_profile-recurring-payments&encrypted_profile_id=%s';
77 77
 
78 78
     /**
79
-	 * Class constructor.
80
-	 */
81
-	public function __construct() {
79
+     * Class constructor.
80
+     */
81
+    public function __construct() {
82 82
 
83 83
         $this->title             = __( 'PayPal Standard', 'invoicing' );
84 84
         $this->method_title      = __( 'PayPal Standard', 'invoicing' );
@@ -92,15 +92,15 @@  discard block
 block discarded – undo
92 92
     }
93 93
 
94 94
     /**
95
-	 * Process Payment.
96
-	 *
97
-	 *
98
-	 * @param WPInv_Invoice $invoice Invoice.
99
-	 * @param array $submission_data Posted checkout fields.
100
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
101
-	 * @return array
102
-	 */
103
-	public function process_payment( $invoice, $submission_data, $submission ) {
95
+     * Process Payment.
96
+     *
97
+     *
98
+     * @param WPInv_Invoice $invoice Invoice.
99
+     * @param array $submission_data Posted checkout fields.
100
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
101
+     * @return array
102
+     */
103
+    public function process_payment( $invoice, $submission_data, $submission ) {
104 104
 
105 105
         // Get redirect url.
106 106
         $paypal_redirect = $this->get_request_url( $invoice );
@@ -123,15 +123,15 @@  discard block
 block discarded – undo
123 123
     }
124 124
 
125 125
     /**
126
-	 * Get the PayPal request URL for an invoice.
127
-	 *
128
-	 * @param  WPInv_Invoice $invoice Invoice object.
129
-	 * @return string
130
-	 */
131
-	public function get_request_url( $invoice ) {
126
+     * Get the PayPal request URL for an invoice.
127
+     *
128
+     * @param  WPInv_Invoice $invoice Invoice object.
129
+     * @return string
130
+     */
131
+    public function get_request_url( $invoice ) {
132 132
 
133 133
         // Endpoint for this request
134
-		$this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
134
+        $this->endpoint    = $this->is_sandbox( $invoice ) ? 'https://www.sandbox.paypal.com/cgi-bin/webscr?test_ipn=1&' : 'https://www.paypal.com/cgi-bin/webscr?';
135 135
 
136 136
         // Retrieve paypal args.
137 137
         $paypal_args       = map_deep( $this->get_paypal_args( $invoice ), 'urlencode' );
@@ -144,44 +144,44 @@  discard block
 block discarded – undo
144 144
 
145 145
         return add_query_arg( $paypal_args, $this->endpoint );
146 146
 
147
-	}
147
+    }
148 148
 
149 149
     /**
150
-	 * Get PayPal Args for passing to PP.
151
-	 *
152
-	 * @param  WPInv_Invoice $invoice Invoice object.
153
-	 * @return array
154
-	 */
155
-	protected function get_paypal_args( $invoice ) {
150
+     * Get PayPal Args for passing to PP.
151
+     *
152
+     * @param  WPInv_Invoice $invoice Invoice object.
153
+     * @return array
154
+     */
155
+    protected function get_paypal_args( $invoice ) {
156 156
 
157 157
         // Whether or not to send the line items as one item.
158
-		$force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice );
159
-
160
-		if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
161
-			$force_one_line_item = true;
162
-		}
163
-
164
-		$paypal_args = apply_filters(
165
-			'getpaid_paypal_args',
166
-			array_merge(
167
-				$this->get_transaction_args( $invoice ),
168
-				$this->get_line_item_args( $invoice, $force_one_line_item )
169
-			),
170
-			$invoice
171
-		);
172
-
173
-		return $this->fix_request_length( $invoice, $paypal_args );
158
+        $force_one_line_item = apply_filters( 'getpaid_paypal_force_one_line_item', false, $invoice );
159
+
160
+        if ( $invoice->is_recurring() || ( wpinv_use_taxes() && wpinv_prices_include_tax() ) ) {
161
+            $force_one_line_item = true;
162
+        }
163
+
164
+        $paypal_args = apply_filters(
165
+            'getpaid_paypal_args',
166
+            array_merge(
167
+                $this->get_transaction_args( $invoice ),
168
+                $this->get_line_item_args( $invoice, $force_one_line_item )
169
+            ),
170
+            $invoice
171
+        );
172
+
173
+        return $this->fix_request_length( $invoice, $paypal_args );
174 174
     }
175 175
 
176 176
     /**
177
-	 * Get transaction args for paypal request.
178
-	 *
179
-	 * @param WPInv_Invoice $invoice Invoice object.
180
-	 * @return array
181
-	 */
182
-	protected function get_transaction_args( $invoice ) {
177
+     * Get transaction args for paypal request.
178
+     *
179
+     * @param WPInv_Invoice $invoice Invoice object.
180
+     * @return array
181
+     */
182
+    protected function get_transaction_args( $invoice ) {
183 183
 
184
-		return array(
184
+        return array(
185 185
             'cmd'           => '_cart',
186 186
             'business'      => wpinv_get_option( 'paypal_email', false ),
187 187
             'no_shipping'   => '1',
@@ -206,16 +206,16 @@  discard block
 block discarded – undo
206 206
     }
207 207
 
208 208
     /**
209
-	 * Get line item args for paypal request.
210
-	 *
211
-	 * @param  WPInv_Invoice $invoice Invoice object.
212
-	 * @param  bool     $force_one_line_item Create only one item for this invoice.
213
-	 * @return array
214
-	 */
215
-	protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
209
+     * Get line item args for paypal request.
210
+     *
211
+     * @param  WPInv_Invoice $invoice Invoice object.
212
+     * @param  bool     $force_one_line_item Create only one item for this invoice.
213
+     * @return array
214
+     */
215
+    protected function get_line_item_args( $invoice, $force_one_line_item = false ) {
216 216
 
217 217
         // Maybe send invoice as a single item.
218
-		if ( $force_one_line_item ) {
218
+        if ( $force_one_line_item ) {
219 219
             return $this->get_line_item_args_single_item( $invoice );
220 220
         }
221 221
 
@@ -235,129 +235,129 @@  discard block
 block discarded – undo
235 235
             $line_item_args['discount_amount_cart'] = wpinv_sanitize_amount( (float) $invoice->get_total_discount(), 2 );
236 236
         }
237 237
 
238
-		return array_merge( $line_item_args, $this->get_line_items() );
238
+        return array_merge( $line_item_args, $this->get_line_items() );
239 239
 
240 240
     }
241 241
 
242 242
     /**
243
-	 * Get line item args for paypal request as a single line item.
244
-	 *
245
-	 * @param  WPInv_Invoice $invoice Invoice object.
246
-	 * @return array
247
-	 */
248
-	protected function get_line_item_args_single_item( $invoice ) {
249
-		$this->delete_line_items();
243
+     * Get line item args for paypal request as a single line item.
244
+     *
245
+     * @param  WPInv_Invoice $invoice Invoice object.
246
+     * @return array
247
+     */
248
+    protected function get_line_item_args_single_item( $invoice ) {
249
+        $this->delete_line_items();
250 250
 
251 251
         $item_name = sprintf( __( 'Invoice #%s', 'invoicing' ), $invoice->get_number() );
252
-		$this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() );
252
+        $this->add_line_item( $item_name, 1, wpinv_sanitize_amount( (float) $invoice->get_total(), 2 ), $invoice->get_id() );
253 253
 
254
-		return $this->get_line_items();
254
+        return $this->get_line_items();
255 255
     }
256 256
 
257 257
     /**
258
-	 * Return all line items.
259
-	 */
260
-	protected function get_line_items() {
261
-		return $this->line_items;
262
-	}
258
+     * Return all line items.
259
+     */
260
+    protected function get_line_items() {
261
+        return $this->line_items;
262
+    }
263 263
 
264 264
     /**
265
-	 * Remove all line items.
266
-	 */
267
-	protected function delete_line_items() {
268
-		$this->line_items = array();
265
+     * Remove all line items.
266
+     */
267
+    protected function delete_line_items() {
268
+        $this->line_items = array();
269 269
     }
270 270
 
271 271
     /**
272
-	 * Prepare line items to send to paypal.
273
-	 *
274
-	 * @param  WPInv_Invoice $invoice Invoice object.
275
-	 */
276
-	protected function prepare_line_items( $invoice ) {
277
-		$this->delete_line_items();
278
-
279
-		// Items.
280
-		foreach ( $invoice->get_items() as $item ) {
281
-			$amount   = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total();
282
-			$quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
283
-			$this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
272
+     * Prepare line items to send to paypal.
273
+     *
274
+     * @param  WPInv_Invoice $invoice Invoice object.
275
+     */
276
+    protected function prepare_line_items( $invoice ) {
277
+        $this->delete_line_items();
278
+
279
+        // Items.
280
+        foreach ( $invoice->get_items() as $item ) {
281
+            $amount   = $invoice->get_template() == 'amount' ? $item->get_price() : $item->get_sub_total();
282
+            $quantity = $invoice->get_template() == 'amount' ? 1 : $item->get_quantity();
283
+            $this->add_line_item( $item->get_raw_name(), $quantity, $amount, $item->get_id() );
284 284
         }
285 285
 
286 286
         // Fees.
287
-		foreach ( $invoice->get_fees() as $fee => $data ) {
287
+        foreach ( $invoice->get_fees() as $fee => $data ) {
288 288
             $this->add_line_item( $fee, 1, $data['amount'] );
289 289
         }
290 290
 
291 291
     }
292 292
 
293 293
     /**
294
-	 * Add PayPal Line Item.
295
-	 *
296
-	 * @param  string $item_name Item name.
297
-	 * @param  int    $quantity Item quantity.
298
-	 * @param  float  $amount Amount.
299
-	 * @param  string $item_number Item number.
300
-	 */
301
-	protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
302
-		$index = ( count( $this->line_items ) / 4 ) + 1;
303
-
304
-		$item = apply_filters(
305
-			'getpaid_paypal_line_item',
306
-			array(
307
-				'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
308
-				'quantity'    => (int) $quantity,
309
-				'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
310
-				'item_number' => $item_number,
311
-			),
312
-			$item_name,
313
-			$quantity,
314
-			$amount,
315
-			$item_number
316
-		);
317
-
318
-		$this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
294
+     * Add PayPal Line Item.
295
+     *
296
+     * @param  string $item_name Item name.
297
+     * @param  int    $quantity Item quantity.
298
+     * @param  float  $amount Amount.
299
+     * @param  string $item_number Item number.
300
+     */
301
+    protected function add_line_item( $item_name, $quantity = 1, $amount = 0.0, $item_number = '' ) {
302
+        $index = ( count( $this->line_items ) / 4 ) + 1;
303
+
304
+        $item = apply_filters(
305
+            'getpaid_paypal_line_item',
306
+            array(
307
+                'item_name'   => html_entity_decode( getpaid_limit_length( $item_name ? wp_strip_all_tags( $item_name ) : __( 'Item', 'invoicing' ), 127 ), ENT_NOQUOTES, 'UTF-8' ),
308
+                'quantity'    => (int) $quantity,
309
+                'amount'      => wpinv_sanitize_amount( (float) $amount, 2 ),
310
+                'item_number' => $item_number,
311
+            ),
312
+            $item_name,
313
+            $quantity,
314
+            $amount,
315
+            $item_number
316
+        );
317
+
318
+        $this->line_items[ 'item_name_' . $index ]   = getpaid_limit_length( $item['item_name'], 127 );
319 319
         $this->line_items[ 'quantity_' . $index ]    = $item['quantity'];
320 320
         
321 321
         // The price or amount of the product, service, or contribution, not including shipping, handling, or tax.
322
-		$this->line_items[ 'amount_' . $index ]      = $item['amount'];
323
-		$this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
322
+        $this->line_items[ 'amount_' . $index ]      = $item['amount'];
323
+        $this->line_items[ 'item_number_' . $index ] = getpaid_limit_length( $item['item_number'], 127 );
324 324
     }
325 325
 
326 326
     /**
327
-	 * If the default request with line items is too long, generate a new one with only one line item.
328
-	 *
329
-	 * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
330
-	 *
331
-	 * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
332
-	 * @param array    $paypal_args Arguments sent to Paypal in the request.
333
-	 * @return array
334
-	 */
335
-	protected function fix_request_length( $invoice, $paypal_args ) {
336
-		$max_paypal_length = 2083;
337
-		$query_candidate   = http_build_query( $paypal_args, '', '&' );
338
-
339
-		if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
340
-			return $paypal_args;
341
-		}
342
-
343
-		return apply_filters(
344
-			'getpaid_paypal_args',
345
-			array_merge(
346
-				$this->get_transaction_args( $invoice ),
347
-				$this->get_line_item_args( $invoice, true )
348
-			),
349
-			$invoice
350
-		);
327
+     * If the default request with line items is too long, generate a new one with only one line item.
328
+     *
329
+     * https://support.microsoft.com/en-us/help/208427/maximum-url-length-is-2-083-characters-in-internet-explorer.
330
+     *
331
+     * @param WPInv_Invoice $invoice Invoice to be sent to Paypal.
332
+     * @param array    $paypal_args Arguments sent to Paypal in the request.
333
+     * @return array
334
+     */
335
+    protected function fix_request_length( $invoice, $paypal_args ) {
336
+        $max_paypal_length = 2083;
337
+        $query_candidate   = http_build_query( $paypal_args, '', '&' );
338
+
339
+        if ( strlen( $this->endpoint . $query_candidate ) <= $max_paypal_length ) {
340
+            return $paypal_args;
341
+        }
342
+
343
+        return apply_filters(
344
+            'getpaid_paypal_args',
345
+            array_merge(
346
+                $this->get_transaction_args( $invoice ),
347
+                $this->get_line_item_args( $invoice, true )
348
+            ),
349
+            $invoice
350
+        );
351 351
 
352 352
     }
353 353
     
354 354
     /**
355
-	 * Processes recurring invoices.
356
-	 *
357
-	 * @param  array $paypal_args PayPal args.
358
-	 * @param  WPInv_Invoice    $invoice Invoice object.
359
-	 */
360
-	public function process_subscription( $paypal_args, $invoice ) {
355
+     * Processes recurring invoices.
356
+     *
357
+     * @param  array $paypal_args PayPal args.
358
+     * @param  WPInv_Invoice    $invoice Invoice object.
359
+     */
360
+    public function process_subscription( $paypal_args, $invoice ) {
361 361
 
362 362
         // Make sure this is a subscription.
363 363
         if ( ! $invoice->is_recurring() || ! $subscription = wpinv_get_subscription( $invoice ) ) {
@@ -382,11 +382,11 @@  discard block
 block discarded – undo
382 382
 
383 383
             $paypal_args['a1'] = 0 == $initial_amount ? 0 : $initial_amount;
384 384
 
385
-			// Trial period length.
386
-			$paypal_args['p1'] = $subscription_item->get_trial_interval();
385
+            // Trial period length.
386
+            $paypal_args['p1'] = $subscription_item->get_trial_interval();
387 387
 
388
-			// Trial period.
389
-			$paypal_args['t1'] = $subscription_item->get_trial_period();
388
+            // Trial period.
389
+            $paypal_args['t1'] = $subscription_item->get_trial_period();
390 390
 
391 391
         } else if ( $initial_amount != $recurring_amount ) {
392 392
 
@@ -409,40 +409,40 @@  discard block
 block discarded – undo
409 409
         }
410 410
 
411 411
         // We have a recurring payment
412
-		if ( ! isset( $param_number ) || 1 == $param_number ) {
412
+        if ( ! isset( $param_number ) || 1 == $param_number ) {
413 413
 
414
-			// Subscription price
415
-			$paypal_args['a3'] = $recurring_amount;
414
+            // Subscription price
415
+            $paypal_args['a3'] = $recurring_amount;
416 416
 
417
-			// Subscription duration
418
-			$paypal_args['p3'] = $interval;
417
+            // Subscription duration
418
+            $paypal_args['p3'] = $interval;
419 419
 
420
-			// Subscription period
421
-			$paypal_args['t3'] = $period;
420
+            // Subscription period
421
+            $paypal_args['t3'] = $period;
422 422
 
423 423
         }
424 424
         
425 425
         // Recurring payments
426
-		if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
426
+        if ( 1 == $bill_times || ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() && 2 == $bill_times ) ) {
427 427
 
428
-			// Non-recurring payments
429
-			$paypal_args['src'] = 0;
428
+            // Non-recurring payments
429
+            $paypal_args['src'] = 0;
430 430
 
431
-		} else {
431
+        } else {
432 432
 
433
-			$paypal_args['src'] = 1;
433
+            $paypal_args['src'] = 1;
434 434
 
435
-			if ( $bill_times > 0 ) {
435
+            if ( $bill_times > 0 ) {
436 436
 
437
-				// An initial period is being used to charge a sign-up fee
438
-				if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
439
-					$bill_times--;
440
-				}
437
+                // An initial period is being used to charge a sign-up fee
438
+                if ( $initial_amount != $recurring_amount && ! $subscription_item->has_free_trial() ) {
439
+                    $bill_times--;
440
+                }
441 441
 
442 442
                 // Make sure it's not over the max of 52
443 443
                 $paypal_args['srt'] = ( $bill_times <= 52 ? absint( $bill_times ) : 52 );
444 444
 
445
-			}
445
+            }
446 446
         }
447 447
         
448 448
         // Force return URL so that order description & instructions display
@@ -458,24 +458,24 @@  discard block
 block discarded – undo
458 458
         }
459 459
 
460 460
         return apply_filters(
461
-			'getpaid_paypal_subscription_args',
462
-			$paypal_args,
463
-			$invoice
461
+            'getpaid_paypal_subscription_args',
462
+            $paypal_args,
463
+            $invoice
464 464
         );
465 465
 
466 466
     }
467 467
 
468 468
     /**
469
-	 * Processes ipns and marks payments as complete.
470
-	 *
471
-	 * @return void
472
-	 */
473
-	public function verify_ipn() {
469
+     * Processes ipns and marks payments as complete.
470
+     *
471
+     * @return void
472
+     */
473
+    public function verify_ipn() {
474 474
 
475 475
         // Validate the IPN.
476 476
         if ( empty( $_POST ) || ! $this->validate_ipn() ) {
477
-		    wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) );
478
-		}
477
+            wp_die( 'PayPal IPN Request Failure', 'PayPal IPN', array( 'response' => 500 ) );
478
+        }
479 479
 
480 480
         // Process the IPN.
481 481
         $posted  = wp_unslash( $_POST );
@@ -483,13 +483,13 @@  discard block
 block discarded – undo
483 483
 
484 484
         if ( $invoice && $this->id == $invoice->get_gateway() ) {
485 485
 
486
-			$posted['payment_status'] = strtolower( $posted['payment_status'] );
486
+            $posted['payment_status'] = strtolower( $posted['payment_status'] );
487 487
 
488 488
             wpinv_error_log( 'Found invoice #' . $invoice->get_number() );
489 489
             wpinv_error_log( 'Payment status:' . $posted['payment_status'] );
490 490
 
491
-			if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
492
-				call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
491
+            if ( method_exists( $this, 'ipn_txn_' . $posted['txn_type'] ) ) {
492
+                call_user_func( array( $this, 'ipn_txn_' . $posted['txn_type'] ), $invoice, $posted );
493 493
             } else {
494 494
                 wpinv_error_log( 'Aborting, Invalid type:' . $posted['txn_type'] );
495 495
             }
@@ -501,33 +501,33 @@  discard block
 block discarded – undo
501 501
     }
502 502
 
503 503
     /**
504
-	 * Check PayPal IPN validity.
505
-	 */
506
-	public function validate_ipn() {
507
-
508
-		wpinv_error_log( 'Validating PayPal IPN response' );
509
-
510
-		// Get received values from post data.
511
-		$validate_ipn        = wp_unslash( $_POST );
512
-		$validate_ipn['cmd'] = '_notify-validate';
513
-
514
-		// Send back post vars to paypal.
515
-		$params = array(
516
-			'body'        => $validate_ipn,
517
-			'timeout'     => 60,
518
-			'httpversion' => '1.1',
519
-			'compress'    => false,
520
-			'decompress'  => false,
521
-			'user-agent'  => 'GetPaid/' . WPINV_VERSION,
522
-		);
504
+     * Check PayPal IPN validity.
505
+     */
506
+    public function validate_ipn() {
507
+
508
+        wpinv_error_log( 'Validating PayPal IPN response' );
509
+
510
+        // Get received values from post data.
511
+        $validate_ipn        = wp_unslash( $_POST );
512
+        $validate_ipn['cmd'] = '_notify-validate';
513
+
514
+        // Send back post vars to paypal.
515
+        $params = array(
516
+            'body'        => $validate_ipn,
517
+            'timeout'     => 60,
518
+            'httpversion' => '1.1',
519
+            'compress'    => false,
520
+            'decompress'  => false,
521
+            'user-agent'  => 'GetPaid/' . WPINV_VERSION,
522
+        );
523 523
 
524
-		// Post back to get a response.
525
-		$response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
524
+        // Post back to get a response.
525
+        $response = wp_safe_remote_post( $this->is_sandbox() ? 'https://www.sandbox.paypal.com/cgi-bin/webscr' : 'https://www.paypal.com/cgi-bin/webscr', $params );
526 526
 
527 527
         // Check to see if the request was valid.
528
-		if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
528
+        if ( ! is_wp_error( $response ) && $response['response']['code'] >= 200 && $response['response']['code'] < 300 && strstr( $response['body'], 'VERIFIED' ) ) {
529 529
             wpinv_error_log( $response['body'], 'Received valid response from PayPal IPN' );
530
-			return true;
530
+            return true;
531 531
         }
532 532
 
533 533
         if ( is_wp_error( $response ) ) {
@@ -541,63 +541,63 @@  discard block
 block discarded – undo
541 541
     }
542 542
 
543 543
     /**
544
-	 * Check currency from IPN matches the invoice.
545
-	 *
546
-	 * @param WPInv_Invoice $invoice          Invoice object.
547
-	 * @param string   $currency currency to validate.
548
-	 */
549
-	protected function validate_ipn_currency( $invoice, $currency ) {
550
-		if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
544
+     * Check currency from IPN matches the invoice.
545
+     *
546
+     * @param WPInv_Invoice $invoice          Invoice object.
547
+     * @param string   $currency currency to validate.
548
+     */
549
+    protected function validate_ipn_currency( $invoice, $currency ) {
550
+        if ( strtolower( $invoice->get_currency() ) !== strtolower( $currency ) ) {
551 551
             wpinv_record_gateway_error( 'IPN Error', "Currencies do not match: {$currency} instead of {$invoice->get_currency()}" );
552 552
 
553
-			/* translators: %s: currency code. */
554
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
555
-			exit;
556
-		}
557
-	}
558
-
559
-	/**
560
-	 * Check payment amount from IPN matches the invoice.
561
-	 *
562
-	 * @param WPInv_Invoice $invoice          Invoice object.
563
-	 * @param float   $amount amount to validate.
564
-	 */
565
-	protected function validate_ipn_amount( $invoice, $amount ) {
566
-		if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
553
+            /* translators: %s: currency code. */
554
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal currencies do not match (code %s).', 'invoicing' ), $currency ) );
555
+            exit;
556
+        }
557
+    }
558
+
559
+    /**
560
+     * Check payment amount from IPN matches the invoice.
561
+     *
562
+     * @param WPInv_Invoice $invoice          Invoice object.
563
+     * @param float   $amount amount to validate.
564
+     */
565
+    protected function validate_ipn_amount( $invoice, $amount ) {
566
+        if ( number_format( $invoice->get_total(), 2, '.', '' ) !== number_format( $amount, 2, '.', '' ) ) {
567 567
             wpinv_record_gateway_error( 'IPN Error', "Amounts do not match: {$amount} instead of {$invoice->get_total()}" );
568 568
 
569
-			/* translators: %s: Amount. */
570
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
571
-			exit;
572
-		}
573
-	}
574
-
575
-	/**
576
-	 * Verify receiver email from PayPal.
577
-	 *
578
-	 * @param WPInv_Invoice $invoice          Invoice object.
579
-	 * @param string   $receiver_email Email to validate.
580
-	 */
581
-	protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
569
+            /* translators: %s: Amount. */
570
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal amounts do not match (gross %s).', 'invoicing' ), $amount ) );
571
+            exit;
572
+        }
573
+    }
574
+
575
+    /**
576
+     * Verify receiver email from PayPal.
577
+     *
578
+     * @param WPInv_Invoice $invoice          Invoice object.
579
+     * @param string   $receiver_email Email to validate.
580
+     */
581
+    protected function validate_ipn_receiver_email( $invoice, $receiver_email ) {
582 582
         $paypal_email = wpinv_get_option( 'paypal_email' );
583 583
 
584
-		if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
584
+        if ( strcasecmp( trim( $receiver_email ), trim( $paypal_email ) ) !== 0 ) {
585 585
             wpinv_record_gateway_error( 'IPN Error', "IPN Response is for another account: {$receiver_email}. Your email is {$paypal_email}" );
586 586
 
587
-			/* translators: %s: email address . */
588
-			$invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
589
-			exit;
587
+            /* translators: %s: email address . */
588
+            $invoice->update_status( 'wpi-processing', sprintf( __( 'Validation error: PayPal IPN response from a different email address (%s).', 'invoicing' ), $receiver_email ) );
589
+            exit;
590 590
         }
591 591
 
592
-	}
592
+    }
593 593
 
594 594
     /**
595
-	 * Handles one time payments.
596
-	 *
597
-	 * @param WPInv_Invoice $invoice  Invoice object.
598
-	 * @param array    $posted Posted data.
599
-	 */
600
-	protected function ipn_txn_web_accept( $invoice, $posted ) {
595
+     * Handles one time payments.
596
+     *
597
+     * @param WPInv_Invoice $invoice  Invoice object.
598
+     * @param array    $posted Posted data.
599
+     */
600
+    protected function ipn_txn_web_accept( $invoice, $posted ) {
601 601
 
602 602
         // Collect payment details
603 603
         $payment_status = strtolower( $posted['payment_status'] );
@@ -658,27 +658,27 @@  discard block
 block discarded – undo
658 658
         // Process failures.
659 659
 
660 660
         /* translators: %s: payment status. */
661
-		$invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) );
662
-
663
-	}
664
-
665
-	/**
666
-	 * Handles one time payments.
667
-	 *
668
-	 * @param WPInv_Invoice $invoice  Invoice object.
669
-	 * @param array    $posted Posted data.
670
-	 */
671
-	protected function ipn_txn_cart( $invoice, $posted ) {
672
-		$this->ipn_txn_web_accept( $invoice, $posted );
661
+        $invoice->update_status( 'wpi-failed', sprintf( __( 'Payment %s via IPN.', 'invoicing' ), wpinv_clean( $posted['payment_status'] ) ) );
662
+
663
+    }
664
+
665
+    /**
666
+     * Handles one time payments.
667
+     *
668
+     * @param WPInv_Invoice $invoice  Invoice object.
669
+     * @param array    $posted Posted data.
670
+     */
671
+    protected function ipn_txn_cart( $invoice, $posted ) {
672
+        $this->ipn_txn_web_accept( $invoice, $posted );
673 673
     }
674 674
 
675 675
     /**
676
-	 * Handles subscription sign ups.
677
-	 *
678
-	 * @param WPInv_Invoice $invoice  Invoice object.
679
-	 * @param array    $posted Posted data.
680
-	 */
681
-	protected function ipn_txn_subscr_signup( $invoice, $posted ) {
676
+     * Handles subscription sign ups.
677
+     *
678
+     * @param WPInv_Invoice $invoice  Invoice object.
679
+     * @param array    $posted Posted data.
680
+     */
681
+    protected function ipn_txn_subscr_signup( $invoice, $posted ) {
682 682
 
683 683
         // Make sure the invoice has a subscription.
684 684
         $subscription = wpinv_get_subscription( $invoice );
@@ -717,12 +717,12 @@  discard block
 block discarded – undo
717 717
     }
718 718
 
719 719
     /**
720
-	 * Handles subscription renewals.
721
-	 *
722
-	 * @param WPInv_Invoice $invoice  Invoice object.
723
-	 * @param array    $posted Posted data.
724
-	 */
725
-	protected function ipn_txn_subscr_payment( $invoice, $posted ) {
720
+     * Handles subscription renewals.
721
+     *
722
+     * @param WPInv_Invoice $invoice  Invoice object.
723
+     * @param array    $posted Posted data.
724
+     */
725
+    protected function ipn_txn_subscr_payment( $invoice, $posted ) {
726 726
 
727 727
         // Make sure the invoice has a subscription.
728 728
         $subscription = wpinv_get_subscription( $invoice );
@@ -765,12 +765,12 @@  discard block
 block discarded – undo
765 765
     }
766 766
 
767 767
     /**
768
-	 * Handles subscription cancelations.
769
-	 *
770
-	 * @param WPInv_Invoice $invoice  Invoice object.
771
-	 * @param array    $posted Posted data.
772
-	 */
773
-	protected function ipn_txn_subscr_cancel( $invoice, $posted ) {
768
+     * Handles subscription cancelations.
769
+     *
770
+     * @param WPInv_Invoice $invoice  Invoice object.
771
+     * @param array    $posted Posted data.
772
+     */
773
+    protected function ipn_txn_subscr_cancel( $invoice, $posted ) {
774 774
 
775 775
         if ( $subscription = wpinv_get_subscription( $invoice ) ) {
776 776
             $subscription->cancel();
@@ -779,12 +779,12 @@  discard block
 block discarded – undo
779 779
     }
780 780
 
781 781
     /**
782
-	 * Handles subscription completions.
783
-	 *
784
-	 * @param WPInv_Invoice $invoice  Invoice object.
785
-	 * @param array    $posted Posted data.
786
-	 */
787
-	protected function ipn_txn_subscr_eot( $invoice, $posted ) {
782
+     * Handles subscription completions.
783
+     *
784
+     * @param WPInv_Invoice $invoice  Invoice object.
785
+     * @param array    $posted Posted data.
786
+     */
787
+    protected function ipn_txn_subscr_eot( $invoice, $posted ) {
788 788
 
789 789
         if ( $subscription = wpinv_get_subscription( $invoice ) ) {
790 790
             $subscription->complete();
@@ -793,12 +793,12 @@  discard block
 block discarded – undo
793 793
     }
794 794
 
795 795
     /**
796
-	 * Handles subscription fails.
797
-	 *
798
-	 * @param WPInv_Invoice $invoice  Invoice object.
799
-	 * @param array    $posted Posted data.
800
-	 */
801
-	protected function ipn_txn_subscr_failed( $invoice, $posted ) {
796
+     * Handles subscription fails.
797
+     *
798
+     * @param WPInv_Invoice $invoice  Invoice object.
799
+     * @param array    $posted Posted data.
800
+     */
801
+    protected function ipn_txn_subscr_failed( $invoice, $posted ) {
802 802
 
803 803
         if ( $subscription = wpinv_get_subscription( $invoice ) ) {
804 804
             $subscription->failing();
Please login to merge, or discard this patch.
includes/gateways/class-getpaid-worldpay-gateway.php 1 patch
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_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.
includes/gateways/class-getpaid-payment-gateway.php 1 patch
Indentation   +530 added lines, -530 removed lines patch added patch discarded remove patch
@@ -13,566 +13,566 @@
 block discarded – undo
13 13
  */
14 14
 abstract class GetPaid_Payment_Gateway {
15 15
 
16
-	/**
17
-	 * Set if the place checkout button should be renamed on selection.
18
-	 *
19
-	 * @var string
20
-	 */
21
-	public $checkout_button_text;
22
-
23
-	/**
24
-	 * Boolean whether the method is enabled.
25
-	 *
26
-	 * @var bool
27
-	 */
28
-	public $enabled = true;
29
-
30
-	/**
31
-	 * Payment method id.
32
-	 *
33
-	 * @var string
34
-	 */
35
-	public $id;
36
-
37
-	/**
38
-	 * Payment method order.
39
-	 *
40
-	 * @var int
41
-	 */
42
-	public $order = 10;
43
-
44
-	/**
45
-	 * Payment method title for the frontend.
46
-	 *
47
-	 * @var string
48
-	 */
49
-	public $title;
50
-
51
-	/**
52
-	 * Payment method description for the frontend.
53
-	 *
54
-	 * @var string
55
-	 */
56
-	public $description;
57
-
58
-	/**
59
-	 * Gateway title.
60
-	 *
61
-	 * @var string
62
-	 */
63
-	public $method_title = '';
64
-
65
-	/**
66
-	 * Gateway description.
67
-	 *
68
-	 * @var string
69
-	 */
70
-	public $method_description = '';
71
-
72
-	/**
73
-	 * Countries this gateway is allowed for.
74
-	 *
75
-	 * @var array
76
-	 */
77
-	public $countries;
78
-
79
-	/**
80
-	 * Currencies this gateway is allowed for.
81
-	 *
82
-	 * @var array
83
-	 */
84
-	public $currencies;
85
-
86
-	/**
87
-	 * Currencies this gateway is not allowed for.
88
-	 *
89
-	 * @var array
90
-	 */
91
-	public $exclude_currencies;
92
-
93
-	/**
94
-	 * Maximum transaction amount, zero does not define a maximum.
95
-	 *
96
-	 * @var int
97
-	 */
98
-	public $max_amount = 0;
99
-
100
-	/**
101
-	 * Optional URL to view a transaction.
102
-	 *
103
-	 * @var string
104
-	 */
105
-	public $view_transaction_url = '';
106
-
107
-	/**
108
-	 * Optional URL to view a subscription.
109
-	 *
110
-	 * @var string
111
-	 */
112
-	public $view_subscription_url = '';
113
-
114
-	/**
115
-	 * Optional label to show for "new payment method" in the payment
116
-	 * method/token selection radio selection.
117
-	 *
118
-	 * @var string
119
-	 */
120
-	public $new_method_label = '';
121
-
122
-	/**
123
-	 * Contains a users saved tokens for this gateway.
124
-	 *
125
-	 * @var array
126
-	 */
127
-	protected $tokens = array();
128
-
129
-	/**
130
-	 * An array of features that this gateway supports.
131
-	 *
132
-	 * @var array
133
-	 */
134
-	protected $supports = array();
135
-
136
-	/**
137
-	 * Class constructor.
138
-	 */
139
-	public function __construct() {
140
-		$this->enabled = wpinv_is_gateway_active( $this->id );
141
-
142
-		// Register gateway.
143
-		add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
144
-
145
-		// Enable Subscriptions.
146
-		if ( $this->supports( 'subscription' ) ) {
147
-			add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
148
-		}
149
-
150
-		// Enable sandbox.
151
-		if ( $this->supports( 'sandbox' ) ) {
152
-			add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
153
-		}
154
-
155
-		// Gateway settings.
156
-		add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
16
+    /**
17
+     * Set if the place checkout button should be renamed on selection.
18
+     *
19
+     * @var string
20
+     */
21
+    public $checkout_button_text;
22
+
23
+    /**
24
+     * Boolean whether the method is enabled.
25
+     *
26
+     * @var bool
27
+     */
28
+    public $enabled = true;
29
+
30
+    /**
31
+     * Payment method id.
32
+     *
33
+     * @var string
34
+     */
35
+    public $id;
36
+
37
+    /**
38
+     * Payment method order.
39
+     *
40
+     * @var int
41
+     */
42
+    public $order = 10;
43
+
44
+    /**
45
+     * Payment method title for the frontend.
46
+     *
47
+     * @var string
48
+     */
49
+    public $title;
50
+
51
+    /**
52
+     * Payment method description for the frontend.
53
+     *
54
+     * @var string
55
+     */
56
+    public $description;
57
+
58
+    /**
59
+     * Gateway title.
60
+     *
61
+     * @var string
62
+     */
63
+    public $method_title = '';
64
+
65
+    /**
66
+     * Gateway description.
67
+     *
68
+     * @var string
69
+     */
70
+    public $method_description = '';
71
+
72
+    /**
73
+     * Countries this gateway is allowed for.
74
+     *
75
+     * @var array
76
+     */
77
+    public $countries;
78
+
79
+    /**
80
+     * Currencies this gateway is allowed for.
81
+     *
82
+     * @var array
83
+     */
84
+    public $currencies;
85
+
86
+    /**
87
+     * Currencies this gateway is not allowed for.
88
+     *
89
+     * @var array
90
+     */
91
+    public $exclude_currencies;
92
+
93
+    /**
94
+     * Maximum transaction amount, zero does not define a maximum.
95
+     *
96
+     * @var int
97
+     */
98
+    public $max_amount = 0;
99
+
100
+    /**
101
+     * Optional URL to view a transaction.
102
+     *
103
+     * @var string
104
+     */
105
+    public $view_transaction_url = '';
106
+
107
+    /**
108
+     * Optional URL to view a subscription.
109
+     *
110
+     * @var string
111
+     */
112
+    public $view_subscription_url = '';
113
+
114
+    /**
115
+     * Optional label to show for "new payment method" in the payment
116
+     * method/token selection radio selection.
117
+     *
118
+     * @var string
119
+     */
120
+    public $new_method_label = '';
121
+
122
+    /**
123
+     * Contains a users saved tokens for this gateway.
124
+     *
125
+     * @var array
126
+     */
127
+    protected $tokens = array();
128
+
129
+    /**
130
+     * An array of features that this gateway supports.
131
+     *
132
+     * @var array
133
+     */
134
+    protected $supports = array();
135
+
136
+    /**
137
+     * Class constructor.
138
+     */
139
+    public function __construct() {
140
+        $this->enabled = wpinv_is_gateway_active( $this->id );
141
+
142
+        // Register gateway.
143
+        add_filter( 'wpinv_payment_gateways', array( $this, 'register_gateway' ) );
144
+
145
+        // Enable Subscriptions.
146
+        if ( $this->supports( 'subscription' ) ) {
147
+            add_filter( "wpinv_{$this->id}_support_subscription", '__return_true' );
148
+        }
149
+
150
+        // Enable sandbox.
151
+        if ( $this->supports( 'sandbox' ) ) {
152
+            add_filter( "wpinv_{$this->id}_supports_sandbox", '__return_true' );
153
+        }
154
+
155
+        // Gateway settings.
156
+        add_filter( "wpinv_gateway_settings_{$this->id}", array( $this, 'admin_settings' ) );
157 157
 		
158 158
 
159
-		// Gateway checkout fiellds.
160
-		add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
161
-
162
-		// Process payment.
163
-		add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
164
-
165
-		// Change the checkout button text.
166
-		if ( ! empty( $this->checkout_button_text ) ) {
167
-			add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
168
-		}
169
-
170
-		// Check if a gateway is valid for a given currency.
171
-		add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
172
-
173
-		// Generate the transaction url.
174
-		add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
175
-
176
-		// Generate the subscription url.
177
-		add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
178
-
179
-		// Confirm payments.
180
-		add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
181
-
182
-		// Verify IPNs.
183
-		add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
184
-
185
-	}
186
-
187
-	/**
188
-	 * Checks if this gateway is a given gateway.
189
-	 *
190
-	 * @since 1.0.19
191
-	 * @return bool
192
-	 */
193
-	public function is( $gateway ) {
194
-		return $gateway == $this->id;
195
-	}
196
-
197
-	/**
198
-	 * Returns a users saved tokens for this gateway.
199
-	 *
200
-	 * @since 1.0.19
201
-	 * @return array
202
-	 */
203
-	public function get_tokens() {
204
-
205
-		if ( count( $this->tokens ) > 0 ) {
206
-			return $this->tokens;
207
-		}
208
-
209
-		if ( is_user_logged_in() && $this->supports( 'tokens' ) ) {
210
-			$tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
211
-
212
-			if ( is_array( $tokens ) ) {
213
-				$this->tokens = $tokens;
214
-			}
215
-
216
-		}
217
-
218
-		return $this->tokens;
219
-	}
220
-
221
-	/**
222
-	 * Return the title for admin screens.
223
-	 *
224
-	 * @return string
225
-	 */
226
-	public function get_method_title() {
227
-		return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
228
-	}
229
-
230
-	/**
231
-	 * Return the description for admin screens.
232
-	 *
233
-	 * @return string
234
-	 */
235
-	public function get_method_description() {
236
-		return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
237
-	}
238
-
239
-	/**
240
-	 * Get the success url.
241
-	 *
242
-	 * @param WPInv_Invoice $invoice Invoice object.
243
-	 * @return string
244
-	 */
245
-	public function get_return_url( $invoice ) {
246
-
247
-		// Payment success url
248
-		$return_url = add_query_arg(
249
-			array(
250
-				'payment-confirm' => $this->id,
251
-				'invoice_key'     => $invoice->get_key(),
252
-				'utm_nooverride'  => 1
253
-			),
254
-			wpinv_get_success_page_uri()
255
-		);
256
-
257
-		return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
258
-	}
259
-
260
-	/**
261
-	 * Confirms payments when rendering the success page.
262
-	 *
263
-	 * @param string $content Success page content.
264
-	 * @return string
265
-	 */
266
-	public function get_confirm_payment( $content ) {
159
+        // Gateway checkout fiellds.
160
+        add_action( "wpinv_{$this->id}_cc_form", array( $this, 'payment_fields' ), 10, 2 );
161
+
162
+        // Process payment.
163
+        add_action( "getpaid_gateway_{$this->id}", array( $this, 'process_payment' ), 10, 3 );
164
+
165
+        // Change the checkout button text.
166
+        if ( ! empty( $this->checkout_button_text ) ) {
167
+            add_filter( "getpaid_gateway_{$this->id}_checkout_button_label", array( $this, 'rename_checkout_button' ) );
168
+        }
169
+
170
+        // Check if a gateway is valid for a given currency.
171
+        add_filter( "getpaid_gateway_{$this->id}_is_valid_for_currency", array( $this, 'validate_currency' ), 10, 2 );
172
+
173
+        // Generate the transaction url.
174
+        add_filter( "getpaid_gateway_{$this->id}_transaction_url", array( $this, 'filter_transaction_url' ), 10, 2 );
175
+
176
+        // Generate the subscription url.
177
+        add_filter( "getpaid_gateway_{$this->id}_subscription_url", array( $this, 'filter_subscription_url' ), 10, 2 );
178
+
179
+        // Confirm payments.
180
+        add_filter( "wpinv_payment_confirm_{$this->id}", array( $this, 'confirm_payment' ), 10, 2 );
181
+
182
+        // Verify IPNs.
183
+        add_action( "wpinv_verify_{$this->id}_ipn", array( $this, 'verify_ipn' ) );
184
+
185
+    }
186
+
187
+    /**
188
+     * Checks if this gateway is a given gateway.
189
+     *
190
+     * @since 1.0.19
191
+     * @return bool
192
+     */
193
+    public function is( $gateway ) {
194
+        return $gateway == $this->id;
195
+    }
196
+
197
+    /**
198
+     * Returns a users saved tokens for this gateway.
199
+     *
200
+     * @since 1.0.19
201
+     * @return array
202
+     */
203
+    public function get_tokens() {
204
+
205
+        if ( count( $this->tokens ) > 0 ) {
206
+            return $this->tokens;
207
+        }
208
+
209
+        if ( is_user_logged_in() && $this->supports( 'tokens' ) ) {
210
+            $tokens = get_user_meta( get_current_user_id(), "getpaid_{$this->id}_tokens", true );
211
+
212
+            if ( is_array( $tokens ) ) {
213
+                $this->tokens = $tokens;
214
+            }
215
+
216
+        }
217
+
218
+        return $this->tokens;
219
+    }
220
+
221
+    /**
222
+     * Return the title for admin screens.
223
+     *
224
+     * @return string
225
+     */
226
+    public function get_method_title() {
227
+        return apply_filters( 'getpaid_gateway_method_title', $this->method_title, $this );
228
+    }
229
+
230
+    /**
231
+     * Return the description for admin screens.
232
+     *
233
+     * @return string
234
+     */
235
+    public function get_method_description() {
236
+        return apply_filters( 'getpaid_gateway_method_description', $this->method_description, $this );
237
+    }
238
+
239
+    /**
240
+     * Get the success url.
241
+     *
242
+     * @param WPInv_Invoice $invoice Invoice object.
243
+     * @return string
244
+     */
245
+    public function get_return_url( $invoice ) {
246
+
247
+        // Payment success url
248
+        $return_url = add_query_arg(
249
+            array(
250
+                'payment-confirm' => $this->id,
251
+                'invoice_key'     => $invoice->get_key(),
252
+                'utm_nooverride'  => 1
253
+            ),
254
+            wpinv_get_success_page_uri()
255
+        );
256
+
257
+        return apply_filters( 'getpaid_gateway_success_url', $return_url, $invoice, $this );
258
+    }
259
+
260
+    /**
261
+     * Confirms payments when rendering the success page.
262
+     *
263
+     * @param string $content Success page content.
264
+     * @return string
265
+     */
266
+    public function get_confirm_payment( $content ) {
267 267
 		
268
-		// Retrieve the invoice.
269
-		$invoice_id = getpaid_get_current_invoice_id();
270
-		$invoice    = wpinv_get_invoice( $invoice_id );
268
+        // Retrieve the invoice.
269
+        $invoice_id = getpaid_get_current_invoice_id();
270
+        $invoice    = wpinv_get_invoice( $invoice_id );
271 271
 	
272
-		// Ensure that it exists and that it is pending payment.
273
-		if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
274
-			return $content;
275
-		}
272
+        // Ensure that it exists and that it is pending payment.
273
+        if ( empty( $invoice_id ) || ! $invoice->needs_payment() ) {
274
+            return $content;
275
+        }
276 276
 	
277
-		// Can the user view this invoice??
278
-		if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
279
-			return $content;
280
-		}
277
+        // Can the user view this invoice??
278
+        if ( ! wpinv_user_can_view_invoice( $invoice ) ) {
279
+            return $content;
280
+        }
281 281
 	
282
-		// Show payment processing indicator.
283
-		return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
284
-	}
285
-
286
-	/**
287
-	 * Processes ipns and marks payments as complete.
288
-	 *
289
-	 * @return void
290
-	 */
291
-	public function verify_ipn() {}
292
-
293
-	/**
294
-	 * Get a link to the transaction on the 3rd party gateway site (if applicable).
295
-	 *
296
-	 * @param string $transaction_url transaction url.
297
-	 * @param WPInv_Invoice $invoice Invoice object.
298
-	 * @return string transaction URL, or empty string.
299
-	 */
300
-	public function filter_transaction_url( $transaction_url, $invoice ) {
301
-
302
-		$transaction_id  = $invoice->get_transaction_id();
303
-
304
-		if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
305
-			$transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
306
-			$replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
307
-			$transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
308
-		}
309
-
310
-		return $transaction_url;
311
-	}
312
-
313
-	/**
314
-	 * Get a link to the subscription on the 3rd party gateway site (if applicable).
315
-	 *
316
-	 * @param string $subscription_url transaction url.
317
-	 * @param WPInv_Invoice $invoice Invoice object.
318
-	 * @return string subscription URL, or empty string.
319
-	 */
320
-	public function filter_subscription_url( $subscription_url, $invoice ) {
321
-
322
-		$profile_id      = $invoice->get_subscription_id();
323
-
324
-		if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
325
-
326
-			$subscription_url = sprintf( $this->view_subscription_url, $profile_id );
327
-			$replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
328
-			$subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
329
-
330
-		}
331
-
332
-		return $subscription_url;
333
-	}
334
-
335
-	/**
336
-	 * Check if the gateway is available for use.
337
-	 *
338
-	 * @return bool
339
-	 */
340
-	public function is_available() {
341
-		return ! empty( $this->enabled );
342
-	}
343
-
344
-	/**
345
-	 * Return the gateway's title.
346
-	 *
347
-	 * @return string
348
-	 */
349
-	public function get_title() {
350
-		return apply_filters( 'getpaid_gateway_title', $this->title, $this );
351
-	}
352
-
353
-	/**
354
-	 * Return the gateway's description.
355
-	 *
356
-	 * @return string
357
-	 */
358
-	public function get_description() {
359
-		return apply_filters( 'getpaid_gateway_description', $this->description, $this );
360
-	}
361
-
362
-	/**
363
-	 * Process Payment.
364
-	 *
365
-	 *
366
-	 * @param WPInv_Invoice $invoice Invoice.
367
-	 * @param array $submission_data Posted checkout fields.
368
-	 * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
369
-	 * @return void
370
-	 */
371
-	public function process_payment( $invoice, $submission_data, $submission ) {
372
-		// Process the payment then either redirect to the success page or the gateway.
373
-	}
374
-
375
-	/**
376
-	 * Process refund.
377
-	 *
378
-	 * If the gateway declares 'refunds' support, this will allow it to refund.
379
-	 * a passed in amount.
380
-	 *
381
-	 * @param WPInv_Invoice $invoice Invoice.
382
-	 * @param  float  $amount Refund amount.
383
-	 * @param  string $reason Refund reason.
384
-	 * @return WP_Error|bool True or false based on success, or a WP_Error object.
385
-	 */
386
-	public function process_refund( $invoice, $amount = null, $reason = '' ) {
387
-		return false;
388
-	}
389
-
390
-	/**
391
-	 * Displays the payment fields, credit cards etc.
392
-	 * 
393
-	 * @param int $invoice_id 0 or invoice id.
394
-	 * @param GetPaid_Payment_Form $form Current payment form.
395
-	 */
396
-	public function payment_fields( $invoice_id, $form ) {}
397
-
398
-	/**
399
-	 * Filters the gateway settings.
400
-	 * 
401
-	 * @param array $admin_settings
402
-	 */
403
-	public function admin_settings( $admin_settings ) {
404
-		return $admin_settings;
405
-	}
406
-
407
-	/**
408
-	 * Retrieves the value of a gateway setting.
409
-	 * 
410
-	 * @param string $option
411
-	 */
412
-	public function get_option( $option, $default = false ) {
413
-		return wpinv_get_option( $this->id . '_' . $option, $default );
414
-	}
415
-
416
-	/**
417
-	 * Check if a gateway supports a given feature.
418
-	 *
419
-	 * Gateways should override this to declare support (or lack of support) for a feature.
420
-	 * For backward compatibility, gateways support 'products' by default, but nothing else.
421
-	 *
422
-	 * @param string $feature string The name of a feature to test support for.
423
-	 * @return bool True if the gateway supports the feature, false otherwise.
424
-	 * @since 1.0.19
425
-	 */
426
-	public function supports( $feature ) {
427
-		return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
428
-	}
429
-
430
-	/**
431
-	 * Grab and display our saved payment methods.
432
-	 *
433
-	 * @since 1.0.19
434
-	 */
435
-	public function saved_payment_methods() {
436
-		$html = '<ul class="getpaid-saved-payment-methods" data-count="' . esc_attr( count( $this->get_tokens() ) ) . '">';
437
-
438
-		foreach ( $this->get_tokens() as $token ) {
439
-			$html .= $this->get_saved_payment_method_option_html( $token );
440
-		}
441
-
442
-		$html .= $this->get_new_payment_method_option_html();
443
-		$html .= '</ul>';
444
-
445
-		echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
446
-	}
447
-
448
-	/**
449
-	 * Gets saved payment method HTML from a token.
450
-	 *
451
-	 * @since 1.0.19
452
-	 * @param  array $token Payment Token.
453
-	 * @return string Generated payment method HTML
454
-	 */
455
-	public function get_saved_payment_method_option_html( $token ) {
456
-
457
-		return sprintf(
458
-			'<li class="getpaid-payment-method form-group">
282
+        // Show payment processing indicator.
283
+        return wpinv_get_template_html( 'wpinv-payment-processing.php', compact( 'invoice' ) );
284
+    }
285
+
286
+    /**
287
+     * Processes ipns and marks payments as complete.
288
+     *
289
+     * @return void
290
+     */
291
+    public function verify_ipn() {}
292
+
293
+    /**
294
+     * Get a link to the transaction on the 3rd party gateway site (if applicable).
295
+     *
296
+     * @param string $transaction_url transaction url.
297
+     * @param WPInv_Invoice $invoice Invoice object.
298
+     * @return string transaction URL, or empty string.
299
+     */
300
+    public function filter_transaction_url( $transaction_url, $invoice ) {
301
+
302
+        $transaction_id  = $invoice->get_transaction_id();
303
+
304
+        if ( ! empty( $this->view_transaction_url ) && ! empty( $transaction_id ) ) {
305
+            $transaction_url = sprintf( $this->view_transaction_url, $transaction_id );
306
+            $replace         = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
307
+            $transaction_url = str_replace( '{sandbox}', $replace, $transaction_url );
308
+        }
309
+
310
+        return $transaction_url;
311
+    }
312
+
313
+    /**
314
+     * Get a link to the subscription on the 3rd party gateway site (if applicable).
315
+     *
316
+     * @param string $subscription_url transaction url.
317
+     * @param WPInv_Invoice $invoice Invoice object.
318
+     * @return string subscription URL, or empty string.
319
+     */
320
+    public function filter_subscription_url( $subscription_url, $invoice ) {
321
+
322
+        $profile_id      = $invoice->get_subscription_id();
323
+
324
+        if ( ! empty( $this->view_subscription_url ) && ! empty( $profile_id ) ) {
325
+
326
+            $subscription_url = sprintf( $this->view_subscription_url, $profile_id );
327
+            $replace          = $this->is_sandbox( $invoice ) ? 'sandbox' : '';
328
+            $subscription_url = str_replace( '{sandbox}', $replace, $subscription_url );
329
+
330
+        }
331
+
332
+        return $subscription_url;
333
+    }
334
+
335
+    /**
336
+     * Check if the gateway is available for use.
337
+     *
338
+     * @return bool
339
+     */
340
+    public function is_available() {
341
+        return ! empty( $this->enabled );
342
+    }
343
+
344
+    /**
345
+     * Return the gateway's title.
346
+     *
347
+     * @return string
348
+     */
349
+    public function get_title() {
350
+        return apply_filters( 'getpaid_gateway_title', $this->title, $this );
351
+    }
352
+
353
+    /**
354
+     * Return the gateway's description.
355
+     *
356
+     * @return string
357
+     */
358
+    public function get_description() {
359
+        return apply_filters( 'getpaid_gateway_description', $this->description, $this );
360
+    }
361
+
362
+    /**
363
+     * Process Payment.
364
+     *
365
+     *
366
+     * @param WPInv_Invoice $invoice Invoice.
367
+     * @param array $submission_data Posted checkout fields.
368
+     * @param GetPaid_Payment_Form_Submission $submission Checkout submission.
369
+     * @return void
370
+     */
371
+    public function process_payment( $invoice, $submission_data, $submission ) {
372
+        // Process the payment then either redirect to the success page or the gateway.
373
+    }
374
+
375
+    /**
376
+     * Process refund.
377
+     *
378
+     * If the gateway declares 'refunds' support, this will allow it to refund.
379
+     * a passed in amount.
380
+     *
381
+     * @param WPInv_Invoice $invoice Invoice.
382
+     * @param  float  $amount Refund amount.
383
+     * @param  string $reason Refund reason.
384
+     * @return WP_Error|bool True or false based on success, or a WP_Error object.
385
+     */
386
+    public function process_refund( $invoice, $amount = null, $reason = '' ) {
387
+        return false;
388
+    }
389
+
390
+    /**
391
+     * Displays the payment fields, credit cards etc.
392
+     * 
393
+     * @param int $invoice_id 0 or invoice id.
394
+     * @param GetPaid_Payment_Form $form Current payment form.
395
+     */
396
+    public function payment_fields( $invoice_id, $form ) {}
397
+
398
+    /**
399
+     * Filters the gateway settings.
400
+     * 
401
+     * @param array $admin_settings
402
+     */
403
+    public function admin_settings( $admin_settings ) {
404
+        return $admin_settings;
405
+    }
406
+
407
+    /**
408
+     * Retrieves the value of a gateway setting.
409
+     * 
410
+     * @param string $option
411
+     */
412
+    public function get_option( $option, $default = false ) {
413
+        return wpinv_get_option( $this->id . '_' . $option, $default );
414
+    }
415
+
416
+    /**
417
+     * Check if a gateway supports a given feature.
418
+     *
419
+     * Gateways should override this to declare support (or lack of support) for a feature.
420
+     * For backward compatibility, gateways support 'products' by default, but nothing else.
421
+     *
422
+     * @param string $feature string The name of a feature to test support for.
423
+     * @return bool True if the gateway supports the feature, false otherwise.
424
+     * @since 1.0.19
425
+     */
426
+    public function supports( $feature ) {
427
+        return apply_filters( 'getpaid_payment_gateway_supports', in_array( $feature, $this->supports ), $feature, $this );
428
+    }
429
+
430
+    /**
431
+     * Grab and display our saved payment methods.
432
+     *
433
+     * @since 1.0.19
434
+     */
435
+    public function saved_payment_methods() {
436
+        $html = '<ul class="getpaid-saved-payment-methods" data-count="' . esc_attr( count( $this->get_tokens() ) ) . '">';
437
+
438
+        foreach ( $this->get_tokens() as $token ) {
439
+            $html .= $this->get_saved_payment_method_option_html( $token );
440
+        }
441
+
442
+        $html .= $this->get_new_payment_method_option_html();
443
+        $html .= '</ul>';
444
+
445
+        echo apply_filters( 'getpaid_payment_gateway_form_saved_payment_methods_html', $html, $this );
446
+    }
447
+
448
+    /**
449
+     * Gets saved payment method HTML from a token.
450
+     *
451
+     * @since 1.0.19
452
+     * @param  array $token Payment Token.
453
+     * @return string Generated payment method HTML
454
+     */
455
+    public function get_saved_payment_method_option_html( $token ) {
456
+
457
+        return sprintf(
458
+            '<li class="getpaid-payment-method form-group">
459 459
 				<label>
460 460
 					<input name="getpaid-%1$s-payment-method" type="radio" value="%2$s" style="width:auto;" class="getpaid-saved-payment-method-token-input" %4$s />
461 461
 					<span>%3$s</span>
462 462
 				</label>
463 463
 			</li>',
464
-			esc_attr( $this->id ),
465
-			esc_attr( $token['id'] ),
466
-			esc_html( $token['name'] ),
467
-			checked( empty( $token['default'] ), false, false )
468
-		);
464
+            esc_attr( $this->id ),
465
+            esc_attr( $token['id'] ),
466
+            esc_html( $token['name'] ),
467
+            checked( empty( $token['default'] ), false, false )
468
+        );
469 469
 
470
-	}
470
+    }
471 471
 
472
-	/**
473
-	 * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
474
-	 *
475
-	 * @since 1.0.19
476
-	 */
477
-	public function get_new_payment_method_option_html() {
472
+    /**
473
+     * Displays a radio button for entering a new payment method (new CC details) instead of using a saved method.
474
+     *
475
+     * @since 1.0.19
476
+     */
477
+    public function get_new_payment_method_option_html() {
478 478
 
479
-		$label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
479
+        $label = apply_filters( 'getpaid_new_payment_method_label', $this->new_method_label ? $this->new_method_label : __( 'Use a new payment method', 'invoicing' ), $this );
480 480
 
481
-		return sprintf(
482
-			'<li class="getpaid-new-payment-method">
481
+        return sprintf(
482
+            '<li class="getpaid-new-payment-method">
483 483
 				<label>
484 484
 					<input name="getpaid-%1$s-payment-method" type="radio" value="new" style="width:auto;" />
485 485
 					<span>%2$s</span>
486 486
 				</label>
487 487
 			</li>',
488
-			esc_attr( $this->id ),
489
-			esc_html( $label )
490
-		);
491
-
492
-	}
493
-
494
-	/**
495
-	 * Outputs a checkbox for saving a new payment method to the database.
496
-	 *
497
-	 * @since 1.0.19
498
-	 */
499
-	public function save_payment_method_checkbox() {
488
+            esc_attr( $this->id ),
489
+            esc_html( $label )
490
+        );
491
+
492
+    }
493
+
494
+    /**
495
+     * Outputs a checkbox for saving a new payment method to the database.
496
+     *
497
+     * @since 1.0.19
498
+     */
499
+    public function save_payment_method_checkbox() {
500 500
 	
501
-		return sprintf(
502
-			'<p class="form-group getpaid-save-payment-method">
501
+        return sprintf(
502
+            '<p class="form-group getpaid-save-payment-method">
503 503
 				<label>
504 504
 					<input name="getpaid-%1$s-new-payment-method" type="checkbox" value="true" style="width:auto;" />
505 505
 					<span>%2$s</span>
506 506
 				</label>
507 507
 			</p>',
508
-			esc_attr( $this->id ),
509
-			esc_html__( 'Save payment method', 'invoicing' )
510
-		);
508
+            esc_attr( $this->id ),
509
+            esc_html__( 'Save payment method', 'invoicing' )
510
+        );
511 511
 
512
-	}
512
+    }
513 513
 
514
-	/**
515
-	 * Registers the gateway.
516
-	 *
517
-	 * @return array
518
-	 */
519
-	public function register_gateway( $gateways ) {
514
+    /**
515
+     * Registers the gateway.
516
+     *
517
+     * @return array
518
+     */
519
+    public function register_gateway( $gateways ) {
520 520
 
521
-		$gateways[ $this->id ] = array(
521
+        $gateways[ $this->id ] = array(
522 522
 
523
-			'admin_label'    => $this->method_title,
523
+            'admin_label'    => $this->method_title,
524 524
             'checkout_label' => $this->title,
525
-			'ordering'       => $this->order,
526
-
527
-		);
528
-
529
-		return $gateways;
530
-
531
-	}
532
-
533
-	/**
534
-	 * Checks whether or not this is a sandbox request.
535
-	 *
536
-	 * @param  WPInv_Invoice|null $invoice Invoice object or null.
537
-	 * @return bool
538
-	 */
539
-	public function is_sandbox( $invoice = null ) {
540
-
541
-		if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
542
-			return $invoice->get_mode() == 'test';
543
-		}
544
-
545
-		return wpinv_is_test_mode( $this->id );
546
-
547
-	}
548
-
549
-	/**
550
-	 * Renames the checkout button
551
-	 *
552
-	 * @return string
553
-	 */
554
-	public function rename_checkout_button() {
555
-		return $this->checkout_button_text;
556
-	}
557
-
558
-	/**
559
-	 * Validate gateway currency
560
-	 *
561
-	 * @return bool
562
-	 */
563
-	public function validate_currency( $validation, $currency ) {
564
-
565
-		// Required currencies.
566
-		if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
567
-			return false;
568
-		}
569
-
570
-		// Excluded currencies.
571
-		if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
572
-			return false;
573
-		}
574
-
575
-		return $validation;
576
-	}
525
+            'ordering'       => $this->order,
526
+
527
+        );
528
+
529
+        return $gateways;
530
+
531
+    }
532
+
533
+    /**
534
+     * Checks whether or not this is a sandbox request.
535
+     *
536
+     * @param  WPInv_Invoice|null $invoice Invoice object or null.
537
+     * @return bool
538
+     */
539
+    public function is_sandbox( $invoice = null ) {
540
+
541
+        if ( ! empty( $invoice ) && ! $invoice->needs_payment() ) {
542
+            return $invoice->get_mode() == 'test';
543
+        }
544
+
545
+        return wpinv_is_test_mode( $this->id );
546
+
547
+    }
548
+
549
+    /**
550
+     * Renames the checkout button
551
+     *
552
+     * @return string
553
+     */
554
+    public function rename_checkout_button() {
555
+        return $this->checkout_button_text;
556
+    }
557
+
558
+    /**
559
+     * Validate gateway currency
560
+     *
561
+     * @return bool
562
+     */
563
+    public function validate_currency( $validation, $currency ) {
564
+
565
+        // Required currencies.
566
+        if ( ! empty( $this->currencies ) && ! in_array( $currency, $this->currencies ) ) {
567
+            return false;
568
+        }
569
+
570
+        // Excluded currencies.
571
+        if ( ! empty( $this->exclude_currencies ) && in_array( $currency, $this->exclude_currencies ) ) {
572
+            return false;
573
+        }
574
+
575
+        return $validation;
576
+    }
577 577
 
578 578
 }
Please login to merge, or discard this patch.
includes/class-wpinv.php 1 patch
Indentation   +51 added lines, -51 removed lines patch added patch discarded remove patch
@@ -178,10 +178,10 @@  discard block
 block discarded – undo
178 178
         require_once( WPINV_PLUGIN_DIR . 'includes/wpinv-error-functions.php' );
179 179
 
180 180
         // Register autoloader.
181
-		try {
182
-			spl_autoload_register( array( $this, 'autoload' ), true );
183
-		} catch ( Exception $e ) {
184
-			wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
181
+        try {
182
+            spl_autoload_register( array( $this, 'autoload' ), true );
183
+        } catch ( Exception $e ) {
184
+            wpinv_error_log( $e->getMessage(), '', __FILE__, 149, true );
185 185
         }
186 186
 
187 187
         require_once( WPINV_PLUGIN_DIR . 'includes/class-getpaid-post-types.php' );
@@ -206,11 +206,11 @@  discard block
 block discarded – undo
206 206
         require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-privacy.php' );
207 207
         require_once( WPINV_PLUGIN_DIR . 'includes/libraries/class-ayecode-addons.php' );
208 208
         require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-addons.php' );
209
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
210
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
211
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
212
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
213
-	    require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
209
+        require_once( WPINV_PLUGIN_DIR . 'widgets/checkout.php' );
210
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-history.php' );
211
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-receipt.php' );
212
+        require_once( WPINV_PLUGIN_DIR . 'widgets/invoice-messages.php' );
213
+        require_once( WPINV_PLUGIN_DIR . 'widgets/subscriptions.php' );
214 214
         require_once( WPINV_PLUGIN_DIR . 'widgets/buy-item.php' );
215 215
         require_once( WPINV_PLUGIN_DIR . 'widgets/getpaid.php' );
216 216
         require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-payment-form-elements.php' );
@@ -272,48 +272,48 @@  discard block
 block discarded – undo
272 272
     }
273 273
 
274 274
     /**
275
-	 * Class autoloader
276
-	 *
277
-	 * @param       string $class_name The name of the class to load.
278
-	 * @access      public
279
-	 * @since       1.0.19
280
-	 * @return      void
281
-	 */
282
-	public function autoload( $class_name ) {
283
-
284
-		// Normalize the class name...
285
-		$class_name  = strtolower( $class_name );
286
-
287
-		// ... and make sure it is our class.
288
-		if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
289
-			return;
290
-		}
291
-
292
-		// Next, prepare the file name from the class.
293
-		$file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
275
+     * Class autoloader
276
+     *
277
+     * @param       string $class_name The name of the class to load.
278
+     * @access      public
279
+     * @since       1.0.19
280
+     * @return      void
281
+     */
282
+    public function autoload( $class_name ) {
283
+
284
+        // Normalize the class name...
285
+        $class_name  = strtolower( $class_name );
286
+
287
+        // ... and make sure it is our class.
288
+        if ( false === strpos( $class_name, 'getpaid_' ) && false === strpos( $class_name, 'wpinv_' ) ) {
289
+            return;
290
+        }
291
+
292
+        // Next, prepare the file name from the class.
293
+        $file_name = 'class-' . str_replace( '_', '-', $class_name ) . '.php';
294 294
 
295 295
         // Base path of the classes.
296 296
         $plugin_path = untrailingslashit( WPINV_PLUGIN_DIR );
297 297
 
298
-		// And an array of possible locations in order of importance.
299
-		$locations = array(
298
+        // And an array of possible locations in order of importance.
299
+        $locations = array(
300 300
             "$plugin_path/includes",
301 301
             "$plugin_path/includes/data-stores",
302 302
             "$plugin_path/includes/gateways",
303 303
             "$plugin_path/includes/admin",
304 304
             "$plugin_path/includes/admin/meta-boxes",
305
-		);
305
+        );
306 306
 
307
-		foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
307
+        foreach ( apply_filters( 'getpaid_autoload_locations', $locations ) as $location ) {
308 308
 
309
-			if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
310
-				include trailingslashit( $location ) . $file_name;
311
-				break;
312
-			}
309
+            if ( file_exists( trailingslashit( $location ) . $file_name ) ) {
310
+                include trailingslashit( $location ) . $file_name;
311
+                break;
312
+            }
313 313
 
314
-		}
314
+        }
315 315
 
316
-	}
316
+    }
317 317
 
318 318
     /**
319 319
      * Inits hooks etc.
@@ -427,7 +427,7 @@  discard block
 block discarded – undo
427 427
             wp_register_style( 'jquery-ui-css', WPINV_PLUGIN_URL . 'assets/css/jquery-ui' . $suffix . '.css', array(), '1.8.16' );
428 428
             wp_enqueue_style( 'jquery-ui-css' );
429 429
             wp_deregister_style( 'yoast-seo-select2' );
430
-	        wp_deregister_style( 'yoast-seo-monorepo' );
430
+            wp_deregister_style( 'yoast-seo-monorepo' );
431 431
         }
432 432
 
433 433
         wp_register_style( 'wpinv_meta_box_style', WPINV_PLUGIN_URL . 'assets/css/meta-box.css', array(), WPINV_VERSION );
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
         if ( $page == 'wpinv-subscriptions' ) {
442 442
             wp_enqueue_script( 'jquery-ui-datepicker' );
443 443
             wp_deregister_style( 'yoast-seo-select2' );
444
-	        wp_deregister_style( 'yoast-seo-monorepo' );
444
+            wp_deregister_style( 'yoast-seo-monorepo' );
445 445
         }
446 446
         
447 447
         if ( $enqueue_datepicker = apply_filters( 'wpinv_admin_enqueue_jquery_ui_datepicker', $enqueue ) ) {
@@ -610,19 +610,19 @@  discard block
 block discarded – undo
610 610
         require_once( WPINV_PLUGIN_DIR . 'includes/class-wpinv-bp-core.php' );
611 611
     }
612 612
 
613
-	/**
614
-	 * Register widgets
615
-	 *
616
-	 */
617
-	public function register_widgets() {
618
-		register_widget( "WPInv_Checkout_Widget" );
619
-		register_widget( "WPInv_History_Widget" );
620
-		register_widget( "WPInv_Receipt_Widget" );
621
-		register_widget( "WPInv_Subscriptions_Widget" );
622
-		register_widget( "WPInv_Buy_Item_Widget" );
613
+    /**
614
+     * Register widgets
615
+     *
616
+     */
617
+    public function register_widgets() {
618
+        register_widget( "WPInv_Checkout_Widget" );
619
+        register_widget( "WPInv_History_Widget" );
620
+        register_widget( "WPInv_Receipt_Widget" );
621
+        register_widget( "WPInv_Subscriptions_Widget" );
622
+        register_widget( "WPInv_Buy_Item_Widget" );
623 623
         register_widget( "WPInv_Messages_Widget" );
624 624
         register_widget( 'WPInv_GetPaid_Widget' );
625
-	}
625
+    }
626 626
     
627 627
     /**
628 628
      * Remove our pages from yoast sitemaps.
Please login to merge, or discard this patch.