Passed
Pull Request — master (#375)
by Brian
101:34
created
templates/payment-forms/elements/price_input.php 1 patch
Indentation   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -30,6 +30,6 @@
 block discarded – undo
30 30
         'label_type'        => 'vertical',
31 31
         'help_text'         => empty( $description ) ? '' : wp_kses_post( $description ),
32 32
         'input_group_right' => $position == 'right' ? wpinv_currency_symbol() : '',
33
-		'input_group_left'  => $position == 'left' ? wpinv_currency_symbol() : '',
33
+        'input_group_left'  => $position == 'left' ? wpinv_currency_symbol() : '',
34 34
     )
35 35
 );
Please login to merge, or discard this patch.
includes/wpinv-helper-functions.php 1 patch
Indentation   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -708,13 +708,13 @@  discard block
 block discarded – undo
708 708
  * @param mixed  $value Value.
709 709
  */
710 710
 function getpaid_maybe_define_constant( $name, $value ) {
711
-	if ( ! defined( $name ) ) {
712
-		define( $name, $value );
713
-	}
711
+    if ( ! defined( $name ) ) {
712
+        define( $name, $value );
713
+    }
714 714
 }
715 715
 
716 716
 function wpinv_get_php_arg_separator_output() {
717
-	return ini_get( 'arg_separator.output' );
717
+    return ini_get( 'arg_separator.output' );
718 718
 }
719 719
 
