Passed
Push — master ( 256d53...35ff88 )
by Brian
10:46
created
includes/payments/class-getpaid-payment-form.php 1 patch
Indentation   +580 added lines, -580 removed lines patch added patch discarded remove patch
@@ -1,6 +1,6 @@  discard block
 block discarded – undo
1 1
 <?php
2 2
 if ( ! defined( 'ABSPATH' ) ) {
3
-	exit;
3
+    exit;
4 4
 }
5 5
 
6 6
 /**
@@ -10,55 +10,55 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form extends GetPaid_Data {
11 11
 
12 12
     /**
13
-	 * Which data store to load.
14
-	 *
15
-	 * @var string
16
-	 */
13
+     * Which data store to load.
14
+     *
15
+     * @var string
16
+     */
17 17
     protected $data_store_name = 'payment_form';
18 18
 
19 19
     /**
20
-	 * This is the name of this object type.
21
-	 *
22
-	 * @var string
23
-	 */
24
-	protected $object_type = 'payment_form';
20
+     * This is the name of this object type.
21
+     *
22
+     * @var string
23
+     */
24
+    protected $object_type = 'payment_form';
25 25
 
26 26
     /**
27
-	 * Form Data array. This is the core form data exposed in APIs.
28
-	 *
29
-	 * @since 1.0.19
30
-	 * @var array
31
-	 */
32
-	protected $data = array(
33
-		'status'               => 'draft',
34
-		'version'              => '',
35
-		'date_created'         => null,
27
+     * Form Data array. This is the core form data exposed in APIs.
28
+     *
29
+     * @since 1.0.19
30
+     * @var array
31
+     */
32
+    protected $data = array(
33
+        'status'               => 'draft',
34
+        'version'              => '',
35
+        'date_created'         => null,
36 36
         'date_modified'        => null,
37 37
         'name'                 => '',
38 38
         'author'               => 1,
39 39
         'elements'             => null,
40
-		'items'                => null,
41
-		'earned'               => 0,
42
-		'refunded'             => 0,
43
-		'cancelled'            => 0,
44
-		'failed'               => 0,
45
-	);
46
-
47
-    /**
48
-	 * Stores meta in cache for future reads.
49
-	 *
50
-	 * A group must be set to to enable caching.
51
-	 *
52
-	 * @var string
53
-	 */
54
-	protected $cache_group = 'getpaid_forms';
55
-
56
-	/**
57
-	 * Stores a reference to the invoice if the form is for an invoice..
58
-	 *
59
-	 * @var WPInv_Invoice
60
-	 */
61
-	public $invoice = 0;
40
+        'items'                => null,
41
+        'earned'               => 0,
42
+        'refunded'             => 0,
43
+        'cancelled'            => 0,
44
+        'failed'               => 0,
45
+    );
46
+
47
+    /**
48
+     * Stores meta in cache for future reads.
49
+     *
50
+     * A group must be set to to enable caching.
51
+     *
52
+     * @var string
53
+     */
54
+    protected $cache_group = 'getpaid_forms';
55
+
56
+    /**
57
+     * Stores a reference to the invoice if the form is for an invoice..
58
+     *
59
+     * @var WPInv_Invoice
60
+     */
61
+    public $invoice = 0;
62 62
 
63 63
     /**
64 64
      * Stores a reference to the original WP_Post object
@@ -68,35 +68,35 @@  discard block
 block discarded – undo
68 68
     protected $post = null;
69 69
 
70 70
     /**
71
-	 * Get the form if ID is passed, otherwise the form is new and empty.
72
-	 *
73
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
-	 */
75
-	public function __construct( $form = 0 ) {
76
-		parent::__construct( $form );
71
+     * Get the form if ID is passed, otherwise the form is new and empty.
72
+     *
73
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
74
+     */
75
+    public function __construct( $form = 0 ) {
76
+        parent::__construct( $form );
77 77
 
78
-		if ( is_numeric( $form ) && $form > 0 ) {
79
-			$this->set_id( $form );
80
-		} elseif ( $form instanceof self ) {
78
+        if ( is_numeric( $form ) && $form > 0 ) {
79
+            $this->set_id( $form );
80
+        } elseif ( $form instanceof self ) {
81 81
 
82
-			$this->set_id( $form->get_id() );
83
-			$this->invoice = $form->invoice;
82
+            $this->set_id( $form->get_id() );
83
+            $this->invoice = $form->invoice;
84 84
 
85
-		} elseif ( ! empty( $form->ID ) ) {
86
-			$this->set_id( $form->ID );
87
-		} else {
88
-			$this->set_object_read( true );
89
-		}
85
+        } elseif ( ! empty( $form->ID ) ) {
86
+            $this->set_id( $form->ID );
87
+        } else {
88
+            $this->set_object_read( true );
89
+        }
90 90
 
91 91
         // Load the datastore.
92
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
92
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
93 93
 
94
-		if ( $this->get_id() > 0 ) {
94
+        if ( $this->get_id() > 0 ) {
95 95
             $this->post = get_post( $this->get_id() );
96
-			$this->data_store->read( $this );
96
+            $this->data_store->read( $this );
97 97
         }
98 98
 
99
-	}
99
+    }
100 100
 
101 101
     /*
102 102
 	|--------------------------------------------------------------------------
@@ -114,358 +114,358 @@  discard block
 block discarded – undo
114 114
     */
115 115
 
116 116
     /**
117
-	 * Get plugin version when the form was created.
118
-	 *
119
-	 * @since 1.0.19
120
-	 * @param  string $context View or edit context.
121
-	 * @return string
122
-	 */
123
-	public function get_version( $context = 'view' ) {
124
-		return $this->get_prop( 'version', $context );
117
+     * Get plugin version when the form was created.
118
+     *
119
+     * @since 1.0.19
120
+     * @param  string $context View or edit context.
121
+     * @return string
122
+     */
123
+    public function get_version( $context = 'view' ) {
124
+        return $this->get_prop( 'version', $context );
125 125
     }
126 126
 
127 127
     /**
128
-	 * Get date when the form was created.
129
-	 *
130
-	 * @since 1.0.19
131
-	 * @param  string $context View or edit context.
132
-	 * @return string
133
-	 */
134
-	public function get_date_created( $context = 'view' ) {
135
-		return $this->get_prop( 'date_created', $context );
128
+     * Get date when the form was created.
129
+     *
130
+     * @since 1.0.19
131
+     * @param  string $context View or edit context.
132
+     * @return string
133
+     */
134
+    public function get_date_created( $context = 'view' ) {
135
+        return $this->get_prop( 'date_created', $context );
136 136
     }
137 137
 
138 138
     /**
139
-	 * Get GMT date when the form was created.
140
-	 *
141
-	 * @since 1.0.19
142
-	 * @param  string $context View or edit context.
143
-	 * @return string
144
-	 */
145
-	public function get_date_created_gmt( $context = 'view' ) {
139
+     * Get GMT date when the form was created.
140
+     *
141
+     * @since 1.0.19
142
+     * @param  string $context View or edit context.
143
+     * @return string
144
+     */
145
+    public function get_date_created_gmt( $context = 'view' ) {
146 146
         $date = $this->get_date_created( $context );
147 147
 
148 148
         if ( $date ) {
149 149
             $date = get_gmt_from_date( $date );
150 150
         }
151
-		return $date;
151
+        return $date;
152 152
     }
153 153
 
154 154
     /**
155
-	 * Get date when the form was last modified.
156
-	 *
157
-	 * @since 1.0.19
158
-	 * @param  string $context View or edit context.
159
-	 * @return string
160
-	 */
161
-	public function get_date_modified( $context = 'view' ) {
162
-		return $this->get_prop( 'date_modified', $context );
155
+     * Get date when the form was last modified.
156
+     *
157
+     * @since 1.0.19
158
+     * @param  string $context View or edit context.
159
+     * @return string
160
+     */
161
+    public function get_date_modified( $context = 'view' ) {
162
+        return $this->get_prop( 'date_modified', $context );
163 163
     }
164 164
 
165 165
     /**
166
-	 * Get GMT date when the form was last modified.
167
-	 *
168
-	 * @since 1.0.19
169
-	 * @param  string $context View or edit context.
170
-	 * @return string
171
-	 */
172
-	public function get_date_modified_gmt( $context = 'view' ) {
166
+     * Get GMT date when the form was last modified.
167
+     *
168
+     * @since 1.0.19
169
+     * @param  string $context View or edit context.
170
+     * @return string
171
+     */
172
+    public function get_date_modified_gmt( $context = 'view' ) {
173 173
         $date = $this->get_date_modified( $context );
174 174
 
175 175
         if ( $date ) {
176 176
             $date = get_gmt_from_date( $date );
177 177
         }
178
-		return $date;
178
+        return $date;
179 179
     }
180 180
 
181 181
     /**
182
-	 * Get the form name.
183
-	 *
184
-	 * @since 1.0.19
185
-	 * @param  string $context View or edit context.
186
-	 * @return string
187
-	 */
188
-	public function get_name( $context = 'view' ) {
189
-		return $this->get_prop( 'name', $context );
182
+     * Get the form name.
183
+     *
184
+     * @since 1.0.19
185
+     * @param  string $context View or edit context.
186
+     * @return string
187
+     */
188
+    public function get_name( $context = 'view' ) {
189
+        return $this->get_prop( 'name', $context );
190 190
     }
191 191
 
192 192
     /**
193
-	 * Alias of self::get_name().
194
-	 *
195
-	 * @since 1.0.19
196
-	 * @param  string $context View or edit context.
197
-	 * @return string
198
-	 */
199
-	public function get_title( $context = 'view' ) {
200
-		return $this->get_name( $context );
201
-	}
193
+     * Alias of self::get_name().
194
+     *
195
+     * @since 1.0.19
196
+     * @param  string $context View or edit context.
197
+     * @return string
198
+     */
199
+    public function get_title( $context = 'view' ) {
200
+        return $this->get_name( $context );
201
+    }
202 202
 
203 203
     /**
204
-	 * Get the owner of the form.
205
-	 *
206
-	 * @since 1.0.19
207
-	 * @param  string $context View or edit context.
208
-	 * @return int
209
-	 */
210
-	public function get_author( $context = 'view' ) {
211
-		return (int) $this->get_prop( 'author', $context );
204
+     * Get the owner of the form.
205
+     *
206
+     * @since 1.0.19
207
+     * @param  string $context View or edit context.
208
+     * @return int
209
+     */
210
+    public function get_author( $context = 'view' ) {
211
+        return (int) $this->get_prop( 'author', $context );
212 212
     }
213 213
 
214 214
     /**
215
-	 * Get the elements that make up the form.
216
-	 *
217
-	 * @since 1.0.19
218
-	 * @param  string $context View or edit context.
219
-	 * @return array
220
-	 */
221
-	public function get_elements( $context = 'view' ) {
222
-		$elements = $this->get_prop( 'elements', $context );
215
+     * Get the elements that make up the form.
216
+     *
217
+     * @since 1.0.19
218
+     * @param  string $context View or edit context.
219
+     * @return array
220
+     */
221
+    public function get_elements( $context = 'view' ) {
222
+        $elements = $this->get_prop( 'elements', $context );
223 223
 
224
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
224
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
225 225
             return wpinv_get_data( 'sample-payment-form' );
226
-		}
226
+        }
227 227
 
228
-		// Ensure that all required elements exist.
229
-		$_elements = array();
230
-		foreach ( $elements as $element ) {
228
+        // Ensure that all required elements exist.
229
+        $_elements = array();
230
+        foreach ( $elements as $element ) {
231 231
 
232
-			if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
232
+            if ( $element['type'] == 'pay_button' && ! $this->has_element_type( 'gateway_select' ) ) {
233 233
 
234
-				$_elements[] = array(
235
-					'text'        => __( 'Select Payment Method', 'invoicing' ),
236
-					'id'          => 'gtscicd',
237
-					'name'        => 'gtscicd',
238
-					'type'        => 'gateway_select',
239
-					'premade'     => true
234
+                $_elements[] = array(
235
+                    'text'        => __( 'Select Payment Method', 'invoicing' ),
236
+                    'id'          => 'gtscicd',
237
+                    'name'        => 'gtscicd',
238
+                    'type'        => 'gateway_select',
239
+                    'premade'     => true
240 240
 			
241
-				);
241
+                );
242 242
 
243
-			}
243
+            }
244 244
 
245
-			$_elements[] = $element;
245
+            $_elements[] = $element;
246 246
 
247
-		}
247
+        }
248 248
 
249 249
         return $_elements;
250
-	}
251
-
252
-	/**
253
-	 * Get the items sold via the form.
254
-	 *
255
-	 * @since 1.0.19
256
-	 * @param  string $context View or edit context.
257
-	 * @param  string $return objects or arrays.
258
-	 * @return GetPaid_Form_Item[]
259
-	 */
260
-	public function get_items( $context = 'view', $return = 'objects' ) {
261
-		$items = $this->get_prop( 'items', $context );
262
-
263
-		if ( empty( $items ) || ! is_array( $items ) ) {
250
+    }
251
+
252
+    /**
253
+     * Get the items sold via the form.
254
+     *
255
+     * @since 1.0.19
256
+     * @param  string $context View or edit context.
257
+     * @param  string $return objects or arrays.
258
+     * @return GetPaid_Form_Item[]
259
+     */
260
+    public function get_items( $context = 'view', $return = 'objects' ) {
261
+        $items = $this->get_prop( 'items', $context );
262
+
263
+        if ( empty( $items ) || ! is_array( $items ) ) {
264 264
             $items = wpinv_get_data( 'sample-payment-form-items' );
265
-		}
265
+        }
266 266
 
267
-		// Convert the items.
268
-		$prepared = array();
267
+        // Convert the items.
268
+        $prepared = array();
269 269
 
270
-		foreach ( $items as $key => $value ) {
270
+        foreach ( $items as $key => $value ) {
271 271
 
272
-			// Form items.
273
-			if ( $value instanceof GetPaid_Form_Item ) {
272
+            // Form items.
273
+            if ( $value instanceof GetPaid_Form_Item ) {
274 274
 
275
-				if ( $value->can_purchase() ) {
276
-					$prepared[] = $value;
277
-				}
275
+                if ( $value->can_purchase() ) {
276
+                    $prepared[] = $value;
277
+                }
278 278
 
279
-				continue;
279
+                continue;
280 280
 
281
-			}
281
+            }
282 282
 
283
-			// $item_id => $quantity (buy buttons)
284
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
-				$item = new GetPaid_Form_Item( $key );
283
+            // $item_id => $quantity (buy buttons)
284
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
285
+                $item = new GetPaid_Form_Item( $key );
286 286
 
287
-				if ( $item->can_purchase() ) {
287
+                if ( $item->can_purchase() ) {
288 288
 
289
-					$value = (float) $value;
290
-					$item->set_quantity( $value );
291
-					if ( 0 == $value ) {
292
-						$item->set_quantity( 1 );
293
-						$item->set_allow_quantities( true );
294
-					}
289
+                    $value = (float) $value;
290
+                    $item->set_quantity( $value );
291
+                    if ( 0 == $value ) {
292
+                        $item->set_quantity( 1 );
293
+                        $item->set_allow_quantities( true );
294
+                    }
295 295
 
296
-					$prepared[] = $item;
297
-				}
296
+                    $prepared[] = $item;
297
+                }
298 298
 
299
-				continue;
300
-			}
299
+                continue;
300
+            }
301 301
 
302
-			// Items saved via payment forms editor.
303
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
302
+            // Items saved via payment forms editor.
303
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
304 304
 
305
-				$item = new GetPaid_Form_Item( $value['id'] );
305
+                $item = new GetPaid_Form_Item( $value['id'] );
306 306
 
307
-				if ( ! $item->can_purchase() ) {
308
-					continue;
309
-				}
307
+                if ( ! $item->can_purchase() ) {
308
+                    continue;
309
+                }
310 310
 
311
-				// Sub-total (Cart items).
312
-				if ( isset( $value['subtotal'] ) ) {
313
-					$item->set_price( $value['subtotal'] );
314
-				}
311
+                // Sub-total (Cart items).
312
+                if ( isset( $value['subtotal'] ) ) {
313
+                    $item->set_price( $value['subtotal'] );
314
+                }
315 315
 
316
-				if ( isset( $value['quantity'] ) ) {
317
-					$item->set_quantity( $value['quantity'] );
318
-				}
316
+                if ( isset( $value['quantity'] ) ) {
317
+                    $item->set_quantity( $value['quantity'] );
318
+                }
319 319
 
320
-				if ( isset( $value['allow_quantities'] ) ) {
321
-					$item->set_allow_quantities( $value['allow_quantities'] );
322
-				}
320
+                if ( isset( $value['allow_quantities'] ) ) {
321
+                    $item->set_allow_quantities( $value['allow_quantities'] );
322
+                }
323 323
 
324
-				if ( isset( $value['required'] ) ) {
325
-					$item->set_is_required( $value['required'] );
326
-				}
324
+                if ( isset( $value['required'] ) ) {
325
+                    $item->set_is_required( $value['required'] );
326
+                }
327 327
 
328
-				if ( isset( $value['description'] ) ) {
329
-					$item->set_custom_description( $value['description'] );
330
-				}
328
+                if ( isset( $value['description'] ) ) {
329
+                    $item->set_custom_description( $value['description'] );
330
+                }
331 331
 
332
-				$prepared[] = $item;
333
-				continue;
332
+                $prepared[] = $item;
333
+                continue;
334 334
 
335
-			}
335
+            }
336 336
 
337
-			// $item_id => array( 'price' => 10 ) (item variations)
338
-			if ( is_numeric( $key ) && is_array( $value ) ) {
339
-				$item = new GetPaid_Form_Item( $key );
337
+            // $item_id => array( 'price' => 10 ) (item variations)
338
+            if ( is_numeric( $key ) && is_array( $value ) ) {
339
+                $item = new GetPaid_Form_Item( $key );
340 340
 
341
-				if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
-					$item->set_price( $value['price'] );
343
-				}
344
-
345
-				if ( $item->can_purchase() ) {
346
-					$prepared[] = $item;
347
-				}
348
-
349
-				continue;
350
-			}
351
-
352
-		}
353
-
354
-		if ( 'objects' == $return && 'view' == $context ) {
355
-			return $prepared;
356
-		}
357
-
358
-		$items = array();
359
-		foreach ( $prepared as $item ) {
360
-			$items[] = $item->prepare_data_for_use();
361
-		}
362
-
363
-		return $items;
364
-	}
365
-
366
-	/**
367
-	 * Get a single item belonging to the form.
368
-	 *
369
-	 * @since 1.0.19
370
-	 * @param  int $item_id The item id to return.
371
-	 * @return GetPaid_Form_Item|bool
372
-	 */
373
-	public function get_item( $item_id ) {
374
-
375
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
376
-			return false;
377
-		}
378
-
379
-		foreach( $this->get_items() as $item ) {
380
-			if ( $item->get_id() == (int) $item_id ) {
381
-				return $item;
382
-			}
383
-		}
384
-
385
-		return false;
386
-
387
-	}
388
-
389
-	/**
390
-	 * Gets a single element.
391
-	 *
392
-	 * @since 1.0.19
393
-	 * @param  string $element_type The element type to return.
394
-	 * @return array|bool
395
-	 */
396
-	public function get_element_type( $element_type ) {
397
-
398
-		if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
399
-			return false;
400
-		}
401
-
402
-		foreach ( $this->get_prop( 'elements' ) as $element ) {
403
-
404
-			if ( $element['type'] == $element_type ) {
405
-				return $element;
406
-			}
407
-
408
-		}
409
-
410
-		return false;
411
-
412
-	}
413
-
414
-	/**
415
-	 * Get the total amount earned via this form.
416
-	 *
417
-	 * @since 1.0.19
418
-	 * @param  string $context View or edit context.
419
-	 * @return float
420
-	 */
421
-	public function get_earned( $context = 'view' ) {
422
-		return $this->get_prop( 'earned', $context );
423
-	}
424
-
425
-	/**
426
-	 * Get the total amount refunded via this form.
427
-	 *
428
-	 * @since 1.0.19
429
-	 * @param  string $context View or edit context.
430
-	 * @return float
431
-	 */
432
-	public function get_refunded( $context = 'view' ) {
433
-		return $this->get_prop( 'refunded', $context );
434
-	}
435
-
436
-	/**
437
-	 * Get the total amount cancelled via this form.
438
-	 *
439
-	 * @since 1.0.19
440
-	 * @param  string $context View or edit context.
441
-	 * @return float
442
-	 */
443
-	public function get_cancelled( $context = 'view' ) {
444
-		return $this->get_prop( 'cancelled', $context );
445
-	}
446
-
447
-	/**
448
-	 * Get the total amount failed via this form.
449
-	 *
450
-	 * @since 1.0.19
451
-	 * @param  string $context View or edit context.
452
-	 * @return float
453
-	 */
454
-	public function get_failed( $context = 'view' ) {
455
-		return $this->get_prop( 'failed', $context );
456
-	}
457
-
458
-	/**
459
-	 * Get the currency.
460
-	 *
461
-	 * @since 1.0.19
462
-	 * @param  string $context View or edit context.
463
-	 * @return string
464
-	 */
465
-	public function get_currency() {
466
-		$currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
467
-		return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
468
-	}
341
+                if ( isset( $value['price'] ) && $item->user_can_set_their_price() ) {
342
+                    $item->set_price( $value['price'] );
343
+                }
344
+
345
+                if ( $item->can_purchase() ) {
346
+                    $prepared[] = $item;
347
+                }
348
+
349
+                continue;
350
+            }
351
+
352
+        }
353
+
354
+        if ( 'objects' == $return && 'view' == $context ) {
355
+            return $prepared;
356
+        }
357
+
358
+        $items = array();
359
+        foreach ( $prepared as $item ) {
360
+            $items[] = $item->prepare_data_for_use();
361
+        }
362
+
363
+        return $items;
364
+    }
365
+
366
+    /**
367
+     * Get a single item belonging to the form.
368
+     *
369
+     * @since 1.0.19
370
+     * @param  int $item_id The item id to return.
371
+     * @return GetPaid_Form_Item|bool
372
+     */
373
+    public function get_item( $item_id ) {
374
+
375
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
376
+            return false;
377
+        }
378
+
379
+        foreach( $this->get_items() as $item ) {
380
+            if ( $item->get_id() == (int) $item_id ) {
381
+                return $item;
382
+            }
383
+        }
384
+
385
+        return false;
386
+
387
+    }
388
+
389
+    /**
390
+     * Gets a single element.
391
+     *
392
+     * @since 1.0.19
393
+     * @param  string $element_type The element type to return.
394
+     * @return array|bool
395
+     */
396
+    public function get_element_type( $element_type ) {
397
+
398
+        if ( empty( $element_type ) || ! is_scalar( $element_type ) ) {
399
+            return false;
400
+        }
401
+
402
+        foreach ( $this->get_prop( 'elements' ) as $element ) {
403
+
404
+            if ( $element['type'] == $element_type ) {
405
+                return $element;
406
+            }
407
+
408
+        }
409
+
410
+        return false;
411
+
412
+    }
413
+
414
+    /**
415
+     * Get the total amount earned via this form.
416
+     *
417
+     * @since 1.0.19
418
+     * @param  string $context View or edit context.
419
+     * @return float
420
+     */
421
+    public function get_earned( $context = 'view' ) {
422
+        return $this->get_prop( 'earned', $context );
423
+    }
424
+
425
+    /**
426
+     * Get the total amount refunded via this form.
427
+     *
428
+     * @since 1.0.19
429
+     * @param  string $context View or edit context.
430
+     * @return float
431
+     */
432
+    public function get_refunded( $context = 'view' ) {
433
+        return $this->get_prop( 'refunded', $context );
434
+    }
435
+
436
+    /**
437
+     * Get the total amount cancelled via this form.
438
+     *
439
+     * @since 1.0.19
440
+     * @param  string $context View or edit context.
441
+     * @return float
442
+     */
443
+    public function get_cancelled( $context = 'view' ) {
444
+        return $this->get_prop( 'cancelled', $context );
445
+    }
446
+
447
+    /**
448
+     * Get the total amount failed via this form.
449
+     *
450
+     * @since 1.0.19
451
+     * @param  string $context View or edit context.
452
+     * @return float
453
+     */
454
+    public function get_failed( $context = 'view' ) {
455
+        return $this->get_prop( 'failed', $context );
456
+    }
457
+
458
+    /**
459
+     * Get the currency.
460
+     *
461
+     * @since 1.0.19
462
+     * @param  string $context View or edit context.
463
+     * @return string
464
+     */
465
+    public function get_currency() {
466
+        $currency = empty( $this->invoice ) ? wpinv_get_currency() : $this->invoice->get_currency();
467
+        return apply_filters( 'getpaid-payment-form-currency', $currency, $this );
468
+    }
469 469
 