720 720
 function wpinv_rgb_from_hex( $color ) {
@@ -1058,11 +1058,11 @@  discard block
 block discarded – undo
1058 1058
  * @return array Sanitized array of values.
1059 1059
  */
1060 1060
 function wpinv_parse_list( $list ) {
1061
-	if ( ! is_array( $list ) ) {
1062
-		return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1063
-	}
1061
+    if ( ! is_array( $list ) ) {
1062
+        return preg_split( '/[\s,]+/', $list, -1, PREG_SPLIT_NO_EMPTY );
1063
+    }
1064 1064
 
1065
-	return $list;
1065
+    return $list;
1066 1066
 }
1067 1067
 
1068 1068
 /**
@@ -1082,9 +1082,9 @@  discard block
 block discarded – undo
1082 1082
     }
1083 1083
 
1084 1084
     $data = apply_filters( "wpinv_get_$key", include WPINV_PLUGIN_DIR . "includes/data/$key.php" );
1085
-	wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1085
+    wp_cache_set( "wpinv-$key", $data, 'wpinv' );
1086 1086
 
1087
-	return $data;
1087
+    return $data;
1088 1088
 }
1089 1089
 
1090 1090
 /**
@@ -1113,17 +1113,17 @@  discard block
 block discarded – undo
1113 1113
  */
1114 1114
 function wpinv_clean( $var ) {
1115 1115
 
1116
-	if ( is_array( $var ) ) {
1117
-		return array_map( 'wpinv_clean', $var );
1116
+    if ( is_array( $var ) ) {
1117
+        return array_map( 'wpinv_clean', $var );
1118 1118
     }
1119 1119
 
1120 1120
     if ( is_object( $var ) ) {
1121
-		$object_vars = get_object_vars( $var );
1122
-		foreach ( $object_vars as $property_name => $property_value ) {
1123
-			$var->$property_name = wpinv_clean( $property_value );
1121
+        $object_vars = get_object_vars( $var );
1122
+        foreach ( $object_vars as $property_name => $property_value ) {
1123
+            $var->$property_name = wpinv_clean( $property_value );
1124 1124
         }
1125 1125
         return $var;
1126
-	}
1126
+    }
1127 1127
     
1128 1128
     return is_string( $var ) ? sanitize_text_field( $var ) : $var;
1129 1129
 }
@@ -1136,7 +1136,7 @@  discard block
 block discarded – undo
1136 1136
  */
1137 1137
 function getpaid_convert_price_string_to_options( $str ) {
1138 1138
 
1139
-	$raw_options = array_map( 'trim', explode( ',', $str ) );
1139
+    $raw_options = array_map( 'trim', explode( ',', $str ) );
1140 1140
     $options     = array();
1141 1141
 
1142 1142
     foreach ( $raw_options as $option ) {
Please login to merge, or discard this patch.
includes/class-getpaid-payment-form.php 1 patch
Indentation   +441 added lines, -441 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,48 +10,48 @@  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
-	);
40
+        'items'                => null,
41
+        'earned'               => 0,
42
+        'refunded'             => 0,
43
+        'cancelled'            => 0,
44
+        'failed'               => 0,
45
+    );
46 46
 
47 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';
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 55
 
56 56
     /**
57 57
      * Stores a reference to the original WP_Post object
@@ -61,32 +61,32 @@  discard block
 block discarded – undo
61 61
     protected $post = null;
62 62
 
63 63
     /**
64
-	 * Get the form if ID is passed, otherwise the form is new and empty.
65
-	 *
66
-	 * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
67
-	 */
68
-	public function __construct( $form = 0 ) {
69
-		parent::__construct( $form );
70
-
71
-		if ( is_numeric( $form ) && $form > 0 ) {
72
-			$this->set_id( $form );
73
-		} elseif ( $form instanceof self ) {
74
-			$this->set_id( $form->get_id() );
75
-		} elseif ( ! empty( $form->ID ) ) {
76
-			$this->set_id( $form->ID );
77
-		} else {
78
-			$this->set_object_read( true );
79
-		}
64
+     * Get the form if ID is passed, otherwise the form is new and empty.
65
+     *
66
+     * @param  int|object|GetPaid_Payment_Form|WP_Post $form Form to read.
67
+     */
68
+    public function __construct( $form = 0 ) {
69
+        parent::__construct( $form );
70
+
71
+        if ( is_numeric( $form ) && $form > 0 ) {
72
+            $this->set_id( $form );
73
+        } elseif ( $form instanceof self ) {
74
+            $this->set_id( $form->get_id() );
75
+        } elseif ( ! empty( $form->ID ) ) {
76
+            $this->set_id( $form->ID );
77
+        } else {
78
+            $this->set_object_read( true );
79
+        }
80 80
 
81 81
         // Load the datastore.
82
-		$this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
82
+        $this->data_store = GetPaid_Data_Store::load( $this->data_store_name );
83 83
 
84
-		if ( $this->get_id() > 0 ) {
84
+        if ( $this->get_id() > 0 ) {
85 85
             $this->post = get_post( $this->get_id() );
86
-			$this->data_store->read( $this );
86
+            $this->data_store->read( $this );
87 87
         }
88 88
 
89
-	}
89
+    }
90 90
 
91 91
     /*
92 92
 	|--------------------------------------------------------------------------
@@ -104,268 +104,268 @@  discard block
 block discarded – undo
104 104
     */
105 105
 
106 106
     /**
107
-	 * Get plugin version when the form was created.
108
-	 *
109
-	 * @since 1.0.19
110
-	 * @param  string $context View or edit context.
111
-	 * @return string
112
-	 */
113
-	public function get_version( $context = 'view' ) {
114
-		return $this->get_prop( 'version', $context );
107
+     * Get plugin version when the form was created.
108
+     *
109
+     * @since 1.0.19
110
+     * @param  string $context View or edit context.
111
+     * @return string
112
+     */
113
+    public function get_version( $context = 'view' ) {
114
+        return $this->get_prop( 'version', $context );
115 115
     }
116 116
 
117 117
     /**
118
-	 * Get date when the form was created.
119
-	 *
120
-	 * @since 1.0.19
121
-	 * @param  string $context View or edit context.
122
-	 * @return string
123
-	 */
124
-	public function get_date_created( $context = 'view' ) {
125
-		return $this->get_prop( 'date_created', $context );
118
+     * Get date when the form was created.
119
+     *
120
+     * @since 1.0.19
121
+     * @param  string $context View or edit context.
122
+     * @return string
123
+     */
124
+    public function get_date_created( $context = 'view' ) {
125
+        return $this->get_prop( 'date_created', $context );
126 126
     }
127 127
 
128 128
     /**
129
-	 * Get GMT date when the form was created.
130
-	 *
131
-	 * @since 1.0.19
132
-	 * @param  string $context View or edit context.
133
-	 * @return string
134
-	 */
135
-	public function get_date_created_gmt( $context = 'view' ) {
129
+     * Get GMT date when the form was created.
130
+     *
131
+     * @since 1.0.19
132
+     * @param  string $context View or edit context.
133
+     * @return string
134
+     */
135
+    public function get_date_created_gmt( $context = 'view' ) {
136 136
         $date = $this->get_date_created( $context );
137 137
 
138 138
         if ( $date ) {
139 139
             $date = get_gmt_from_date( $date );
140 140
         }
141
-		return $date;
141
+        return $date;
142 142
     }
143 143
 
144 144
     /**
145
-	 * Get date when the form was last modified.
146
-	 *
147
-	 * @since 1.0.19
148
-	 * @param  string $context View or edit context.
149
-	 * @return string
150
-	 */
151
-	public function get_date_modified( $context = 'view' ) {
152
-		return $this->get_prop( 'date_modified', $context );
145
+     * Get date when the form was last modified.
146
+     *
147
+     * @since 1.0.19
148
+     * @param  string $context View or edit context.
149
+     * @return string
150
+     */
151
+    public function get_date_modified( $context = 'view' ) {
152
+        return $this->get_prop( 'date_modified', $context );
153 153
     }
154 154
 
155 155
     /**
156
-	 * Get GMT date when the form was last modified.
157
-	 *
158
-	 * @since 1.0.19
159
-	 * @param  string $context View or edit context.
160
-	 * @return string
161
-	 */
162
-	public function get_date_modified_gmt( $context = 'view' ) {
156
+     * Get GMT date when the form was last modified.
157
+     *
158
+     * @since 1.0.19
159
+     * @param  string $context View or edit context.
160
+     * @return string
161
+     */
162
+    public function get_date_modified_gmt( $context = 'view' ) {
163 163
         $date = $this->get_date_modified( $context );
164 164
 
165 165
         if ( $date ) {
166 166
             $date = get_gmt_from_date( $date );
167 167
         }
168
-		return $date;
168
+        return $date;
169 169
     }
170 170
 
171 171
     /**
172
-	 * Get the form name.
173
-	 *
174
-	 * @since 1.0.19
175
-	 * @param  string $context View or edit context.
176
-	 * @return string
177
-	 */
178
-	public function get_name( $context = 'view' ) {
179
-		return $this->get_prop( 'name', $context );
172
+     * Get the form name.
173
+     *
174
+     * @since 1.0.19
175
+     * @param  string $context View or edit context.
176
+     * @return string
177
+     */
178
+    public function get_name( $context = 'view' ) {
179
+        return $this->get_prop( 'name', $context );
180 180
     }
181 181
 
182 182
     /**
183
-	 * Alias of self::get_name().
184
-	 *
185
-	 * @since 1.0.19
186
-	 * @param  string $context View or edit context.
187
-	 * @return string
188
-	 */
189
-	public function get_title( $context = 'view' ) {
190
-		return $this->get_name( $context );
191
-	}
183
+     * Alias of self::get_name().
184
+     *
185
+     * @since 1.0.19
186
+     * @param  string $context View or edit context.
187
+     * @return string
188
+     */
189
+    public function get_title( $context = 'view' ) {
190
+        return $this->get_name( $context );
191
+    }
192 192
 
193 193
     /**
194
-	 * Get the owner of the form.
195
-	 *
196
-	 * @since 1.0.19
197
-	 * @param  string $context View or edit context.
198
-	 * @return int
199
-	 */
200
-	public function get_author( $context = 'view' ) {
201
-		return (int) $this->get_prop( 'author', $context );
194
+     * Get the owner of the form.
195
+     *
196
+     * @since 1.0.19
197
+     * @param  string $context View or edit context.
198
+     * @return int
199
+     */
200
+    public function get_author( $context = 'view' ) {
201
+        return (int) $this->get_prop( 'author', $context );
202 202
     }
203 203
 
204 204
     /**
205
-	 * Get the elements that make up the form.
206
-	 *
207
-	 * @since 1.0.19
208
-	 * @param  string $context View or edit context.
209
-	 * @return array
210
-	 */
211
-	public function get_elements( $context = 'view' ) {
212
-		$elements = $this->get_prop( 'elements', $context );
205
+     * Get the elements that make up the form.
206
+     *
207
+     * @since 1.0.19
208
+     * @param  string $context View or edit context.
209
+     * @return array
210
+     */
211
+    public function get_elements( $context = 'view' ) {
212
+        $elements = $this->get_prop( 'elements', $context );
213 213
 
214
-		if ( empty( $elements ) || ! is_array( $elements ) ) {
214
+        if ( empty( $elements ) || ! is_array( $elements ) ) {
215 215
             return wpinv_get_data( 'sample-payment-form' );
216 216
         }
217 217
         return $elements;
218
-	}
219
-
220
-	/**
221
-	 * Get the items sold via the form.
222
-	 *
223
-	 * @since 1.0.19
224
-	 * @param  string $context View or edit context.
225
-	 * @param  string $return objects or arrays.
226
-	 * @return GetPaid_Form_Item[]
227
-	 */
228
-	public function get_items( $context = 'view', $return = 'objects' ) {
229
-		$items = $this->get_prop( 'items', $context );
230
-
231
-		if ( empty( $items ) || ! is_array( $items ) ) {
218
+    }
219
+
220
+    /**
221
+     * Get the items sold via the form.
222
+     *
223
+     * @since 1.0.19
224
+     * @param  string $context View or edit context.
225
+     * @param  string $return objects or arrays.
226
+     * @return GetPaid_Form_Item[]
227
+     */
228
+    public function get_items( $context = 'view', $return = 'objects' ) {
229
+        $items = $this->get_prop( 'items', $context );
230
+
231
+        if ( empty( $items ) || ! is_array( $items ) ) {
232 232
             $items = wpinv_get_data( 'sample-payment-form-items' );
233
-		}
233
+        }
234
+
235
+        if ( 'view' != $context ) {
236
+            return $items;
237
+        }
238
+
239
+        // Convert the items.
240
+        $prepared = array();
241
+
242
+        foreach ( $items as $key => $value ) {
243
+
244
+            // $item_id => $quantity
245
+            if ( is_numeric( $key ) && is_numeric( $value ) ) {
246
+                $item   = new GetPaid_Form_Item( $key );
247
+
248
+                if ( $item->can_purchase() ) {
249
+                    $item->set_quantity( $value );
250
+                    $prepared[] = $item;
251
+                }
252
+
253
+                continue;
254
+            }
255
+
256
+            if ( is_array( $value ) && isset( $value['id'] ) ) {
257
+
258
+                $item = new GetPaid_Form_Item( $value['id'] );
259
+
260
+                if ( ! $item->can_purchase() ) {
261
+                    continue;
262
+                }
263
+
264
+                // Sub-total (Cart items).
265
+                if ( isset( $value['subtotal'] ) ) {
266
+                    $item->set_price( $value['subtotal'] );
267
+                }
268
+
269
+                if ( isset( $value['quantity'] ) ) {
270
+                    $item->set_quantity( $value['quantity'] );
271
+                }
272
+
273
+                if ( isset( $value['allow_quantities'] ) ) {
274
+                    $item->set_allow_quantities( $value['allow_quantities'] );
275
+                }
276
+
277
+                if ( isset( $value['required'] ) ) {
278
+                    $item->set_is_required( $value['required'] );
279
+                }
280
+
281
+                if ( isset( $value['description'] ) ) {
282
+                    $item->set_custom_description( $value['description'] );
283
+                }
284
+
285
+                $prepared[] = $item;
286
+                continue;
287
+
288
+            }
289
+        }
290
+
291
+        if ( 'objects' == $return ) {
292
+            return $prepared;
293
+        }
294
+
295
+        $items = array();
296
+        foreach ( $prepared as $item ) {
297
+            $items[] = $item->prepare_data_for_use();
298
+        }
299
+
300
+        return $items;
301
+    }
302
+
303
+    /**
304
+     * Get a single item belonging to the form.
305
+     *
306
+     * @since 1.0.19
307
+     * @param  int $item_id The item id to return.
308
+     * @return GetPaid_Form_Item|bool
309
+     */
310
+    public function get_item( $item_id ) {
311
+
312
+        if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
313
+            return false;
314
+        }
315
+
316
+        foreach( $this->get_items() as $item ) {
317
+            if ( $item->get_id() == (int) $item_id ) {
318
+                return $item;
319
+            }
320
+        }
321
+
322
+        return false;
323
+
324
+    }
325
+
326
+    /**
327
+     * Get the total amount earned via this form.
328
+     *
329
+     * @since 1.0.19
330
+     * @param  string $context View or edit context.
331
+     * @return array
332
+     */
333
+    public function get_earned( $context = 'view' ) {
334
+        return $this->get_prop( 'earned', $context );
335
+    }
234 336
 
235
-		if ( 'view' != $context ) {
236
-			return $items;
237
-		}
337
+    /**
338
+     * Get the total amount refunded via this form.
339
+     *
340
+     * @since 1.0.19
341
+     * @param  string $context View or edit context.
342
+     * @return array
343
+     */
344
+    public function get_refunded( $context = 'view' ) {
345
+        return $this->get_prop( 'refunded', $context );
346
+    }
238 347
 
239
-		// Convert the items.
240
-		$prepared = array();
241
-
242
-		foreach ( $items as $key => $value ) {
243
-
244
-			// $item_id => $quantity
245
-			if ( is_numeric( $key ) && is_numeric( $value ) ) {
246
-				$item   = new GetPaid_Form_Item( $key );
247
-
248
-				if ( $item->can_purchase() ) {
249
-					$item->set_quantity( $value );
250
-					$prepared[] = $item;
251
-				}
252
-
253
-				continue;
254
-			}
255
-
256
-			if ( is_array( $value ) && isset( $value['id'] ) ) {
257
-
258
-				$item = new GetPaid_Form_Item( $value['id'] );
259
-
260
-				if ( ! $item->can_purchase() ) {
261
-					continue;
262
-				}
263
-
264
-				// Sub-total (Cart items).
265
-				if ( isset( $value['subtotal'] ) ) {
266
-					$item->set_price( $value['subtotal'] );
267
-				}
268
-
269
-				if ( isset( $value['quantity'] ) ) {
270
-					$item->set_quantity( $value['quantity'] );
271
-				}
272
-
273
-				if ( isset( $value['allow_quantities'] ) ) {
274
-					$item->set_allow_quantities( $value['allow_quantities'] );
275
-				}
276
-
277
-				if ( isset( $value['required'] ) ) {
278
-					$item->set_is_required( $value['required'] );
279
-				}
280
-
281
-				if ( isset( $value['description'] ) ) {
282
-					$item->set_custom_description( $value['description'] );
283
-				}
284
-
285
-				$prepared[] = $item;
286
-				continue;
287
-
288
-			}
289
-		}
290
-
291
-		if ( 'objects' == $return ) {
292
-			return $prepared;
293
-		}
294
-
295
-		$items = array();
296
-		foreach ( $prepared as $item ) {
297
-			$items[] = $item->prepare_data_for_use();
298
-		}
299
-
300
-		return $items;
301
-	}
302
-
303
-	/**
304
-	 * Get a single item belonging to the form.
305
-	 *
306
-	 * @since 1.0.19
307
-	 * @param  int $item_id The item id to return.
308
-	 * @return GetPaid_Form_Item|bool
309
-	 */
310
-	public function get_item( $item_id ) {
311
-
312
-		if ( empty( $item_id ) || ! is_numeric( $item_id ) ) {
313
-			return false;
314
-		}
315
-
316
-		foreach( $this->get_items() as $item ) {
317
-			if ( $item->get_id() == (int) $item_id ) {
318
-				return $item;
319
-			}
320
-		}
321
-
322
-		return false;
323
-
324
-	}
325
-
326
-	/**
327
-	 * Get the total amount earned via this form.
328
-	 *
329
-	 * @since 1.0.19
330
-	 * @param  string $context View or edit context.
331
-	 * @return array
332
-	 */
333
-	public function get_earned( $context = 'view' ) {
334
-		return $this->get_prop( 'earned', $context );
335
-	}
336
-
337
-	/**
338
-	 * Get the total amount refunded via this form.
339
-	 *
340
-	 * @since 1.0.19
341
-	 * @param  string $context View or edit context.
342
-	 * @return array
343
-	 */
344
-	public function get_refunded( $context = 'view' ) {
345
-		return $this->get_prop( 'refunded', $context );
346
-	}
347
-
348
-	/**
349
-	 * Get the total amount cancelled via this form.
350
-	 *
351
-	 * @since 1.0.19
352
-	 * @param  string $context View or edit context.
353
-	 * @return array
354
-	 */
355
-	public function get_cancelled( $context = 'view' ) {
356
-		return $this->get_prop( 'cancelled', $context );
357
-	}
358
-
359
-	/**
360
-	 * Get the total amount failed via this form.
361
-	 *
362
-	 * @since 1.0.19
363
-	 * @param  string $context View or edit context.
364
-	 * @return array
365
-	 */
366
-	public function get_failed( $context = 'view' ) {
367
-		return $this->get_prop( 'failed', $context );
368
-	}
348
+    /**
349
+     * Get the total amount cancelled via this form.
350
+     *
351
+     * @since 1.0.19
352
+     * @param  string $context View or edit context.
353
+     * @return array
354
+     */
355
+    public function get_cancelled( $context = 'view' ) {
356
+        return $this->get_prop( 'cancelled', $context );
357
+    }
358
+
359
+    /**
360
+     * Get the total amount failed via this form.
361
+     *
362
+     * @since 1.0.19
363
+     * @param  string $context View or edit context.
364
+     * @return array
365
+     */
366
+    public function get_failed( $context = 'view' ) {
367
+        return $this->get_prop( 'failed', $context );
368
+    }
369 369
 
370 370
     /*
371 371
 	|--------------------------------------------------------------------------
@@ -378,22 +378,22 @@  discard block
 block discarded – undo
378 378
     */
379 379
 
380 380
     /**
381
-	 * Set plugin version when the item was created.
382
-	 *
383
-	 * @since 1.0.19
384
-	 */
385
-	public function set_version( $value ) {
386
-		$this->set_prop( 'version', $value );
381
+     * Set plugin version when the item was created.
382
+     *
383
+     * @since 1.0.19
384
+     */
385
+    public function set_version( $value ) {
386
+        $this->set_prop( 'version', $value );
387 387
     }
388 388
 
389 389
     /**
390
-	 * Set date when the item was created.
391
-	 *
392
-	 * @since 1.0.19
393
-	 * @param string $value Value to set.
390
+     * Set date when the item was created.
391
+     *
392
+     * @since 1.0.19
393
+     * @param string $value Value to set.
394 394
      * @return bool Whether or not the date was set.
395
-	 */
396
-	public function set_date_created( $value ) {
395
+     */
396
+    public function set_date_created( $value ) {
397 397
         $date = strtotime( $value );
398 398
 
399 399
         if ( $date ) {
@@ -406,13 +406,13 @@  discard block
 block discarded – undo
406 406
     }
407 407
 
408 408
     /**
409
-	 * Set date when the item was last modified.
410
-	 *
411
-	 * @since 1.0.19
412
-	 * @param string $value Value to set.
409
+     * Set date when the item was last modified.
410
+     *
411
+     * @since 1.0.19
412
+     * @param string $value Value to set.
413 413
      * @return bool Whether or not the date was set.
414
-	 */
415
-	public function set_date_modified( $value ) {
414
+     */
415
+    public function set_date_modified( $value ) {
416 416
         $date = strtotime( $value );
417 417
 
418 418
         if ( $date ) {
@@ -425,118 +425,118 @@  discard block
 block discarded – undo
425 425
     }
426 426
 
427 427
     /**
428
-	 * Set the item name.
429
-	 *
430
-	 * @since 1.0.19
431
-	 * @param  string $value New name.
432
-	 */
433
-	public function set_name( $value ) {
434
-		$this->set_prop( 'name', sanitize_text_field( $value ) );
435
-    }
436
-
437
-    /**
438
-	 * Alias of self::set_name().
439
-	 *
440
-	 * @since 1.0.19
441
-	 * @param  string $value New name.
442
-	 */
443
-	public function set_title( $value ) {
444
-		$this->set_name( $value );
445
-    }
446
-
447
-    /**
448
-	 * Set the owner of the item.
449
-	 *
450
-	 * @since 1.0.19
451
-	 * @param  int $value New author.
452
-	 */
453
-	public function set_author( $value ) {
454
-		$this->set_prop( 'author', (int) $value );
455
-	}
456
-
457
-	/**
458
-	 * Set the form elements.
459
-	 *
460
-	 * @since 1.0.19
461
-	 * @param  array $value Form elements.
462
-	 */
463
-	public function set_elements( $value ) {
464
-		if ( is_array( $value ) ) {
465
-			$this->set_prop( 'elements', $value );
466
-		}
467
-	}
468
-
469
-	/**
470
-	 * Set the form items.
471
-	 *
472
-	 * @since 1.0.19
473
-	 * @param  array $value Form elements.
474
-	 */
475
-	public function set_items( $value ) {
476
-		if ( is_array( $value ) ) {
477
-			$this->set_prop( 'items', $value );
478
-		}
479
-	}
480
-
481
-	/**
482
-	 * Set the total amount earned via this form.
483
-	 *
484
-	 * @since 1.0.19
485
-	 * @param  float $value Amount earned.
486
-	 * @return array
487
-	 */
488
-	public function set_earned( $value ) {
489
-		return $this->set_prop( 'earned', $value );
490
-	}
491
-
492
-	/**
493
-	 * Set the total amount refunded via this form.
494
-	 *
495
-	 * @since 1.0.19
496
-	 * @param  float $value Amount refunded.
497
-	 * @return array
498
-	 */
499
-	public function set_refunded( $value ) {
500
-		return $this->set_prop( 'refunded', $value );
501
-	}
502
-
503
-	/**
504
-	 * Set the total amount cancelled via this form.
505
-	 *
506
-	 * @since 1.0.19
507
-	 * @param  float $value Amount cancelled.
508
-	 * @return array
509
-	 */
510
-	public function set_cancelled( $value ) {
511
-		return $this->set_prop( 'cancelled', $value );
512
-	}
513
-
514
-	/**
515
-	 * Set the total amount failed via this form.
516
-	 *
517
-	 * @since 1.0.19
518
-	 * @param  float $value Amount cancelled.
519
-	 * @return array
520
-	 */
521
-	public function set_failed( $value ) {
522
-		return $this->set_prop( 'failed', $value );
523
-	}
428
+     * Set the item name.
429
+     *
430
+     * @since 1.0.19
431
+     * @param  string $value New name.
432
+     */
433
+    public function set_name( $value ) {
434
+        $this->set_prop( 'name', sanitize_text_field( $value ) );
435
+    }
436
+
437
+    /**
438
+     * Alias of self::set_name().
439
+     *
440
+     * @since 1.0.19
441
+     * @param  string $value New name.
442
+     */
443
+    public function set_title( $value ) {
444
+        $this->set_name( $value );
445
+    }
446
+
447
+    /**
448
+     * Set the owner of the item.
449
+     *
450
+     * @since 1.0.19
451
+     * @param  int $value New author.
452
+     */
453
+    public function set_author( $value ) {
454
+        $this->set_prop( 'author', (int) $value );
455
+    }
456
+
457
+    /**
458
+     * Set the form elements.
459
+     *
460
+     * @since 1.0.19
461
+     * @param  array $value Form elements.
462
+     */
463
+    public function set_elements( $value ) {
464
+        if ( is_array( $value ) ) {
465
+            $this->set_prop( 'elements', $value );
466
+        }
467
+    }
468
+
469
+    /**
470
+     * Set the form items.
471
+     *
472
+     * @since 1.0.19
473
+     * @param  array $value Form elements.
474
+     */
475
+    public function set_items( $value ) {
476
+        if ( is_array( $value ) ) {
477
+            $this->set_prop( 'items', $value );
478
+        }
479
+    }
480
+
481
+    /**
482
+     * Set the total amount earned via this form.
483
+     *
484
+     * @since 1.0.19
485
+     * @param  float $value Amount earned.
486
+     * @return array
487
+     */
488
+    public function set_earned( $value ) {
489
+        return $this->set_prop( 'earned', $value );
490
+    }
491
+
492
+    /**
493
+     * Set the total amount refunded via this form.
494
+     *
495
+     * @since 1.0.19
496
+     * @param  float $value Amount refunded.
497
+     * @return array
498
+     */
499
+    public function set_refunded( $value ) {
500
+        return $this->set_prop( 'refunded', $value );
501
+    }
502
+
503
+    /**
504
+     * Set the total amount cancelled via this form.
505
+     *
506
+     * @since 1.0.19
507
+     * @param  float $value Amount cancelled.
508
+     * @return array
509
+     */
510
+    public function set_cancelled( $value ) {
511
+        return $this->set_prop( 'cancelled', $value );
512
+    }
513
+
514
+    /**
515
+     * Set the total amount failed via this form.
516
+     *
517
+     * @since 1.0.19
518
+     * @param  float $value Amount cancelled.
519
+     * @return array
520
+     */
521
+    public function set_failed( $value ) {
522
+        return $this->set_prop( 'failed', $value );
523
+    }
524 524
 
525 525
     /**
526 526
      * Create an item. For backwards compatibilty.
527 527
      *
528 528
      * @deprecated
529
-	 * @return int item id
529
+     * @return int item id
530 530
      */
531 531
     public function create( $data = array() ) {
532 532
 
533
-		// Set the properties.
534
-		if ( is_array( $data ) ) {
535
-			$this->set_props( $data );
536
-		}
533
+        // Set the properties.
534
+        if ( is_array( $data ) ) {
535
+            $this->set_props( $data );
536
+        }
537 537
 
538
-		// Save the item.
539
-		return $this->save();
538
+        // Save the item.
539
+        return $this->save();
540 540
 
541 541
     }
542 542
 
@@ -544,7 +544,7 @@  discard block
 block discarded – undo
544 544
      * Updates an item. For backwards compatibilty.
545 545
      *
546 546
      * @deprecated
547
-	 * @return int item id
547
+     * @return int item id
548 548
      */
549 549
     public function update( $data = array() ) {
550 550
         return $this->create( $data );
@@ -560,22 +560,22 @@  discard block
 block discarded – undo
560 560
 	*/
561 561
 
562 562
     /**
563
-	 * Checks whether this is the default payment form.
564
-	 *
565
-	 * @since 1.0.19
566
-	 * @return bool
567
-	 */
563
+     * Checks whether this is the default payment form.
564
+     *
565
+     * @since 1.0.19
566
+     * @return bool
567
+     */
568 568
     public function is_default() {
569 569
         $is_default = $this->get_id() == wpinv_get_default_payment_form();
570 570
         return (bool) apply_filters( 'wpinv_is_default_payment_form', $is_default, $this->get_id(), $this );
571
-	}
571
+    }
572 572
 
573 573
     /**
574
-	 * Checks whether the form is active.
575
-	 *
576
-	 * @since 1.0.19
577
-	 * @return bool
578
-	 */
574
+     * Checks whether the form is active.
575
+     *
576
+     * @since 1.0.19
577
+     * @return bool
578
+     */
579 579
     public function is_active() {
580 580
         $is_active = null !== $this->get_id();
581 581
 
@@ -584,43 +584,43 @@  discard block
 block discarded – undo
584 584
         }
585 585
 
586 586
         return (bool) apply_filters( 'wpinv_is_payment_form_active', $is_active, $this );
587
-	}
588
-
589
-	/**
590
-	 * Checks whether the form has a given item.
591
-	 *
592
-	 * @since 1.0.19
593
-	 * @return bool
594
-	 */
587
+    }
588
+
589
+    /**
590
+     * Checks whether the form has a given item.
591
+     *
592
+     * @since 1.0.19
593
+     * @return bool
594
+     */
595 595
     public function has_item( $item_id ) {
596 596
         return false !== $this->get_item( $item_id );
597
-	}
598
-
599
-	/**
600
-	 * Displays the payment form.
601
-	 *
602
-	 * @param bool $echo whether to return or echo the value.
603
-	 * @since 1.0.19
604
-	 */
597
+    }
598
+
599
+    /**
600
+     * Displays the payment form.
601
+     *
602
+     * @param bool $echo whether to return or echo the value.
603
+     * @since 1.0.19
604
+     */
605 605
     public function display( $echo = true ) {
606
-		global $invoicing;
607
-
608
-		// Ensure that it is active.
609
-		if ( ! $this->is_active() ) {
610
-			$html = aui()->alert(
611
-				array(
612
-					'type'    => 'warning',
613
-					'content' => __( 'This payment form is no longer active', 'invoicing' ),
614
-				)
615
-			);
616
-
617
-			if ( $echo ) {
618
-				echo $html;
619
-				return;
620
-			}
621
-
622
-			return $html;
623
-		}
606
+        global $invoicing;
607
+
608
+        // Ensure that it is active.
609
+        if ( ! $this->is_active() ) {
610
+            $html = aui()->alert(
611
+                array(
612
+                    'type'    => 'warning',
613
+                    'content' => __( 'This payment form is no longer active', 'invoicing' ),
614
+                )
615
+            );
616
+
617
+            if ( $echo ) {
618
+                echo $html;
619
+                return;
620
+            }
621
+
622
+            return $html;
623
+        }
624 624
     }
625 625
 
626 626
 }
Please login to merge, or discard this patch.
includes/class-getpaid-payment-form-submission.php 1 patch
Indentation   +698 added lines, -698 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,738 +10,738 @@  discard block
 block discarded – undo
10 10
 class GetPaid_Payment_Form_Submission {
11 11
 
12 12
     /**
13
-	 * Submission ID
14
-	 *
15
-	 * @var string
16
-	 */
17
-	public $id = null;
13
+     * Submission ID
14
+     *
15
+     * @var string
16
+     */
17
+    public $id = null;
18 18
 
19
-	/**
20
-	 * Sets the associated payment form.
21
-	 *
22
-	 * @var GetPaid_Payment_Form
23
-	 */
19
+    /**
20
+     * Sets the associated payment form.
21
+     *
22
+     * @var GetPaid_Payment_Form
23
+     */
24 24
     protected $payment_form = null;
25 25
 
26 26
     /**
27
-	 * The country for the submission.
28
-	 *
29
-	 * @var string
30
-	 */
31
-	public $country = null;
32
-
33
-    /**
34
-	 * The state for the submission.
35
-	 *
36
-	 * @since 1.0.19
37
-	 * @var string
38
-	 */
39
-	public $state = null;
40
-
41
-	/**
42
-	 * The invoice associated with the submission.
43
-	 *
44
-	 * @var WPInv_Invoice
45
-	 */
46
-	protected $invoice = null;
47
-
48
-	/**
49
-	 * The discount associated with the submission.
50
-	 *
51
-	 * @var WPInv_Discount
52
-	 */
53
-	protected $discount = null;
54
-
55
-	/**
56
-	 * The raw submission data.
57
-	 *
58
-	 * @var array
59
-	 */
60
-	protected $data = null;
61
-
62
-	/**
63
-	 * Whether this submission contains a recurring item.
64
-	 *
65
-	 * @var bool
66
-	 */
67
-	public $has_recurring = false;
68
-
69
-	/**
70
-	 * The sub total amount for the submission.
71
-	 *
72
-	 * @var float
73
-	 */
74
-	public $subtotal_amount = 0;
75
-
76
-	/**
77
-	 * The total discount amount for the submission.
78
-	 *
79
-	 * @var float
80
-	 */
81
-	protected $total_discount_amount = 0;
82
-
83
-	/**
84
-	 * The total tax amount for the submission.
85
-	 *
86
-	 * @var float
87
-	 */
88
-	protected $total_tax_amount = 0;
89
-
90
-	/**
91
-	 * The total fees amount for the submission.
92
-	 *
93
-	 * @var float
94
-	 */
95
-	protected $total_fees_amount = 0;
96
-
97
-	/**
98
-	 * An array of fees for the submission.
99
-	 *
100
-	 * @var array
101
-	 */
102
-	protected $fees = array();
103
-
104
-	/**
105
-	 * An array of discounts for the submission.
106
-	 *
107
-	 * @var array
108
-	 */
109
-	protected $discounts = array();
110
-
111
-	/**
112
-	 * An array of taxes for the submission.
113
-	 *
114
-	 * @var array
115
-	 */
116
-	protected $taxes = array();
117
-
118
-	/**
119
-	 * An array of items for the submission.
120
-	 *
121
-	 * @var GetPaid_Form_Item[]
122
-	 */
123
-	protected $items = array();
124
-
125
-	/**
126
-	 * The last error.
127
-	 *
128
-	 * @var string
129
-	 */
130
-	public $last_error = null;
131
-
132
-	/**
133
-	 * Is the discount valid?
134
-	 *
135
-	 * @var string
136
-	 */
137
-    public $is_discount_valid = true;
27
+     * The country for the submission.
28
+     *
29
+     * @var string
30
+     */
31
+    public $country = null;
32
+
33
+    /**
34
+     * The state for the submission.
35
+     *
36
+     * @since 1.0.19
37
+     * @var string
38
+     */
39
+    public $state = null;
40
+
41
+    /**
42
+     * The invoice associated with the submission.
43
+     *
44
+     * @var WPInv_Invoice
45
+     */
46
+    protected $invoice = null;
47
+
48
+    /**
49
+     * The discount associated with the submission.
50
+     *
51
+     * @var WPInv_Discount
52
+     */
53
+    protected $discount = null;
138 54
 
139 55
     /**
140
-	 * Class constructor.
141
-	 *
142
-	 */
143
-	public function __construct() {
56
+     * The raw submission data.
57
+     *
58
+     * @var array
59
+     */
60
+    protected $data = null;
144 61
 
145
-		// Set the state and country to the default state and country.
146
-		$this->country = wpinv_default_billing_country();
147
-		$this->state = wpinv_get_default_state();
62
+    /**
63
+     * Whether this submission contains a recurring item.
64
+     *
65
+     * @var bool
66
+     */
67
+    public $has_recurring = false;
68
+
69
+    /**
70
+     * The sub total amount for the submission.
71
+     *
72
+     * @var float
73
+     */
74
+    public $subtotal_amount = 0;
75
+
76
+    /**
77
+     * The total discount amount for the submission.
78
+     *
79
+     * @var float
80
+     */
81
+    protected $total_discount_amount = 0;
82
+
83
+    /**
84
+     * The total tax amount for the submission.
85
+     *
86
+     * @var float
87
+     */
88
+    protected $total_tax_amount = 0;
89
+
90
+    /**
91
+     * The total fees amount for the submission.
92
+     *
93
+     * @var float
94
+     */
95
+    protected $total_fees_amount = 0;
96
+
97
+    /**
98
+     * An array of fees for the submission.
99
+     *
100
+     * @var array
101
+     */
102
+    protected $fees = array();
103
+
104
+    /**
105
+     * An array of discounts for the submission.
106
+     *
107
+     * @var array
108
+     */
109
+    protected $discounts = array();
110
+
111
+    /**
112
+     * An array of taxes for the submission.
113
+     *
114
+     * @var array
115
+     */
116
+    protected $taxes = array();
117
+
118
+    /**
119
+     * An array of items for the submission.
120
+     *
121
+     * @var GetPaid_Form_Item[]
122
+     */
123
+    protected $items = array();
124
+
125
+    /**
126
+     * The last error.
127
+     *
128
+     * @var string
129
+     */
130
+    public $last_error = null;
131
+
132
+    /**
133
+     * Is the discount valid?
134
+     *
135
+     * @var string
136
+     */
137
+    public $is_discount_valid = true;
148 138
 
149
-		// Do we have an actual submission?
150
-		if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
151
-			$this->load_data( $_POST );
152
-		}
153
-	}
139
+    /**
140
+     * Class constructor.
141
+     *
142
+     */
143
+    public function __construct() {
144
+
145
+        // Set the state and country to the default state and country.
146
+        $this->country = wpinv_default_billing_country();
147
+        $this->state = wpinv_get_default_state();
148
+
149
+        // Do we have an actual submission?
150
+        if ( isset( $_POST['getpaid_payment_form_submission'] ) ) {
151
+            $this->load_data( $_POST );
152
+        }
153
+    }
154 154
 
155
-	/**
156
-	 * Loads submission data.
157
-	 *
158
-	 * @param array $data
159
-	 */
160
-	public function load_data( $data ) {
155
+    /**
156
+     * Loads submission data.
157
+     *
158
+     * @param array $data
159
+     */
160
+    public function load_data( $data ) {
161 161
 
162
-		// Prepare submitted data...
163
-		$data = wp_unslash( $data );
162
+        // Prepare submitted data...
163
+        $data = wp_unslash( $data );
164 164
 
165
-		// Fitter the data.
166
-		$data = apply_filters( 'getpaid_submission_data', $data, $this );
165
+        // Fitter the data.
166
+        $data = apply_filters( 'getpaid_submission_data', $data, $this );
167 167
 
168
-		$this->data = $data;
168
+        $this->data = $data;
169 169
 
170
-		$this->id = md5( wp_json_encode( $data ) );
170
+        $this->id = md5( wp_json_encode( $data ) );
171 171
 
172
-		// Every submission needs an active payment form.
173
-		if ( empty( $data['form_id'] ) ) {
174
-			$this->last_error = __( 'Missing payment form', 'invoicing' );
172
+        // Every submission needs an active payment form.
173
+        if ( empty( $data['form_id'] ) ) {
174
+            $this->last_error = __( 'Missing payment form', 'invoicing' );
175 175
             return;
176
-		}
176
+        }
177 177
 
178
-		// Fetch the payment form.
179
-		$form = new GetPaid_Payment_Form( $data['form_id'] );
178
+        // Fetch the payment form.
179
+        $form = new GetPaid_Payment_Form( $data['form_id'] );
180 180
 
181
-		if ( ! $form->is_active() ) {
182
-			$this->last_error = __( 'Payment form not active', 'invoicing' );
183
-			return;
184
-		}
181
+        if ( ! $form->is_active() ) {
182
+            $this->last_error = __( 'Payment form not active', 'invoicing' );
183
+            return;
184
+        }
185 185
 
186
-		// Fetch the payment form.
187
-		$this->payment_form = $form;
186
+        // Fetch the payment form.
187
+        $this->payment_form = $form;
188 188
 
189
-		// For existing invoices, make sure that it is valid.
189
+        // For existing invoices, make sure that it is valid.
190 190
         if ( ! empty( $data['invoice_id'] ) ) {
191 191
             $invoice = wpinv_get_invoice( $data['invoice_id'] );
192 192
 
193 193
             if ( empty( $invoice ) ) {
194
-				$this->last_error = __( 'Invalid invoice', 'invoicing' );
194
+                $this->last_error = __( 'Invalid invoice', 'invoicing' );
195 195
                 return;
196 196
             }
197 197
 
198
-			$this->payment_form->set_items( $invoice->cart_details );
198
+            $this->payment_form->set_items( $invoice->cart_details );
199 199
 
200
-			$this->country = $invoice->country;
201
-			$this->state = $invoice->state;
200
+            $this->country = $invoice->country;
201
+            $this->state = $invoice->state;
202 202
 
203
-		// Default forms do not have items.
203
+        // Default forms do not have items.
204 204
         } else if ( $form->is_default() && isset( $data['form_items'] ) ) {
205
-			$this->payment_form->set_items( $data['form_items'] );
206
-		}
207
-
208
-		// User's country.
209
-		if ( ! empty( $data['wpinv_country'] ) ) {
210
-			$this->country = $data['wpinv_country'];
211
-		}
212
-
213
-		// User's state.
214
-		if ( ! empty( $data['wpinv_state'] ) ) {
215
-			$this->country = $data['wpinv_state'];
216
-		}
217
-
218
-		// Handle discounts.
219
-		$this->maybe_prepare_discount();
220
-
221
-		// Handle items.
222
-		$selected_items = array();
223
-		if ( ! empty( $data['getpaid-items'] ) ) {
224
-			$selected_items = wpinv_clean( $data['getpaid-items'] );
225
-		}
226
-
227
-		foreach ( $this->payment_form->get_items() as $item ) {
228
-
229
-			// Continue if this is an optional item and it has not been selected.
230
-			if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
231
-				continue;
232
-			}
233
-
234
-			// (maybe) let customers change the quantities and prices.
235
-			if ( isset( $selected_items[ $item->get_id() ] ) ) {
236
-
237
-				// Maybe change the quantities.
238
-				if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
239
-					$item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
240
-				}
241
-
242
-				// Maybe change the price.
243
-				if ( $item->user_can_set_their_price() ) {
244
-					$price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
245
-
246
-					// But don't get lower than the minimum price.
247
-					if ( $price < $item->get_minimum_price() ) {
248
-						$price = $item->get_minimum_price();
249
-					}
250
-
251
-					$item->set_price( $price );
252
-
253
-				}
254
-
255
-			}
256
-
257
-			// Add the item to the form.
258
-			$this->add_item( $item );
259
-
260
-		}
261
-
262
-		// Fired when we are done processing a submission.
263
-		do_action( 'getpaid_process_submission', $this );
264
-
265
-		// Remove invalid discount.
266
-		$this->maybe_remove_discount();
267
-
268
-	}
269
-
270
-    /**
271
-	 * Returns the payment form.
272
-	 *
273
-	 * @since 1.0.19
274
-	 * @return GetPaid_Payment_Form
275
-	 */
276
-	public function get_payment_form() {
277
-		return $this->payment_form;
278
-	}
279
-
280
-	/**
281
-	 * Returns the associated invoice.
282
-	 *
283
-	 * @since 1.0.19
284
-	 * @return WPInv_Invoice
285
-	 */
286
-	public function get_invoice() {
287
-		return $this->invoice;
288
-	}
289
-
290
-	/**
291
-	 * Checks whether there is an invoice associated with this submission.
292
-	 *
293
-	 * @since 1.0.19
294
-	 * @return bool
295
-	 */
296
-	public function has_invoice() {
297
-		return ! empty( $this->invoice );
298
-	}
205
+            $this->payment_form->set_items( $data['form_items'] );
206
+        }
207
+
208
+        // User's country.
209
+        if ( ! empty( $data['wpinv_country'] ) ) {
210
+            $this->country = $data['wpinv_country'];
211
+        }
212
+
213
+        // User's state.
214
+        if ( ! empty( $data['wpinv_state'] ) ) {
215
+            $this->country = $data['wpinv_state'];
216
+        }
217
+
218
+        // Handle discounts.
219
+        $this->maybe_prepare_discount();
220
+
221
+        // Handle items.
222
+        $selected_items = array();
223
+        if ( ! empty( $data['getpaid-items'] ) ) {
224
+            $selected_items = wpinv_clean( $data['getpaid-items'] );
225
+        }
226
+
227
+        foreach ( $this->payment_form->get_items() as $item ) {
228
+
229
+            // Continue if this is an optional item and it has not been selected.
230
+            if ( ! $item->is_required() && ! isset( $selected_items[ $item->get_id() ] ) ) {
231
+                continue;
232
+            }
233
+
234
+            // (maybe) let customers change the quantities and prices.
235
+            if ( isset( $selected_items[ $item->get_id() ] ) ) {
236
+
237
+                // Maybe change the quantities.
238
+                if ( $item->allows_quantities() && is_numeric( $selected_items[ $item->get_id() ]['quantity'] ) ) {
239
+                    $item->set_quantity( (int) $selected_items[ $item->get_id() ]['quantity'] );
240
+                }
241
+
242
+                // Maybe change the price.
243
+                if ( $item->user_can_set_their_price() ) {
244
+                    $price = (float) wpinv_sanitize_amount( $selected_items[ $item->get_id() ]['price'] );
245
+
246
+                    // But don't get lower than the minimum price.
247
+                    if ( $price < $item->get_minimum_price() ) {
248
+                        $price = $item->get_minimum_price();
249
+                    }
250
+
251
+                    $item->set_price( $price );
252
+
253
+                }
254
+
255
+            }
256
+
257
+            // Add the item to the form.
258
+            $this->add_item( $item );
259
+
260
+        }
261
+
262
+        // Fired when we are done processing a submission.
263
+        do_action( 'getpaid_process_submission', $this );
264
+
265
+        // Remove invalid discount.
266
+        $this->maybe_remove_discount();
267
+
268
+    }
269
+
270
+    /**
271
+     * Returns the payment form.
272
+     *
273
+     * @since 1.0.19
274
+     * @return GetPaid_Payment_Form
275
+     */
276
+    public function get_payment_form() {
277
+        return $this->payment_form;
278
+    }
279
+
280
+    /**
281
+     * Returns the associated invoice.
282
+     *
283
+     * @since 1.0.19
284
+     * @return WPInv_Invoice
285
+     */
286
+    public function get_invoice() {
287
+        return $this->invoice;
288
+    }
289
+
290
+    /**
291
+     * Checks whether there is an invoice associated with this submission.
292
+     *
293
+     * @since 1.0.19
294
+     * @return bool
295
+     */
296
+    public function has_invoice() {
297
+        return ! empty( $this->invoice );
298
+    }
299 299
 	
300
-	/**
301
-	 * Returns the appropriate currency for the submission.
302
-	 *
303
-	 * @since 1.0.19
304
-	 * @return string
305
-	 */
306
-	public function get_currency() {
307
-		if ( $this->has_invoice() ) {
308
-			return $this->invoice->get_currency();
309
-		}
310
-		return wpinv_get_currency();
311
-    }
312
-
313
-    /**
314
-	 * Returns the raw submission data.
315
-	 *
316
-	 * @since 1.0.19
317
-	 * @return array
318
-	 */
319
-	public function get_data() {
320
-		return $this->data;
321
-	}
322
-
323
-	///////// Items //////////////
324
-
325
-	/**
326
-	 * Adds an item to the submission.
327
-	 *
328
-	 * @since 1.0.19
329
-	 * @param GetPaid_Form_Item $item
330
-	 */
331
-	public function add_item( $item ) {
332
-
333
-		// Make sure that it is available for purchase.
334
-		if ( ! $item->can_purchase() ) {
335
-			return;
336
-		}
337
-
338
-		// Do we have a recurring item?
339
-		if ( $item->is_recurring() ) {
340
-			$this->has_recurring = true;
341
-		}
342
-
343
-		$this->items[ $item->get_id() ] = $item;
344
-
345
-		$this->subtotal_amount += $item->get_price() * $item->get_qantity();
346
-
347
-		$this->process_item_discount( $item );
348
-
349
-		$this->process_item_tax( $item );
350
-	}
351
-
352
-	/**
353
-	 * Retrieves a specific item.
354
-	 *
355
-	 * @since 1.0.19
356
-	 */
357
-	public function get_item( $item_id ) {
358
-		return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
359
-	}
360
-
361
-	/**
362
-	 * Returns all items.
363
-	 *
364
-	 * @since 1.0.19
365
-	 * @return GetPaid_Form_Item[]
366
-	 */
367
-	public function get_items() {
368
-		return $this->items;
369
-	}
370
-
371
-	///////// TAXES //////////////
372
-
373
-	/**
374
-	 * Adds a tax to the submission.
375
-	 *
376
-	 * @since 1.0.19
377
-	 */
378
-	public function add_tax( $name, $amount ) {
379
-		$amount = (float) wpinv_sanitize_amount( $amount );
380
-
381
-		$this->total_tax_amount += $amount;
382
-
383
-		if ( isset( $this->taxes[ $name ] ) ) {
384
-			$this->taxes[ $name ] += $amount;
385
-		} else {
386
-			$this->taxes[ $name ] = $amount;
387
-		}
388
-
389
-	}
390
-
391
-	/**
392
-	 * Whether or not we'll use taxes for the submission.
393
-	 *
394
-	 * @since 1.0.19
395
-	 */
396
-	public function use_taxes() {
397
-
398
-		$use_taxes = wpinv_use_taxes();
399
-
400
-		if ( $this->has_invoice() && $this->invoice->disable_taxes ) {
401
-			$use_taxes = false;
402
-		}
403
-
404
-		return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
405
-
406
-	}
407
-
408
-	/**
409
-	 * Maybe process tax.
410
-	 *
411
-	 * @since 1.0.19 
412
-	 * @param GetPaid_Form_Item $item
413
-	 */
414
-	public function process_item_tax( $item ) {
415
-
416
-		// Abort early if we're not using taxes.
417
-		if ( ! $this->use_taxes() ) {
418
-			return;
419
-		}
420
-
421
-		$rate  = wpinv_get_tax_rate( $this->country, $this->state, $item->get_id() );
422
-		$price = $item->get_sub_total();
423
-
424
-		if ( wpinv_prices_include_tax() ) {
425
-			$item_tax = $price - ( $price - $price * $rate * 0.01 );
426
-		} else {
427
-			$item_tax = $price * $rate * 0.01;
428
-		}
429
-
430
-		$this->add_tax( 'Tax', $item_tax );
431
-
432
-	}
433
-
434
-	/**
435
-	 * Returns the total tax amount.
436
-	 *
437
-	 * @since 1.0.19
438
-	 */
439
-	public function get_total_tax() {
440
-		return $this->total_tax_amount;
441
-	}
442
-
443
-	/**
444
-	 * Retrieves a specific tax.
445
-	 *
446
-	 * @since 1.0.19
447
-	 */
448
-	public function get_tax( $name ) {
449
-		return isset( $this->taxes[ $name ] ) ? $this->taxes[ $name ] : 0;
450
-	}
451
-
452
-	/**
453
-	 * Returns all taxes.
454
-	 *
455
-	 * @since 1.0.19
456
-	 */
457
-	public function get_taxes() {
458
-		return $this->taxes;
459
-	}
460
-
461
-	///////// DISCOUNTS //////////////
462
-
463
-	/**
464
-	 * Adds a discount to the submission.
465
-	 *
466
-	 * @since 1.0.19
467
-	 */
468
-	public function add_discount( $name, $amount ) {
469
-		$amount = wpinv_sanitize_amount( $amount );
470
-
471
-		$this->total_discount_amount += $amount;
472
-
473
-		if ( isset( $this->discounts[ $name ] ) ) {
474
-			$this->discounts[ $name ] += $amount;
475
-		} else {
476
-			$this->discounts[ $name ] = $amount;
477
-		}
478
-
479
-	}
480
-
481
-	/**
482
-	 * Removes a discount from the submission.
483
-	 *
484
-	 * @since 1.0.19
485
-	 */
486
-	public function remove_discount( $name ) {
487
-
488
-		if ( isset( $this->discounts[ $name ] ) ) {
489
-			$this->total_discount_amount -= $this->discounts[ $name ];
490
-			unset( $this->discounts[ $name ] );
491
-		}
492
-
493
-	}
494
-
495
-	/**
496
-	 * Checks whether there is a discount code associated with this submission.
497
-	 *
498
-	 * @since 1.0.19
499
-	 * @return bool
500
-	 */
501
-	public function has_discount_code() {
502
-		return ! empty( $this->discount );
503
-	}
504
-
505
-	/**
506
-	 * Returns the discount code.
507
-	 *
508
-	 * @since 1.0.19
509
-	 * @return bool
510
-	 */
511
-	public function get_discount_code() {
512
-		return $this->has_discount_code() ? $this->discount->code : '';
513
-	}
514
-
515
-	/**
516
-	 * Prepares an item discount.
517
-	 *
518
-	 * @since 1.0.19
519
-	 */
520
-	public function maybe_prepare_discount() {
521
-
522
-		// Do we have a discount?
523
-		if ( empty( $this->data['discount'] ) ) {
524
-			return;
525
-		}
526
-
527
-		// Fetch the discount.
528
-		$discount = wpinv_get_discount_obj( $this->data['discount'] );
529
-
530
-		// Ensure it is active.
300
+    /**
301
+     * Returns the appropriate currency for the submission.
302
+     *
303
+     * @since 1.0.19
304
+     * @return string
305
+     */
306
+    public function get_currency() {
307
+        if ( $this->has_invoice() ) {
308
+            return $this->invoice->get_currency();
309
+        }
310
+        return wpinv_get_currency();
311
+    }
312
+
313
+    /**
314
+     * Returns the raw submission data.
315
+     *
316
+     * @since 1.0.19
317
+     * @return array
318
+     */
319
+    public function get_data() {
320
+        return $this->data;
321
+    }
322
+
323
+    ///////// Items //////////////
324
+
325
+    /**
326
+     * Adds an item to the submission.
327
+     *
328
+     * @since 1.0.19
329
+     * @param GetPaid_Form_Item $item
330
+     */
331
+    public function add_item( $item ) {
332
+
333
+        // Make sure that it is available for purchase.
334
+        if ( ! $item->can_purchase() ) {
335
+            return;
336
+        }
337
+
338
+        // Do we have a recurring item?
339
+        if ( $item->is_recurring() ) {
340
+            $this->has_recurring = true;
341
+        }
342
+
343
+        $this->items[ $item->get_id() ] = $item;
344
+
345
+        $this->subtotal_amount += $item->get_price() * $item->get_qantity();
346
+
347
+        $this->process_item_discount( $item );
348
+
349
+        $this->process_item_tax( $item );
350
+    }
351
+
352
+    /**
353
+     * Retrieves a specific item.
354
+     *
355
+     * @since 1.0.19
356
+     */
357
+    public function get_item( $item_id ) {
358
+        return isset( $this->items[ $item_id ] ) ? $this->items[ $item_id ] : null;
359
+    }
360
+
361
+    /**
362
+     * Returns all items.
363
+     *
364
+     * @since 1.0.19
365
+     * @return GetPaid_Form_Item[]
366
+     */
367
+    public function get_items() {
368
+        return $this->items;
369
+    }
370
+
371
+    ///////// TAXES //////////////
372
+
373
+    /**
374
+     * Adds a tax to the submission.
375
+     *
376
+     * @since 1.0.19
377
+     */
378
+    public function add_tax( $name, $amount ) {
379
+        $amount = (float) wpinv_sanitize_amount( $amount );
380
+
381
+        $this->total_tax_amount += $amount;
382
+
383
+        if ( isset( $this->taxes[ $name ] ) ) {
384
+            $this->taxes[ $name ] += $amount;
385
+        } else {
386
+            $this->taxes[ $name ] = $amount;
387
+        }
388
+
389
+    }
390
+
391
+    /**
392
+     * Whether or not we'll use taxes for the submission.
393
+     *
394
+     * @since 1.0.19
395
+     */
396
+    public function use_taxes() {
397
+
398
+        $use_taxes = wpinv_use_taxes();
399
+
400
+        if ( $this->has_invoice() && $this->invoice->disable_taxes ) {
401
+            $use_taxes = false;
402
+        }
403
+
404
+        return apply_filters( 'getpaid_submission_use_taxes', $use_taxes, $this );
405
+
406
+    }
407
+
408
+    /**
409
+     * Maybe process tax.
410
+     *
411
+     * @since 1.0.19 
412
+     * @param GetPaid_Form_Item $item
413
+     */
414
+    public function process_item_tax( $item ) {
415
+
416
+        // Abort early if we're not using taxes.
417
+        if ( ! $this->use_taxes() ) {
418
+            return;
419
+        }
420
+
421
+        $rate  = wpinv_get_tax_rate( $this->country, $this->state, $item->get_id() );
422
+        $price = $item->get_sub_total();
423
+
424
+        if ( wpinv_prices_include_tax() ) {
425
+            $item_tax = $price - ( $price - $price * $rate * 0.01 );
426
+        } else {
427
+            $item_tax = $price * $rate * 0.01;
428
+        }
429
+
430
+        $this->add_tax( 'Tax', $item_tax );
431
+
432
+    }
433
+
434
+    /**
435
+     * Returns the total tax amount.
436
+     *
437
+     * @since 1.0.19
438
+     */
439
+    public function get_total_tax() {
440
+        return $this->total_tax_amount;
441
+    }
442
+
443
+    /**
444
+     * Retrieves a specific tax.
445
+     *
446
+     * @since 1.0.19
447
+     */
448
+    public function get_tax( $name ) {
449
+        return isset( $this->taxes[ $name ] ) ? $this->taxes[ $name ] : 0;
450
+    }
451
+
452
+    /**
453
+     * Returns all taxes.
454
+     *
455
+     * @since 1.0.19
456
+     */
457
+    public function get_taxes() {
458
+        return $this->taxes;
459
+    }
460
+
461
+    ///////// DISCOUNTS //////////////
462
+
463
+    /**
464
+     * Adds a discount to the submission.
465
+     *
466
+     * @since 1.0.19
467
+     */
468
+    public function add_discount( $name, $amount ) {
469
+        $amount = wpinv_sanitize_amount( $amount );
470
+
471
+        $this->total_discount_amount += $amount;
472
+
473
+        if ( isset( $this->discounts[ $name ] ) ) {
474
+            $this->discounts[ $name ] += $amount;
475
+        } else {
476
+            $this->discounts[ $name ] = $amount;
477
+        }
478
+
479
+    }
480
+
481
+    /**
482
+     * Removes a discount from the submission.
483
+     *
484
+     * @since 1.0.19
485
+     */
486
+    public function remove_discount( $name ) {
487
+
488
+        if ( isset( $this->discounts[ $name ] ) ) {
489
+            $this->total_discount_amount -= $this->discounts[ $name ];
490
+            unset( $this->discounts[ $name ] );
491
+        }
492
+
493
+    }
494
+
495
+    /**
496
+     * Checks whether there is a discount code associated with this submission.
497
+     *
498
+     * @since 1.0.19
499
+     * @return bool
500
+     */
501
+    public function has_discount_code() {
502
+        return ! empty( $this->discount );
503
+    }
504
+
505
+    /**
506
+     * Returns the discount code.
507
+     *
508
+     * @since 1.0.19
509
+     * @return bool
510
+     */
511
+    public function get_discount_code() {
512
+        return $this->has_discount_code() ? $this->discount->code : '';
513
+    }
514
+
515
+    /**
516
+     * Prepares an item discount.
517
+     *
518
+     * @since 1.0.19
519
+     */
520
+    public function maybe_prepare_discount() {
521
+
522
+        // Do we have a discount?
523
+        if ( empty( $this->data['discount'] ) ) {
524
+            return;
525
+        }
526
+
527
+        // Fetch the discount.
528
+        $discount = wpinv_get_discount_obj( $this->data['discount'] );
529
+
530
+        // Ensure it is active.
531 531
         if ( ! $discount->exists() || ! $discount->is_active() || ! $discount->has_started() || $discount->is_expired() ) {
532
-			$this->is_discount_valid = false;
533
-			$this->last_error = __( 'Invalid or expired discount code', 'invoicing' );
534
-			return;
535
-		}
536
-
537
-		// For single use discounts...
538
-		if ( $discount->is_single_use ) {
539
-
540
-			if ( ! $this->has_billing_email() ) {
541
-				$this->is_discount_valid = false;
542
-				$this->last_error = __( 'You need to enter your billing email before applying this discount', 'invoicing' );
543
-				return;
544
-			}
545
-
546
-			if ( ! $discount->is_valid_for_user( $this->get_billing_email() ) ) {
547
-				$this->is_discount_valid = false;
548
-				$this->last_error = __( 'You have already used this discount', 'invoicing' );
549
-				return;
550
-			}
551
-		}
552
-
553
-		// Set the discount.
554
-		$this->discount = $discount;
555
-
556
-	}
557
-
558
-	/**
559
-	 * Removes an invalid discount code.
560
-	 *
561
-	 * @since 1.0.19
562
-	 */
563
-	public function maybe_remove_discount() {
564
-
565
-		// Do we have a discount?
566
-		if ( empty( $this->has_discount_code() ) ) {
567
-			return;
568
-		}
569
-
570
-		// Fetch the discount amount.
571
-		$amount = $this->get_discount( 'Discount' );
572
-
573
-		// Abort early if this is a "zero" discount.
574
-		if ( empty( $amount ) ) {
575
-			return;
576
-		}
577
-
578
-		$total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
579
-
580
-		if ( ! $this->discount->is_minimum_amount_met( $total ) ) {
581
-			$this->is_discount_valid = false;
532
+            $this->is_discount_valid = false;
533
+            $this->last_error = __( 'Invalid or expired discount code', 'invoicing' );
534
+            return;
535
+        }
536
+
537
+        // For single use discounts...
538
+        if ( $discount->is_single_use ) {
539
+
540
+            if ( ! $this->has_billing_email() ) {
541
+                $this->is_discount_valid = false;
542
+                $this->last_error = __( 'You need to enter your billing email before applying this discount', 'invoicing' );
543
+                return;
544
+            }
545
+
546
+            if ( ! $discount->is_valid_for_user( $this->get_billing_email() ) ) {
547
+                $this->is_discount_valid = false;
548
+                $this->last_error = __( 'You have already used this discount', 'invoicing' );
549
+                return;
550
+            }
551
+        }
552
+
553
+        // Set the discount.
554
+        $this->discount = $discount;
555
+
556
+    }
557
+
558
+    /**
559
+     * Removes an invalid discount code.
560
+     *
561
+     * @since 1.0.19
562
+     */
563
+    public function maybe_remove_discount() {
564
+
565
+        // Do we have a discount?
566
+        if ( empty( $this->has_discount_code() ) ) {
567
+            return;
568
+        }
569
+
570
+        // Fetch the discount amount.
571
+        $amount = $this->get_discount( 'Discount' );
572
+
573
+        // Abort early if this is a "zero" discount.
574
+        if ( empty( $amount ) ) {
575
+            return;
576
+        }
577
+
578
+        $total = $this->subtotal_amount + $this->get_total_fees() + $this->get_total_tax();
579
+
580
+        if ( ! $this->discount->is_minimum_amount_met( $total ) ) {
581
+            $this->is_discount_valid = false;
582 582
             $min = wpinv_price( wpinv_format_amount( $$this->discount->min_total ) );
583
-			$this->last_error = sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min );
583
+            $this->last_error = sprintf( __( 'The minimum total for using this discount is %s', 'invoicing' ), $min );
584 584
         }
585 585
 
586 586
         if ( ! $$this->discount->is_maximum_amount_met( $total ) ) {
587
-			$this->is_discount_valid = false;
587
+            $this->is_discount_valid = false;
588 588
             $max = wpinv_price( wpinv_format_amount( $$this->discount->max_total ) );
589
-			$this->last_error = sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max );
590
-		}
591
-
592
-		if ( ! $this->is_discount_valid ) {
593
-			$this->discount = null;
594
-			$this->remove_discount( 'Discount' );
595
-		}
596
-
597
-    }
598
-
599
-	/**
600
-	 * Maybe process discount.
601
-	 *
602
-	 * @since 1.0.19
603
-	 * @param GetPaid_Form_Item $item
604
-	 */
605
-	public function process_item_discount( $item ) {
606
-
607
-		// Abort early if there is no discount.
608
-		if ( ! $this->has_discount_code() ) {
609
-			return;
610
-		}
611
-
612
-		// Ensure that it is valid for this item.
613
-		if ( ! $this->discount->is_valid_for_items( array( $item->get_id() ) ) ) {
614
-			return;
615
-		}
616
-
617
-		// Fetch the discounted amount.
618
-		$discount = $this->discount->get_discounted_amount( $item->get_price() * $item->get_qantity() );
619
-
620
-		$this->add_discount( 'Discount', $discount );
621
-
622
-	}
623
-
624
-	/**
625
-	 * Returns the total discount amount.
626
-	 *
627
-	 * @since 1.0.19
628
-	 */
629
-	public function get_total_discount() {
630
-		return $this->total_discount_amount;
631
-	}
632
-
633
-	/**
634
-	 * Gets a specific discount.
635
-	 *
636
-	 * @since 1.0.19
637
-	 */
638
-	public function get_discount( $name ) {
639
-		return isset( $this->discounts[ $name ] ) ? $this->discounts[ $name ] : 0;
640
-	}
641
-
642
-	/**
643
-	 * Returns all discounts.
644
-	 *
645
-	 * @since 1.0.19
646
-	 */
647
-	public function get_discounts() {
648
-		return $this->discounts;
649
-	}
650
-
651
-	///////// FEES //////////////
652
-
653
-	/**
654
-	 * Adds a fee to the submission.
655
-	 *
656
-	 * @since 1.0.19
657
-	 */
658
-	public function add_fee( $name, $amount ) {
659
-		$amount = wpinv_sanitize_amount( $amount );
660
-
661
-		$this->total_fees_amount += $amount;
662
-
663
-		if ( isset( $this->fees[ $name ] ) ) {
664
-			$this->fees[ $name ] += $amount;
665
-		} else {
666
-			$this->fees[ $name ] = $amount;
667
-		}
668
-
669
-	}
670
-
671
-	/**
672
-	 * Returns the total fees amount.
673
-	 *
674
-	 * @since 1.0.19
675
-	 */
676
-	public function get_total_fees() {
677
-		return $this->total_fees_amount;
678
-	}
679
-
680
-	/**
681
-	 * Retrieves a specific fee.
682
-	 *
683
-	 * @since 1.0.19
684
-	 */
685
-	public function get_fee( $name ) {
686
-		return isset( $this->fees[ $name ] ) ? $this->fees[ $name ] : 0;
687
-	}
688
-
689
-	/**
690
-	 * Returns all fees.
691
-	 *
692
-	 * @since 1.0.19
693
-	 */
694
-	public function get_fees() {
695
-		return $this->fees;
696
-	}
697
-
698
-	// MISC //
699
-
700
-	/**
701
-	 * Returns the total amount to collect for this submission.
702
-	 *
703
-	 * @since 1.0.19
704
-	 */
705
-	public function get_total() {
706
-		$total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
707
-		$total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
708
-		return wpinv_sanitize_amount( $total );
709
-	}
710
-
711
-	/**
712
-	 * Whether payment details should be collected for this submission.
713
-	 *
714
-	 * @since 1.0.19
715
-	 */
716
-	public function get_payment_details() {
717
-		$collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
718
-
719
-		if ( $this->has_recurring ) {
720
-			$collect = true;
721
-		}
722
-
723
-		$collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
724
-		return $collect;
725
-	}
726
-
727
-	/**
728
-	 * Returns the billing email of the user.
729
-	 *
730
-	 * @since 1.0.19
731
-	 */
732
-	public function get_billing_email() {
733
-		$billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
734
-		return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
735
-	}
736
-
737
-	/**
738
-	 * Checks if the submitter has a billing email.
739
-	 *
740
-	 * @since 1.0.19
741
-	 */
742
-	public function has_billing_email() {
743
-		$billing_email = $this->get_billing_email();
744
-		return ! empty( $billing_email );
745
-	}
589
+            $this->last_error = sprintf( __( 'The maximum total for using this discount is %s', 'invoicing' ), $max );
590
+        }
591
+
592
+        if ( ! $this->is_discount_valid ) {
593
+            $this->discount = null;
594
+            $this->remove_discount( 'Discount' );
595
+        }
596
+
597
+    }
598
+
599
+    /**
600
+     * Maybe process discount.
601
+     *
602
+     * @since 1.0.19
603
+     * @param GetPaid_Form_Item $item
604
+     */
605
+    public function process_item_discount( $item ) {
606
+
607
+        // Abort early if there is no discount.
608
+        if ( ! $this->has_discount_code() ) {
609
+            return;
610
+        }
611
+
612
+        // Ensure that it is valid for this item.
613
+        if ( ! $this->discount->is_valid_for_items( array( $item->get_id() ) ) ) {
614
+            return;
615
+        }
616
+
617
+        // Fetch the discounted amount.
618
+        $discount = $this->discount->get_discounted_amount( $item->get_price() * $item->get_qantity() );
619
+
620
+        $this->add_discount( 'Discount', $discount );
621
+
622
+    }
623
+
624
+    /**
625
+     * Returns the total discount amount.
626
+     *
627
+     * @since 1.0.19
628
+     */
629
+    public function get_total_discount() {
630
+        return $this->total_discount_amount;
631
+    }
632
+
633
+    /**
634
+     * Gets a specific discount.
635
+     *
636
+     * @since 1.0.19
637
+     */
638
+    public function get_discount( $name ) {
639
+        return isset( $this->discounts[ $name ] ) ? $this->discounts[ $name ] : 0;
640
+    }
641
+
642
+    /**
643
+     * Returns all discounts.
644
+     *
645
+     * @since 1.0.19
646
+     */
647
+    public function get_discounts() {
648
+        return $this->discounts;
649
+    }
650
+
651
+    ///////// FEES //////////////
652
+
653
+    /**
654
+     * Adds a fee to the submission.
655
+     *
656
+     * @since 1.0.19
657
+     */
658
+    public function add_fee( $name, $amount ) {
659
+        $amount = wpinv_sanitize_amount( $amount );
660
+
661
+        $this->total_fees_amount += $amount;
662
+
663
+        if ( isset( $this->fees[ $name ] ) ) {
664
+            $this->fees[ $name ] += $amount;
665
+        } else {
666
+            $this->fees[ $name ] = $amount;
667
+        }
668
+
669
+    }
670
+
671
+    /**
672
+     * Returns the total fees amount.
673
+     *
674
+     * @since 1.0.19
675
+     */
676
+    public function get_total_fees() {
677
+        return $this->total_fees_amount;
678
+    }
679
+
680
+    /**
681
+     * Retrieves a specific fee.
682
+     *
683
+     * @since 1.0.19
684
+     */
685
+    public function get_fee( $name ) {
686
+        return isset( $this->fees[ $name ] ) ? $this->fees[ $name ] : 0;
687
+    }
688
+
689
+    /**
690
+     * Returns all fees.
691
+     *
692
+     * @since 1.0.19
693
+     */
694
+    public function get_fees() {
695
+        return $this->fees;
696
+    }
697
+
698
+    // MISC //
699
+
700
+    /**
701
+     * Returns the total amount to collect for this submission.
702
+     *
703
+     * @since 1.0.19
704
+     */
705
+    public function get_total() {
706
+        $total = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
707
+        $total = apply_filters( 'getpaid_get_submission_total_amount', $total, $this  );
708
+        return wpinv_sanitize_amount( $total );
709
+    }
710
+
711
+    /**
712
+     * Whether payment details should be collected for this submission.
713
+     *
714
+     * @since 1.0.19
715
+     */
716
+    public function get_payment_details() {
717
+        $collect = $this->subtotal_amount + $this->get_total_fees() - $this->get_total_discount() + $this->get_total_tax();
718
+
719
+        if ( $this->has_recurring ) {
720
+            $collect = true;
721
+        }
722
+
723
+        $collect = apply_filters( 'getpaid_submission_collect_payment_details', $collect, $this  );
724
+        return $collect;
725
+    }
726
+
727
+    /**
728
+     * Returns the billing email of the user.
729
+     *
730
+     * @since 1.0.19
731
+     */
732
+    public function get_billing_email() {
733
+        $billing_email = empty( $this->data['billing_email'] ) ? '' : $this->data['billing_email'];
734
+        return apply_filters( 'getpaid_get_submission_billing_email', $billing_email, $this  );
735
+    }
736
+
737
+    /**
738
+     * Checks if the submitter has a billing email.
739
+     *
740
+     * @since 1.0.19
741
+     */
742
+    public function has_billing_email() {
743
+        $billing_email = $this->get_billing_email();
744
+        return ! empty( $billing_email );
745
+    }
746 746
 
747 747
 }
Please login to merge, or discard this patch.
includes/class-wpinv-item.php 1 patch
Indentation   +605 added lines, -605 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,193 +118,193 @@  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' ) {
292
-
293
-		$price = $this->get_price( $context );
294
-
295
-		if ( $this->has_free_trial() ) {
296
-			$price = wpinv_sanitize_amount( 0 );
297
-		}
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
+
293
+        $price = $this->get_price( $context );
294
+
295
+        if ( $this->has_free_trial() ) {
296
+            $price = wpinv_sanitize_amount( 0 );
297
+        }
298 298
         return apply_filters( 'wpinv_get_initial_item_price', $price, $this );
299 299
     }
300 300
 
301 301
     /**
302
-	 * Returns a formated price.
303
-	 *
304
-	 * @since 1.0.19
305
-	 * @param  string $context View or edit context.
306
-	 * @return string
307
-	 */
302
+     * Returns a formated price.
303
+     *
304
+     * @since 1.0.19
305
+     * @param  string $context View or edit context.
306
+     * @return string
307
+     */
308 308
     public function get_the_price() {
309 309
         $item_price = wpinv_price( $this->get_price() );
310 310
 
@@ -312,175 +312,175 @@  discard block
 block discarded – undo
312 312
     }
313 313
 
314 314
     /**
315
-	 * Get the VAT rule of the item.
316
-	 *
317
-	 * @since 1.0.19
318
-	 * @param  string $context View or edit context.
319
-	 * @return string
320
-	 */
321
-	public function get_vat_rule( $context = 'view' ) {
315
+     * Get the VAT rule of the item.
316
+     *
317
+     * @since 1.0.19
318
+     * @param  string $context View or edit context.
319
+     * @return string
320
+     */
321
+    public function get_vat_rule( $context = 'view' ) {
322 322
         return $this->get_prop( 'vat_rule', $context );
323 323
     }
324 324
 
325 325
     /**
326
-	 * Get the VAT class of the item.
327
-	 *
328
-	 * @since 1.0.19
329
-	 * @param  string $context View or edit context.
330
-	 * @return string
331
-	 */
332
-	public function get_vat_class( $context = 'view' ) {
326
+     * Get the VAT class of the item.
327
+     *
328
+     * @since 1.0.19
329
+     * @param  string $context View or edit context.
330
+     * @return string
331
+     */
332
+    public function get_vat_class( $context = 'view' ) {
333 333
         return $this->get_prop( 'vat_class', $context );
334 334
     }
335 335
 
336 336
     /**
337
-	 * Get the type of the item.
338
-	 *
339
-	 * @since 1.0.19
340
-	 * @param  string $context View or edit context.
341
-	 * @return string
342
-	 */
343
-	public function get_type( $context = 'view' ) {
337
+     * Get the type of the item.
338
+     *
339
+     * @since 1.0.19
340
+     * @param  string $context View or edit context.
341
+     * @return string
342
+     */
343
+    public function get_type( $context = 'view' ) {
344 344
         return $this->get_prop( 'type', $context );
345 345
     }
346 346
 
347 347
     /**
348
-	 * Get the custom id of the item.
349
-	 *
350
-	 * @since 1.0.19
351
-	 * @param  string $context View or edit context.
352
-	 * @return string
353
-	 */
354
-	public function get_custom_id( $context = 'view' ) {
348
+     * Get the custom id of the item.
349
+     *
350
+     * @since 1.0.19
351
+     * @param  string $context View or edit context.
352
+     * @return string
353
+     */
354
+    public function get_custom_id( $context = 'view' ) {
355 355
         return $this->get_prop( 'custom_id', $context );
356 356
     }
357 357
 
358 358
     /**
359
-	 * Get the custom name of the item.
360
-	 *
361
-	 * @since 1.0.19
362
-	 * @param  string $context View or edit context.
363
-	 * @return string
364
-	 */
365
-	public function get_custom_name( $context = 'view' ) {
359
+     * Get the custom name of the item.
360
+     *
361
+     * @since 1.0.19
362
+     * @param  string $context View or edit context.
363
+     * @return string
364
+     */
365
+    public function get_custom_name( $context = 'view' ) {
366 366
         return $this->get_prop( 'custom_name', $context );
367 367
     }
368 368
 
369 369
     /**
370
-	 * Get the custom singular name of the item.
371
-	 *
372
-	 * @since 1.0.19
373
-	 * @param  string $context View or edit context.
374
-	 * @return string
375
-	 */
376
-	public function get_custom_singular_name( $context = 'view' ) {
370
+     * Get the custom singular name of the item.
371
+     *
372
+     * @since 1.0.19
373
+     * @param  string $context View or edit context.
374
+     * @return string
375
+     */
376
+    public function get_custom_singular_name( $context = 'view' ) {
377 377
         return $this->get_prop( 'custom_singular_name', $context );
378 378
     }
379 379
 
380 380
     /**
381
-	 * Checks if an item is editable..
382
-	 *
383
-	 * @since 1.0.19
384
-	 * @param  string $context View or edit context.
385
-	 * @return int
386
-	 */
387
-	public function get_is_editable( $context = 'view' ) {
381
+     * Checks if an item is editable..
382
+     *
383
+     * @since 1.0.19
384
+     * @param  string $context View or edit context.
385
+     * @return int
386
+     */
387
+    public function get_is_editable( $context = 'view' ) {
388 388
         return (int) $this->get_prop( 'is_editable', $context );
389 389
     }
390 390
 
391 391
     /**
392
-	 * Alias of self::get_is_editable().
393
-	 *
394
-	 * @since 1.0.19
395
-	 * @param  string $context View or edit context.
396
-	 * @return int
397
-	 */
398
-	public function get_editable( $context = 'view' ) {
399
-		return $this->get_is_editable( $context );
392
+     * Alias of self::get_is_editable().
393
+     *
394
+     * @since 1.0.19
395
+     * @param  string $context View or edit context.
396
+     * @return int
397
+     */
398
+    public function get_editable( $context = 'view' ) {
399
+        return $this->get_is_editable( $context );
400 400
     }
401 401
 
402 402
     /**
403
-	 * Checks if dynamic pricing is enabled.
404
-	 *
405
-	 * @since 1.0.19
406
-	 * @param  string $context View or edit context.
407
-	 * @return int
408
-	 */
409
-	public function get_is_dynamic_pricing( $context = 'view' ) {
403
+     * Checks if dynamic pricing is enabled.
404
+     *
405
+     * @since 1.0.19
406
+     * @param  string $context View or edit context.
407
+     * @return int
408
+     */
409
+    public function get_is_dynamic_pricing( $context = 'view' ) {
410 410
         return (int) $this->get_prop( 'is_dynamic_pricing', $context );
411 411
     }
412 412
 
413 413
     /**
414
-	 * Returns the minimum price if dynamic pricing is enabled.
415
-	 *
416
-	 * @since 1.0.19
417
-	 * @param  string $context View or edit context.
418
-	 * @return float
419
-	 */
420
-	public function get_minimum_price( $context = 'view' ) {
414
+     * Returns the minimum price if dynamic pricing is enabled.
415
+     *
416
+     * @since 1.0.19
417
+     * @param  string $context View or edit context.
418
+     * @return float
419
+     */
420
+    public function get_minimum_price( $context = 'view' ) {
421 421
         return wpinv_sanitize_amount( $this->get_prop( 'minimum_price', $context ) );
422 422
     }
423 423
 
424 424
     /**
425
-	 * Checks if this is a recurring item.
426
-	 *
427
-	 * @since 1.0.19
428
-	 * @param  string $context View or edit context.
429
-	 * @return int
430
-	 */
431
-	public function get_is_recurring( $context = 'view' ) {
425
+     * Checks if this is a recurring item.
426
+     *
427
+     * @since 1.0.19
428
+     * @param  string $context View or edit context.
429
+     * @return int
430
+     */
431
+    public function get_is_recurring( $context = 'view' ) {
432 432
         return (int) $this->get_prop( 'is_recurring', $context );
433
-	}
433
+    }
434 434
 	
435
-	/**
436
-	 * Get the recurring price of the item.
437
-	 *
438
-	 * @since 1.0.19
439
-	 * @param  string $context View or edit context.
440
-	 * @return float
441
-	 */
442
-	public function get_recurring_price( $context = 'view' ) {
443
-		$price = $this->get_price( $context );
435
+    /**
436
+     * Get the recurring price of the item.
437
+     *
438
+     * @since 1.0.19
439
+     * @param  string $context View or edit context.
440
+     * @return float
441
+     */
442
+    public function get_recurring_price( $context = 'view' ) {
443
+        $price = $this->get_price( $context );
444 444
         return wpinv_sanitize_amount( apply_filters( 'wpinv_get_recurring_item_price', $price, $this->ID ) );
445
-	}
446
-
447
-	/**
448
-	 * Get the first renewal date (in timestamps) of the item.
449
-	 *
450
-	 * @since 1.0.19
451
-	 * @return int
452
-	 */
453
-	public function get_first_renewal_date() {
454
-
455
-		$periods = array(
456
-			'D' => 'days',
457
-			'W' => 'weeks',
458
-			'M' => 'months',
459
-			'Y' => 'years',
460
-		);
461
-
462
-		$period   = $this->get_recurring_period();
463
-		$interval = $this->get_recurring_interval();
464
-
465
-		if ( $this->has_free_trial() ) {
466
-			$period   = $this->get_trial_period();
467
-			$interval = $this->get_trial_interval();
468
-		}
469
-
470
-		$period       = $periods[ $period ];
471
-		$interval     = empty( $interval ) ? 1 : $interval;
472
-		$next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
445
+    }
446
+
447
+    /**
448
+     * Get the first renewal date (in timestamps) of the item.
449
+     *
450
+     * @since 1.0.19
451
+     * @return int
452
+     */
453
+    public function get_first_renewal_date() {
454
+
455
+        $periods = array(
456
+            'D' => 'days',
457
+            'W' => 'weeks',
458
+            'M' => 'months',
459
+            'Y' => 'years',
460
+        );
461
+
462
+        $period   = $this->get_recurring_period();
463
+        $interval = $this->get_recurring_interval();
464
+
465
+        if ( $this->has_free_trial() ) {
466
+            $period   = $this->get_trial_period();
467
+            $interval = $this->get_trial_interval();
468
+        }
469
+
470
+        $period       = $periods[ $period ];
471
+        $interval     = empty( $interval ) ? 1 : $interval;
472
+        $next_renewal = strtotime( "+$interval $period", current_time( 'timestamp' ) );
473 473
         return apply_filters( 'wpinv_get_first_renewal_date', $next_renewal, $this );
474 474
     }
475 475
 
476 476
     /**
477
-	 * Get the recurring period.
478
-	 *
479
-	 * @since 1.0.19
480
-	 * @param  bool $full Return abbreviation or in full.
481
-	 * @return string
482
-	 */
483
-	public function get_recurring_period( $full = false ) {
477
+     * Get the recurring period.
478
+     *
479
+     * @since 1.0.19
480
+     * @param  bool $full Return abbreviation or in full.
481
+     * @return string
482
+     */
483
+    public function get_recurring_period( $full = false ) {
484 484
         $period = $this->get_prop( 'recurring_period', 'view' );
485 485
 
486 486
         if ( $full && ! is_bool( $full ) ) {
@@ -491,63 +491,63 @@  discard block
 block discarded – undo
491 491
     }
492 492
 
493 493
     /**
494
-	 * Get the recurring interval.
495
-	 *
496
-	 * @since 1.0.19
497
-	 * @param  string $context View or edit context.
498
-	 * @return int
499
-	 */
500
-	public function get_recurring_interval( $context = 'view' ) {
501
-		$interval = absint( $this->get_prop( 'recurring_interval', $context ) );
494
+     * Get the recurring interval.
495
+     *
496
+     * @since 1.0.19
497
+     * @param  string $context View or edit context.
498
+     * @return int
499
+     */
500
+    public function get_recurring_interval( $context = 'view' ) {
501
+        $interval = absint( $this->get_prop( 'recurring_interval', $context ) );
502 502
 
503
-		if ( $interval < 1 ) {
504
-			$interval = 1;
505
-		}
503
+        if ( $interval < 1 ) {
504
+            $interval = 1;
505
+        }
506 506
 
507 507
         return $interval;
508 508
     }
509 509
 
510 510
     /**
511
-	 * Get the recurring limit.
512
-	 *
513
-	 * @since 1.0.19
514
-	 * @param  string $context View or edit context.
515
-	 * @return int
516
-	 */
517
-	public function get_recurring_limit( $context = 'view' ) {
511
+     * Get the recurring limit.
512
+     *
513
+     * @since 1.0.19
514
+     * @param  string $context View or edit context.
515
+     * @return int
516
+     */
517
+    public function get_recurring_limit( $context = 'view' ) {
518 518
         return (int) $this->get_prop( 'recurring_limit', $context );
519 519
     }
520 520
 
521 521
     /**
522
-	 * Checks if we have a free trial.
523
-	 *
524
-	 * @since 1.0.19
525
-	 * @param  string $context View or edit context.
526
-	 * @return int
527
-	 */
528
-	public function get_is_free_trial( $context = 'view' ) {
522
+     * Checks if we have a free trial.
523
+     *
524
+     * @since 1.0.19
525
+     * @param  string $context View or edit context.
526
+     * @return int
527
+     */
528
+    public function get_is_free_trial( $context = 'view' ) {
529 529
         return (int) $this->get_prop( 'is_free_trial', $context );
530 530
     }
531 531
 
532 532
     /**
533
-	 * Alias for self::get_is_free_trial().
534
-	 *
535
-	 * @since 1.0.19
536
-	 * @param  string $context View or edit context.
537
-	 * @return int
538
-	 */
539
-	public function get_free_trial( $context = 'view' ) {
533
+     * Alias for self::get_is_free_trial().
534
+     *
535
+     * @since 1.0.19
536
+     * @param  string $context View or edit context.
537
+     * @return int
538
+     */
539
+    public function get_free_trial( $context = 'view' ) {
540 540
         return $this->get_is_free_trial( $context );
541 541
     }
542 542
 
543 543
     /**
544
-	 * Get the trial period.
545
-	 *
546
-	 * @since 1.0.19
547
-	 * @param  bool $full Return abbreviation or in full.
548
-	 * @return string
549
-	 */
550
-	public function get_trial_period( $full = false ) {
544
+     * Get the trial period.
545
+     *
546
+     * @since 1.0.19
547
+     * @param  bool $full Return abbreviation or in full.
548
+     * @return string
549
+     */
550
+    public function get_trial_period( $full = false ) {
551 551
         $period = $this->get_prop( 'trial_period', 'view' );
552 552
 
553 553
         if ( $full && ! is_bool( $full ) ) {
@@ -558,13 +558,13 @@  discard block
 block discarded – undo
558 558
     }
559 559
 
560 560
     /**
561
-	 * Get the trial interval.
562
-	 *
563
-	 * @since 1.0.19
564
-	 * @param  string $context View or edit context.
565
-	 * @return int
566
-	 */
567
-	public function get_trial_interval( $context = 'view' ) {
561
+     * Get the trial interval.
562
+     *
563
+     * @since 1.0.19
564
+     * @param  string $context View or edit context.
565
+     * @return int
566
+     */
567
+    public function get_trial_interval( $context = 'view' ) {
568 568
         return (int) $this->get_prop( 'trial_interval', $context );
569 569
     }
570 570
 
@@ -598,52 +598,52 @@  discard block
 block discarded – undo
598 598
     */
599 599
 
600 600
     /**
601
-	 * Set parent order ID.
602
-	 *
603
-	 * @since 1.0.19
604
-	 */
605
-	public function set_parent_id( $value ) {
606
-		if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
607
-			return;
608
-		}
609
-		$this->set_prop( 'parent_id', absint( $value ) );
610
-	}
611
-
612
-    /**
613
-	 * Sets item status.
614
-	 *
615
-	 * @since 1.0.19
616
-	 * @param  string $status New status.
617
-	 * @return array details of change.
618
-	 */
619
-	public function set_status( $status ) {
601
+     * Set parent order ID.
602
+     *
603
+     * @since 1.0.19
604
+     */
605
+    public function set_parent_id( $value ) {
606
+        if ( $value && ( $value === $this->get_id() || ! get_post( $value ) ) ) {
607
+            return;
608
+        }
609
+        $this->set_prop( 'parent_id', absint( $value ) );
610
+    }
611
+
612
+    /**
613
+     * Sets item status.
614
+     *
615
+     * @since 1.0.19
616
+     * @param  string $status New status.
617
+     * @return array details of change.
618
+     */
619
+    public function set_status( $status ) {
620 620
         $old_status = $this->get_status();
621 621
 
622 622
         $this->set_prop( 'status', $status );
623 623
 
624
-		return array(
625
-			'from' => $old_status,
626
-			'to'   => $status,
627
-		);
624
+        return array(
625
+            'from' => $old_status,
626
+            'to'   => $status,
627
+        );
628 628
     }
629 629
 
630 630
     /**
631
-	 * Set plugin version when the item was created.
632
-	 *
633
-	 * @since 1.0.19
634
-	 */
635
-	public function set_version( $value ) {
636
-		$this->set_prop( 'version', $value );
631
+     * Set plugin version when the item was created.
632
+     *
633
+     * @since 1.0.19
634
+     */
635
+    public function set_version( $value ) {
636
+        $this->set_prop( 'version', $value );
637 637
     }
638 638
 
639 639
     /**
640
-	 * Set date when the item was created.
641
-	 *
642
-	 * @since 1.0.19
643
-	 * @param string $value Value to set.
640
+     * Set date when the item was created.
641
+     *
642
+     * @since 1.0.19
643
+     * @param string $value Value to set.
644 644
      * @return bool Whether or not the date was set.
645
-	 */
646
-	public function set_date_created( $value ) {
645
+     */
646
+    public function set_date_created( $value ) {
647 647
         $date = strtotime( $value );
648 648
 
649 649
         if ( $date ) {
@@ -656,13 +656,13 @@  discard block
 block discarded – undo
656 656
     }
657 657
 
658 658
     /**
659
-	 * Set date when the item was last modified.
660
-	 *
661
-	 * @since 1.0.19
662
-	 * @param string $value Value to set.
659
+     * Set date when the item was last modified.
660
+     *
661
+     * @since 1.0.19
662
+     * @param string $value Value to set.
663 663
      * @return bool Whether or not the date was set.
664
-	 */
665
-	public function set_date_modified( $value ) {
664
+     */
665
+    public function set_date_modified( $value ) {
666 666
         $date = strtotime( $value );
667 667
 
668 668
         if ( $date ) {
@@ -675,105 +675,105 @@  discard block
 block discarded – undo
675 675
     }
676 676
 
677 677
     /**
678
-	 * Set the item name.
679
-	 *
680
-	 * @since 1.0.19
681
-	 * @param  string $value New name.
682
-	 */
683
-	public function set_name( $value ) {
678
+     * Set the item name.
679
+     *
680
+     * @since 1.0.19
681
+     * @param  string $value New name.
682
+     */
683
+    public function set_name( $value ) {
684 684
         $name = sanitize_text_field( $value );
685
-		$this->set_prop( 'name', $name );
685
+        $this->set_prop( 'name', $name );
686 686
     }
687 687
 
688 688
     /**
689
-	 * Alias of self::set_name().
690
-	 *
691
-	 * @since 1.0.19
692
-	 * @param  string $value New name.
693
-	 */
694
-	public function set_title( $value ) {
695
-		$this->set_name( $value );
689
+     * Alias of self::set_name().
690
+     *
691
+     * @since 1.0.19
692
+     * @param  string $value New name.
693
+     */
694
+    public function set_title( $value ) {
695
+        $this->set_name( $value );
696 696
     }
697 697
 
698 698
     /**
699
-	 * Set the item description.
700
-	 *
701
-	 * @since 1.0.19
702
-	 * @param  string $value New description.
703
-	 */
704
-	public function set_description( $value ) {
699
+     * Set the item description.
700
+     *
701
+     * @since 1.0.19
702
+     * @param  string $value New description.
703
+     */
704
+    public function set_description( $value ) {
705 705
         $description = wp_kses_post( $value );
706
-		return $this->set_prop( 'description', $description );
706
+        return $this->set_prop( 'description', $description );
707 707
     }
708 708
 
709 709
     /**
710
-	 * Alias of self::set_description().
711
-	 *
712
-	 * @since 1.0.19
713
-	 * @param  string $value New description.
714
-	 */
715
-	public function set_excerpt( $value ) {
716
-		$this->set_description( $value );
710
+     * Alias of self::set_description().
711
+     *
712
+     * @since 1.0.19
713
+     * @param  string $value New description.
714
+     */
715
+    public function set_excerpt( $value ) {
716
+        $this->set_description( $value );
717 717
     }
718 718
 
719 719
     /**
720
-	 * Alias of self::set_description().
721
-	 *
722
-	 * @since 1.0.19
723
-	 * @param  string $value New description.
724
-	 */
725
-	public function set_summary( $value ) {
726
-		$this->set_description( $value );
720
+     * Alias of self::set_description().
721
+     *
722
+     * @since 1.0.19
723
+     * @param  string $value New description.
724
+     */
725
+    public function set_summary( $value ) {
726
+        $this->set_description( $value );
727 727
     }
728 728
 
729 729
     /**
730
-	 * Set the owner of the item.
731
-	 *
732
-	 * @since 1.0.19
733
-	 * @param  int $value New author.
734
-	 */
735
-	public function set_author( $value ) {
736
-		$this->set_prop( 'author', (int) $value );
730
+     * Set the owner of the item.
731
+     *
732
+     * @since 1.0.19
733
+     * @param  int $value New author.
734
+     */
735
+    public function set_author( $value ) {
736
+        $this->set_prop( 'author', (int) $value );
737 737
     }
738 738
 
739 739
     /**
740
-	 * Set the price of the item.
741
-	 *
742
-	 * @since 1.0.19
743
-	 * @param  float $value New price.
740
+     * Set the price of the item.
741
+     *
742
+     * @since 1.0.19
743
+     * @param  float $value New price.
744 744
 ]	 */
745
-	public function set_price( $value ) {
745
+    public function set_price( $value ) {
746 746
         $this->set_prop( 'price', (float) wpinv_sanitize_amount( $value ) );
747 747
     }
748 748
 
749 749
     /**
750
-	 * Set the VAT rule of the item.
751
-	 *
752
-	 * @since 1.0.19
753
-	 * @param  string $value new rule.
754
-	 */
755
-	public function set_vat_rule( $value ) {
750
+     * Set the VAT rule of the item.
751
+     *
752
+     * @since 1.0.19
753
+     * @param  string $value new rule.
754
+     */
755
+    public function set_vat_rule( $value ) {
756 756
         $this->set_prop( 'vat_rule', $value );
757 757
     }
758 758
 
759 759
     /**
760
-	 * Set the VAT class of the item.
761
-	 *
762
-	 * @since 1.0.19
763
-	 * @param  string $value new class.
764
-	 */
765
-	public function set_vat_class( $value ) {
760
+     * Set the VAT class of the item.
761
+     *
762
+     * @since 1.0.19
763
+     * @param  string $value new class.
764
+     */
765
+    public function set_vat_class( $value ) {
766 766
         $this->set_prop( 'vat_class', $value );
767 767
     }
768 768
 
769 769
     /**
770
-	 * Set the type of the item.
771
-	 *
772
-	 * @since 1.0.19
773
-	 * @param  string $value new item type.
774
-	 * @return string
775
-	 */
776
-	public function set_type( $value ) {
770
+     * Set the type of the item.
771
+     *
772
+     * @since 1.0.19
773
+     * @param  string $value new item type.
774
+     * @return string
775
+     */
776
+    public function set_type( $value ) {
777 777
 
778 778
         if ( empty( $value ) ) {
779 779
             $value = 'custom';
@@ -783,134 +783,134 @@  discard block
 block discarded – undo
783 783
     }
784 784
 
785 785
     /**
786
-	 * Set the custom id of the item.
787
-	 *
788
-	 * @since 1.0.19
789
-	 * @param  string $value new custom id.
790
-	 */
791
-	public function set_custom_id( $value ) {
786
+     * Set the custom id of the item.
787
+     *
788
+     * @since 1.0.19
789
+     * @param  string $value new custom id.
790
+     */
791
+    public function set_custom_id( $value ) {
792 792
         $this->set_prop( 'custom_id', $value );
793 793
     }
794 794
 
795 795
     /**
796
-	 * Set the custom name of the item.
797
-	 *
798
-	 * @since 1.0.19
799
-	 * @param  string $value new custom name.
800
-	 */
801
-	public function set_custom_name( $value ) {
796
+     * Set the custom name of the item.
797
+     *
798
+     * @since 1.0.19
799
+     * @param  string $value new custom name.
800
+     */
801
+    public function set_custom_name( $value ) {
802 802
         $this->set_prop( 'custom_name', $value );
803 803
     }
804 804
 
805 805
     /**
806
-	 * Set the custom singular name of the item.
807
-	 *
808
-	 * @since 1.0.19
809
-	 * @param  string $value new custom singular name.
810
-	 */
811
-	public function set_custom_singular_name( $value ) {
806
+     * Set the custom singular name of the item.
807
+     *
808
+     * @since 1.0.19
809
+     * @param  string $value new custom singular name.
810
+     */
811
+    public function set_custom_singular_name( $value ) {
812 812
         $this->set_prop( 'custom_singular_name', $value );
813 813
     }
814 814
 
815 815
     /**
816
-	 * Sets if an item is editable..
817
-	 *
818
-	 * @since 1.0.19
819
-	 * @param  int|bool $value whether or not the item is editable.
820
-	 */
821
-	public function set_is_editable( $value ) {
822
-		if ( is_numeric( $value ) ) {
823
-			$this->set_prop( 'is_editable', (int) $value );
824
-		}
816
+     * Sets if an item is editable..
817
+     *
818
+     * @since 1.0.19
819
+     * @param  int|bool $value whether or not the item is editable.
820
+     */
821
+    public function set_is_editable( $value ) {
822
+        if ( is_numeric( $value ) ) {
823
+            $this->set_prop( 'is_editable', (int) $value );
824
+        }
825 825
     }
826 826
 
827 827
     /**
828
-	 * Sets if dynamic pricing is enabled.
829
-	 *
830
-	 * @since 1.0.19
831
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
832
-	 */
833
-	public function set_is_dynamic_pricing( $value ) {
828
+     * Sets if dynamic pricing is enabled.
829
+     *
830
+     * @since 1.0.19
831
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
832
+     */
833
+    public function set_is_dynamic_pricing( $value ) {
834 834
         $this->set_prop( 'is_dynamic_pricing', (int) $value );
835 835
     }
836 836
 
837 837
     /**
838
-	 * Sets the minimum price if dynamic pricing is enabled.
839
-	 *
840
-	 * @since 1.0.19
841
-	 * @param  float $value minimum price.
842
-	 */
843
-	public function set_minimum_price( $value ) {
838
+     * Sets the minimum price if dynamic pricing is enabled.
839
+     *
840
+     * @since 1.0.19
841
+     * @param  float $value minimum price.
842
+     */
843
+    public function set_minimum_price( $value ) {
844 844
         $this->set_prop( 'minimum_price',  (float) wpinv_sanitize_amount( $value ) );
845 845
     }
846 846
 
847 847
     /**
848
-	 * Sets if this is a recurring item.
849
-	 *
850
-	 * @since 1.0.19
851
-	 * @param  int|bool $value whether or not dynamic pricing is allowed.
852
-	 */
853
-	public function set_is_recurring( $value ) {
848
+     * Sets if this is a recurring item.
849
+     *
850
+     * @since 1.0.19
851
+     * @param  int|bool $value whether or not dynamic pricing is allowed.
852
+     */
853
+    public function set_is_recurring( $value ) {
854 854
         $this->set_prop( 'is_recurring', (int) $value );
855 855
     }
856 856
 
857 857
     /**
858
-	 * Set the recurring period.
859
-	 *
860
-	 * @since 1.0.19
861
-	 * @param  string $value new period.
862
-	 */
863
-	public function set_recurring_period( $value ) {
858
+     * Set the recurring period.
859
+     *
860
+     * @since 1.0.19
861
+     * @param  string $value new period.
862
+     */
863
+    public function set_recurring_period( $value ) {
864 864
         $this->set_prop( 'recurring_period', $value );
865 865
     }
866 866
 
867 867
     /**
868
-	 * Set the recurring interval.
869
-	 *
870
-	 * @since 1.0.19
871
-	 * @param  int $value recurring interval.
872
-	 */
873
-	public function set_recurring_interval( $value ) {
868
+     * Set the recurring interval.
869
+     *
870
+     * @since 1.0.19
871
+     * @param  int $value recurring interval.
872
+     */
873
+    public function set_recurring_interval( $value ) {
874 874
         return $this->set_prop( 'recurring_interval', (int) $value );
875 875
     }
876 876
 
877 877
     /**
878
-	 * Get the recurring limit.
879
-	 * @since 1.0.19
880
-	 * @param  int $value The recurring limit.
881
-	 * @return int
882
-	 */
883
-	public function set_recurring_limit( $value ) {
878
+     * Get the recurring limit.
879
+     * @since 1.0.19
880
+     * @param  int $value The recurring limit.
881
+     * @return int
882
+     */
883
+    public function set_recurring_limit( $value ) {
884 884
         $this->set_prop( 'recurring_limit', (int) $value );
885 885
     }
886 886
 
887 887
     /**
888
-	 * Checks if we have a free trial.
889
-	 *
890
-	 * @since 1.0.19
891
-	 * @param  int|bool $value whether or not it has a free trial.
892
-	 */
893
-	public function set_is_free_trial( $value ) {
888
+     * Checks if we have a free trial.
889
+     *
890
+     * @since 1.0.19
891
+     * @param  int|bool $value whether or not it has a free trial.
892
+     */
893
+    public function set_is_free_trial( $value ) {
894 894
         $this->set_prop( 'is_free_trial', (int) $value );
895 895
     }
896 896
 
897 897
     /**
898
-	 * Set the trial period.
899
-	 *
900
-	 * @since 1.0.19
901
-	 * @param  string $value trial period.
902
-	 */
903
-	public function set_trial_period( $value ) {
898
+     * Set the trial period.
899
+     *
900
+     * @since 1.0.19
901
+     * @param  string $value trial period.
902
+     */
903
+    public function set_trial_period( $value ) {
904 904
         $this->set_prop( 'trial_period', $value );
905 905
     }
906 906
 
907 907
     /**
908
-	 * Set the trial interval.
909
-	 *
910
-	 * @since 1.0.19
911
-	 * @param  int $value trial interval.
912
-	 */
913
-	public function set_trial_interval( $value ) {
908
+     * Set the trial interval.
909
+     *
910
+     * @since 1.0.19
911
+     * @param  int $value trial interval.
912
+     */
913
+    public function set_trial_interval( $value ) {
914 914
         $this->set_prop( 'trial_interval', $value );
915 915
     }
916 916
 
@@ -918,17 +918,17 @@  discard block
 block discarded – undo
918 918
      * Create an item. For backwards compatibilty.
919 919
      * 
920 920
      * @deprecated
921
-	 * @return int item id
921
+     * @return int item id
922 922
      */
923 923
     public function create( $data = array() ) {
924 924
 
925
-		// Set the properties.
926
-		if ( is_array( $data ) ) {
927
-			$this->set_props( $data );
928
-		}
925
+        // Set the properties.
926
+        if ( is_array( $data ) ) {
927
+            $this->set_props( $data );
928
+        }
929 929
 
930
-		// Save the item.
931
-		return $this->save();
930
+        // Save the item.
931
+        return $this->save();
932 932
 
933 933
     }
934 934
 
@@ -936,7 +936,7 @@  discard block
 block discarded – undo
936 936
      * Updates an item. For backwards compatibilty.
937 937
      * 
938 938
      * @deprecated
939
-	 * @return int item id
939
+     * @return int item id
940 940
      */
941 941
     public function update( $data = array() ) {
942 942
         return $this->create( $data );
@@ -952,84 +952,84 @@  discard block
 block discarded – undo
952 952
 	*/
953 953
 
954 954
     /**
955
-	 * Checks whether the item has enabled dynamic pricing.
956
-	 *
957
-	 * @since 1.0.19
958
-	 * @return bool
959
-	 */
960
-	public function user_can_set_their_price() {
955
+     * Checks whether the item has enabled dynamic pricing.
956
+     *
957
+     * @since 1.0.19
958
+     * @return bool
959
+     */
960
+    public function user_can_set_their_price() {
961 961
         return (bool) $this->get_is_dynamic_pricing();
962
-	}
962
+    }
963 963
 	
964
-	/**
965
-	 * Checks whether the item is recurring.
966
-	 *
967
-	 * @since 1.0.19
968
-	 * @return bool
969
-	 */
970
-	public function is_recurring() {
964
+    /**
965
+     * Checks whether the item is recurring.
966
+     *
967
+     * @since 1.0.19
968
+     * @return bool
969
+     */
970
+    public function is_recurring() {
971 971
         return (bool) $this->get_is_recurring();
972 972
     }
973 973
 
974 974
     /**
975
-	 * Checks whether the item has a free trial.
976
-	 *
977
-	 * @since 1.0.19
978
-	 * @return bool
979
-	 */
975
+     * Checks whether the item has a free trial.
976
+     *
977
+     * @since 1.0.19
978
+     * @return bool
979
+     */
980 980
     public function has_free_trial() {
981 981
         $has_trial = $this->is_recurring() && (bool) $this->get_free_trial() ? true : false;
982 982
         return (bool) apply_filters( 'wpinv_item_has_free_trial', $has_trial, $this->ID, $this );
983 983
     }
984 984
 
985 985
     /**
986
-	 * Checks whether the item is free.
987
-	 *
988
-	 * @since 1.0.19
989
-	 * @return bool
990
-	 */
986
+     * Checks whether the item is free.
987
+     *
988
+     * @since 1.0.19
989
+     * @return bool
990
+     */
991 991
     public function is_free() {
992 992
         $is_free   = $this->get_price() == 0;
993 993
         return (bool) apply_filters( 'wpinv_is_free_item', $is_free, $this->ID, $this );
994 994
     }
995 995
 
996 996
     /**
997
-	 * Checks the item status against a passed in status.
998
-	 *
999
-	 * @param array|string $status Status to check.
1000
-	 * @return bool
1001
-	 */
1002
-	public function has_status( $status ) {
1003
-		$has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1004
-		return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
997
+     * Checks the item status against a passed in status.
998
+     *
999
+     * @param array|string $status Status to check.
1000
+     * @return bool
1001
+     */
1002
+    public function has_status( $status ) {
1003
+        $has_status = ( is_array( $status ) && in_array( $this->get_status(), $status, true ) ) || $this->get_status() === $status;
1004
+        return (bool) apply_filters( 'getpaid_item_has_status', $has_status, $this, $status );
1005 1005
     }
1006 1006
 
1007 1007
     /**
1008
-	 * Checks the item type against a passed in types.
1009
-	 *
1010
-	 * @param array|string $type Type to check.
1011
-	 * @return bool
1012
-	 */
1013
-	public function is_type( $type ) {
1014
-		$is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1015
-		return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1016
-	}
1008
+     * Checks the item type against a passed in types.
1009
+     *
1010
+     * @param array|string $type Type to check.
1011
+     * @return bool
1012
+     */
1013
+    public function is_type( $type ) {
1014
+        $is_type = ( is_array( $type ) && in_array( $this->get_type(), $type, true ) ) || $this->get_type() === $type;
1015
+        return (bool) apply_filters( 'getpaid_item_is_type', $is_type, $this, $type );
1016
+    }
1017 1017
 
1018 1018
     /**
1019
-	 * Checks whether the item is editable.
1020
-	 *
1021
-	 * @since 1.0.19
1022
-	 * @return bool
1023
-	 */
1019
+     * Checks whether the item is editable.
1020
+     *
1021
+     * @since 1.0.19
1022
+     * @return bool
1023
+     */
1024 1024
     public function is_editable() {
1025 1025
         $is_editable = $this->get_is_editable();
1026 1026
         return (bool) apply_filters( 'wpinv_item_is_editable', $is_editable, $this->ID, $this );
1027
-	}
1027
+    }
1028 1028
 
1029
-	/**
1030
-	 * Returns an array of cart fees.
1031
-	 */
1032
-	public function get_fees( $type = 'fee', $item_id = 0 ) {
1029
+    /**
1030
+     * Returns an array of cart fees.
1031
+     */
1032
+    public function get_fees( $type = 'fee', $item_id = 0 ) {
1033 1033
         global $wpi_session;
1034 1034
         
1035 1035
         $fees = $wpi_session->get( 'wpi_cart_fees' );
@@ -1073,11 +1073,11 @@  discard block
 block discarded – undo
1073 1073
     }
1074 1074
 
1075 1075
     /**
1076
-	 * Checks whether the item is purchasable.
1077
-	 *
1078
-	 * @since 1.0.19
1079
-	 * @return bool
1080
-	 */
1076
+     * Checks whether the item is purchasable.
1077
+     *
1078
+     * @since 1.0.19
1079
+     * @return bool
1080
+     */
1081 1081
     public function can_purchase() {
1082 1082
         $can_purchase = null !== $this->get_id();
1083 1083
 
@@ -1089,11 +1089,11 @@  discard block
 block discarded – undo
1089 1089
     }
1090 1090
 
1091 1091
     /**
1092
-	 * Checks whether the item supports dynamic pricing.
1093
-	 *
1094
-	 * @since 1.0.19
1095
-	 * @return bool
1096
-	 */
1092
+     * Checks whether the item supports dynamic pricing.
1093
+     *
1094
+     * @since 1.0.19
1095
+     * @return bool
1096
+     */
1097 1097
     public function supports_dynamic_pricing() {
1098 1098
         return (bool) apply_filters( 'wpinv_item_supports_dynamic_pricing', true, $this );
1099 1099
     }
Please login to merge, or discard this patch.