470 470
     /*
471 471
 	|--------------------------------------------------------------------------
@@ -478,22 +478,22 @@  discard block
 block discarded – undo
478 478
     */
479 479
 
480 480
     /**
481
-	 * Set plugin version when the item was created.
482
-	 *
483
-	 * @since 1.0.19
484
-	 */
485
-	public function set_version( $value ) {
486
-		$this->set_prop( 'version', $value );
481
+     * Set plugin version when the item was created.
482
+     *
483
+     * @since 1.0.19
484
+     */
485
+    public function set_version( $value ) {
486
+        $this->set_prop( 'version', $value );
487 487
     }
488 488
 
489 489
     /**
490
-	 * Set date when the item was created.
491
-	 *
492
-	 * @since 1.0.19
493
-	 * @param string $value Value to set.
490
+     * Set date when the item was created.
491
+     *
492
+     * @since 1.0.19
493
+     * @param string $value Value to set.
494 494
      * @return bool Whether or not the date was set.
495
-	 */
496
-	public function set_date_created( $value ) {
495
+     */
496
+    public function set_date_created( $value ) {
497 497
         $date = strtotime( $value );
498 498
 
499 499
         if ( $date ) {
@@ -506,13 +506,13 @@  discard block
 block discarded – undo
506 506
     }
507 507
 
508 508
     /**
509
-	 * Set date when the item was last modified.
510
-	 *
511
-	 * @since 1.0.19
512
-	 * @param string $value Value to set.
509
+     * Set date when the item was last modified.
510
+     *
511
+     * @since 1.0.19
512
+     * @param string $value Value to set.
513 513
      * @return bool Whether or not the date was set.
514
-	 */
515
-	public function set_date_modified( $value ) {
514
+     */
515
+    public function set_date_modified( $value ) {
516 516
         $date = strtotime( $value );
517 517
 
518 518
         if ( $date ) {
@@ -525,165 +525,165 @@  discard block
 block discarded – undo
525 525
     }
526 526
 
527 527
     /**
528
-	 * Set the item name.
529
-	 *
530
-	 * @since 1.0.19
531
-	 * @param  string $value New name.
532
-	 */
533
-	public function set_name( $value ) {
534
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
535
-    }
536
-
537
-    /**
538
-	 * Alias of self::set_name().
539
-	 *
540
-	 * @since 1.0.19
541
-	 * @param  string $value New name.
542
-	 */
543
-	public function set_title( $value ) {
544
-		$this->set_name( $value );
545
-    }
546
-
547
-    /**
548
-	 * Set the owner of the item.
549
-	 *
550
-	 * @since 1.0.19
551
-	 * @param  int $value New author.
552
-	 */
553
-	public function set_author( $value ) {
554
-		$this->set_prop( 'author', (int) $value );
555
-	}
556
-
557
-	/**
558
-	 * Set the form elements.
559
-	 *
560
-	 * @since 1.0.19
561
-	 * @sinve 2.3.4 Array values sanitized.
562
-	 * @param  array $value Form elements.
563
-	 */
564
-	public function set_elements( $value ) {
565
-		if ( is_array( $value ) ) {
566
-			$this->set_prop( 'elements', wp_kses_post_deep( $value ) );
567
-		}
568
-	}
569
-
570
-	/**
571
-	 * Sanitize array values.
572
-	 *
573
-	 * @param $value
574
-	 *
575
-	 * @return mixed
576
-	 */
577
-	public function sanitize_array_values($value){
578
-
579
-		// sanitize
580
-		if(!empty($value )){
581
-
582
-			foreach($value as $key => $val_arr){
583
-
584
-				if(is_array($val_arr)){
585
-					// check if we have sub array items.
586
-					$sub_arr = array();
587
-					foreach($val_arr as $key2 => $val2){
588
-						if(is_array($val2)){
589
-							$sub_arr[$key2] = $this->sanitize_array_values($val2);
590
-							unset($val_arr[$key][$key2]);
591
-						}
592
-					}
593
-
594
-					// we allow some html in description so we sanitize it separately.
595
-					$help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : '';
596
-
597
-					// sanitize array elements
598
-					$value[$key] = array_map( 'sanitize_text_field', $val_arr );
599
-
600
-					// add back the description if set
601
-					if(isset($val_arr['description'])){ $value[$key]['description'] = $help_text;}
602
-
603
-					// add back sub array items after its been sanitized.
604
-					if ( ! empty( $sub_arr ) ) {
605
-						$value[$key] = array_merge($value[$key],$sub_arr);
606
-					}
607
-				}
608
-
609
-			}
610
-
611
-		}
612
-
613
-		return $value;
614
-	}
615
-
616
-	/**
617
-	 * Set the form items.
618
-	 *
619
-	 * @since 1.0.19
620
-	 * @param  array $value Form elements.
621
-	 */
622
-	public function set_items( $value ) {
623
-		if ( is_array( $value ) ) {
624
-			$this->set_prop( 'items', $value );
625
-		}
626
-	}
627
-
628
-	/**
629
-	 * Set the total amount earned via this form.
630
-	 *
631
-	 * @since 1.0.19
632
-	 * @param  float $value Amount earned.
633
-	 */
634
-	public function set_earned( $value ) {
635
-		$value = max( (float) $value, 0 );
636
-		$this->set_prop( 'earned', $value );
637
-	}
638
-
639
-	/**
640
-	 * Set the total amount refunded via this form.
641
-	 *
642
-	 * @since 1.0.19
643
-	 * @param  float $value Amount refunded.
644
-	 */
645
-	public function set_refunded( $value ) {
646
-		$value = max( (float) $value, 0 );
647
-		$this->set_prop( 'refunded', $value );
648
-	}
649
-
650
-	/**
651
-	 * Set the total amount cancelled via this form.
652
-	 *
653
-	 * @since 1.0.19
654
-	 * @param  float $value Amount cancelled.
655
-	 */
656
-	public function set_cancelled( $value ) {
657
-		$value = max( (float) $value, 0 );
658
-		$this->set_prop( 'cancelled', $value );
659
-	}
660
-
661
-	/**
662
-	 * Set the total amount failed via this form.
663
-	 *
664
-	 * @since 1.0.19
665
-	 * @param  float $value Amount cancelled.
666
-	 */
667
-	public function set_failed( $value ) {
668
-		$value = max( (float) $value, 0 );
669
-		$this->set_prop( 'failed', $value );
670
-	}
528
+     * Set the item name.
529
+     *
530
+     * @since 1.0.19
531
+     * @param  string $value New name.
532
+     */
533
+    public function set_name( $value ) {
534
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
535
+    }
536
+
537
+    /**
538
+     * Alias of self::set_name().
539
+     *
540
+     * @since 1.0.19
541
+     * @param  string $value New name.
542
+     */
543
+    public function set_title( $value ) {
544
+        $this->set_name( $value );
545
+    }
546
+
547
+    /**
548
+     * Set the owner of the item.
549
+     *
550
+     * @since 1.0.19
551
+     * @param  int $value New author.
552
+     */
553
+    public function set_author( $value ) {
554
+        $this->set_prop( 'author', (int) $value );
555
+    }
556
+
557
+    /**
558
+     * Set the form elements.
559
+     *
560
+     * @since 1.0.19
561
+     * @sinve 2.3.4 Array values sanitized.
562
+     * @param  array $value Form elements.
563
+     */
564
+    public function set_elements( $value ) {
565
+        if ( is_array( $value ) ) {
566
+            $this->set_prop( 'elements', wp_kses_post_deep( $value ) );
567
+        }
568
+    }
569
+
570
+    /**
571
+     * Sanitize array values.
572
+     *
573
+     * @param $value
574
+     *
575
+     * @return mixed
576
+     */
577
+    public function sanitize_array_values($value){
578
+
579
+        // sanitize
580
+        if(!empty($value )){
581
+
582
+            foreach($value as $key => $val_arr){
583
+
584
+                if(is_array($val_arr)){
585
+                    // check if we have sub array items.
586
+                    $sub_arr = array();
587
+                    foreach($val_arr as $key2 => $val2){
588
+                        if(is_array($val2)){
589
+                            $sub_arr[$key2] = $this->sanitize_array_values($val2);
590
+                            unset($val_arr[$key][$key2]);
591
+                        }
592
+                    }
593
+
594
+                    // we allow some html in description so we sanitize it separately.
595
+                    $help_text = !empty($val_arr['description']) ? wp_kses_post($val_arr['description']) : '';
596
+
597
+                    // sanitize array elements
598
+                    $value[$key] = array_map( 'sanitize_text_field', $val_arr );
599
+
600
+                    // add back the description if set
601
+                    if(isset($val_arr['description'])){ $value[$key]['description'] = $help_text;}
602
+
603
+                    // add back sub array items after its been sanitized.
604
+                    if ( ! empty( $sub_arr ) ) {
605
+                        $value[$key] = array_merge($value[$key],$sub_arr);
606
+                    }
607
+                }
608
+
609
+            }
610
+
611
+        }
612
+
613
+        return $value;
614
+    }
615
+
616
+    /**
617
+     * Set the form items.
618
+     *
619
+     * @since 1.0.19
620
+     * @param  array $value Form elements.
621
+     */
622
+    public function set_items( $value ) {
623
+        if ( is_array( $value ) ) {
624
+            $this->set_prop( 'items', $value );
625
+        }
626
+    }
627
+
628
+    /**
629
+     * Set the total amount earned via this form.
630
+     *
631
+     * @since 1.0.19
632
+     * @param  float $value Amount earned.
633
+     */
634
+    public function set_earned( $value ) {
635
+        $value = max( (float) $value, 0 );
636
+        $this->set_prop( 'earned', $value );
637
+    }
638
+
639
+    /**
640
+     * Set the total amount refunded via this form.
641
+     *
642
+     * @since 1.0.19
643
+     * @param  float $value Amount refunded.
644
+     */
645
+    public function set_refunded( $value ) {
646
+        $value = max( (float) $value, 0 );
647
+        $this->set_prop( 'refunded', $value );
648
+    }
649
+
650
+    /**
651
+     * Set the total amount cancelled via this form.
652
+     *
653
+     * @since 1.0.19
654
+     * @param  float $value Amount cancelled.
655
+     */
656
+    public function set_cancelled( $value ) {
657
+        $value = max( (float) $value, 0 );
658
+        $this->set_prop( 'cancelled', $value );
659
+    }
660
+
661
+    /**
662
+     * Set the total amount failed via this form.
663
+     *
664
+     * @since 1.0.19
665
+     * @param  float $value Amount cancelled.
666
+     */
667
+    public function set_failed( $value ) {
668
+        $value = max( (float) $value, 0 );
669
+        $this->set_prop( 'failed', $value );
670
+    }
671 671
 
672 672
     /**
673 673
      * Create an item. For backwards compatibilty.
674 674
      *
675 675
      * @deprecated
676
-	 * @return int item id
676
+     * @return int item id
677 677
      */
678 678
     public function create( $data = array() ) {
679 679
 
680
-		// Set the properties.
681
-		if ( is_array( $data ) ) {
682
-			$this->set_props( $data );
683
-		}
680
+        // Set the properties.
681
+        if ( is_array( $data ) ) {
682
+            $this->set_props( $data );
683
+        }
684 684
 
685
-		// Save the item.
686
-		return $this->save();
685
+        // Save the item.
686
+        return $this->save();
687 687
 
688 688
     }
689 689
 
@@ -691,7 +691,7 @@  discard block
 block discarded – undo
691 691
      * Updates an item. For backwards compatibilty.
692 692
      *
693 693
      * @deprecated
694
-	 * @return int item id
694
+     * @return int item id
695 695
      */
696 696
     public function update( $data = array() ) {
697 697
         return $this->create( $data );
@@ -707,22 +707,22 @@  discard block
 block discarded – undo
707 707
 	*/
708 708
 
709 709
     /**
710
-	 * Checks whether this is the default payment form.
711
-	 *
712
-	 * @since 1.0.19
713
-	 * @return bool
714
-	 */
710
+     * Checks whether this is the default payment form.
711
+     *
712
+     * @since 1.0.19
713
+     * @return bool
714
+     */
715 715
     public function is_default() {
716 716
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
717 717
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
718
-	}
718
+    }
719 719
 
720 720
     /**
721
-	 * Checks whether the form is active.
722
-	 *
723
-	 * @since 1.0.19
724
-	 * @return bool
725
-	 */
721
+     * Checks whether the form is active.
722
+     *
723
+     * @since 1.0.19
724
+     * @return bool
725
+     */
726 726
     public function is_active() {
727 727
         $is_active = 0 !== (int) $this->get_id();
728 728
 
@@ -731,76 +731,76 @@  discard block
 block discarded – undo
731 731
         }
732 732
 
733 733
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
734
-	}
735
-
736
-	/**
737
-	 * Checks whether the form has a given item.
738
-	 *
739
-	 * @since 1.0.19
740
-	 * @return bool
741
-	 */
734
+    }
735
+
736
+    /**
737
+     * Checks whether the form has a given item.
738
+     *
739
+     * @since 1.0.19
740
+     * @return bool
741
+     */
742 742
     public function has_item( $item_id ) {
743 743
         return false !== $this->get_item( $item_id );
744
-	}
745
-
746
-	/**
747
-	 * Checks whether the form has a given element.
748
-	 *
749
-	 * @since 1.0.19
750
-	 * @return bool
751
-	 */
744
+    }
745
+
746
+    /**
747
+     * Checks whether the form has a given element.
748
+     *
749
+     * @since 1.0.19
750
+     * @return bool
751
+     */
752 752
     public function has_element_type( $element_type ) {
753 753
         return false !== $this->get_element_type( $element_type );
754
-	}
755
-
756
-	/**
757
-	 * Checks whether this form is recurring or not.
758
-	 *
759
-	 * @since 1.0.19
760
-	 * @return bool
761
-	 */
754
+    }
755
+
756
+    /**
757
+     * Checks whether this form is recurring or not.
758
+     *
759
+     * @since 1.0.19
760
+     * @return bool
761
+     */
762 762
     public function is_recurring() {
763 763
 
764
-		if ( ! empty( $this->invoice ) ) {
765
-			return $this->invoice->is_recurring();
766
-		}
764
+        if ( ! empty( $this->invoice ) ) {
765
+            return $this->invoice->is_recurring();
766
+        }
767 767
 
768
-		foreach ( $this->get_items() as $item ) {
768
+        foreach ( $this->get_items() as $item ) {
769 769
 
770
-			if ( $item->is_recurring() ) {
771
-				return true;
772
-			}
770
+            if ( $item->is_recurring() ) {
771
+                return true;
772
+            }
773 773
 
774
-		}
774
+        }
775 775
 
776 776
         return false;
777
-	}
777
+    }
778 778
 
779
-	/**
780
-	 * Retrieves the form's html.
781
-	 *
782
-	 * @since 1.0.19
783
-	 */
779
+    /**
780
+     * Retrieves the form's html.
781
+     *
782
+     * @since 1.0.19
783
+     */
784 784
     public function get_html( $extra_markup = '' ) {
785 785
 
786
-		// Return the HTML.
787
-		return wpinv_get_template_html(
788
-			'payment-forms/form.php',
789
-			array(
790
-				'form'         => $this,
791
-				'extra_markup' => $extra_markup,
792
-			)
793
-		);
794
-
795
-	}
796
-
797
-	/**
798
-	 * Displays the payment form.
799
-	 *
800
-	 * @since 1.0.19
801
-	 */
786
+        // Return the HTML.
787
+        return wpinv_get_template_html(
788
+            'payment-forms/form.php',
789
+            array(
790
+                'form'         => $this,
791
+                'extra_markup' => $extra_markup,
792
+            )
793
+        );
794
+
795
+    }
796
+
797
+    /**
798
+     * Displays the payment form.
799
+     *
800
+     * @since 1.0.19
801
+     */
802 802
     public function display( $extra_markup = '' ) {
803
-		echo $this->get_html( $extra_markup );
803
+        echo $this->get_html( $extra_markup );
804 804
     }
805 805
 
806 806
 }
Please login to merge, or discard this patch.